MegaThread
Macros | Functions
thread.c File Reference
#include <stddef.h>
#include <stdbool.h>
#include <avr/interrupt.h>
#include "thread.h"

Macros

#define THREAD_DIVISOR   ((F_CPU * THREAD_MS_PER_TICK + 500UL * 1024UL) / (1000UL * 1024UL))
 

Functions

pThread_t threadAdd (threadFunc_t f, void *pArgument, uint16_t periodTicks)
 
void threadStart ()
 
 ISR (TIMER0_COMPA_vect, ISR_NOBLOCK)
 

Macro Definition Documentation

#define THREAD_DIVISOR   ((F_CPU * THREAD_MS_PER_TICK + 500UL * 1024UL) / (1000UL * 1024UL))

Function Documentation

ISR ( TIMER0_COMPA_vect  ,
ISR_NOBLOCK   
)
pThread_t threadAdd ( threadFunc_t  f,
void *  pArgument,
uint16_t  periodTicks 
)

Adds a new thread to the list. This function must not be called after starting the scheduling. The priority of the task depends on the order of the adding of the threads. The first function has the highest, the last the lowest priority.

See also
threadStart
Parameters
fpointer to the thread function
pArgumentthis parameter is delivered to the thread function at every call. Typically it would be a pointer to struct with parameters and/or a pointer to a struct holding the static data of the function. (You should avoid using static variables in function used for a thread)
periodTicksnumber of ticks between to calls. You should use ' [period in ms]/THREAD_MS_PER_TICK' here.
Returns
NULL if the list was already full, not NULL if the task was successfully added.
void threadStart ( )

Configures the timer, enables global interrupts and starts executing of the tasks.