Skip to content

An event-driven programming framework for low power embedded system using 8-bit or 16 MCU

Notifications You must be signed in to change notification settings

yulincoder/eframe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eFrame

eframe is an event-driven programming framework for low power applications using 8-bit or 16 MCU

中文

TODO:

  • handler dynamic binding
  • Supports the handle_done event (maybe refer to the TinyOS)
  • Supports synchronous events by ef_syncpost(), which can preempt common events.

Whether reasonable?

  • The enevt is deivered to the specified handler at runtime.
  • Events should carray some data.

API List:

Two type in eframe, ef_event_tef_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

Serial port API:

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 to buf.

void ef_uart_flush(void) flush the underlying buffer.

Default events in eframe: (Default events does not require binding by ef_bindhandler())

  1. booted The same as main function. The first event posted by the MCU when it starts.
  2. efEVENT_SCH: That synchronously post the event will tigger the schudler of eframe.

Examples:

1. External interrpt example
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.
}
2. Serial example
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);
}

About

An event-driven programming framework for low power embedded system using 8-bit or 16 MCU

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages