Skip to content
Permalink
Browse files

fixing tickless idle mode for S08 and ColdFire

  • Loading branch information...
ErichStyger committed Jul 17, 2014
1 parent 1372819 commit 019b94b200c167c45c7f8c69fb4d4da2f9390381
Showing with 117 additions and 120 deletions.
  1. +4 −4 Beans/FreeRTOS/TickCntr.dev
  2. +80 −75 Drivers/freeRTOS/FreeRTOSConfig.h
  3. +31 −41 Drivers/freeRTOS/port.c
  4. +2 −0 Drivers/sw/FreeRTOS.drv
@@ -240,10 +240,10 @@
<ItemState>
<ItemSymbol>SetCompare</ItemSymbol>
<ReadOnly>false</ReadOnly>
<Index>1</Index>
<Value>false</Value>
<LastSelection>false</LastSelection>
<LastUserSel>no</LastUserSel>
<Index>0</Index>
<Value>true</Value>
<LastSelection>true</LastSelection>
<LastUserSel>yes</LastUserSel>
<UsrMethodName>SetCompare</UsrMethodName>
</ItemState>
<ItemState>
@@ -77,6 +77,82 @@
%if (CPUfamily = "ColdFireV1") | (CPUfamily = "HCS08") | (CPUfamily = "HC08")
#include <hidef.h>
%endif
/* -------------------------------------------------------------------- */
/* Macros to identify the compiler used: */
#define configCOMPILER_ARM_GCC %>45 1 /* GNU ARM gcc compiler */
#define configCOMPILER_ARM_IAR %>45 2 /* IAR ARM compiler */
#define configCOMPILER_ARM_FSL %>45 3 /* Legacy Freescale ARM compiler */
#define configCOMPILER_ARM_KEIL %>45 4 /* ARM/Keil compiler */
#define configCOMPILER_S08_FSL %>45 5 /* Freescale HCS08 compiler */
#define configCOMPILER_S12_FSL %>45 6 /* Freescale HCS12(X) compiler */
#define configCOMPILER_CF1_FSL %>45 7 /* Freescale ColdFire V1 compiler */
#define configCOMPILER_CF2_FSL %>45 8 /* Freescale ColdFire V2 compiler */
#define configCOMPILER_DSC_FSL %>45 9 /* Freescale DSC compiler */

%if (%configCOMPILER='automatic')
%if (%Compiler = "IARARM")
#define configCOMPILER %>50 configCOMPILER_ARM_IAR
%elif (%Compiler = "GNUC")
#define configCOMPILER %>50 configCOMPILER_ARM_GCC
%elif (%Compiler = "CodeWarriorARM")
#define configCOMPILER %>50 configCOMPILER_ARM_FSL
%elif (%Compiler = "ARM_CC")
#define configCOMPILER %>50 configCOMPILER_ARM_KEIL
%elif (%Compiler = "MetrowerksHC08CC") | (%Compiler = "MetrowerksHCS08CC")
#define configCOMPILER %>50 configCOMPILER_S08_FSL
%elif (%Compiler = "MetrowerksHC12CC") | (%Compiler = "MetrowerksHC12XCC")
#define configCOMPILER %>50 configCOMPILER_S12_FSL
%elif (%Compiler = "CodeWarriorColdFireV1")
#define configCOMPILER %>50 configCOMPILER_CF1_FSL
%elif (%Compiler = "CodeWarriorMCF")
#define configCOMPILER %>50 configCOMPILER_CF2_FSL
%elif (%Compiler = "MetrowerksDSP")
#define configCOMPILER %>50 configCOMPILER_DSC_FSL
%else
#define configCOMPILER %>50 0
#error "unknown compiler %Compiler?"
%endif
%else %- non-automatic compiler selection
#define configCOMPILER %>50 %configCompiler
%endif
/* -------------------------------------------------------------------- */
/* CPU family identification */
#define configCPU_FAMILY_S08 %>45 1 /* S08 core */
#define configCPU_FAMILY_S12 %>45 2 /* S12(X) core */
#define configCPU_FAMILY_CF1 %>45 3 /* ColdFire V1 core */
#define configCPU_FAMILY_CF2 %>45 4 /* ColdFire V2 core */
#define configCPU_FAMILY_DSC %>45 5 /* 56800/DSC */
#define configCPU_FAMILY_ARM_M0P %>45 6 /* ARM Cortex-M0+ */
#define configCPU_FAMILY_ARM_M4 %>45 7 /* ARM Cortex-M4 */
#define configCPU_FAMILY_ARM_M4F %>45 8 /* ARM Cortex-M4F (with floating point unit) */
/* Macros to identify set of core families */
#define configCPU_FAMILY_IS_ARM_M4(fam) %>45 (((fam)==configCPU_FAMILY_ARM_M4) || ((fam)==configCPU_FAMILY_ARM_M4F))
#define configCPU_FAMILY_IS_ARM(fam) %>45 (((fam)==configCPU_FAMILY_ARM_M0P) || configCPU_FAMILY_IS_ARM_M4(fam))

