diff --git a/portable/CCS/ARM_Cortex-R4/port.c b/portable/CCS/ARM_Cortex-R4/port.c index 1f3f31c64..972150b78 100644 --- a/portable/CCS/ARM_Cortex-R4/port.c +++ b/portable/CCS/ARM_Cortex-R4/port.c @@ -37,28 +37,28 @@ uint32_t ulCriticalNesting = 9999; /*-----------------------------------------------------------*/ /* Registers required to configure the RTI. */ -#define portRTI_GCTRL_REG ( *( ( volatile uint32_t * ) 0xFFFFFC00 ) ) -#define portRTI_TBCTRL_REG ( *( ( volatile uint32_t * ) 0xFFFFFC04 ) ) -#define portRTI_COMPCTRL_REG ( *( ( volatile uint32_t * ) 0xFFFFFC0C ) ) -#define portRTI_CNT0_FRC0_REG ( *( ( volatile uint32_t * ) 0xFFFFFC10 ) ) -#define portRTI_CNT0_UC0_REG ( *( ( volatile uint32_t * ) 0xFFFFFC14 ) ) -#define portRTI_CNT0_CPUC0_REG ( *( ( volatile uint32_t * ) 0xFFFFFC18 ) ) -#define portRTI_CNT0_COMP0_REG ( *( ( volatile uint32_t * ) 0xFFFFFC50 ) ) -#define portRTI_CNT0_UDCP0_REG ( *( ( volatile uint32_t * ) 0xFFFFFC54 ) ) -#define portRTI_SETINTENA_REG ( *( ( volatile uint32_t * ) 0xFFFFFC80 ) ) -#define portRTI_CLEARINTENA_REG ( *( ( volatile uint32_t * ) 0xFFFFFC84 ) ) -#define portRTI_INTFLAG_REG ( *( ( volatile uint32_t * ) 0xFFFFFC88 ) ) +#define portRTI_GCTRL_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC00 ) ) +#define portRTI_TBCTRL_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC04 ) ) +#define portRTI_COMPCTRL_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC0C ) ) +#define portRTI_CNT0_FRC0_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC10 ) ) +#define portRTI_CNT0_UC0_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC14 ) ) +#define portRTI_CNT0_CPUC0_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC18 ) ) +#define portRTI_CNT0_COMP0_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC50 ) ) +#define portRTI_CNT0_UDCP0_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC54 ) ) +#define portRTI_SETINTENA_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC80 ) ) +#define portRTI_CLEARINTENA_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC84 ) ) +#define portRTI_INTFLAG_REG ( * ( ( volatile uint32_t * ) 0xFFFFFC88 ) ) /* Constants required to set up the initial stack of each task. */ -#define portINITIAL_SPSR ( ( StackType_t ) 0x1F ) -#define portINITIAL_FPSCR ( ( StackType_t ) 0x00 ) -#define portINSTRUCTION_SIZE ( ( StackType_t ) 0x04 ) -#define portTHUMB_MODE_BIT ( ( StackType_t ) 0x20 ) +#define portINITIAL_SPSR ( ( StackType_t ) 0x1F ) +#define portINITIAL_FPSCR ( ( StackType_t ) 0x00 ) +#define portINSTRUCTION_SIZE ( ( StackType_t ) 0x04 ) +#define portTHUMB_MODE_BIT ( ( StackType_t ) 0x20 ) /* The number of words on the stack frame between the saved Top Of Stack and - * R0 (in which the parameters are passed. */ -#define portSPACE_BETWEEN_TOS_AND_PARAMETERS ( 12 ) +R0 (in which the parameters are passed. */ +#define portSPACE_BETWEEN_TOS_AND_PARAMETERS ( 12 ) /*-----------------------------------------------------------*/ @@ -68,7 +68,7 @@ extern void vPortStartFirstTask( void ); /*-----------------------------------------------------------*/ /* Saved as part of the task context. Set to pdFALSE if the task does not - * require an FPU context. */ +require an FPU context. */ uint32_t ulTaskHasFPUContext = 0; /*-----------------------------------------------------------*/ @@ -77,183 +77,181 @@ uint32_t ulTaskHasFPUContext = 0; /* * See header file for description. */ -StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, - TaskFunction_t pxCode, - void * pvParameters ) +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) { - StackType_t * pxOriginalTOS; +StackType_t *pxOriginalTOS; - pxOriginalTOS = pxTopOfStack; + pxOriginalTOS = pxTopOfStack; - #if __TI_VFP_SUPPORT__ - { - /* Ensure the stack is correctly aligned on exit. */ - pxTopOfStack--; - } - #endif + #if __TI_VFP_SUPPORT__ + { + /* Ensure the stack is correctly aligned on exit. */ + pxTopOfStack--; + } + #endif - /* Setup the initial stack of the task. The stack is set exactly as - * expected by the portRESTORE_CONTEXT() macro. */ + /* Setup the initial stack of the task. The stack is set exactly as + expected by the portRESTORE_CONTEXT() macro. */ - /* First on the stack is the return address - which is the start of the as - * the task has not executed yet. The offset is added to make the return - * address appear as it would within an IRQ ISR. */ - *pxTopOfStack = ( StackType_t ) pxCode + portINSTRUCTION_SIZE; - pxTopOfStack--; + /* First on the stack is the return address - which is the start of the as + the task has not executed yet. The offset is added to make the return + address appear as it would within an IRQ ISR. */ + *pxTopOfStack = ( StackType_t ) pxCode + portINSTRUCTION_SIZE; + pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x00000000; /* R14 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* Stack used when task starts goes in R13. */ - pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x00000000; /* R14 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* Stack used when task starts goes in R13. */ + pxTopOfStack--; - #ifdef portPRELOAD_TASK_REGISTERS - { - *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */ - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */ - pxTopOfStack--; - } - #else /* ifdef portPRELOAD_TASK_REGISTERS */ - { - pxTopOfStack -= portSPACE_BETWEEN_TOS_AND_PARAMETERS; - } - #endif /* ifdef portPRELOAD_TASK_REGISTERS */ + #ifdef portPRELOAD_TASK_REGISTERS + { + *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */ + pxTopOfStack--; + } + #else + { + pxTopOfStack -= portSPACE_BETWEEN_TOS_AND_PARAMETERS; + } + #endif - /* Function parameters are passed in R0. */ - *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ - pxTopOfStack--; + /* Function parameters are passed in R0. */ + *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ + pxTopOfStack--; - /* Set the status register for system mode, with interrupts enabled. */ - *pxTopOfStack = ( StackType_t ) ( ( _get_CPSR() & ~0xFF ) | portINITIAL_SPSR ); + /* Set the status register for system mode, with interrupts enabled. */ + *pxTopOfStack = ( StackType_t ) ( ( _get_CPSR() & ~0xFF ) | portINITIAL_SPSR ); - if( ( ( uint32_t ) pxCode & 0x01UL ) != 0x00 ) - { - /* The task will start in thumb mode. */ - *pxTopOfStack |= portTHUMB_MODE_BIT; - } + if( ( ( uint32_t ) pxCode & 0x01UL ) != 0x00 ) + { + /* The task will start in thumb mode. */ + *pxTopOfStack |= portTHUMB_MODE_BIT; + } - #ifdef __TI_VFP_SUPPORT__ - { - pxTopOfStack--; + #ifdef __TI_VFP_SUPPORT__ + { + pxTopOfStack--; - /* The last thing on the stack is the tasks ulUsingFPU value, which by - * default is set to indicate that the stack frame does not include FPU - * registers. */ - *pxTopOfStack = pdFALSE; - } - #endif + /* The last thing on the stack is the tasks ulUsingFPU value, which by + default is set to indicate that the stack frame does not include FPU + registers. */ + *pxTopOfStack = pdFALSE; + } + #endif - return pxTopOfStack; + return pxTopOfStack; } /*-----------------------------------------------------------*/ -static void prvSetupTimerInterrupt( void ) +static void prvSetupTimerInterrupt(void) { - /* Disable timer 0. */ - portRTI_GCTRL_REG &= 0xFFFFFFFEUL; + /* Disable timer 0. */ + portRTI_GCTRL_REG &= 0xFFFFFFFEUL; - /* Use the internal counter. */ - portRTI_TBCTRL_REG = 0x00000000U; + /* Use the internal counter. */ + portRTI_TBCTRL_REG = 0x00000000U; - /* COMPSEL0 will use the RTIFRC0 counter. */ - portRTI_COMPCTRL_REG = 0x00000000U; + /* COMPSEL0 will use the RTIFRC0 counter. */ + portRTI_COMPCTRL_REG = 0x00000000U; - /* Initialise the counter and the prescale counter registers. */ - portRTI_CNT0_UC0_REG = 0x00000000U; - portRTI_CNT0_FRC0_REG = 0x00000000U; + /* Initialise the counter and the prescale counter registers. */ + portRTI_CNT0_UC0_REG = 0x00000000U; + portRTI_CNT0_FRC0_REG = 0x00000000U; - /* Set Prescalar for RTI clock. */ - portRTI_CNT0_CPUC0_REG = 0x00000001U; - portRTI_CNT0_COMP0_REG = ( configCPU_CLOCK_HZ / 2 ) / configTICK_RATE_HZ; - portRTI_CNT0_UDCP0_REG = ( configCPU_CLOCK_HZ / 2 ) / configTICK_RATE_HZ; + /* Set Prescalar for RTI clock. */ + portRTI_CNT0_CPUC0_REG = 0x00000001U; + portRTI_CNT0_COMP0_REG = ( configCPU_CLOCK_HZ / 2 ) / configTICK_RATE_HZ; + portRTI_CNT0_UDCP0_REG = ( configCPU_CLOCK_HZ / 2 ) / configTICK_RATE_HZ; - /* Clear interrupts. */ - portRTI_INTFLAG_REG = 0x0007000FU; - portRTI_CLEARINTENA_REG = 0x00070F0FU; + /* Clear interrupts. */ + portRTI_INTFLAG_REG = 0x0007000FU; + portRTI_CLEARINTENA_REG = 0x00070F0FU; - /* Enable the compare 0 interrupt. */ - portRTI_SETINTENA_REG = 0x00000001U; - portRTI_GCTRL_REG |= 0x00000001U; + /* Enable the compare 0 interrupt. */ + portRTI_SETINTENA_REG = 0x00000001U; + portRTI_GCTRL_REG |= 0x00000001U; } /*-----------------------------------------------------------*/ /* * See header file for description. */ -BaseType_t xPortStartScheduler( void ) +BaseType_t xPortStartScheduler(void) { - /* Start the timer that generates the tick ISR. */ - prvSetupTimerInterrupt(); + /* Start the timer that generates the tick ISR. */ + prvSetupTimerInterrupt(); - /* Reset the critical section nesting count read to execute the first task. */ - ulCriticalNesting = 0; + /* Reset the critical section nesting count read to execute the first task. */ + ulCriticalNesting = 0; - /* Start the first task. This is done from portASM.asm as ARM mode must be - * used. */ - vPortStartFirstTask(); + /* Start the first task. This is done from portASM.asm as ARM mode must be + used. */ + vPortStartFirstTask(); - /* Should not get here! */ - return pdFAIL; + /* Should not get here! */ + return pdFAIL; } /*-----------------------------------------------------------*/ /* * See header file for description. */ -void vPortEndScheduler( void ) +void vPortEndScheduler(void) { - /* Not implemented in ports where there is nothing to return to. - * Artificially force an assert. */ - configASSERT( ulCriticalNesting == 1000UL ); + /* Not implemented in ports where there is nothing to return to. + Artificially force an assert. */ + configASSERT( ulCriticalNesting == 1000UL ); } /*-----------------------------------------------------------*/ #if configUSE_PREEMPTION == 0 -/* The cooperative scheduler requires a normal IRQ service routine to - * simply increment the system tick. */ - __interrupt void vPortNonPreemptiveTick( void ) - { - /* clear clock interrupt flag */ - portRTI_INTFLAG_REG = 0x00000001; + /* The cooperative scheduler requires a normal IRQ service routine to + * simply increment the system tick. */ + __interrupt void vPortNonPreemptiveTick( void ) + { + /* clear clock interrupt flag */ + portRTI_INTFLAG_REG = 0x00000001; - /* Increment the tick count - this may make a delaying task ready - * to run - but a context switch is not performed. */ - xTaskIncrementTick(); - } + /* Increment the tick count - this may make a delaying task ready + to run - but a context switch is not performed. */ + xTaskIncrementTick(); + } -#else /* if configUSE_PREEMPTION == 0 */ + #else -/* - ************************************************************************** - * The preemptive scheduler ISR is written in assembler and can be found - * in the portASM.asm file. This will only get used if portUSE_PREEMPTION - * is set to 1 in portmacro.h - ************************************************************************** - */ - void vPortPreemptiveTick( void ); + /* + ************************************************************************** + * The preemptive scheduler ISR is written in assembler and can be found + * in the portASM.asm file. This will only get used if portUSE_PREEMPTION + * is set to 1 in portmacro.h + ************************************************************************** + */ + void vPortPreemptiveTick( void ); -#endif /* if configUSE_PREEMPTION == 0 */ +#endif /*-----------------------------------------------------------*/ @@ -262,13 +260,13 @@ void vPortEndScheduler( void ) */ void vPortEnterCritical( void ) { - /* Disable interrupts as per portDISABLE_INTERRUPTS(); */ - portDISABLE_INTERRUPTS(); + /* Disable interrupts as per portDISABLE_INTERRUPTS(); */ + portDISABLE_INTERRUPTS(); - /* Now interrupts are disabled ulCriticalNesting can be accessed - * directly. Increment ulCriticalNesting to keep a count of how many times - * portENTER_CRITICAL() has been called. */ - ulCriticalNesting++; + /* Now interrupts are disabled ulCriticalNesting can be accessed + directly. Increment ulCriticalNesting to keep a count of how many times + portENTER_CRITICAL() has been called. */ + ulCriticalNesting++; } /*-----------------------------------------------------------*/ @@ -278,36 +276,37 @@ void vPortEnterCritical( void ) */ void vPortExitCritical( void ) { - if( ulCriticalNesting > 0 ) - { - /* Decrement the nesting count as we are leaving a critical section. */ - ulCriticalNesting--; + if( ulCriticalNesting > 0 ) + { + /* Decrement the nesting count as we are leaving a critical section. */ + ulCriticalNesting--; - /* If the nesting level has reached zero then interrupts should be - * re-enabled. */ - if( ulCriticalNesting == 0 ) - { - /* Enable interrupts as per portENABLE_INTERRUPTS(). */ - portENABLE_INTERRUPTS(); - } - } + /* If the nesting level has reached zero then interrupts should be + re-enabled. */ + if( ulCriticalNesting == 0 ) + { + /* Enable interrupts as per portENABLE_INTERRUPTS(). */ + portENABLE_INTERRUPTS(); + } + } } /*-----------------------------------------------------------*/ #if __TI_VFP_SUPPORT__ - void vPortTaskUsesFPU( void ) - { - extern void vPortInitialiseFPSCR( void ); + void vPortTaskUsesFPU( void ) + { + extern void vPortInitialiseFPSCR( void ); - /* A task is registering the fact that it needs an FPU context. Set the - * FPU flag (saved as part of the task context. */ - ulTaskHasFPUContext = pdTRUE; + /* A task is registering the fact that it needs an FPU context. Set the + FPU flag (saved as part of the task context. */ + ulTaskHasFPUContext = pdTRUE; - /* Initialise the floating point status register. */ - vPortInitialiseFPSCR(); - } + /* Initialise the floating point status register. */ + vPortInitialiseFPSCR(); + } #endif /* __TI_VFP_SUPPORT__ */ /*-----------------------------------------------------------*/ + diff --git a/portable/CCS/ARM_Cortex-R4/portmacro.h b/portable/CCS/ARM_Cortex-R4/portmacro.h index 1536b0f44..d8a9a4c2b 100644 --- a/portable/CCS/ARM_Cortex-R4/portmacro.h +++ b/portable/CCS/ARM_Cortex-R4/portmacro.h @@ -39,78 +39,79 @@ */ /* Type definitions. */ -#define portCHAR char -#define portFLOAT float -#define portDOUBLE double -#define portLONG long -#define portSHORT short -#define portSTACK_TYPE uint32_t -#define portBASE_TYPE long +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT short +#define portSTACK_TYPE uint32_t +#define portBASE_TYPE long -typedef portSTACK_TYPE StackType_t; -typedef long BaseType_t; -typedef unsigned long UBaseType_t; +typedef portSTACK_TYPE StackType_t; +typedef long BaseType_t; +typedef unsigned long UBaseType_t; -#if ( configUSE_16_BIT_TICKS == 1 ) - typedef uint16_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xFFFF +#if (configUSE_16_BIT_TICKS == 1) + typedef uint16_t TickType_t; + #define portMAX_DELAY (TickType_t) 0xFFFF #else - typedef uint32_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xFFFFFFFFF + typedef uint32_t TickType_t; + #define portMAX_DELAY (TickType_t) 0xFFFFFFFFF -/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do - * not need to be guarded with a critical section. */ - #define portTICK_TYPE_IS_ATOMIC 1 + /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do + not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 #endif /* Architecture specifics. */ -#define portSTACK_GROWTH ( -1 ) -#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) -#define portBYTE_ALIGNMENT 8 +#define portSTACK_GROWTH (-1) +#define portTICK_PERIOD_MS ((TickType_t) 1000 / configTICK_RATE_HZ) +#define portBYTE_ALIGNMENT 8 /* Critical section handling. */ -extern void vPortEnterCritical( void ); -extern void vPortExitCritical( void ); -#define portENTER_CRITICAL() vPortEnterCritical() -#define portEXIT_CRITICAL() vPortExitCritical() -#define portDISABLE_INTERRUPTS() asm ( " CPSID I" ) -#define portENABLE_INTERRUPTS() asm ( " CPSIE I" ) +extern void vPortEnterCritical(void); +extern void vPortExitCritical(void); +#define portENTER_CRITICAL() vPortEnterCritical() +#define portEXIT_CRITICAL() vPortExitCritical() +#define portDISABLE_INTERRUPTS() asm( " CPSID I" ) +#define portENABLE_INTERRUPTS() asm( " CPSIE I" ) /* Scheduler utilities. */ #pragma SWI_ALIAS( vPortYield, 0 ) extern void vPortYield( void ); -#define portYIELD() vPortYield() -#define portSYS_SSIR1_REG ( *( ( volatile uint32_t * ) 0xFFFFFFB0 ) ) -#define portSYS_SSIR1_SSKEY ( 0x7500UL ) -#define portYIELD_WITHIN_API() { portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY; asm ( " DSB " ); asm ( " ISB " ); } -#define portYIELD_FROM_ISR( x ) if( x != pdFALSE ) { portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY; ( void ) portSYS_SSIR1_REG; } +#define portYIELD() vPortYield() +#define portSYS_SSIR1_REG ( * ( ( volatile uint32_t * ) 0xFFFFFFB0 ) ) +#define portSYS_SSIR1_SSKEY ( 0x7500UL ) +#define portYIELD_WITHIN_API() { portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY; asm( " DSB " ); asm( " ISB " ); } +#define portYIELD_FROM_ISR( x ) if( x != pdFALSE ){ portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY; ( void ) portSYS_SSIR1_REG; } #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 #endif /* Architecture specific optimisations. */ #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 -/* Check the configuration. */ - #if ( configMAX_PRIORITIES > 32 ) - #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. - #endif + /* Check the configuration. */ + #if( configMAX_PRIORITIES > 32 ) + #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. + #endif -/* Store/clear the ready priorities in a bit map. */ - #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) - #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) + /* Store/clear the ready priorities in a bit map. */ + #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) + #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) -/*-----------------------------------------------------------*/ + /*-----------------------------------------------------------*/ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __clz( ( uxReadyPriorities ) ) ) + #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __clz( ( uxReadyPriorities ) ) ) #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ /* Task function macros as described on the FreeRTOS.org WEB site. */ -#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) -#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) +#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void *pvParameters) +#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters) #endif /* __PORTMACRO_H__ */ + diff --git a/portable/CCS/MSP430X/data_model.h b/portable/CCS/MSP430X/data_model.h index 6a0787cf8..fcfcfabb7 100644 --- a/portable/CCS/MSP430X/data_model.h +++ b/portable/CCS/MSP430X/data_model.h @@ -1,48 +1,53 @@ -; /* - * ; * FreeRTOS Kernel V10.3.1 - * ; * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * ; * - * ; * Permission is hereby granted, free of charge, to any person obtaining a copy of - * ; * this software and associated documentation files (the "Software"), to deal in - * ; * the Software without restriction, including without limitation the rights to - * ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * ; * the Software, and to permit persons to whom the Software is furnished to do so, - * ; * subject to the following conditions: - * ; * - * ; * The above copyright notice and this permission notice shall be included in all - * ; * copies or substantial portions of the Software. - * ; * - * ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * ; * - * ; * http://www.FreeRTOS.org - * ; * http://aws.amazon.com/freertos - * ; * - * ; * 1 tab == 4 spaces! - * ; */ +;/* +; * FreeRTOS Kernel V10.3.1 +; * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +; * +; * Permission is hereby granted, free of charge, to any person obtaining a copy of +; * this software and associated documentation files (the "Software"), to deal in +; * the Software without restriction, including without limitation the rights to +; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +; * the Software, and to permit persons to whom the Software is furnished to do so, +; * subject to the following conditions: +; * +; * The above copyright notice and this permission notice shall be included in all +; * copies or substantial portions of the Software. +; * +; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +; * +; * http://www.FreeRTOS.org +; * http://aws.amazon.com/freertos +; * +; * 1 tab == 4 spaces! +; */ + + .if $DEFINED( __LARGE_DATA_MODEL__ ) + .define "pushm.a", pushm_x + .define "popm.a", popm_x + .define "push.a", push_x + .define "pop.a", pop_x + .define "mov.a", mov_x + .else + .define "pushm.w", pushm_x + .define "popm.w", popm_x + .define "push.w", push_x + .define "pop.w", pop_x + .define "mov.w", mov_x + .endif + + .if $DEFINED( __LARGE_CODE_MODEL__ ) + .define "calla", call_x + .define "reta", ret_x + .else + .define "call", call_x + .define "ret", ret_x + .endif + + + -.if $DEFINED( __LARGE_DATA_MODEL__ ) - .define "pushm.a", pushm_x - .define "popm.a", popm_x - .define "push.a", push_x - .define "pop.a", pop_x - .define "mov.a", mov_x - .else - .define "pushm.w", pushm_x - .define "popm.w", popm_x - .define "push.w", push_x - .define "pop.w", pop_x - .define "mov.w", mov_x - .endif - .if $DEFINED( __LARGE_CODE_MODEL__ ) - .define "calla", call_x - .define "reta", ret_x - .else - .define "call", call_x - .define "ret", ret_x - .endif diff --git a/portable/CCS/MSP430X/port.c b/portable/CCS/MSP430X/port.c index 6e0d85787..c6abcedfb 100644 --- a/portable/CCS/MSP430X/port.c +++ b/portable/CCS/MSP430X/port.c @@ -30,28 +30,28 @@ #include "task.h" /*----------------------------------------------------------- -* Implementation of functions defined in portable.h for the MSP430X port. -*----------------------------------------------------------*/ + * Implementation of functions defined in portable.h for the MSP430X port. + *----------------------------------------------------------*/ /* Constants required for hardware setup. The tick ISR runs off the ACLK, - * not the MCLK. */ -#define portACLK_FREQUENCY_HZ ( ( TickType_t ) 32768 ) -#define portINITIAL_CRITICAL_NESTING ( ( uint16_t ) 10 ) -#define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x08 ) +not the MCLK. */ +#define portACLK_FREQUENCY_HZ ( ( TickType_t ) 32768 ) +#define portINITIAL_CRITICAL_NESTING ( ( uint16_t ) 10 ) +#define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x08 ) /* We require the address of the pxCurrentTCB variable, but don't want to know - * any details of its type. */ +any details of its type. */ typedef void TCB_t; extern volatile TCB_t * volatile pxCurrentTCB; /* Each task maintains a count of the critical section nesting depth. Each - * time a critical section is entered the count is incremented. Each time a - * critical section is exited the count is decremented - with interrupts only - * being re-enabled if the count is zero. - * - * usCriticalNesting will get set to zero when the scheduler starts, but must - * not be initialised to zero as this will cause problems during the startup - * sequence. */ +time a critical section is entered the count is incremented. Each time a +critical section is exited the count is decremented - with interrupts only +being re-enabled if the count is zero. + +usCriticalNesting will get set to zero when the scheduler starts, but must +not be initialised to zero as this will cause problems during the startup +sequence. */ volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING; /*-----------------------------------------------------------*/ @@ -69,96 +69,94 @@ void vPortSetupTimerInterrupt( void ); * * See the header file portable.h. */ -StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, - TaskFunction_t pxCode, - void * pvParameters ) +StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) { - uint16_t * pusTopOfStack; - uint32_t * pulTopOfStack, ulTemp; +uint16_t *pusTopOfStack; +uint32_t *pulTopOfStack, ulTemp; - /* - * Place a few bytes of known values on the bottom of the stack. - * This is just useful for debugging and can be included if required. - * - * pxTopOfStack = ( StackType_t ) 0x1111; - * pxTopOfStack--; - * pxTopOfStack = ( StackType_t ) 0x2222; - * pxTopOfStack--; - * pxTopOfStack = ( StackType_t ) 0x3333; - * pxTopOfStack--; - */ + /* + Place a few bytes of known values on the bottom of the stack. + This is just useful for debugging and can be included if required. - /* Data types are need either 16 bits or 32 bits depending on the data - * and code model used. */ - if( sizeof( pxCode ) == sizeof( uint16_t ) ) - { - pusTopOfStack = ( uint16_t * ) pxTopOfStack; - ulTemp = ( uint32_t ) pxCode; - *pusTopOfStack = ( uint16_t ) ulTemp; - } - else - { - /* Make room for a 20 bit value stored as a 32 bit value. */ - pusTopOfStack = ( uint16_t * ) pxTopOfStack; - pusTopOfStack--; - pulTopOfStack = ( uint32_t * ) pusTopOfStack; - *pulTopOfStack = ( uint32_t ) pxCode; - } + *pxTopOfStack = ( StackType_t ) 0x1111; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x2222; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x3333; + pxTopOfStack--; + */ - pusTopOfStack--; - *pusTopOfStack = portFLAGS_INT_ENABLED; - pusTopOfStack -= ( sizeof( StackType_t ) / 2 ); + /* Data types are need either 16 bits or 32 bits depending on the data + and code model used. */ + if( sizeof( pxCode ) == sizeof( uint16_t ) ) + { + pusTopOfStack = ( uint16_t * ) pxTopOfStack; + ulTemp = ( uint32_t ) pxCode; + *pusTopOfStack = ( uint16_t ) ulTemp; + } + else + { + /* Make room for a 20 bit value stored as a 32 bit value. */ + pusTopOfStack = ( uint16_t * ) pxTopOfStack; + pusTopOfStack--; + pulTopOfStack = ( uint32_t * ) pusTopOfStack; + *pulTopOfStack = ( uint32_t ) pxCode; + } - /* From here on the size of stacked items depends on the memory model. */ - pxTopOfStack = ( StackType_t * ) pusTopOfStack; + pusTopOfStack--; + *pusTopOfStack = portFLAGS_INT_ENABLED; + pusTopOfStack -= ( sizeof( StackType_t ) / 2 ); + + /* From here on the size of stacked items depends on the memory model. */ + pxTopOfStack = ( StackType_t * ) pusTopOfStack; - /* Next the general purpose registers. */ - #ifdef PRELOAD_REGISTER_VALUES - *pxTopOfStack = ( StackType_t ) 0xffff; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0xeeee; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0xdddd; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) pvParameters; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0xbbbb; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0xaaaa; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x9999; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x8888; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x5555; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x6666; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x5555; - pxTopOfStack--; - *pxTopOfStack = ( StackType_t ) 0x4444; - pxTopOfStack--; - #else /* ifdef PRELOAD_REGISTER_VALUES */ - pxTopOfStack -= 3; - *pxTopOfStack = ( StackType_t ) pvParameters; - pxTopOfStack -= 9; - #endif /* ifdef PRELOAD_REGISTER_VALUES */ + /* Next the general purpose registers. */ + #ifdef PRELOAD_REGISTER_VALUES + *pxTopOfStack = ( StackType_t ) 0xffff; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0xeeee; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0xdddd; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) pvParameters; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0xbbbb; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0xaaaa; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x9999; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x8888; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x5555; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x6666; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x5555; + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) 0x4444; + pxTopOfStack--; + #else + pxTopOfStack -= 3; + *pxTopOfStack = ( StackType_t ) pvParameters; + pxTopOfStack -= 9; + #endif - /* A variable is used to keep track of the critical section nesting. - * This variable has to be stored as part of the task context and is - * initially set to zero. */ - *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING; + /* A variable is used to keep track of the critical section nesting. + This variable has to be stored as part of the task context and is + initially set to zero. */ + *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING; - /* Return a pointer to the top of the stack we have generated so this can - * be stored in the task control block for the task. */ - return pxTopOfStack; + /* Return a pointer to the top of the stack we have generated so this can + be stored in the task control block for the task. */ + return pxTopOfStack; } /*-----------------------------------------------------------*/ void vPortEndScheduler( void ) { - /* It is unlikely that the MSP430 port will get stopped. If required simply - * disable the tick interrupt here. */ + /* It is unlikely that the MSP430 port will get stopped. If required simply + disable the tick interrupt here. */ } /*-----------------------------------------------------------*/ @@ -167,21 +165,23 @@ void vPortEndScheduler( void ) */ void vPortSetupTimerInterrupt( void ) { - vApplicationSetupTimerInterrupt(); + vApplicationSetupTimerInterrupt(); } /*-----------------------------------------------------------*/ #pragma vector=configTICK_VECTOR interrupt void vTickISREntry( void ) { - extern void vPortTickISR( void ); +extern void vPortTickISR( void ); - __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF ); - #if configUSE_PREEMPTION == 1 - extern void vPortPreemptiveTickISR( void ); - vPortPreemptiveTickISR(); - #else - extern void vPortCooperativeTickISR( void ); - vPortCooperativeTickISR(); - #endif + __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF ); + #if configUSE_PREEMPTION == 1 + extern void vPortPreemptiveTickISR( void ); + vPortPreemptiveTickISR(); + #else + extern void vPortCooperativeTickISR( void ); + vPortCooperativeTickISR(); + #endif } + + diff --git a/portable/CCS/MSP430X/portmacro.h b/portable/CCS/MSP430X/portmacro.h index 78612e3e6..ca2f02fe1 100644 --- a/portable/CCS/MSP430X/portmacro.h +++ b/portable/CCS/MSP430X/portmacro.h @@ -42,72 +42,72 @@ #include "msp430.h" /* Type definitions. */ -#define portCHAR char -#define portFLOAT float -#define portDOUBLE double -#define portLONG long -#define portSHORT int -#define portBASE_TYPE portSHORT +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT int +#define portBASE_TYPE portSHORT /* The stack type changes depending on the data model. */ #ifdef __LARGE_DATA_MODEL__ - #define portSTACK_TYPE uint32_t + #define portSTACK_TYPE uint32_t #else - #define portSTACK_TYPE uint16_t - #define portPOINTER_SIZE_TYPE uint16_t + #define portSTACK_TYPE uint16_t + #define portPOINTER_SIZE_TYPE uint16_t #endif -typedef portSTACK_TYPE StackType_t; -typedef short BaseType_t; -typedef unsigned short UBaseType_t; +typedef portSTACK_TYPE StackType_t; +typedef short BaseType_t; +typedef unsigned short UBaseType_t; -#if ( configUSE_16_BIT_TICKS == 1 ) - typedef uint16_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffff +#if( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff #else - typedef uint32_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL #endif /*-----------------------------------------------------------*/ /* Interrupt control macros. */ -#define portDISABLE_INTERRUPTS() _disable_interrupt(); _nop() -#define portENABLE_INTERRUPTS() _enable_interrupt(); _nop() +#define portDISABLE_INTERRUPTS() _disable_interrupt(); _nop() +#define portENABLE_INTERRUPTS() _enable_interrupt(); _nop() /*-----------------------------------------------------------*/ /* Critical section control macros. */ -#define portNO_CRITICAL_SECTION_NESTING ( ( uint16_t ) 0 ) +#define portNO_CRITICAL_SECTION_NESTING ( ( uint16_t ) 0 ) -#define portENTER_CRITICAL() \ - { \ - extern volatile uint16_t usCriticalNesting; \ - \ - portDISABLE_INTERRUPTS(); \ - \ - /* Now interrupts are disabled usCriticalNesting can be accessed */ \ - /* directly. Increment ulCriticalNesting to keep a count of how many */ \ - /* times portENTER_CRITICAL() has been called. */ \ - usCriticalNesting++; \ - } +#define portENTER_CRITICAL() \ +{ \ +extern volatile uint16_t usCriticalNesting; \ + \ + portDISABLE_INTERRUPTS(); \ + \ + /* Now interrupts are disabled usCriticalNesting can be accessed */ \ + /* directly. Increment ulCriticalNesting to keep a count of how many */ \ + /* times portENTER_CRITICAL() has been called. */ \ + usCriticalNesting++; \ +} -#define portEXIT_CRITICAL() \ - { \ - extern volatile uint16_t usCriticalNesting; \ - \ - if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING ) \ - { \ - /* Decrement the nesting count as we are leaving a critical section. */ \ - usCriticalNesting--; \ - \ - /* If the nesting level has reached zero then interrupts should be */ \ - /* re-enabled. */ \ - if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \ - { \ - portENABLE_INTERRUPTS(); \ - } \ - } \ - } +#define portEXIT_CRITICAL() \ +{ \ +extern volatile uint16_t usCriticalNesting; \ + \ + if( usCriticalNesting > portNO_CRITICAL_SECTION_NESTING ) \ + { \ + /* Decrement the nesting count as we are leaving a critical section. */ \ + usCriticalNesting--; \ + \ + /* If the nesting level has reached zero then interrupts should be */ \ + /* re-enabled. */ \ + if( usCriticalNesting == portNO_CRITICAL_SECTION_NESTING ) \ + { \ + portENABLE_INTERRUPTS(); \ + } \ + } \ +} /*-----------------------------------------------------------*/ /* Task utilities. */ @@ -116,27 +116,28 @@ typedef unsigned short UBaseType_t; * Manual context switch called by portYIELD or taskYIELD. */ extern void vPortYield( void ); -#define portYIELD() vPortYield() +#define portYIELD() vPortYield() /*-----------------------------------------------------------*/ /* Hardware specifics. */ -#define portBYTE_ALIGNMENT 2 -#define portSTACK_GROWTH ( -1 ) -#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) -#define portNOP() __no_operation() +#define portBYTE_ALIGNMENT 2 +#define portSTACK_GROWTH ( -1 ) +#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) +#define portNOP() __no_operation() /*-----------------------------------------------------------*/ /* Task function macros as described on the FreeRTOS.org WEB site. */ -#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) -#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) extern void vTaskSwitchContext( void ); -#define portYIELD_FROM_ISR( x ) if( x ) vPortYield() +#define portYIELD_FROM_ISR( x ) if( x ) vPortYield() void vApplicationSetupTimerInterrupt( void ); /* sizeof( int ) != sizeof( long ) so a full printf() library is required if - * run time stats information is to be displayed. */ +run time stats information is to be displayed. */ #define portLU_PRINTF_SPECIFIER_REQUIRED #endif /* PORTMACRO_H */ +