]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_Kinetis_K60_Tower_IAR/main_blinky.c
Add lwIP V1.4.0 source files.
[freertos] / Demo / CORTEX_Kinetis_K60_Tower_IAR / main_blinky.c
index 30adfece2813870a2db39b0662138283717e8865..bf91b4c29849e413789043b71ecdc0f154afcf27 100644 (file)
@@ -65,8 +65,9 @@
  * one queue, and one timer.  It also demonstrates how Cortex-M3 interrupts can\r
  * interact with FreeRTOS tasks/timers.\r
  *\r
- * This simple demo project runs on the SK-FM3-100PMC evaluation board, which\r
- * is populated with an MB9B500 microcontroller.\r
+ * This simple demo project runs 'stand alone' (without the rest of the tower\r
+ * system) on the TWR-K60N512 tower module, which is populated with a K60N512\r
+ * Cortex-M4 microcontroller.\r
  *\r
  * The idle hook function:\r
  * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
  * in this file.  prvQueueReceiveTask() sits in a loop that causes it to\r
  * repeatedly attempt to read data from the queue that was created within\r
  * main().  When data is received, the task checks the value of the data, and\r
- * if the value equals the expected 100, toggles an LED on the 7 segment\r
- * display.  The 'block time' parameter passed to the queue receive function\r
- * specifies that the task should be held in the Blocked state indefinitely to\r
- * wait for data to be available on the queue.  The queue receive task will only\r
- * leave the Blocked state when the queue send task writes to the queue.  As the\r
- * queue send task writes to the queue every 200 milliseconds, the queue receive\r
- * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
- * the LED every 200 milliseconds.\r
+ * if the value equals the expected 100, toggles the blue LED.  The 'block \r
+ * time' parameter passed to the queue receive function specifies that the task \r
+ * should be held in the Blocked state indefinitely to wait for data to be \r
+ * available on the queue.  The queue receive task will only leave the Blocked \r
+ * state when the queue send task writes to the queue.  As the queue send task \r
+ * writes to the queue every 200 milliseconds, the queue receive task leaves the \r
+ * Blocked state every 200 milliseconds, and therefore toggles the blue LED \r
+ * every 200 milliseconds.\r
  *\r
  * The LED Software Timer and the Button Interrupt:\r
  * The user button SW2 is configured to generate an interrupt each time it is\r
- * pressed.  The interrupt service routine switches an LED in the 7 segment\r
- * display on, and resets the LED software timer.  The LED timer has a 5000\r
- * millisecond (5 second) period, and uses a callback function that is defined\r
- * to just turn the LED off again.  Therefore, pressing the user button will\r
- * turn the LED on, and the LED will remain on until a full five seconds pass\r
- * without the button being pressed.\r
+ * pressed.  The interrupt service routine switches the green LED on, and \r
+ * resets the LED software timer.  The LED timer has a 5000 millisecond (5 \r
+ * second) period, and uses a callback function that is defined to just turn the \r
+ * LED off again.  Therefore, pressing the user button will turn the LED on, and \r
+ * the LED will remain on until a full five seconds pass without the button \r
+ * being pressed.\r
  */\r
 \r
 /* Kernel includes. */\r
 converted to ticks using the portTICK_RATE_MS constant. */\r
 #define mainQUEUE_SEND_FREQUENCY_MS                    ( 200 / portTICK_RATE_MS )\r
 \r
+/* The LED will remain on until the button has not been pushed for a full\r
+5000ms. */\r
+#define mainBUTTON_LED_TIMER_PERIOD_MS         ( 5000UL / portTICK_RATE_MS )\r
+\r
 /* The number of items the queue can hold.  This is 1 as the receive task\r
 will remove items as they are added, meaning the send task should always find\r
 the queue empty. */\r
 #define mainQUEUE_LENGTH                                       ( 1 )\r
 \r
 /* The LED toggle by the queue receive task (blue). */\r
-#define mainTASK_CONTROLLED_LED                                10\r
+#define mainTASK_CONTROLLED_LED                                ( 1UL << 10UL )\r
 \r
-/* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
-#define mainTIMER_CONTROLLED_LED                       29\r
+/* The LED turned on by the button interrupt, and turned off by the LED timer\r
+(green). */\r
+#define mainTIMER_CONTROLLED_LED                       ( 1UL << 29UL )\r
 \r
-#define mainGPIO_E_VECTOR                                      ( 107 - 16 )\r
+/* The vector used by the GPIO port E.  Button SW2 is configured to generate\r
+an interrupt on this port. */\r
+#define mainGPIO_E_VECTOR                                      ( 91 )\r
 \r
