8000 GitHub - massimilianogalanti/ticker: Very tiny embedded scheduler for HRT applications
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

massimilianogalanti/ticker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

ticker

Ticker is a naive embedded scheduler for HRT applications in just one include file. Code has currently been ported successfully to STM32, SPC5 and PICmicro families.

Platform requirements

You need to adapt the code to your hardware platform by simply adding the proper include(s) and defining two macros in ticker.h.

#ifndef GetSysCount
/* Platform dependent */

#include "stm32f4xx_hal.h"

#define GetSysCount() HAL_GetTick()
#define SYSCNTxMS 1
#endif

Setup

#include "ticker.h"
...
static ticker_t mainTicker;
...
tickerInit(&mainTicker);

Basic usage in main loop

This is the most simple usage, just needs to add proper checks in your main loop.

while (1) {
  tickerTick(&mainTicker);
  
  if (mainTicker.Hz100) {
    // toggle led2 @ 100Hz
  }
  
  if (mainTicker.Hz1) {
    // toggle led1 @ 1Hz
  }
  ...
}

Callback mode

Same effect can be obtained using callbacks (note that this syntax uses function pointers).

static task_return_t myTaskOneShot(ticker_t *t, void *pdata)
{
  // do something here

  return TASK_DONE;
}

static task_return_t myTaskPeriodic(ticker_t *t, void *pdata)
{
  // do something here

  return TASK_REPEAT;
}
...
int pdata1 = 7;
char pdata[] = "hello";
...
tickerScheduleTaskMs(&mainTicker, 1000 /* ms */, myTaskOneShot, pdata1, TASK_FLAG_NONE);
tickerScheduleTaskMs(&mainTicker, 100 /* ms */, myTaskPeriodic, pdata2, TASK_FLAG_PERIODIC);

while (1) {
  tickerTick(&mainTicker);
  
  if (mainTicker.Hz100) {
    // this is still valid if you want to mix usages
  }
  ...
}

About

Very tiny embedded scheduler for HRT applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0