Francisco Paez / Mbed 2 deprecated frdm_k64f_freertos_lib

Dependencies:   freertos mbed

Committer:
fep
Date:
Wed May 31 02:56:40 2017 +0000
Revision:
0:1937678a6b68
Example program for FRDM-K64F that uses FreeRTOS to create a single periodic task.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fep 0:1937678a6b68 1 #include "mbed.h"
fep 0:1937678a6b68 2 #include "FreeRTOS.h"
fep 0:1937678a6b68 3 #include "task.h"
fep 0:1937678a6b68 4
fep 0:1937678a6b68 5 #define TASK_STACK_SIZE 128
fep 0:1937678a6b68 6
fep 0:1937678a6b68 7 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
fep 0:1937678a6b68 8 * within this file. The extern "C" is required to avoid name mangling between
fep 0:1937678a6b68 9 * C and C++ code.
fep 0:1937678a6b68 10 */
fep 0:1937678a6b68 11 extern "C"
fep 0:1937678a6b68 12 {
fep 0:1937678a6b68 13 #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
fep 0:1937678a6b68 14 void vApplicationMallocFailedHook( void );
fep 0:1937678a6b68 15 #endif
fep 0:1937678a6b68 16 #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
fep 0:1937678a6b68 17 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
fep 0:1937678a6b68 18 #endif
fep 0:1937678a6b68 19 }
fep 0:1937678a6b68 20
fep 0:1937678a6b68 21 DigitalOut led1(LED1);
fep 0:1937678a6b68 22
fep 0:1937678a6b68 23 void task (void*);
fep 0:1937678a6b68 24
fep 0:1937678a6b68 25 int main()
fep 0:1937678a6b68 26 {
fep 0:1937678a6b68 27 led1 = 0;
fep 0:1937678a6b68 28
fep 0:1937678a6b68 29 // Create a task.
fep 0:1937678a6b68 30 xTaskCreate( task, "T01", TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
fep 0:1937678a6b68 31
fep 0:1937678a6b68 32 // Start FreeRTOS scheduler.
fep 0:1937678a6b68 33 vTaskStartScheduler();
fep 0:1937678a6b68 34
fep 0:1937678a6b68 35 // Should never reach here.
fep 0:1937678a6b68 36 for(;;);
fep 0:1937678a6b68 37 }
fep 0:1937678a6b68 38
fep 0:1937678a6b68 39 /*
fep 0:1937678a6b68 40 * Blink LED1 every second (1000 ticks).
fep 0:1937678a6b68 41 */
fep 0:1937678a6b68 42 void task (void *param)
fep 0:1937678a6b68 43 {
fep 0:1937678a6b68 44 TickType_t xPreviousWakeTime = ( TickType_t ) 0U;
fep 0:1937678a6b68 45
fep 0:1937678a6b68 46 for(;;) {
fep 0:1937678a6b68 47 led1 = !led1;
fep 0:1937678a6b68 48
fep 0:1937678a6b68 49 // Delay the task until next period (1 sec)
fep 0:1937678a6b68 50 vTaskDelayUntil( &xPreviousWakeTime, ( TickType_t ) 1000 );
fep 0:1937678a6b68 51 }
fep 0:1937678a6b68 52 }
fep 0:1937678a6b68 53
fep 0:1937678a6b68 54 #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
fep 0:1937678a6b68 55 void vApplicationMallocFailedHook( void )
fep 0:1937678a6b68 56 {
fep 0:1937678a6b68 57 taskDISABLE_INTERRUPTS();
fep 0:1937678a6b68 58
fep 0:1937678a6b68 59 DigitalOut led4(LED4);
fep 0:1937678a6b68 60
fep 0:1937678a6b68 61 for( ;; ) {
fep 0:1937678a6b68 62 led4 = 1;
fep 0:1937678a6b68 63 wait_ms(1000);
fep 0:1937678a6b68 64 led4 = 0;
fep 0:1937678a6b68 65 wait_ms(1000);
fep 0:1937678a6b68 66 }
fep 0:1937678a6b68 67 }
fep 0:1937678a6b68 68 #endif
fep 0:1937678a6b68 69
fep 0:1937678a6b68 70 #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
fep 0:1937678a6b68 71 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
fep 0:1937678a6b68 72 {
fep 0:1937678a6b68 73 ( void ) pcTaskName;
fep 0:1937678a6b68 74 ( void ) pxTask;
fep 0:1937678a6b68 75
fep 0:1937678a6b68 76 taskDISABLE_INTERRUPTS();
fep 0:1937678a6b68 77
fep 0:1937678a6b68 78 DigitalOut led4(LED4);
fep 0:1937678a6b68 79
fep 0:1937678a6b68 80 for( ;; ) {
fep 0:1937678a6b68 81 led4 = 1;
fep 0:1937678a6b68 82 wait_ms(500);
fep 0:1937678a6b68 83 led4 = 0;
fep 0:1937678a6b68 84 wait_ms(500);
fep 0:1937678a6b68 85 }
fep 0:1937678a6b68 86 }
fep 0:1937678a6b68 87 #endif