-#define GPIO_PIN_MASK            0x1Fu\r
-#define GPIO_PIN( x )              ( ( ( 1 ) << ( x & GPIO_PIN_MASK ) ) )\r
+/* A block time of zero simply means "don't block". */\r
+#define mainDONT_BLOCK                                         ( 0UL )\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -157,16 +165,16 @@ static void prvQueueSendTask( void *pvParameters );
  * The LED timer callback function.  This does nothing but switch off the\r
  * LED defined by the mainTIMER_CONTROLLED_LED constant.\r
  */\r
-static void vLEDTimerCallback( xTimerHandle xTimer );\r
+static void prvButtonLEDTimerCallback( xTimerHandle xTimer );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /* The queue used by both tasks. */\r
 static xQueueHandle xQueue = NULL;\r
 \r
-/* The LED software timer.  This uses vLEDTimerCallback() as its callback\r
+/* The LED software timer.  This uses prvButtonLEDTimerCallback() as its callback\r
 function. */\r
-static xTimerHandle xLEDTimer = NULL;\r
+static xTimerHandle xButtonLEDTimer = NULL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -188,11 +196,11 @@ void main( void )
                /* Create the software timer that is responsible for turning off the LED\r
                if the button is not pushed within 5000ms, as described at the top of\r
                this file. */\r
