diff options
| author | hathach <[email protected]> | 2018-08-23 14:11:21 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-08-23 14:11:21 +0700 |
| commit | d18a9e8759fb168a55a2ded6f1f5b9d7db6ea078 (patch) | |
| tree | da682e33448848a793c83d2b542101cb723e13bf /examples/device | |
| parent | 5d365193158c9429ca279ab5f8fa4446bcc9663f (diff) | |
freertos blinky with software timer
Diffstat (limited to 'examples/device')
| -rw-r--r-- | examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject | 47 | ||||
| -rw-r--r-- | examples/device/nrf52840_freertos/src/main.c | 37 | ||||
| -rw-r--r-- | examples/device/nrf52840_freertos/src/tusb_config.h | 4 |
3 files changed, 70 insertions, 18 deletions
diff --git a/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject b/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject index cee328c73..dd9edb8dd 100644 --- a/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject +++ b/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject @@ -20,13 +20,13 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056" - c_user_include_directories="../src;$(tusbDir)/hw/cmsis/Include;$(tusbDir)/hw;$(tusbDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include" + c_user_include_directories="../src;$(tusbDir)/hw/cmsis/Include;$(tusbDir)/hw;$(tusbDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(freertosDir);$(freertosDir)/Source/include;$(freertosDir)/Source/portable/GCC/ARM_CM4F" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_target_connection="J-Link" gcc_entry_point="Reset_Handler" linker_memory_map_file="$(ProjectDir)/nRF52840_xxAA_MemoryMap.xml" linker_section_placement_file="$(ProjectDir)/flash_placement.xml" - macros="DeviceHeaderFile=$(PackagesDir)/nRF/CMSIS/Device/Include/nrf.h;DeviceLibraryIdentifier=M4lf;DeviceSystemFile=$(PackagesDir)/nRF/CMSIS/Device/Source/system_nrf52840.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/ses_nrf52840_Vectors.s;DeviceFamily=nRF;Target=nRF52840_xxAA;Placement=Flash;tusbDir=../../../..;nrfxDir=../../../../hw/mcu/nordic/nrfx" + macros="DeviceHeaderFile=$(PackagesDir)/nRF/CMSIS/Device/Include/nrf.h;DeviceLibraryIdentifier=M4lf;DeviceSystemFile=$(PackagesDir)/nRF/CMSIS/Device/Source/system_nrf52840.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/ses_nrf52840_Vectors.s;DeviceFamily=nRF;Target=nRF52840_xxAA;Placement=Flash;tusbDir=../../../..;nrfxDir=../../../../hw/mcu/nordic/nrfx;freertosDir=../../../../lib/FreeRTOS" project_directory="" project_type="Executable" target_reset_script="Reset();" @@ -103,6 +103,49 @@ </folder> </folder> <configuration Name="Debug" build_treat_warnings_as_errors="Yes" /> + <folder Name="lib"> + <folder Name="FreeRTOS"> + <folder Name="Source"> + <folder Name="include"> + <file file_name="../../../../lib/FreeRTOS/Source/include/croutine.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/deprecated_definitions.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/event_groups.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/FreeRTOS.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/list.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/message_buffer.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/mpu_prototypes.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/mpu_wrappers.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/portable.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/projdefs.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/queue.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/semphr.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/stack_macros.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/StackMacros.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/stream_buffer.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/task.h" /> + <file file_name="../../../../lib/FreeRTOS/Source/include/timers.h" /> + </folder> + <folder Name="portable"> + <folder Name="Common" /> + <folder Name="GCC"> + <folder Name="ARM_CM4F"> + <file file_name="../../../../lib/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c" /> + <file file_name="../../../../lib/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h" /> + </folder> + </folder> + <folder Name="MemMang"> + <file file_name="../../../../lib/FreeRTOS/Source/portable/MemMang/heap_4.c" /> + </folder> + </folder> + <file file_name="../../../../lib/FreeRTOS/Source/list.c" /> + <file file_name="../../../../lib/FreeRTOS/Source/queue.c" /> + <file file_name="../../../../lib/FreeRTOS/Source/tasks.c" /> + <file file_name="../../../../lib/FreeRTOS/Source/timers.c" /> + </folder> + <file file_name="../../../../lib/FreeRTOS/FreeRTOSConfig.h" /> + <file file_name="../../../../lib/FreeRTOS/freertos_hook.c" /> + </folder> + </folder> </project> <configuration Name="Debug" diff --git a/examples/device/nrf52840_freertos/src/main.c b/examples/device/nrf52840_freertos/src/main.c index 9a80accc9..644829a66 100644 --- a/examples/device/nrf52840_freertos/src/main.c +++ b/examples/device/nrf52840_freertos/src/main.c @@ -43,6 +43,12 @@ #include <stdio.h> #include <string.h> +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "queue.h" +#include "semphr.h" + #include "bsp/board.h" #include "tusb.h" @@ -54,27 +60,33 @@ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ void print_greeting(void); -void led_blinking_task(void); +void led_blinky_cb(TimerHandle_t xTimer); void virtual_com_task(void); void usb_hid_task(void); + /*------------- MAIN -------------*/ int main(void) { board_init(); print_greeting(); - tusb_init(); + //tusb_init(); - while (1) - { - tusb_task(); + // soft timer for blinky + TimerHandle_t tm_hdl = xTimerCreate(NULL, pdMS_TO_TICKS(1000), true, NULL, led_blinky_cb); + xTimerStart(tm_hdl, 0); - led_blinking_task(); - virtual_com_task(); + vTaskStartScheduler(); - usb_hid_task(); - } + NVIC_SystemReset(); + +// while (1) +// { +// virtual_com_task(); +// +// usb_hid_task(); +// } return 0; } @@ -173,14 +185,11 @@ void tud_cdc_rx_cb(uint8_t itf) //--------------------------------------------------------------------+ // BLINKING TASK //--------------------------------------------------------------------+ -void led_blinking_task(void) +void led_blinky_cb(TimerHandle_t xTimer) { - static tu_timeout_t tm = { .start = 0, .interval = 1000 }; // Blink every 1000 ms + (void) xTimer; static bool led_state = false; - if ( !tu_timeout_expired(&tm) ) return; // not enough time - tu_timeout_reset(&tm); - board_led_control(BOARD_LED0, led_state); led_state = 1 - led_state; // toggle } diff --git a/examples/device/nrf52840_freertos/src/tusb_config.h b/examples/device/nrf52840_freertos/src/tusb_config.h index 9e6b01616..6b8b0af96 100644 --- a/examples/device/nrf52840_freertos/src/tusb_config.h +++ b/examples/device/nrf52840_freertos/src/tusb_config.h @@ -52,8 +52,8 @@ #define CFG_TUSB_DEBUG 2 /*------------- RTOS -------------*/ -#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching -//#define CFG_TUD_TASK_PRIO 0 +#define CFG_TUSB_OS OPT_OS_FREERTOS +#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-2) //#define CFG_TUD_TASK_QUEUE_SZ 16 //#define CFG_TUD_TASK_STACK_SZ 150 |
