moved tasks to their own folder
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/09.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "platform/lock_jumper.h"
|
||||
#include "status_led.h"
|
||||
#include "utils/stacksmon.h"
|
||||
#include "vfs/vfs_manager.h"
|
||||
#include "usbd_cdc.h"
|
||||
#include "usb_device.h"
|
||||
#include "usbd_msc.h"
|
||||
#include "task_main.h"
|
||||
|
||||
extern void plat_init(void);
|
||||
|
||||
/* TaskUsbEvent function */
|
||||
void TaskMain(void const * argument)
|
||||
{
|
||||
dbg("> Main task started!");
|
||||
|
||||
vfs_if_usbd_msc_init();
|
||||
vfs_mngr_init(1);
|
||||
|
||||
uint32_t startTime = xTaskGetTickCount();
|
||||
uint32_t cnt = 1;
|
||||
while(1) {
|
||||
uint32_t msg;
|
||||
xTaskNotifyWait(0, UINT32_MAX, &msg, 100); // time out if nothing happened
|
||||
|
||||
// periodic updates to the VFS driver
|
||||
uint32_t now = xTaskGetTickCount();
|
||||
uint32_t elapsed = now - startTime;
|
||||
if (elapsed >= 100) {
|
||||
// interval 100ms or more - slow periodic
|
||||
vfs_mngr_periodic(elapsed);
|
||||
LockJumper_Check();
|
||||
startTime = now;
|
||||
|
||||
cnt++;
|
||||
if (cnt%5==0) StatusLed_Heartbeat();
|
||||
}
|
||||
|
||||
// if no message and it just timed out, go wait some more...
|
||||
if (msg == 0) {
|
||||
// Low priority periodic tasks... (TODO move to a timer?)
|
||||
|
||||
// Periodically check stacks for overrun
|
||||
stackmon_check_canaries();
|
||||
// Periodically dump all stacks - for checking levels before critical (to reduce size if not needed)
|
||||
if ((cnt%50)==0) stackmon_dump();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Endpoint 0 - control messages for the different classes
|
||||
if (msg & USBEVT_FLAG_EP0_RX_RDY) {
|
||||
USBD_CDC_EP0_RxReady(&hUsbDeviceFS);
|
||||
}
|
||||
|
||||
if (msg & USBEVT_FLAG_EP0_TX_SENT) {
|
||||
//
|
||||
}
|
||||
|
||||
// MSC - read/write etc
|
||||
if (msg & (USBEVT_FLAG_EPx_IN(MSC_EPIN_ADDR))) {
|
||||
USBD_MSC_DataIn(&hUsbDeviceFS, MSC_EPIN_ADDR);
|
||||
}
|
||||
|
||||
if (msg & (USBEVT_FLAG_EPx_OUT(MSC_EPOUT_ADDR))) {
|
||||
USBD_MSC_DataOut(&hUsbDeviceFS, MSC_EPOUT_ADDR);
|
||||
}
|
||||
|
||||
// CDC - config packets and data in/out
|
||||
if (msg & (USBEVT_FLAG_EPx_IN(CDC_IN_EP))) {
|
||||
USBD_CDC_DataIn(&hUsbDeviceFS, CDC_IN_EP);
|
||||
}
|
||||
if (msg & (USBEVT_FLAG_EPx_IN(CDC_CMD_EP))) {
|
||||
USBD_CDC_DataIn(&hUsbDeviceFS, CDC_CMD_EP);
|
||||
}
|
||||
if (msg & (USBEVT_FLAG_EPx_OUT(CDC_OUT_EP))) {
|
||||
USBD_CDC_DataOut(&hUsbDeviceFS, CDC_OUT_EP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/09.
|
||||
//
|
||||
|
||||
#ifndef GEX_TASK_MAIN_H
|
||||
#define GEX_TASK_MAIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
extern osThreadId tskMainHandle;
|
||||
void TaskMain(const void *argument);
|
||||
|
||||
// Notify flags:
|
||||
#define USBEVT_FLAG_EPx_IN(ep) (uint32_t)(1<<((ep)&0x7))
|
||||
#define USBEVT_FLAG_EPx_OUT(ep) (uint32_t)(1<<(8 + ((ep)&0x7)))
|
||||
#define USBEVT_FLAG_EP0_RX_RDY (1<<16)
|
||||
#define USBEVT_FLAG_EP0_TX_SENT (1<<17)
|
||||
|
||||
#endif //GEX_TASK_MAIN_H
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/21.
|
||||
//
|
||||
|
||||
#include "platform.h"
|
||||
#include "task_sched.h"
|
||||
|
||||
extern osMessageQId queSchedLPHandle;
|
||||
extern osMessageQId queSchedHPHandle;
|
||||
|
||||
volatile uint32_t jobQueHighWaterMarkHP = 0;
|
||||
volatile uint32_t jobQueHighWaterMarkLP = 0;
|
||||
|
||||
/**
|
||||
* Schedule a function for later execution in the jobs thread
|
||||
*
|
||||
* @param callback - the callback function
|
||||
* @param prio - priority, selects which job queue to use
|
||||
* @param data1 - first data object, NULL if not needed; usually context/handle
|
||||
* @param data2 - second data object, NULL if not needed; usually data/argument
|
||||
*/
|
||||
void scheduleJob(Job *job, enum task_sched_prio prio)
|
||||
{
|
||||
QueueHandle_t que = (prio == TSK_SCHED_LOW ? queSchedLPHandle : queSchedHPHandle);
|
||||
|
||||
assert_param(que != NULL);
|
||||
assert_param(job->cb != NULL);
|
||||
|
||||
uint32_t count;
|
||||
if (inIRQ()) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
assert_param(pdPASS == xQueueSendFromISR(que, job, &xHigherPriorityTaskWoken));
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
|
||||
#if USE_STACK_MONITOR
|
||||
count = (uint32_t) uxQueueMessagesWaitingFromISR(que);
|
||||
#endif
|
||||
} else {
|
||||
assert_param(pdPASS == xQueueSend(que, job, 100));
|
||||
|
||||
#if USE_STACK_MONITOR
|
||||
count = (uint32_t) uxQueueMessagesWaiting(que);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if USE_STACK_MONITOR
|
||||
if (prio == TSK_SCHED_LOW) {
|
||||
jobQueHighWaterMarkLP = MAX(jobQueHighWaterMarkLP, count);
|
||||
} else {
|
||||
jobQueHighWaterMarkHP = MAX(jobQueHighWaterMarkHP, count);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Low priority task queue handler
|
||||
*
|
||||
* @param argument
|
||||
*/
|
||||
void TaskSchedLP (const void * argument)
|
||||
{
|
||||
dbg("> Low priority queue task started!");
|
||||
|
||||
struct sched_que_item job;
|
||||
while (1) {
|
||||
xQueueReceive(queSchedLPHandle, &job, osWaitForever);
|
||||
|
||||
assert_param(job.cb != NULL);
|
||||
job.cb(&job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High priority task queue handler
|
||||
*
|
||||
* @param argument
|
||||
*/
|
||||
void TaskSchedHP (const void * argument)
|
||||
{
|
||||
dbg("> High priority queue task started!");
|
||||
|
||||
struct sched_que_item job;
|
||||
while (1) {
|
||||
xQueueReceive(queSchedHPHandle, &job, osWaitForever);
|
||||
|
||||
assert_param(job.cb != NULL);
|
||||
job.cb(&job);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/11/21.
|
||||
//
|
||||
|
||||
#ifndef GEX_TASK_SCHED_H
|
||||
#define GEX_TASK_SCHED_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "sched_queue.h"
|
||||
|
||||
enum task_sched_prio {
|
||||
TSK_SCHED_LOW = 0,
|
||||
TSK_SCHED_HIGH = 1,
|
||||
};
|
||||
|
||||
#if USE_STACK_MONITOR
|
||||
extern volatile uint32_t jobQueHighWaterMarkHP;
|
||||
extern volatile uint32_t jobQueHighWaterMarkLP;
|
||||
#endif
|
||||
|
||||
extern osThreadId tskSchedLPHandle;
|
||||
void TaskSchedLP (const void * argument);
|
||||
|
||||
extern osThreadId tskSchedHPHandle;
|
||||
void TaskSchedHP (const void * argument);
|
||||
|
||||
void scheduleJob(Job *job, enum task_sched_prio prio);
|
||||
|
||||
#endif //GEX_TASK_SCHED_H
|
||||
Reference in New Issue
Block a user