freertos blinky with software timer

This commit is contained in:
hathach 2018-08-23 14:11:21 +07:00
parent 5d36519315
commit d18a9e8759
6 changed files with 84 additions and 29 deletions

View File

@ -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"

View File

@ -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
}

View File

@ -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

View File

@ -59,6 +59,7 @@ uint8_t _button_pins[] = { 11, 12, 24, 25 };
/*------------------------------------------------------------------*/
/* TUSB HAL MILLISECOND
*------------------------------------------------------------------*/
#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
@ -70,6 +71,7 @@ uint32_t tusb_hal_millis(void)
{
return board_tick2ms(system_ticks);
}
#endif
/*------------------------------------------------------------------*/
/* BOARD API
@ -92,9 +94,10 @@ void board_init(void)
// Button
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) nrf_gpio_cfg_input(_button_pins[i], NRF_GPIO_PIN_PULLUP);
#if CFG_TUSB_OS == OPT_OS_NONE
// Tick init
SysTick_Config(SystemCoreClock/1000);
NVIC_EnableIRQ(SysTick_IRQn);
#endif
// USB power may already be ready at this time -> no event generated
// We need to invoke the handler based on the status initially

View File

@ -4,13 +4,18 @@
//--------------------------------------------------------------------+
// See http://www.freertos.org/a00110.html.
//--------------------------------------------------------------------+
//#include "bsp/board.h"
#include "nrf.h"
#if 0
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX
// TODO remove
#include "lpc43xx_cgu.h"
#define configCPU_CLOCK_HZ CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)
#else
#define configCPU_CLOCK_HZ SystemCoreClock
#endif
#endif
#define configCPU_CLOCK_HZ SystemCoreClock
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
@ -31,9 +36,10 @@
#define configENABLE_BACKWARD_COMPATIBILITY 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 1
#define configCHECK_FOR_STACK_OVERFLOW 2
@ -48,7 +54,7 @@
#define configMAX_CO_ROUTINE_PRIORITIES 2
/* Software timer related definitions. */
#define configUSE_TIMERS 0
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 3 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

View File

@ -50,12 +50,6 @@ void vApplicationMallocFailedHook(void)
TU_ASSERT(false, );
}
void vApplicationIdleHook(void)
{
// no freeRTOS blocking API should be called here
__WFI(); // sleep until next interrupt
}
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void) pxTask;