%if (CPUfamily = "HCS08") | (CPUfamily = "HC08")
#define configCPU_FAMILY %>50 configCPU_FAMILY_S08
%elif (CPUfamily = "HCS12") | (CPUfamily = "HCS12X")
#define configCPU_FAMILY %>50 configCPU_FAMILY_S12
%elif (CPUfamily = "ColdFireV1")
#define configCPU_FAMILY %>50 configCPU_FAMILY_CF1
%elif (CPUfamily = "MCF")
#define configCPU_FAMILY %>50 configCPU_FAMILY_CF2
%elif (CPUfamily = "56800")
#define configCPU_FAMILY %>50 configCPU_FAMILY_DSC
%elif (CPUfamily = "Kinetis")
%if %CPUDB_prph_has_feature(CPU,ARM_CORTEX_M0P) = 'yes' %- Note: for IAR this is defined in portasm.s too!
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M0P
%else %-M4 or M4F
%if %CPUDB_prph_has_feature(CPU, FPU) = 'no'
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M4
%else
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M4F
%endif
%endif
%else
#define configCPU_FAMILY %>50 0
#error "Unknown CPU family %CPUfamily?"
%endif
/*-----------------------------------------------------------
* Application specific definitions.
*
@@ -148,7 +224,11 @@
%if defined(configCPU_CLOCK_HZ)
#define configCPU_CLOCK_HZ %>50 %configCPU_CLOCK_HZ /* CPU clock frequency */
%else
#if configCPU_FAMILY_IS_ARM(configCPU_FAMILY) /* Kinetis defines this one in Cpu.h */
#define configCPU_CLOCK_HZ %>50 CPU_CORE_CLK_HZ /* CPU core clock defined in %ProcessorModule.h */
#else
#define configCPU_CLOCK_HZ %>50 CPU_INSTR_CLK_HZ /* CPU core clock defined in %ProcessorModule.h */
#endif
%endif
%if defined(configBUS_CLOCK_HZ)
#define configBUS_CLOCK_HZ %>50 %configBUS_CLOCK_HZ /* Bus clock frequency */
@@ -380,82 +460,7 @@
%else
#define INCLUDE_pcTaskGetTaskName %>50 0
%endif
/* -------------------------------------------------------------------- */
/* Macros to identify the compiler used: */
#define configCOMPILER_ARM_GCC %>45 1 /* GNU ARM gcc compiler */
#define configCOMPILER_ARM_IAR %>45 2 /* IAR ARM compiler */
#define configCOMPILER_ARM_FSL %>45 3 /* Legacy Freescale ARM compiler */
#define configCOMPILER_ARM_KEIL %>45 4 /* ARM/Keil compiler */
#define configCOMPILER_S08_FSL %>45 5 /* Freescale HCS08 compiler */
#define configCOMPILER_S12_FSL %>45 6 /* Freescale HCS12(X) compiler */
#define configCOMPILER_CF1_FSL %>45 7 /* Freescale ColdFire V1 compiler */
#define configCOMPILER_CF2_FSL %>45 8 /* Freescale ColdFire V2 compiler */
#define configCOMPILER_DSC_FSL %>45 9 /* Freescale DSC compiler */

