eframe is an event-driven programming framework for low power applications using 8-bit or 16 MCU
- handler dynamic binding
- Supports the
handle_done
event (maybe refer to the TinyOS) - Supports synchronous events by
ef_syncpost()
, which can preempt common events.
- The enevt is deivered to the specified handler at runtime.
- Events should carray some data.
Two type in eframe,
ef_event_t
和ef_err_t
efPROC(handler) {}
Implementation of a handler
ef_event_init()
Initizlizing a variable such as define a KEY eventevent_t KEY = ef_event_init();
ef_bindhandler(event, handler)
binding a handler to a event
ef_post(event)
post a event to the queue.
ef_syncpost(event)
post a synchronization event, which is going to be processed immediately.
ef_idle()
idle handler
void ef_tofaceuart(const u8 b)
place the function to the interrupt of usart.
void ef_uart_recv(char *buf)
read the data in underlying buffer tobuf
.
void ef_uart_flush(void)
flush the underlying buffer.
booted
The same as main function. The first event posted by the MCU when it starts.efEVENT_SCH
: That synchronously post the event will tigger the schudler of eframe.
xxx_it.c file
-----------------------------------
#include "eframe.h"
// external interrupt
external interrupt function()
{
ef_post(KEY); // post a KEY event to queue.
}
main.c file
-----------------------------------
#include "eframe.h"
// Define the handler in order to process a KEY event
efPROC(key_handler)
{
printf("The KEY1 is pressed.\n");
}
efPROC(booted) // define the handler related `booted`
{
event_t KEY = ef_event_init(); // allocate a unique ID to event.
ef_bindhandler(KEY, key_handler); //bind the key handler to KEY event.
ef_syncpost(efEVENT_SCH); // tigger the scheduler of eframe.
}
uart_it.c file
-----------------------------------
#include "uartdriver.h"
uart interrupt function()
{
...
ef_tofaceuart(BUFF);
...
}
main.c file
-----------------------------------
efPROC(uart_handler)
{
static char buf[20] = {0};
ef_uart_recv(buf); // read the data from usart buffer
ef_uart_flush(); // flush it
puts(buf); //
}
efPROC(booted)
{
ef_bindhandler(EVENT_UART_EF, uart_handler);
ef_syncpost(efEVENT_SCH);
}