1- /*
2- * Copyright (c) 2023 STMicroelectronics
3- *
4- * SPDX-License-Identifier: Apache-2.0
5- */
6-
7-
8-
1+ /* USER CODE BEGIN Header */
2+ /**
3+ ******************************************************************************
4+ * @file linklayer_plat.c
5+ * @author MCD Application Team
6+ * @brief Source file for the linklayer plateform adaptation layer
7+ ******************************************************************************
8+ * @attention
9+ *
10+ * Copyright (c) 2022 STMicroelectronics.
11+ * All rights reserved.
12+ *
13+ * This software is licensed under terms that can be found in the LICENSE file
14+ * in the root directory of this software component.
15+ * If no LICENSE file comes with this software, it is provided AS-IS.
16+ *
17+ ******************************************************************************
18+ */
919/* USER CODE END Header */
1020
1121#ifndef __ZEPHYR__
2737#endif /* (CFG_LPM_LEVEL != 0) */
2838/* USER CODE BEGIN Includes */
2939
40+ /* USER CODE END Includes */
41+
3042#else
3143#include "scm.h"
3244#endif
@@ -104,6 +116,44 @@ void LINKLAYER_PLAT_WaitHclkRdy(void)
104116 while (HAL_RCCEx_GetRadioBusClockReadiness () != RCC_RADIO_BUS_CLOCK_READY );
105117}
106118
119+ /**
120+ * @brief Notify the Link Layer platform layer the system will enter in WFI
121+ * and AHB5 clock may be turned of regarding the 2.4Ghz radio state.
122+ * @param None
123+ * @retval None
124+ */
125+ void LINKLAYER_PLAT_NotifyWFIEnter (void )
126+ {
127+ /* Check if Radio state will allow the AHB5 clock to be cut */
128+
129+ /* AHB5 clock will be cut in the following cases:
130+ * - 2.4GHz radio is not in ACTIVE mode (in SLEEP or DEEPSLEEP mode).
131+ * - RADIOSMEN and STRADIOCLKON bits are at 0.
132+ */
133+ if ((LL_PWR_GetRadioMode () != LL_PWR_RADIO_ACTIVE_MODE ) ||
134+ ((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED () == 0 ) && (LL_RCC_RADIO_IsEnabledSleepTimerClock () == 0 )))
135+ {
136+ AHB5_SwitchedOff = 1 ;
137+ }
138+ }
139+
140+ /**
141+ * @brief Notify the Link Layer platform layer the system exited WFI and AHB5
142+ * clock may be resynchronized as is may have been turned of during
143+ * low power mode entry.
144+ * @param None
145+ * @retval None
146+ */
147+ void LINKLAYER_PLAT_NotifyWFIExit (void )
148+ {
149+ /* Check if AHB5 clock has been turned of and needs resynchronisation */
150+ if (AHB5_SwitchedOff )
151+ {
152+ /* Read sleep register as earlier as possible */
153+ radio_sleep_timer_val = ll_intf_cmn_get_slptmr_value ();
154+ }
155+ }
156+
107157/**
108158 * @brief Active wait on bus clock readiness.
109159 * @param None
@@ -273,9 +323,9 @@ void LINKLAYER_PLAT_EnableSpecificIRQ(uint8_t isr_type)
273323 {
274324 /* When specific counter for link layer high ISR reaches 0, interrupt is enabled */
275325 HAL_NVIC_EnableIRQ (RADIO_INTR_NUM );
276- /* USER CODE BEGIN LINKLAYER_PLAT_EnableSpecificIRQ_1*/
326+ /* USER CODE BEGIN LINKLAYER_PLAT_EnableSpecificIRQ_1 */
277327
278- /* USER CODE END LINKLAYER_PLAT_EnableSpecificIRQ_1*/
328+ /* USER CODE END LINKLAYER_PLAT_EnableSpecificIRQ_1 */
279329 }
280330 }
281331
@@ -318,9 +368,9 @@ void LINKLAYER_PLAT_DisableSpecificIRQ(uint8_t isr_type)
318368 prio_high_isr_counter ++ ;
319369 if (prio_high_isr_counter == 1 )
320370 {
321- /* USER CODE BEGIN LINKLAYER_PLAT_DisableSpecificIRQ_1*/
371+ /* USER CODE BEGIN LINKLAYER_PLAT_DisableSpecificIRQ_1 */
322372
323- /* USER CODE END LINKLAYER_PLAT_DisableSpecificIRQ_1*/
373+ /* USER CODE END LINKLAYER_PLAT_DisableSpecificIRQ_1 */
324374 /* When specific counter for link layer high ISR value is 1, interrupt is disabled */
325375 HAL_NVIC_DisableIRQ (RADIO_INTR_NUM );
326376 }
@@ -358,15 +408,15 @@ void LINKLAYER_PLAT_DisableSpecificIRQ(uint8_t isr_type)
358408 */
359409void LINKLAYER_PLAT_EnableRadioIT (void )
360410{
361- /* USER CODE BEGIN LINKLAYER_PLAT_EnableRadioIT_1*/
411+ /* USER CODE BEGIN LINKLAYER_PLAT_EnableRadioIT_1 */
362412
363- /* USER CODE END LINKLAYER_PLAT_EnableRadioIT_1*/
413+ /* USER CODE END LINKLAYER_PLAT_EnableRadioIT_1 */
364414
365415 HAL_NVIC_EnableIRQ ((IRQn_Type ) RADIO_INTR_NUM );
366416
367- /* USER CODE BEGIN LINKLAYER_PLAT_EnableRadioIT_2*/
417+ /* USER CODE BEGIN LINKLAYER_PLAT_EnableRadioIT_2 */
368418
369- /* USER CODE END LINKLAYER_PLAT_EnableRadioIT_2*/
419+ /* USER CODE END LINKLAYER_PLAT_EnableRadioIT_2 */
370420}
371421
372422/**
@@ -376,15 +426,15 @@ void LINKLAYER_PLAT_EnableRadioIT(void)
376426 */
377427void LINKLAYER_PLAT_DisableRadioIT (void )
378428{
379- /* USER CODE BEGIN LINKLAYER_PLAT_DisableRadioIT_1*/
429+ /* USER CODE BEGIN LINKLAYER_PLAT_DisableRadioIT_1 */
380430
381- /* USER CODE END LINKLAYER_PLAT_DisableRadioIT_1*/
431+ /* USER CODE END LINKLAYER_PLAT_DisableRadioIT_1 */
382432
383433 HAL_NVIC_DisableIRQ ((IRQn_Type ) RADIO_INTR_NUM );
384434
385- /* USER CODE BEGIN LINKLAYER_PLAT_DisableRadioIT_2*/
435+ /* USER CODE BEGIN LINKLAYER_PLAT_DisableRadioIT_2 */
386436
387- /* USER CODE END LINKLAYER_PLAT_DisableRadioIT_2*/
437+ /* USER CODE END LINKLAYER_PLAT_DisableRadioIT_2 */
388438}
389439
390440#ifndef __ZEPHYR__
@@ -473,6 +523,12 @@ void LINKLAYER_PLAT_RequestTemperature(void)
473523 */
474524void LINKLAYER_PLAT_EnableOSContextSwitch (void )
475525{
526+ /* USER CODE BEGIN LINKLAYER_PLAT_EnableOSContextSwitch_0 */
527+
528+ /* USER CODE END LINKLAYER_PLAT_EnableOSContextSwitch_0 */
529+ /* USER CODE BEGIN LINKLAYER_PLAT_EnableOSContextSwitch_1 */
530+
531+ /* USER CODE END LINKLAYER_PLAT_EnableOSContextSwitch_1 */
476532}
477533
478534/**
@@ -482,6 +538,12 @@ void LINKLAYER_PLAT_EnableOSContextSwitch(void)
482538 */
483539void LINKLAYER_PLAT_DisableOSContextSwitch (void )
484540{
541+ /* USER CODE BEGIN LINKLAYER_PLAT_DisableOSContextSwitch_0 */
542+
543+ /* USER CODE END LINKLAYER_PLAT_DisableOSContextSwitch_0 */
544+ /* USER CODE BEGIN LINKLAYER_PLAT_DisableOSContextSwitch_1 */
545+
546+ /* USER CODE END LINKLAYER_PLAT_DisableOSContextSwitch_1 */
485547}
486548
487549/**
@@ -515,50 +577,7 @@ uint32_t LINKLAYER_PLAT_GetUDN(void)
515577{
516578 return LL_FLASH_GetUDN ();
517579}
518-
519- /* USER CODE BEGIN LINKLAYER_PLAT 0 */
520-
521- /* Radio bus clock control variables */
522- uint8_t AHB5_SwitchedOff = 0 ;
523- uint32_t radio_sleep_timer_val = 0 ;
524580#endif
525-
526- /**
527- * @brief Notify the Link Layer platform layer the system will enter in WFI
528- * and AHB5 clock may be turned of regarding the 2.4Ghz radio state.
529- * @param None
530- * @retval None
531- */
532- void LINKLAYER_PLAT_NotifyWFIEnter (void )
533- {
534- /* Check if Radio state will allow the AHB5 clock to be cut */
535-
536- /* AHB5 clock will be cut in the following cases:
537- * - 2.4GHz radio is not in ACTIVE mode (in SLEEP or DEEPSLEEP mode).
538- * - RADIOSMEN and STRADIOCLKON bits are at 0.
539- */
540- if ((LL_PWR_GetRadioMode () != LL_PWR_RADIO_ACTIVE_MODE ) ||
541- ((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED () == 0 ) && (LL_RCC_RADIO_IsEnabledSleepTimerClock () == 0 )))
542- {
543- AHB5_SwitchedOff = 1 ;
544- }
545- }
546-
547- /**
548- * @brief Notify the Link Layer platform layer the system exited WFI and AHB5
549- * clock may be resynchronized as is may have been turned of during
550- * low power mode entry.
551- * @param None
552- * @retval None
553- */
554- void LINKLAYER_PLAT_NotifyWFIExit (void )
555- {
556- /* Check if AHB5 clock has been turned of and needs resynchronisation */
557- if (AHB5_SwitchedOff )
558- {
559- /* Read sleep register as earlier as possible */
560- radio_sleep_timer_val = ll_intf_cmn_get_slptmr_value ();
561- }
562- }
581+ /* USER CODE BEGIN LINKLAYER_PLAT 0 */
563582
564583/* USER CODE END LINKLAYER_PLAT 0 */
0 commit comments