%if (%configCOMPILER='automatic')
%if (%Compiler = "IARARM")
#define configCOMPILER %>50 configCOMPILER_ARM_IAR
%elif (%Compiler = "GNUC")
#define configCOMPILER %>50 configCOMPILER_ARM_GCC
%elif (%Compiler = "CodeWarriorARM")
#define configCOMPILER %>50 configCOMPILER_ARM_FSL
%elif (%Compiler = "ARM_CC")
#define configCOMPILER %>50 configCOMPILER_ARM_KEIL
%elif (%Compiler = "MetrowerksHC08CC") | (%Compiler = "MetrowerksHCS08CC")
#define configCOMPILER %>50 configCOMPILER_S08_FSL
%elif (%Compiler = "MetrowerksHC12CC") | (%Compiler = "MetrowerksHC12XCC")
#define configCOMPILER %>50 configCOMPILER_S12_FSL
%elif (%Compiler = "CodeWarriorColdFireV1")
#define configCOMPILER %>50 configCOMPILER_CF1_FSL
%elif (%Compiler = "CodeWarriorMCF")
#define configCOMPILER %>50 configCOMPILER_CF2_FSL
%elif (%Compiler = "MetrowerksDSP")
#define configCOMPILER %>50 configCOMPILER_DSC_FSL
%else
#define configCOMPILER %>50 0
#error "unknown compiler %Compiler?"
%endif
%else %- non-automatic compiler selection
#define configCOMPILER %>50 %configCompiler
%endif
/* -------------------------------------------------------------------- */
/* CPU family identification */
#define configCPU_FAMILY_S08 %>45 1 /* S08 core */
#define configCPU_FAMILY_S12 %>45 2 /* S12(X) core */
#define configCPU_FAMILY_CF1 %>45 3 /* ColdFire V1 core */
#define configCPU_FAMILY_CF2 %>45 4 /* ColdFire V2 core */
#define configCPU_FAMILY_DSC %>45 5 /* 56800/DSC */
#define configCPU_FAMILY_ARM_M0P %>45 6 /* ARM Cortex-M0+ */
#define configCPU_FAMILY_ARM_M4 %>45 7 /* ARM Cortex-M4 */
#define configCPU_FAMILY_ARM_M4F %>45 8 /* ARM Cortex-M4F (with floating point unit) */
/* Macros to identify set of core families */
#define configCPU_FAMILY_IS_ARM_M4(fam) %>45 (((fam)==configCPU_FAMILY_ARM_M4) || ((fam)==configCPU_FAMILY_ARM_M4F))
#define configCPU_FAMILY_IS_ARM(fam) %>45 (((fam)==configCPU_FAMILY_ARM_M0P) || configCPU_FAMILY_IS_ARM_M4(fam))

%if (CPUfamily = "HCS08") | (CPUfamily = "HC08")
#define configCPU_FAMILY %>50 configCPU_FAMILY_S08
%elif (CPUfamily = "HCS12") | (CPUfamily = "HCS12X")
#define configCPU_FAMILY %>50 configCPU_FAMILY_S12
%elif (CPUfamily = "ColdFireV1")
#define configCPU_FAMILY %>50 configCPU_FAMILY_CF1
%elif (CPUfamily = "MCF")
#define configCPU_FAMILY %>50 configCPU_FAMILY_CF2
%elif (CPUfamily = "56800")
#define configCPU_FAMILY %>50 configCPU_FAMILY_DSC
%elif (CPUfamily = "Kinetis")
%if %CPUDB_prph_has_feature(CPU,ARM_CORTEX_M0P) = 'yes' %- Note: for IAR this is defined in portasm.s too!
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M0P
%else %-M4 or M4F
%if %CPUDB_prph_has_feature(CPU, FPU) = 'no'
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M4
%else
#define configCPU_FAMILY %>50 configCPU_FAMILY_ARM_M4F
%endif
%endif
%else
#define configCPU_FAMILY %>50 0
#error "Unknown CPU family %CPUfamily?"
%endif
/* -------------------------------------------------------------------- */
%if (CPUfamily = "ColdFireV1")
/* It is not advisable to change these values on a ColdFire V1 core. */
@@ -75,6 +75,19 @@
#include "LPTMR_PDD.h" /* PDD interface to low power timer */
#include "SIM_PDD.h" /* PDD interface to system integration module */
#endif
#if !configPEX_KINETIS_SDK
#include "%ProcessorModule.h"
#endif

