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

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