-               xLEDTimer = xTimerCreate(       ( const signed char * ) "LEDTimer", /* A text name, purely to help debugging. */\r
-                                                                       ( 5000 / portTICK_RATE_MS ),            /* The timer period, in this case 5000ms (5s). */\r
-                                                                       pdFALSE,                                                        /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
-                                                                       ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
-                                                                       vLEDTimerCallback                                       /* The callback function that switches the LED off. */\r
+               xButtonLEDTimer = xTimerCreate( ( const signed char * ) "ButtonLEDTimer", /* A text name, purely to help debugging. */\r
+                                                                       mainBUTTON_LED_TIMER_PERIOD_MS,                 /* The timer period, in this case 5000ms (5s). */\r
+                                                                       pdFALSE,                                                                /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
+                                                                       ( void * ) 0,                                                   /* The ID is not used, so can be set to anything. */\r
+                                                                       prvButtonLEDTimerCallback                               /* The callback function that switches the LED off. */\r
                                                                );\r
 \r
                /* Start the tasks and timer running. */\r
@@ -208,14 +216,11 @@ void main( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void vLEDTimerCallback( xTimerHandle xTimer )\r
+static void prvButtonLEDTimerCallback( xTimerHandle xTimer )\r
 {\r
        /* The timer has expired - so no button pushes have occurred in the last\r
-       five seconds - turn the LED off.  NOTE - accessing the LED port should use\r
-       a critical section because it is accessed from multiple tasks, and the\r
-       button interrupt - in this trivial case, for simplicity, the critical\r
-       section is omitted. */\r
-       GPIOA_PDOR |= GPIO_PDOR_PDO( GPIO_PIN( mainTIMER_CONTROLLED_LED ) );\r
+       five seconds - turn the LED off. */\r
+       GPIOA_PSOR = mainTIMER_CONTROLLED_LED;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -227,15 +232,14 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
        /* The button was pushed, so ensure the LED is on before resetting the\r
        LED timer.  The LED timer will turn the LED off if the button is not\r
        pushed within 5000ms. */\r
-       GPIOA_PDOR &= ~GPIO_PDOR_PDO( GPIO_PIN( mainTIMER_CONTROLLED_LED ) );\r
+       GPIOA_PCOR = mainTIMER_CONTROLLED_LED;\r
 \r
        /* This interrupt safe FreeRTOS function can be called from this interrupt\r
        because the interrupt priority is below the\r
-       configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
-       xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );\r
+       configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
+       xTimerResetFromISR( xButtonLEDTimer, &xHigherPriorityTaskWoken );\r
 \r
-       /* Clear the interrupt before leaving.  This just clears all the interrupts\r
-       for simplicity, as only one is actually used in this simple demo anyway. */\r
+       /* Clear the interrupt before leaving. */\r
        PORTE_ISFR = 0xFFFFFFFFUL;\r
 \r
        /* If calling xTimerResetFromISR() caused a task (in this case the timer\r
@@ -267,7 +271,7 @@ const unsigned long ulValueToSend = 100UL;
                toggle an LED.  0 is used as the block time so the sending operation\r
                will not block - it shouldn't need to block as the queue should always\r
                be empty at this point in the code. */\r
-               xQueueSend( xQueue, &ulValueToSend, 0 );\r
+               xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -287,11 +291,7 @@ unsigned long ulReceivedValue;
                is it the expected value?  If it is, toggle the LED. */\r
                if( ulReceivedValue == 100UL )\r
                {\r
-                       /* NOTE - accessing the LED port should use a critical section\r
-                       because it is accessed from multiple tasks, and the button interrupt\r
-                       - in this trivial case, for simplicity, the critical section is\r
-                       omitted. */\r
-                   GPIOA_PTOR |= GPIO_PDOR_PDO( GPIO_PIN( mainTASK_CONTROLLED_LED ) );\r
+                   GPIOA_PTOR = mainTASK_CONTROLLED_LED;\r
                }\r
        }\r
 }\r
@@ -299,14 +299,14 @@ unsigned long ulReceivedValue;
 \r
 static void prvSetupHardware( void )\r
 {\r
-       /* Turn on all port clocks */\r
-       SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;\r
-\r
        /* Enable the interrupt on SW1. */\r
        PORTE_PCR26 = PORT_PCR_MUX( 1 ) | PORT_PCR_IRQC( 0xA ) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;\r
-\r
        enable_irq( mainGPIO_E_VECTOR );\r
        \r
+       /* The interrupt calls an interrupt safe API function - so its priority must\r
+       be equal to or lower than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. */\r
+       set_irq_priority( mainGPIO_E_VECTOR, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
+       \r
        /* Set PTA10, PTA11, PTA28, and PTA29 (connected to LED's) for GPIO\r
        functionality. */\r
        PORTA_PCR10 = ( 0 | PORT_PCR_MUX( 1 ) );\r
@@ -314,8 +314,8 @@ static void prvSetupHardware( void )
        PORTA_PCR28 = ( 0 | PORT_PCR_MUX( 1 ) );\r
        PORTA_PCR29 = ( 0 | PORT_PCR_MUX( 1 ) );\r
        \r
-       /* Change PTA10, PTA11, PTA28, PTA29 to outputs. */\r
-       GPIOA_PDDR=GPIO_PDDR_PDD( GPIO_PIN( mainTASK_CONTROLLED_LED ) | GPIO_PIN( mainTIMER_CONTROLLED_LED ) ); \r
+       /* Change PTA10, PTA29 to outputs. */\r
+       GPIOA_PDDR=GPIO_PDDR_PDD( mainTASK_CONTROLLED_LED | mainTIMER_CONTROLLED_LED ); \r
 \r
        /* Start with LEDs off. */\r
        GPIOA_PTOR = ~0U;\r
@@ -329,6 +329,7 @@ void vApplicationMallocFailedHook( void )
        internally by FreeRTOS API functions that create tasks, queues, software\r
        timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
        configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
+       taskDISABLE_INTERRUPTS();\r
        for( ;; );\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -339,21 +340,13 @@ void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName
        ( void ) pxTask;\r
 \r
        /* Run time stack overflow checking is performed if\r
-       configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
+       configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
        function is called if a stack overflow is detected. */\r
+       taskDISABLE_INTERRUPTS();\r
        for( ;; );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationTickHook( void )\r
-{\r
-       /* A tick hook is used by the "Full" build configuration.  The Full and\r
-       blinky build configurations share a FreeRTOSConfig.h header file, so this\r
-       simple build configuration also has to define a tick hook - even though it\r
-       does not actually use it for anything. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
 void vApplicationIdleHook( void )\r
 {\r
 volatile size_t xFreeHeapSpace;\r
@@ -373,6 +366,30 @@ volatile size_t xFreeHeapSpace;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+/* The Blinky build configuration does not include Ethernet functionality,\r
+however, the Full and Blinky build configurations share a vectors.h header file.\r
+Therefore, dummy Ethernet interrupt handers need to be defined to keep the\r
+linker happy. */\r
+void vEMAC_TxISRHandler( void ) {}\r
+void vEMAC_RxISRHandler( void ){}\r
+void vEMAC_ErrorISRHandler( void ) {}\r
+\r
+/* The Blinky build configuration does not include run time stats gathering,\r
+however, the Full and Blinky build configurations share a FreeRTOSConfig.h\r
+file.  Therefore, dummy run time stats functions need to be defined to keep the\r
+linker happy. */\r
+void vMainConfigureTimerForRunTimeStats( void ) {}\r
+unsigned long ulMainGetRunTimeCounterValue( void ) { return 0UL; }\r
+\r
+/* A tick hook is used by the "Full" build configuration.  The Full and blinky \r
+build configurations share a FreeRTOSConfig.h header file, so this simple build \r
+configuration also has to define a tick hook - even though it does not actually \r
+use it for anything. */\r
+void vApplicationTickHook( void ) {}\r
+\r
+\r
+\r
+\r
 \r
 \r
 \r