/* --------------------------------------------------- */
/* Let the user override the pre-loading of the initial LR with the address of
prvTaskExitError() in case is messes up unwinding of the stack in the
debugger. */
#ifdef configTASK_RETURN_ADDRESS
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
#else
#define portTASK_RETURN_ADDRESS prvTaskExitError
#endif
/* --------------------------------------------------- */
/* macros dealing with tick counter */
%if (CPUfamily = "Kinetis")
@@ -125,7 +138,7 @@ typedef %@TickCntr@'ModuleName'%.TTimerValue TickCounter_t; /* for holding count
#if configUSE_TICKLESS_IDLE == 1
static TickCounter_t currTickDuration; /* holds the modulo counter/tick duration as no API to get it from the FreeCntr component */
#endif
#define SET_TICK_DURATION(val) (void)%@TickCntr@'ModuleName'%.SetCompare(val); currTickDuration=val
#define SET_TICK_DURATION(val) (void)%@TickCntr@'ModuleName'%.SetCompare((%@TickCntr@'ModuleName'%.TTimerValue)(val)); currTickDuration=(TickCounter_t)(val)
#define GET_TICK_DURATION() currTickDuration
#define GET_TICK_CURRENT_VAL(addr) (void)%@TickCntr@'ModuleName'%.GetCounterValue(addr)
%endif
@@ -321,15 +334,6 @@ static void NVIC_EnableIRQ(IRQn_Type IRQn) {
#define portINITIAL_XPSR (0x01000000)
#define portINITIAL_EXEC_RETURN (0xfffffffd)

/* Let the user override the pre-loading of the initial LR with the address of
prvTaskExitError() in case is messes up unwinding of the stack in the
debugger. */
#ifdef configTASK_RETURN_ADDRESS
#define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
#else
#define portTASK_RETURN_ADDRESS prvTaskExitError
#endif

#if (configCPU_FAMILY==configCPU_FAMILY_ARM_M4F)
/* Constants required to manipulate the VFP. */
#define portFPCCR ((volatile unsigned long *)0xe000ef34) /* Floating point context control register. */
@@ -362,15 +366,17 @@ static jmp_buf xJumpBuf; /* Used to restore the original context when the schedu
#endif
/*-----------------------------------------------------------*/
static void prvTaskExitError(void) {
/* A function that implements a task must not exit or attempt to return to
its caller as there is nothing to return to. If a task wants to exit it
should instead call vTaskDelete( NULL ).
Artificially force an assert() to be triggered if configASSERT() is
defined, then stop here so application writers can catch the error. */
configASSERT(uxCriticalNesting == ~0UL);
portDISABLE_INTERRUPTS();
for(;;);
/* A function that implements a task must not exit or attempt to return to
its caller as there is nothing to return to. If a task wants to exit it
should instead call vTaskDelete( NULL ).
Artificially force an assert() to be triggered if configASSERT() is
defined, then stop here so application writers can catch the error. */
configASSERT(uxCriticalNesting == ~0UL);
portDISABLE_INTERRUPTS();
for(;;) {
/* wait here */
}
}
/*-----------------------------------------------------------*/
#if (configCOMPILER==configCOMPILER_ARM_KEIL) && configCPU_FAMILY_IS_ARM_M4(configCPU_FAMILY)
@@ -482,7 +488,7 @@ extern tskTCB *volatile pxCurrentTCB;
} while(0)

