- with commercial development and support options.
- ***************************************************************************
-*/
-
-#include <stdlib.h>
-
-#include "FreeRTOS.h"
-#include "FreeRTOSConfig.h"
-#include "task.h"
-
-/* ------------------------ Types ----------------------------------------- */
-typedef volatile unsigned long vuint32;
-typedef volatile unsigned short vuint16;
-typedef volatile unsigned char vuint8;
-
-/* ------------------------ Defines --------------------------------------- */
-#define portVECTOR_TABLE __RAMVEC
-#define portVECTOR_SYSCALL ( 32 + portTRAP_YIELD )
-#define portVECTOR_TIMER ( 64 + 36 )
-
-#define MCF_PIT_PRESCALER 512UL
-#define MCF_PIT_TIMER_TICKS ( FSYS_2 / MCF_PIT_PRESCALER )
-#define MCF_PIT_MODULUS_REGISTER(freq) ( MCF_PIT_TIMER_TICKS / ( freq ) - 1UL)
-
-#define MCF_PIT_PMR0 ( *( vuint16 * )( void * )( &__IPSBAR[ 0x150002 ] ) )
-#define MCF_PIT_PCSR0 ( *( vuint16 * )( void * )( &__IPSBAR[ 0x150000 ] ) )
-#define MCF_PIT_PCSR_PRE(x) ( ( ( x ) & 0x000F ) << 8 )
-#define MCF_PIT_PCSR_EN ( 0x0001 )
-#define MCF_PIT_PCSR_RLD ( 0x0002 )
-#define MCF_PIT_PCSR_PIF ( 0x0004 )
-#define MCF_PIT_PCSR_PIE ( 0x0008 )
-#define MCF_PIT_PCSR_OVW ( 0x0010 )
-#define MCF_INTC0_ICR36 ( *( vuint8 * )( void * )( &__IPSBAR[ 0x000C64 ] ) )
-#define MCF_INTC0_IMRH ( *( vuint32 * )( void * )( &__IPSBAR[ 0x000C08 ] ) )
-#define MCF_INTC0_IMRH_INT_MASK36 ( 0x00000010 )
-#define MCF_INTC0_IMRH_MASKALL ( 0x00000001 )
-#define MCF_INTC0_ICRn_IP(x) ( ( ( x ) & 0x07 ) << 0 )
-#define MCF_INTC0_ICRn_IL(x) ( ( ( x ) & 0x07 ) << 3 )
-
-#define portNO_CRITICAL_NESTING ( ( unsigned portLONG ) 0 )
-#define portINITIAL_CRITICAL_NESTING ( ( unsigned portLONG ) 10 )
-
-/* ------------------------ Static variables ------------------------------ */
-volatile unsigned portLONG ulCriticalNesting = portINITIAL_CRITICAL_NESTING;
-
-/* ------------------------ Static functions ------------------------------ */
-#if configUSE_PREEMPTION == 0
-static void prvPortPreemptiveTick ( void ) __attribute__ ((interrupt_handler));
-#else
-static void prvPortPreemptiveTick ( void );
-#endif
-
-/* ------------------------ Start implementation -------------------------- */
-
-portSTACK_TYPE *
-pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode,
- void *pvParameters )
-{
- /* Place the parameter on the stack in the expected location. */
- *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
- pxTopOfStack--;
-
- /* Place dummy return address on stack. Tasks should never terminate so
- * we can set this to anything. */
- *pxTopOfStack = ( portSTACK_TYPE ) 0;
- pxTopOfStack--;
-
- /* Create a Motorola Coldfire exception stack frame. First comes the return
- * address. */
- *pxTopOfStack = ( portSTACK_TYPE ) pxCode;
- pxTopOfStack--;
-
- /* Format, fault-status, vector number for exception stack frame. Task
- * run in supervisor mode. */
- *pxTopOfStack = 0x40002000UL | ( portVECTOR_SYSCALL + 32 ) << 18;
- pxTopOfStack--;
-
- /* Set the initial critical section nesting counter to zero. This value
- * is used to restore the value of ulCriticalNesting. */
- *pxTopOfStack = 0;
- *pxTopOfStack--;
-
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA6; /* A6 / FP */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA5; /* A5 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA4; /* A4 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA3; /* A3 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA2; /* A2 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA1; /* A1 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xA0; /* A0 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD7; /* D7 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD6; /* D6 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD5; /* D5 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD4; /* D4 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD3; /* D3 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD2; /* D2 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD1; /* D1 */
- pxTopOfStack--;
- *pxTopOfStack = ( portSTACK_TYPE ) 0xD0; /* D0 */
-
- return pxTopOfStack;
-}
-
-/*
- * Called by portYIELD() or taskYIELD() to manually force a context switch.
- */
-static void
-prvPortYield( void )
-{
- asm volatile ( "move.w #0x2700, %sr\n\t" );
-#if _GCC_USES_FP == 1
- asm volatile ( "unlk %fp\n\t" );
-#endif
- /* Perform the context switch. First save the context of the current task. */
- portSAVE_CONTEXT( );
-
- /* Find the highest priority task that is ready to run. */
- vTaskSwitchContext( );
-
- /* Restore the context of the new task. */
- portRESTORE_CONTEXT( );
-}
-
-#if configUSE_PREEMPTION == 0
-/*
- * The ISR used for the scheduler tick depends on whether the cooperative or
- * the preemptive scheduler is being used.
- */
-static void
-prvPortPreemptiveTick ( void )
-{
- /* The cooperative scheduler requires a normal IRQ service routine to
- * simply increment the system tick.
- */
-
- vTaskIncrementTick( );
- MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIF;
-}
-
-#else
-
-static void
-prvPortPreemptiveTick( void )
-{
- asm volatile ( "move.w #0x2700, %sr\n\t" );
-#if _GCC_USES_FP == 1
- asm volatile ( "unlk %fp\n\t" );
-#endif
- portSAVE_CONTEXT( );
- MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIF;
- vTaskIncrementTick( );
- vTaskSwitchContext( );
- portRESTORE_CONTEXT( );
-}
-#endif
-
-void
-vPortEnterCritical()
-{
- /* FIXME: We should store the old IPL here - How are we supposed to do
- * this.
- */
- ( void )portSET_IPL( portIPL_MAX );
-
- /* 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++;
-}
-
-void
-vPortExitCritical()
-{
- if( ulCriticalNesting > portNO_CRITICAL_NESTING )
- {
- /* 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 == portNO_CRITICAL_NESTING )
- {
- ( void )portSET_IPL( 0 );
- }
- }
-}
-
-portBASE_TYPE
-xPortStartScheduler( void )
-{
- extern void ( *portVECTOR_TABLE[ ] ) ( );
-
- /* Add entry in vector table for yield system call. */
- portVECTOR_TABLE[ portVECTOR_SYSCALL ] = prvPortYield;
- /* Add entry in vector table for periodic timer. */
- portVECTOR_TABLE[ portVECTOR_TIMER ] = prvPortPreemptiveTick;
-
- /* Configure the timer for the system clock. */
- if ( configTICK_RATE_HZ > 0)
- {
- /* Configure prescaler */
- MCF_PIT_PCSR0 = MCF_PIT_PCSR_PRE( 0x9 ) | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_OVW;
- /* Initialize the periodic timer interrupt. */
- MCF_PIT_PMR0 = MCF_PIT_MODULUS_REGISTER( configTICK_RATE_HZ );
- /* Configure interrupt priority and level and unmask interrupt. */
- MCF_INTC0_ICR36 = MCF_INTC0_ICRn_IL( 0x1 ) | MCF_INTC0_ICRn_IP( 0x1 );
- MCF_INTC0_IMRH &= ~( MCF_INTC0_IMRH_INT_MASK36 | MCF_INTC0_IMRH_MASKALL );
- /* Enable interrupts */
- MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_EN | MCF_PIT_PCSR_PIF;
- }
-
- /* Restore the context of the first task that is going to run. */
- portRESTORE_CONTEXT( );
-
- /* Should not get here. */
- return pdTRUE;
-}
-
-void
-vPortEndScheduler( void )
-{
-}
+ with commercial development and support options.\r
+ ***************************************************************************\r
+*/\r
+\r
+#include <stdlib.h>\r
+\r
+#include "FreeRTOS.h"\r
+#include "FreeRTOSConfig.h"\r
+#include "task.h"\r
+\r
+/* ------------------------ Types ----------------------------------------- */\r
+typedef volatile unsigned long vuint32;\r
+typedef volatile unsigned short vuint16;\r
+typedef volatile unsigned char vuint8;\r
+\r
+/* ------------------------ Defines --------------------------------------- */\r
+#define portVECTOR_TABLE __RAMVEC\r
+#define portVECTOR_SYSCALL ( 32 + portTRAP_YIELD )\r
+#define portVECTOR_TIMER ( 64 + 36 )\r
+\r
+#define MCF_PIT_PRESCALER 512UL\r
+#define MCF_PIT_TIMER_TICKS ( FSYS_2 / MCF_PIT_PRESCALER )\r
+#define MCF_PIT_MODULUS_REGISTER(freq) ( MCF_PIT_TIMER_TICKS / ( freq ) - 1UL)\r
+\r
+#define MCF_PIT_PMR0 ( *( vuint16 * )( void * )( &__IPSBAR[ 0x150002 ] ) )\r
+#define MCF_PIT_PCSR0 ( *( vuint16 * )( void * )( &__IPSBAR[ 0x150000 ] ) )\r
+#define MCF_PIT_PCSR_PRE(x) ( ( ( x ) & 0x000F ) << 8 )\r
+#define MCF_PIT_PCSR_EN ( 0x0001 )\r
+#define MCF_PIT_PCSR_RLD ( 0x0002 )\r
+#define MCF_PIT_PCSR_PIF ( 0x0004 )\r
+#define MCF_PIT_PCSR_PIE ( 0x0008 )\r
+#define MCF_PIT_PCSR_OVW ( 0x0010 )\r
+#define MCF_INTC0_ICR36 ( *( vuint8 * )( void * )( &__IPSBAR[ 0x000C64 ] ) )\r
+#define MCF_INTC0_IMRH ( *( vuint32 * )( void * )( &__IPSBAR[ 0x000C08 ] ) )\r
+#define MCF_INTC0_IMRH_INT_MASK36 ( 0x00000010 )\r
+#define MCF_INTC0_IMRH_MASKALL ( 0x00000001 )\r
+#define MCF_INTC0_ICRn_IP(x) ( ( ( x ) & 0x07 ) << 0 )\r
+#define MCF_INTC0_ICRn_IL(x) ( ( ( x ) & 0x07 ) << 3 )\r
+\r
+#define portNO_CRITICAL_NESTING ( ( unsigned portLONG ) 0 )\r
+#define portINITIAL_CRITICAL_NESTING ( ( unsigned portLONG ) 10 )\r
+\r
+/* ------------------------ Static variables ------------------------------ */\r
+volatile unsigned portLONG ulCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
+\r
+/* ------------------------ Static functions ------------------------------ */\r
+#if configUSE_PREEMPTION == 0\r
+static void prvPortPreemptiveTick ( void ) __attribute__ ((interrupt_handler));\r
+#else\r
+static void prvPortPreemptiveTick ( void );\r
+#endif\r
+\r
+/* ------------------------ Start implementation -------------------------- */\r
+\r
+portSTACK_TYPE *\r
+pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode,\r
+ void *pvParameters )\r
+{\r
+ /* Place the parameter on the stack in the expected location. */\r
+ *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
+ pxTopOfStack--;\r
+\r
+ /* Place dummy return address on stack. Tasks should never terminate so\r
+ * we can set this to anything. */\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0;\r
+ pxTopOfStack--;\r
+\r
+ /* Create a Motorola Coldfire exception stack frame. First comes the return\r
+ * address. */\r
+ *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
+ pxTopOfStack--;\r
+\r
+ /* Format, fault-status, vector number for exception stack frame. Task\r
+ * run in supervisor mode. */\r
+ *pxTopOfStack = 0x40002000UL | ( portVECTOR_SYSCALL + 32 ) << 18;\r
+ pxTopOfStack--;\r
+\r
+ /* Set the initial critical section nesting counter to zero. This value\r
+ * is used to restore the value of ulCriticalNesting. */\r
+ *pxTopOfStack = 0;\r
+ *pxTopOfStack--;\r
+\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA6; /* A6 / FP */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA5; /* A5 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA4; /* A4 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA3; /* A3 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA2; /* A2 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA1; /* A1 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xA0; /* A0 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD7; /* D7 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD6; /* D6 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD5; /* D5 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD4; /* D4 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD3; /* D3 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD2; /* D2 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD1; /* D1 */\r
+ pxTopOfStack--;\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0xD0; /* D0 */\r
+\r
+ return pxTopOfStack;\r
+}\r
+\r
+/*\r
+ * Called by portYIELD() or taskYIELD() to manually force a context switch.\r
+ */\r
+static void\r
+prvPortYield( void )\r
+{\r
+ asm volatile ( "move.w #0x2700, %sr\n\t" );\r
+#if _GCC_USES_FP == 1\r
+ asm volatile ( "unlk %fp\n\t" );\r
+#endif\r
+ /* Perform the context switch. First save the context of the current task. */\r
+ portSAVE_CONTEXT( );\r
+\r
+ /* Find the highest priority task that is ready to run. */\r
+ vTaskSwitchContext( );\r
+\r
+ /* Restore the context of the new task. */\r
+ portRESTORE_CONTEXT( );\r
+}\r
+\r
+#if configUSE_PREEMPTION == 0\r
+/*\r
+ * The ISR used for the scheduler tick depends on whether the cooperative or\r
+ * the preemptive scheduler is being used.\r
+ */\r
+static void\r
+prvPortPreemptiveTick ( void )\r
+{\r
+ /* The cooperative scheduler requires a normal IRQ service routine to\r
+ * simply increment the system tick.\r
+ */\r
+\r
+ vTaskIncrementTick( );\r
+ MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIF;\r
+}\r
+\r
+#else\r
+\r
+static void\r
+prvPortPreemptiveTick( void )\r
+{\r
+ asm volatile ( "move.w #0x2700, %sr\n\t" );\r
+#if _GCC_USES_FP == 1\r
+ asm volatile ( "unlk %fp\n\t" );\r
+#endif\r
+ portSAVE_CONTEXT( );\r
+ MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIF;\r
+ vTaskIncrementTick( );\r
+ vTaskSwitchContext( );\r
+ portRESTORE_CONTEXT( );\r
+}\r
+#endif\r
+\r
+void\r
+vPortEnterCritical()\r
+{\r
+ /* FIXME: We should store the old IPL here - How are we supposed to do\r
+ * this.\r
+ */\r
+ ( void )portSET_IPL( portIPL_MAX );\r
+\r
+ /* Now interrupts are disabled ulCriticalNesting can be accessed\r
+ * directly. Increment ulCriticalNesting to keep a count of how many times\r
+ * portENTER_CRITICAL() has been called. */\r
+ ulCriticalNesting++;\r
+}\r
+\r
+void\r
+vPortExitCritical()\r
+{\r
+ if( ulCriticalNesting > portNO_CRITICAL_NESTING )\r
+ {\r
+ /* Decrement the nesting count as we are leaving a critical section. */\r
+ ulCriticalNesting--;\r
+\r
+ /* If the nesting level has reached zero then interrupts should be\r
+ re-enabled. */\r
+ if( ulCriticalNesting == portNO_CRITICAL_NESTING )\r
+ {\r
+ ( void )portSET_IPL( 0 );\r
+ }\r
+ }\r
+}\r
+\r
+portBASE_TYPE\r
+xPortStartScheduler( void )\r
+{\r
+ extern void ( *portVECTOR_TABLE[ ] ) ( );\r
+\r
+ /* Add entry in vector table for yield system call. */\r
+ portVECTOR_TABLE[ portVECTOR_SYSCALL ] = prvPortYield;\r
+ /* Add entry in vector table for periodic timer. */\r
+ portVECTOR_TABLE[ portVECTOR_TIMER ] = prvPortPreemptiveTick;\r
+\r
+ /* Configure the timer for the system clock. */\r
+ if ( configTICK_RATE_HZ > 0)\r
+ {\r
+ /* Configure prescaler */\r
+ MCF_PIT_PCSR0 = MCF_PIT_PCSR_PRE( 0x9 ) | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_OVW;\r
+ /* Initialize the periodic timer interrupt. */\r
+ MCF_PIT_PMR0 = MCF_PIT_MODULUS_REGISTER( configTICK_RATE_HZ );\r
+ /* Configure interrupt priority and level and unmask interrupt. */\r
+ MCF_INTC0_ICR36 = MCF_INTC0_ICRn_IL( 0x1 ) | MCF_INTC0_ICRn_IP( 0x1 );\r
+ MCF_INTC0_IMRH &= ~( MCF_INTC0_IMRH_INT_MASK36 | MCF_INTC0_IMRH_MASKALL );\r
+ /* Enable interrupts */\r
+ MCF_PIT_PCSR0 |= MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_EN | MCF_PIT_PCSR_PIF;\r
+ }\r
+\r
+ /* Restore the context of the first task that is going to run. */\r
+ portRESTORE_CONTEXT( );\r
+\r
+ /* Should not get here. */\r
+ return pdTRUE;\r
+}\r
+\r
+void\r
+vPortEndScheduler( void )\r
+{\r
+}\r