Coder Social home page Coder Social logo

eframe's Introduction

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);
}

eframe's People

Contributors

yulincoder avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.