2 * Copyright (c) 2019, The OpenThread Authors.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
32 * This file includes the platform-specific initializers.
35 #include <openthread-core-config.h>
36 #include <openthread/config.h>
41 #include "openthread-system.h"
42 #include <openthread/platform/uart.h>
44 #include "common/logging.hpp"
51 #include "em_system.h"
52 #include "hal-config.h"
53 #include "hal_common.h"
56 #include "sl_sleeptimer.h"
58 #include "platform-efr32.h"
61 #include "fem-control.h"
64 #define USE_EFR32_LOG (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
66 void halInitChipSpecific(void);
68 otInstance *sInstance;
69 static bool (*sCanSleepCallback)(void);
70 static void (*sDeviceOutOfSleepCb)(void);
72 void otSysInit(int argc, char *argv[])
74 OT_UNUSED_VARIABLE(argc);
75 OT_UNUSED_VARIABLE(argv);
80 #undef FIXED_EXCEPTION
81 #define FIXED_EXCEPTION(vectorNumber, functionName, deviceIrqn, deviceIrqHandler)
82 #define EXCEPTION(vectorNumber, functionName, deviceIrqn, deviceIrqHandler, priorityLevel, subpriority) \
83 NVIC_SetPriority(deviceIrqn, NVIC_EncodePriority(PRIGROUP_POSITION - 1, priorityLevel, subpriority));
87 NVIC_SetPriorityGrouping(PRIGROUP_POSITION - 1);
89 halInitChipSpecific();
90 BSP_Init(BSP_INIT_BCC);
92 CMU_OscillatorEnable(cmuOsc_LFRCO, true, true);
93 CMU_ClockEnable(cmuClock_RTCC, true);
95 status = sl_sleeptimer_init();
96 assert(status == SL_STATUS_OK);
113 bool otSysPseudoResetWasRequested(void)
118 void otSysDeinit(void)
127 void efr32SetSleepCallback(bool (*aCallback)(void), void (*aCallbackWake)(void))
129 sCanSleepCallback = aCallback;
130 sDeviceOutOfSleepCb = aCallbackWake;
133 void efr32Sleep(void)
135 bool canDeepSleep = false;
136 int wakeupProcessTime = 1000;
137 CORE_DECLARE_IRQ_STATE;
139 if (RAIL_Sleep(wakeupProcessTime, &canDeepSleep) == RAIL_STATUS_NO_ERROR)
144 if (sCanSleepCallback != NULL && sCanSleepCallback())
149 // TODO OT will handle an interrupt here and it mustn't call any RAIL APIs
151 while (RAIL_Wake(0) != RAIL_STATUS_NO_ERROR)
155 if (sDeviceOutOfSleepCb != NULL)
157 sDeviceOutOfSleepCb();
163 if (sCanSleepCallback != NULL && sCanSleepCallback())
172 void otSysProcessDrivers(otInstance *aInstance)
174 sInstance = aInstance;
176 // should sleep and wait for interrupts here
179 efr32RadioProcess(aInstance);
180 efr32AlarmProcess(aInstance);
183 __WEAK void otSysEventSignalPending(void)
185 // Intentionally empty