2 * Copyright (c) 2020, 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);
71 void otSysInit(int argc, char *argv[])
73 OT_UNUSED_VARIABLE(argc);
74 OT_UNUSED_VARIABLE(argv);
79 #undef FIXED_EXCEPTION
80 #define FIXED_EXCEPTION(vectorNumber, functionName, deviceIrqn, deviceIrqHandler)
81 #define EXCEPTION(vectorNumber, functionName, deviceIrqn, deviceIrqHandler, priorityLevel, subpriority) \
82 NVIC_SetPriority(deviceIrqn, NVIC_EncodePriority(PRIGROUP_POSITION, priorityLevel, subpriority));
86 NVIC_SetPriorityGrouping(PRIGROUP_POSITION);
88 halInitChipSpecific();
89 BSP_Init(BSP_INIT_BCC);
91 CMU_ClockSelectSet(cmuClock_LFE, cmuSelect_LFRCO);
92 CMU_ClockEnable(cmuClock_CORELE, true);
93 CMU_ClockEnable(cmuClock_RTCC, true);
94 status = sl_sleeptimer_init();
95 assert(status == SL_STATUS_OK);
113 bool otSysPseudoResetWasRequested(void)
118 void otSysDeinit(void)
127 void efr32SetSleepCallback(bool (*aCallback)(void))
129 sCanSleepCallback = aCallback;
132 void efr32Sleep(void)
134 bool canDeepSleep = false;
135 int wakeupProcessTime = 1000;
136 CORE_DECLARE_IRQ_STATE;
138 if (RAIL_Sleep(wakeupProcessTime, &canDeepSleep) == RAIL_STATUS_NO_ERROR)
143 if (sCanSleepCallback != NULL && sCanSleepCallback())
148 // TODO OT will handle an interrupt here and it mustn't call any RAIL APIs
150 while (RAIL_Wake(0) != RAIL_STATUS_NO_ERROR)
157 if (sCanSleepCallback != NULL && sCanSleepCallback())
166 void otSysProcessDrivers(otInstance *aInstance)
168 sInstance = aInstance;
170 // should sleep and wait for interrupts here
173 efr32RadioProcess(aInstance);
174 efr32AlarmProcess(aInstance);
177 __WEAK void otSysEventSignalPending(void)
179 // Intentionally empty