From 7213b0c2a8fc151fe6cb950d91aefb71ebde510a Mon Sep 17 00:00:00 2001 From: richardbarry Date: Sun, 7 Apr 2013 19:30:25 +0000 Subject: [PATCH] Updated the sleep function to ensure it left interrupts disabled when returning. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1851 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../FreeRTOS_Demo.cproj | 228 +++++++++--------- .../src/SAM4L_low_power_tick_management.c | 12 +- .../src/asf/sam/drivers/bpm/bpm.c | 4 +- .../src/asf/sam/drivers/bpm/sleep.h | 4 +- .../src/config/FreeRTOSConfig.h | 19 +- 5 files changed, 135 insertions(+), 132 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/FreeRTOS_Demo.cproj b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/FreeRTOS_Demo.cproj index c553fcd0c..227cab4fd 100644 --- a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/FreeRTOS_Demo.cproj +++ b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/FreeRTOS_Demo.cproj @@ -132,14 +132,14 @@ com.atmel.avrdbg.tool.samice J-Link-OB-SAM3U128 - 000480008423 + 000480008435 true false 127.0.0.1 - 4788 + 1882 False @@ -273,118 +273,118 @@ - __ATSAM4LC4C__ - True - True - True - True - True - - - BOARD=SAM4L_EK - ARM_MATH_CM4=true - __SAM4LC4C__ - - - False - - - ../src/asf/sam/utils/preprocessor - ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek - ../src/asf/sam/utils/cmsis/sam4l/include - ../src/asf/common/services/sleepmgr - ../src/asf/sam/utils - ../src/asf/common/boards - ../src/asf/sam/drivers/flashcalw - ../src/asf/sam/boards - ../src/asf/common/services/clock - ../src/asf/sam/drivers/bpm - ../src/asf/thirdparty/CMSIS/Include - ../src/asf/sam/boards/sam4l_ek - ../src/asf/sam/utils/header_files - ../src/asf/common/services/ioport - ../src/asf/sam/utils/cmsis/sam4l/source/templates - ../src/asf/common/utils - ../src/asf/thirdparty/CMSIS/Lib/GCC - ../src - ../src/config - ../src/asf/sam/drivers/ast - ../../../Source/include - ../../../Source/portable/GCC/ARM_CM3 - ../../Common/include - - - -fdata-sections - True - Maximum (-g3) - True - -std=gnu99 -Wmissing-field-initializers - - - arm_cortexM4l_math - m - - - - - ../cmsis/linkerScripts - ../src/asf/thirdparty/CMSIS/Lib/GCC - - - True - -T../src/asf/sam/utils/linker_scripts/sam4l/sam4l4/gcc/flash.ld -Wl,--cref -Wl,--entry=Reset_Handler -mthumb - - - ../src/asf/sam/utils/preprocessor - ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek - ../src/asf/sam/utils/cmsis/sam4l/include - ../src/asf/common/services/sleepmgr - ../src/asf/sam/utils - ../src/asf/common/boards - ../src/asf/sam/drivers/flashcalw - ../src/asf/sam/boards - ../src/asf/common/services/clock - ../src/asf/sam/drivers/bpm - ../src/asf/thirdparty/CMSIS/Include - ../src/asf/sam/boards/sam4l_ek - ../src/asf/sam/utils/header_files - ../src/asf/common/services/ioport - ../src/asf/sam/utils/cmsis/sam4l/source/templates - ../src/asf/common/utils - ../src/asf/thirdparty/CMSIS/Lib/GCC - ../src - ../src/config - ../src/asf/sam/drivers/ast - - - Default (-g) - -DARM_MATH_CM4=true -DBOARD=SAM4L_EK -D__ATSAM4LC4C__ - - - ../src/asf/sam/utils/preprocessor - ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek - ../src/asf/sam/utils/cmsis/sam4l/include - ../src/asf/common/services/sleepmgr - ../src/asf/sam/utils - ../src/asf/common/boards - ../src/asf/sam/drivers/flashcalw - ../src/asf/sam/boards - ../src/asf/common/services/clock - ../src/asf/sam/drivers/bpm - ../src/asf/thirdparty/CMSIS/Include - ../src/asf/sam/boards/sam4l_ek - ../src/asf/sam/utils/header_files - ../src/asf/common/services/ioport - ../src/asf/sam/utils/cmsis/sam4l/source/templates - ../src/asf/common/utils - ../src/asf/thirdparty/CMSIS/Lib/GCC - ../src - ../src/config - ../src/asf/sam/drivers/ast - - - Default (-Wa,-g) - + __ATSAM4LC4C__ + True + True + True + True + True + + + BOARD=SAM4L_EK + ARM_MATH_CM4=true + __SAM4LC4C__ + + + False + + + ../src/asf/sam/utils/preprocessor + ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek + ../src/asf/sam/utils/cmsis/sam4l/include + ../src/asf/common/services/sleepmgr + ../src/asf/sam/utils + ../src/asf/common/boards + ../src/asf/sam/drivers/flashcalw + ../src/asf/sam/boards + ../src/asf/common/services/clock + ../src/asf/sam/drivers/bpm + ../src/asf/thirdparty/CMSIS/Include + ../src/asf/sam/boards/sam4l_ek + ../src/asf/sam/utils/header_files + ../src/asf/common/services/ioport + ../src/asf/sam/utils/cmsis/sam4l/source/templates + ../src/asf/common/utils + ../src/asf/thirdparty/CMSIS/Lib/GCC + ../src + ../src/config + ../src/asf/sam/drivers/ast + ../../../Source/include + ../../../Source/portable/GCC/ARM_CM3 + ../../Common/include + + + -fdata-sections + True + Maximum (-g3) + True + -std=gnu99 -Wmissing-field-initializers + + + arm_cortexM4l_math + m + + + + + ../cmsis/linkerScripts + ../src/asf/thirdparty/CMSIS/Lib/GCC + + + True + -T../src/asf/sam/utils/linker_scripts/sam4l/sam4l4/gcc/flash.ld -Wl,--cref -Wl,--entry=Reset_Handler -mthumb + + + ../src/asf/sam/utils/preprocessor + ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek + ../src/asf/sam/utils/cmsis/sam4l/include + ../src/asf/common/services/sleepmgr + ../src/asf/sam/utils + ../src/asf/common/boards + ../src/asf/sam/drivers/flashcalw + ../src/asf/sam/boards + ../src/asf/common/services/clock + ../src/asf/sam/drivers/bpm + ../src/asf/thirdparty/CMSIS/Include + ../src/asf/sam/boards/sam4l_ek + ../src/asf/sam/utils/header_files + ../src/asf/common/services/ioport + ../src/asf/sam/utils/cmsis/sam4l/source/templates + ../src/asf/common/utils + ../src/asf/thirdparty/CMSIS/Lib/GCC + ../src + ../src/config + ../src/asf/sam/drivers/ast + + + Default (-g) + -DARM_MATH_CM4=true -DBOARD=SAM4L_EK -D__ATSAM4LC4C__ + + + ../src/asf/sam/utils/preprocessor + ../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek + ../src/asf/sam/utils/cmsis/sam4l/include + ../src/asf/common/services/sleepmgr + ../src/asf/sam/utils + ../src/asf/common/boards + ../src/asf/sam/drivers/flashcalw + ../src/asf/sam/boards + ../src/asf/common/services/clock + ../src/asf/sam/drivers/bpm + ../src/asf/thirdparty/CMSIS/Include + ../src/asf/sam/boards/sam4l_ek + ../src/asf/sam/utils/header_files + ../src/asf/common/services/ioport + ../src/asf/sam/utils/cmsis/sam4l/source/templates + ../src/asf/common/utils + ../src/asf/thirdparty/CMSIS/Lib/GCC + ../src + ../src/config + ../src/asf/sam/drivers/ast + + + Default (-Wa,-g) + diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/SAM4L_low_power_tick_management.c b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/SAM4L_low_power_tick_management.c index dcfa82514..9aa8210c9 100644 --- a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/SAM4L_low_power_tick_management.c +++ b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/SAM4L_low_power_tick_management.c @@ -263,6 +263,7 @@ void vPortSuppressTicksAndSleep( portTickType xExpectedIdleTime ) uint32_t ulAlarmValue, ulCompleteTickPeriods; eSleepModeStatus eSleepAction; portTickType xModifiableIdleTime; +enum sleepmgr_mode xSleepMode; /* THIS FUNCTION IS CALLED WITH THE SCHEDULER SUSPENDED. */ @@ -332,8 +333,14 @@ portTickType xModifiableIdleTime; instruction. */ if( xModifiableIdleTime > 0 ) { - /* Sleep until something happens. */ - sleepmgr_enter_sleep(); + /* Find the deepest allowable sleep mode. */ + xSleepMode = sleepmgr_get_sleep_mode(); + + if( xSleepMode != SLEEPMGR_ACTIVE ) + { + /* Sleep until something happens. */ + bpm_sleep( BPM, xSleepMode ); + } } /* Allow the application to define some post sleep processing. */ @@ -347,7 +354,6 @@ portTickType xModifiableIdleTime; /* Re-enable interrupts - see comments above the cpsid instruction() above. */ -#warning The sleep manager will have re-enabled interrupts already, does this matter? __asm volatile( "cpsie i" ); if( ulTickFlag != pdFALSE ) diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/bpm.c b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/bpm.c index 407034ec3..5124955db 100644 --- a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/bpm.c +++ b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/bpm.c @@ -294,5 +294,7 @@ void bpm_sleep(Bpm *bpm, uint32_t sleep_mode) * Please note that we should probably use something like * cpu_leave_critical(), using set_pri_mask(0) */ - cpu_irq_enable(); + /* In this demo interrupts are managed by the FreeRTOS kernel and must not + be altered here so the following line has been removed _RB_ + cpu_irq_enable(); */ } diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/sleep.h b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/sleep.h index 168ac7c93..b6108c7df 100644 --- a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/sleep.h +++ b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/asf/sam/drivers/bpm/sleep.h @@ -127,7 +127,9 @@ static inline void bpm_sleep(Bpm *bpm, uint32_t sleep_mode) * Please note that we should probably use something like * cpu_leave_critical(), using set_pri_mask(0) */ - cpu_irq_enable(); + /* In this demo interrupts are managed by the FreeRTOS kernel and must not + be altered here so the following line has been removed _RB_ + cpu_irq_enable(); */ } diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/config/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/config/FreeRTOSConfig.h index 44976b5c3..4e23adaa8 100644 --- a/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/config/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/CORTEX_M4_ATSAM4L_Atmel_Studio/src/config/FreeRTOSConfig.h @@ -140,19 +140,6 @@ to exclude the API function. */ #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 -/* FreeRTOS+CLI definitions. */ - -/* Dimensions a buffer into which command outputs can be written. The buffer -can be declared in the CLI code itself, to allow multiple command consoles to -share the same buffer. For example, an application may allow access to the -command interpreter by UART and by Ethernet. Sharing a buffer is done purely -to save RAM. Note, however, that the command console itself is not re-entrant, -so only one command interpreter interface can be used at any one time. For -that reason, no attempt at providing mutual exclusion to the buffer is -attempted. */ -#define configCOMMAND_INT_MAX_OUTPUT_SIZE 400 - - /* Cortex-M specific definitions. */ #ifdef __NVIC_PRIO_BITS @@ -192,5 +179,11 @@ void vPostSleepProcessing( unsigned long xExpectedIdleTime ); #define configPRE_SLEEP_PROCESSING( xExpectedIdleTime ) vPreSleepProcessing( xExpectedIdleTime ); #define configPOST_SLEEP_PROCESSING( xExpectedIdleTime ) vPostSleepProcessing( xExpectedIdleTime ); +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler + #endif /* FREERTOS_CONFIG_H */ -- 2.39.5