simple handler for system_os_task/system_os_post

we wrap both functions in much easier ones (register_usr_task, post_usr_task).
register_usr_task requires an os_task_t parameter (the task itself) and returns a
task number (0...MAXUSRTASKS) which is later on used by "post_usr_task".
register_usr_task is self-initializing. no static arrays - malloc only...
pull/73/head
susisstrolch 9 years ago
parent 65f22d5dcf
commit 0cb217046d
  1. 78
      esp-link/task.c
  2. 20
      esp-link/task.h
  3. 11
      serial/uart.c

@ -0,0 +1,78 @@
/*
* task.c
*
* Copyright 2015 Susi's Strolch
*
* For license information see projects "License.txt"
*
* Not sure if it's save to use ICACHE_FLASH_ATTR, so we're running from RAM
*/
#undef USRTASK_DBG
#include "esp8266.h"
#include <task.h>
#define MAXUSRTASKS 8
#ifdef USRTASK_DBG
#define DBG_USRTASK(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG_USRTASK(format, ...) do { } while(0)
#endif
LOCAL os_event_t *_task_queue = NULL; // system_os_task queue
LOCAL os_task_t *usr_task_queue = NULL; // user task queue
// it seems save to run the usr_event_handler from RAM, so no ICACHE_FLASH_ATTR here...
LOCAL void usr_event_handler(os_event_t *e)
{
DBG_USRTASK("usr_event_handler: event %p (sig=%d, par=%p)\n", e, (int)e->sig, (void *)e->par);
if (usr_task_queue[e->sig] == NULL || e->sig < 0 || e->sig >= MAXUSRTASKS) {
os_printf("usr_event_handler: task %d %s\n", (int)e->sig,
usr_task_queue[e->sig] == NULL ? "not registered" : "out of range");
return;
}
(usr_task_queue[e->sig])(e);
}
LOCAL void init_usr_task() {
if (_task_queue == NULL)
_task_queue = (os_event_t *)os_zalloc(sizeof(os_event_t) * _task_queueLen);
if (usr_task_queue == NULL)
usr_task_queue = (os_task_t *)os_zalloc(sizeof(os_task_t) * MAXUSRTASKS);
system_os_task(usr_event_handler, _taskPrio, _task_queue, _task_queueLen);
}
// public functions
bool post_usr_task(uint8_t task, os_param_t par)
{
return system_os_post(_taskPrio, task, par);
}
uint8_t register_usr_task (os_task_t event)
{
int task;
DBG_USRTASK("register_usr_task: %p\n", event);
if (_task_queue == NULL || usr_task_queue == NULL)
init_usr_task();
for (task = 0; task < MAXUSRTASKS; task++) {
if (usr_task_queue[task] == event)
return task; // task already registered - bail out...
}
for (task = 0; task < MAXUSRTASKS; task++) {
if (usr_task_queue[task] == NULL) {
DBG_USRTASK("register_usr_task: assign task #%d\n", task);
usr_task_queue[task] = event;
break;
}
}
return task;
}

@ -0,0 +1,20 @@
/*
* task.h
*
* Copyright 2015 Susi's Strolch
*
* For license information see projects "License.txt"
*
*
*/
#ifndef USRTASK_H
#define USRTASK_H
#define _taskPrio 1
#define _task_queueLen 64
uint8_t register_usr_task (os_task_t event);
bool post_usr_task(uint8_t task, os_param_t par);
#endif

@ -18,6 +18,7 @@
* Heavily modified and enhanced by Thorsten von Eicken in 2015 * Heavily modified and enhanced by Thorsten von Eicken in 2015
*/ */
#include "esp8266.h" #include "esp8266.h"
#include "task.h"
#include "uart.h" #include "uart.h"
#ifdef UART_DBG #ifdef UART_DBG
@ -26,14 +27,10 @@
#define DBG_UART(format, ...) do { } while(0) #define DBG_UART(format, ...) do { } while(0)
#endif #endif
#define recvTaskPrio 1 LOCAL uint8_t uart_recvTaskNum;
#define recvTaskQueueLen 64
// UartDev is defined and initialized in rom code. // UartDev is defined and initialized in rom code.
extern UartDevice UartDev; extern UartDevice UartDev;
os_event_t recvTaskQueue[recvTaskQueueLen];
#define MAX_CB 4 #define MAX_CB 4
static UartRecv_cb uart_recv_cb[4]; static UartRecv_cb uart_recv_cb[4];
@ -208,7 +205,7 @@ uart0_rx_intr_handler(void *para)
{ {
//DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no)); //DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
ETS_UART_INTR_DISABLE(); ETS_UART_INTR_DISABLE();
system_os_post(recvTaskPrio, 0, 0); post_usr_task(uart_recvTaskNum, 0);
} }
} }
@ -284,7 +281,7 @@ uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
// install uart1 putc callback // install uart1 putc callback
os_install_putc1((void *)uart0_write_char); os_install_putc1((void *)uart0_write_char);
system_os_task(uart_recvTask, recvTaskPrio, recvTaskQueue, recvTaskQueueLen); uart_recvTaskNum = register_usr_task(uart_recvTask);
} }
void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR

Loading…
Cancel
Save