%endif %- (CPUfamily = "56800")
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) {
portSTACK_TYPE *pxPortInitialiseStack(portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters) {
%if (CPUfamily = "ColdFireV1") | (CPUfamily = "MCF")
unsigned portLONG ulOriginalA5;

@@ -508,16 +514,11 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_COD

return pxTopOfStack;
%elif (CPUfamily = "HCS08") | (CPUfamily = "HC08")
/*
Place a few bytes of known values on the bottom of the stack.
This can be uncommented to provide useful stack markers when debugging.
*pxTopOfStack = (portSTACK_TYPE)0x11;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0x22;
/* Set as task caller the prvTaskExitError function. */
*pxTopOfStack = (uint8_t)portTASK_RETURN_ADDRESS;
pxTopOfStack--;
*pxTopOfStack = (portSTACK_TYPE)0x33;
*pxTopOfStack = (uint8_t)(((uint16_t)portTASK_RETURN_ADDRESS)>>8);
pxTopOfStack--;
*/

/* Setup the initial stack of the task. The stack is set exactly as
expected by the portRESTORE_CONTEXT() macro. In this case the stack as
@@ -620,7 +621,6 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_COD
*pxTopOfStack = (portSTACK_TYPE)0x40; /* have the X bit still masked */
pxTopOfStack--;
#endif

#ifdef __BANKED__
#ifdef __HCS12X__
*pxTopOfStack = (portSTACK_TYPE) *(((portSTACK_TYPE*)(&pxCode))+2); /* PPage of task created */
@@ -637,12 +637,9 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_COD
pxTopOfStack--;
#endif
#endif

/* Finally the critical nesting depth is initialised with 0 (not within a critical section). */
*pxTopOfStack = (portSTACK_TYPE)0x00;

return pxTopOfStack;

%elif (CPUfamily = "Kinetis")
/* Simulate the stack frame as it would be created by a context switch interrupt. */
pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts,
@@ -672,7 +669,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_COD

const portSTACK_TYPE xInitialStack[] =
{
0x03030303UL, /* R3 */
0x03030303UL, /* R3 */
0x04040404UL, /* R4 */
0x05050505UL, /* R5 */
0x06060606UL, /* N */
@@ -828,17 +825,10 @@ void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
ENABLE_TICK_COUNTER(); /* Restart SysTick. */
TICKLESS_ENABLE_INTERRUPTS();
} else {
#if configUSE_LP_TIMER
DisableDevice();
ClearInterruptFlag();
WriteCompareReg(xExpectedIdleTime-1);
EnableDevice(); /* start timer */
#else
SET_TICK_DURATION(ulReloadValue); /* Set the new reload value. */
RESET_TICK_COUNTER_VAL(); /* Reset the counter. */
ENABLE_TICK_COUNTER(); /* Restart tick timer. */
TICK_INTERRUPT_FLAG_RESET(); /* reset flag so we know later if it has fired */
#endif

/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
* set its parameter to 0 to indicate that its implementation contains
@@ -874,7 +864,7 @@ void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
* inevitably result in some tiny drift of the time maintained by the
* kernel with respect to calendar time.
*/
tickISRfired = TICK_INTERRUPT_HAS_FIRED(); /* need to check Interrupt flag here, as might be modified below */
tickISRfired = (bool)TICK_INTERRUPT_HAS_FIRED(); /* need to check Interrupt flag here, as might be modified below */
DISABLE_TICK_COUNTER();
TICKLESS_ENABLE_INTERRUPTS();/* Re-enable interrupts */
if (tickISRfired) {
@@ -3016,6 +3016,7 @@ void %vApplicationMallocFailedHook(void)
%include Common\FreeRTOSvOnPostSleepProcessing.Inc
void %vOnPostSleepProcessing(portTickType expectedIdleTicks)
{
(void)expectedIdleTicks; /* not used (yet?) */
/* Write your code here ... */
}

@@ -3028,6 +3029,7 @@ void %vOnPostSleepProcessing(portTickType expectedIdleTicks)
%include Common\FreeRTOSvOnPreSleepProcessing.Inc
void %vOnPreSleepProcessing(portTickType expectedIdleTicks)
{
(void)expectedIdleTicks; /* not used */
%if (CPUfamily = "Kinetis")
#if 1
%else

0 comments on commit 019b94b

Please sign in to comment.
You can’t perform that action at this time.