My Project - RET HER
versionsnr
|
Go to the source code of this file.
Macros | |
#define | KRNLTMRVECTOR TIMER0_OVF_vect |
#define | MICROSECONDS_PER_TIMER0_OVERFLOW (1024) |
#define | MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) |
#define | FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) |
#define | FRACT_MAX (1000 >> 3) |
Functions | |
void | enQ (struct k_t *Q, struct k_t *el) |
struct k_t * | deQ (struct k_t *el) |
void | prio_enQ (struct k_t *Q, struct k_t *el) |
ISR (KRNLTMRVECTOR, ISR_NAKED) | |
void | __attribute__ ((naked, noinline)) |
void | jumper () |
struct k_t * | k_crt_task (void(*pTask)(void), char prio, int stkSize) |
int | freeRam (void) |
int | k_sleep (int time) |
void | k_eat_ticks (int ticks) |
int | k_unused_stak (struct k_t *t) |
int | k_set_prio (char prio) |
int | k_mut_ceil_set (struct k_t *sem, char prio) |
struct k_t * | k_crt_sem (char init_val, int maxvalue) |
int | k_set_sem_timer (struct k_t *sem, int val) |
int | ki_signal (struct k_t *sem) |
int | k_signal (struct k_t *sem) |
int | ki_wait (struct k_t *sem, int timeout) |
int | k_wait (struct k_t *sem, int timeout) |
int | k_mut_ceil_enter (struct k_t *sem, int timeout) |
int | k_mut_ceil_leave (struct k_t *sem) |
int | k_sem_signals_lost (struct k_t *sem) |
int | ki_semval (struct k_t *sem) |
int | k_semval (struct k_t *sem) |
int | ki_msg_count (struct k_msg_t *m) |
int | k_msg_count (struct k_msg_t *m) |
struct k_msg_t * | k_crt_send_Q (int nr_el, int el_size, void *pBuf) |
char | ki_send (struct k_msg_t *pB, void *el) |
char | k_send (struct k_msg_t *pB, void *el) |
char | ki_receive (struct k_msg_t *pB, void *el, int *lost_msg) |
char | k_receive (struct k_msg_t *pB, void *el, int timeout, int *lost_msg) |
void | k_round_robbin (void) |
void | k_release (void) |
int | k_init (int nrTask, int nrSem, int nrMsg) |
int | k_start (int tick) |
int | k_stop (unsigned int exitVal) |
unsigned long | ki_millis (void) |
unsigned long | k_millis (void) |
int | k_tmrInfo (void) |
void | __attribute__ ((weak)) |
Variables | |
int | k_config |
int * | sem_pool |
int | AQ |
int * | pmain_el |
int * | pAQ |
int * | pRun |
int * | pSleepSem |
struct k_msg_t * | send_pool |
int | k_task |
int | k_sem |
int | k_msg |
char | nr_task = 0 |
char | nr_sem = 0 |
char | nr_send = 0 |
volatile char | k_running = 0 |
volatile char | k_err_cnt = 0 |
volatile unsigned int | tcntValue |
volatile int | fakecnt |
volatile int | fakecnt_preset |
static volatile char | stopp = 0 |
unsigned long | k_millis_counter = 0 |
unsigned int | k_tick_size |
int | tmr_indx |
volatile unsigned long | timer0_overflow_count |
volatile unsigned long | timer0_millis |
unsigned char | timer0_fract |
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) |
#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) |
void __attribute__ | ( | (naked, noinline) | ) |
void __attribute__ | ( | (weak) | ) |
a function for overloading on usersite which is called when a semaphore is overflooding no reset occur - it's only reading out semaphore idendity Signal operations has not taken place ! 1: means first semahore allocated by user, 2 the next etc Interrupt is disabled when called and must not be enabled during.. so no print etc
[in] | nr | id of semaphore 1,2,3,... |
[in] | nrClip | number of times clip has occured (may be reset by call k_wait_lost) |
called in a signal call val is sem val AFTER signal has taken place
called when wait called. val is sem value after countdown has taken place NB is the wait call willl not wait and there is no token at the semaphore val will be -1111
a function for overloading on usersite which is called when a msgQ is overflooding no reset occur - it's only readind out smsgQ idendity 1: means first msgQ allocated by user etc Interrupt is disabled when called and must not be enabled during.. so no print etc
nr | : id of send Q 0,1,2,... |
nrClip | number of times clip has occured (may be reset by call k_receive and lost parm not eq NULL) |
Breakout function called from scheduler
Definition at line 345 of file krnl.c.
References k_t::next, and k_t::pred.
Referenced by ISR(), k_mut_ceil_enter(), k_mut_ceil_leave(), k_round_robbin(), k_set_prio(), ki_signal(), and ki_wait().
int freeRam | ( | void | ) |
ISR | ( | KRNLTMRVECTOR | , |
ISR_NAKED | |||
) |
Definition at line 416 of file krnl.c.
References k_t::cnt1, k_t::cnt2, k_t::cnt3, deQ(), fakecnt, FRACT_INC, FRACT_MAX, K_CHG_STAK, k_millis_counter, k_running, k_tick_size, ki_signal(), MILLIS_INC, nr_sem, nr_task, pAQ, prio_enQ(), pRun, sem_pool, task_pool, tcntValue, timer0_fract, timer0_millis, timer0_overflow_count, and tmr_indx.
void jumper | ( | ) |
Definition at line 556 of file krnl.c.
References k_set_prio(), pRun, and ZOMBI_PRIO.
Referenced by k_crt_task().
struct k_t* k_crt_sem | ( | char | init_val, |
int | maxvalue | ||
) |
creates a standard Dijkstra semaphore. It can be initialized to values in range [0..maxvalue]
[in] | init_val | startvalue of semaphore 0,1,2,... maxvalue |
[in] | maxvalue | which is maxvalue semaphore can reach |
Definition at line 773 of file krnl.c.
References k_t::ceiling_prio, k_t::clip, k_t::cnt1, k_t::cnt2, k_err_cnt, k_running, k_sem, k_t::maxv, k_t::next, k_t::nr, nr_sem, k_t::pred, k_t::prio, QHD_PRIO, k_t::saved_prio, SEM_MAX_VALUE, and sem_pool.
Referenced by k_crt_send_Q(), and k_init().
struct k_msg_t* k_crt_send_Q | ( | int | nr_el, |
int | el_size, | ||
void * | pBuf | ||
) |
Definition at line 1044 of file krnl.c.
References k_msg_t::cnt, k_msg_t::el_size, k_crt_sem(), k_err_cnt, k_msg, k_running, k_sem, k_msg_t::lost_msg, k_msg_t::nr, k_msg_t::nr_el, nr_sem, nr_send, k_msg_t::pBuf, k_msg_t::r, k_msg_t::sem, send_pool, and k_msg_t::w.
struct k_t* k_crt_task | ( | void(*)(void) | pTask, |
char | prio, | ||
int | stkSize | ||
) |
creates a task and put it in the active Q
[in] | pTask | pointer to function for code ( void task(void) ...) |
[in] | prio | Priority 1: highest (QHEAD_PRIO-1): lowest |
[in] | stkSize | size of data area(in bytes) to be used for stak |
Definition at line 566 of file krnl.c.
References k_t::cnt1, k_t::cnt2, k_t::cnt3, DMY_PRIO, hi8, jumper(), k_err_cnt, k_running, k_task, lo8, k_t::maxv, k_t::nr, nr_task, pAQ, k_t::prio, prio_enQ(), k_t::pt, k_t::sp_hi, k_t::sp_lo, STAK_HASH, and task_pool.
Referenced by setup().
void k_eat_ticks | ( | int | ticks | ) |
eat time in quant og krnl ticks starting from now but not from next tick
Definition at line 688 of file krnl.c.
References k_tick_size.
int k_init | ( | int | nrTask, |
int | nrSem, | ||
int | nrMsg | ||
) |
Initialise KRNL. First function to be called. You have to give max number of tasks, semaphores and message queues you will use
[in] | nrTask | ... |
[in] | nrSem | ... |
[in] | nrMsg | ... |
void setup() { allocate resources for creation of 3 tasks 2 semaphores 1 mailboxes k_init(3,2,1); ...
}
Definition at line 1262 of file krnl.c.
References AQ, DMY_PRIO, k_crt_sem(), k_err_cnt, k_msg, k_running, k_sem, k_task, nr_send, nr_task, pAQ, pmain_el, prio_enQ(), pSleepSem, QHD_PRIO, sem_pool, send_pool, and task_pool.
Referenced by setup().
unsigned long k_millis | ( | void | ) |
Returns nr of milliseconds since krnl was started by k_start
Definition at line 1444 of file krnl.c.
References k_millis_counter.
int k_msg_count | ( | struct k_msg_t * | m | ) |
returns nr of pending messages
[in] | msgbuffer | handle |
Definition at line 1034 of file krnl.c.
References ki_msg_count().
int k_mut_ceil_enter | ( | struct k_t * | sem, |
int | timeout | ||
) |
Enter mutex (eq to k_wait...) use k_mut_enter / k_mut_leave instead of wait and signal
[in] | sem | aka mutex |
[in] | timeout | timeout value |
Definition at line 940 of file krnl.c.
References k_t::ceiling_prio, CEILINGFAIL, deQ(), ki_task_shift(), ki_wait(), pAQ, prio_enQ(), pRun, and k_t::saved_prio.
int k_mut_ceil_leave | ( | struct k_t * | sem | ) |
Leave mutex (eq to k_signal...) use k_mut_enter/ k_mut_leave instead of wait and signal
[in] | sem | used as mutex |
Definition at line 976 of file krnl.c.
References k_t::ceiling_prio, deQ(), k_signal(), ki_signal(), ki_task_shift(), pAQ, prio_enQ(), pRun, and k_t::saved_prio.
int k_mut_ceil_set | ( | struct k_t * | sem, |
char | prio | ||
) |
adds ceiling priority to semaphore use k_mut_ceil_enter k_mut_ceil_leave instead of wait and signal Can only be called before k_start
[in] | sem | reference to sem used for mutex - no check |
[in] | prio | Ceiling pirority |
Definition at line 754 of file krnl.c.
References k_t::ceiling_prio, DMY_PRIO, k_running, and k_t::prio.
char k_receive | ( | struct k_msg_t * | pB, |
void * | el, | ||
int | timeout, | ||
int * | lost_msg | ||
) |
Receive data (one element of el_size)in the ringbuffer if there are data DONE BY COPY !
[in] | pB | Ref to message buffer |
[out] | el | Reference to where data shall be copied to at your site |
[in] | timeout | Max time you want to wait on data, -1: never, 0: forever, positive: nr of KRNL timer quants |
[out] | lost_msg | nr of lost messages since last receive. will clip at 10000. If lost_msg ptr is NULL then overrun counter is not reset to 0. |
Definition at line 1183 of file krnl.c.
References k_msg_t::cnt, k_msg_t::el_size, ki_wait(), k_msg_t::lost_msg, k_msg_t::nr_el, k_msg_t::pBuf, k_msg_t::r, and k_msg_t::sem.
void k_release | ( | void | ) |
release switch running to task in front of Active Q
Definition at line 1238 of file krnl.c.
References ki_task_shift().
void k_round_robbin | ( | void | ) |
round robbin
Definition at line 1226 of file krnl.c.
References deQ(), ki_task_shift(), pAQ, prio_enQ(), and pRun.
int k_sem_signals_lost | ( | struct k_t * | sem | ) |
int k_semval | ( | struct k_t * | sem | ) |
returns value of semaphore
[in] | sem | semaphore handle |
Definition at line 1020 of file krnl.c.
References ki_semval().
char k_send | ( | struct k_msg_t * | pB, |
void * | el | ||
) |
Put data (one element of el_size)in the ringbuffer if there are room for it. DONE BY COPY !
[in] | pB | Ref to message buffer |
[in] | el | Reference to data to be put in buffer. Size if already given in k_crt_send |
Definition at line 1130 of file krnl.c.
References ki_send(), and ki_task_shift().
int k_set_prio | ( | char | prio | ) |
change priority of calling task)
[in] | prio | new prio, Priority 1: highest (QHEAD_PRIO-1): lowest |
Definition at line 726 of file krnl.c.
References deQ(), DMY_PRIO, k_running, ki_task_shift(), pAQ, k_t::prio, prio_enQ(), and pRun.
Referenced by jumper().
int k_set_sem_timer | ( | struct k_t * | sem, |
int | val | ||
) |
attach a timer to the semaphore so KRNL will signal the semaphore with regular intervals. Can be used for cyclic real time run of a task.
[in] | sem | semaphore handle |
[in] | val | interval in quant of KRNL ticks (0: disable cyclic timer, 1,2,3... cyclic quant) |
int k_signal | ( | struct k_t * | sem | ) |
Signal a semaphore. Task shift will task place if a task is started by the signal and has higher priority than you.
[in] | sem | semaphore handle |
Definition at line 868 of file krnl.c.
References ki_signal(), and ki_task_shift().
Referenced by k_mut_ceil_leave().
int k_sleep | ( | int | time | ) |
Set task asleep for a number of ticks.
[in] | time | nr of ticks to sleep < 0 |
Definition at line 678 of file krnl.c.
References k_wait(), and pSleepSem.
Referenced by t1().
int k_start | ( | int | tm | ) |
start KRNL with tm tick speed (1= 1 msec, 5 = 5 msec)
[in] | tm | Tick length in milli seconds(1..10,20,30..10000 |
Definition at line 1304 of file krnl.c.
References fakecnt, fakecnt_preset, k_err_cnt, k_running, k_tick_size, ki_task_shift(), pmain_el, pRun, stopp, and tcntValue.
Referenced by setup().
int k_stop | ( | unsigned int | exitVal | ) |
stop KRNL
[in] | exitVal | Will be returned in k_start to creator (old main) |
Definition at line 1408 of file krnl.c.
References AQ, k_running, ki_task_shift(), pmain_el, and stopp.
int k_tmrInfo | ( | void | ) |
int k_unused_stak | ( | struct k_t * | t | ) |
int k_wait | ( | struct k_t * | sem, |
int | timeout | ||
) |
Wait on a semaphore. Task shift will task place if you are blocked.
[in] | sem | semaphore handle |
[in] | timeout | "<0" you will be started after timeout ticks, "=0" wait forever "-1" you will not wait |
Definition at line 931 of file krnl.c.
References ki_wait().
Referenced by k_sleep().
unsigned long ki_millis | ( | void | ) |
Returns nr of milliseconds since krnl was started by k_start
Definition at line 1435 of file krnl.c.
References k_millis_counter.
int ki_msg_count | ( | struct k_msg_t * | m | ) |
returns nr of pending messages
[in] | msgbuffer | handle |
Definition at line 1028 of file krnl.c.
References k_msg_t::cnt.
Referenced by k_msg_count().
char ki_receive | ( | struct k_msg_t * | pB, |
void * | el, | ||
int * | lost_msg | ||
) |
Receive data (one element of el_size)in the ringbuffer if there are data DONE BY COPY ! No blocking if no data Interrupt will not be enabled after ki_receive
[in] | pB | Ref to message buffer |
[out] | el | Reference to where data shall be copied to at your site |
[out] | lost_msg | nr of lost messages since last receive. will clip at 10000. If lost_msg ptr is NULL then overrun counter is not reset to 0 |
Definition at line 1146 of file krnl.c.
References k_msg_t::cnt, k_msg_t::el_size, ki_wait(), k_msg_t::lost_msg, k_msg_t::nr_el, k_msg_t::pBuf, k_msg_t::r, and k_msg_t::sem.
int ki_semval | ( | struct k_t * | sem | ) |
returns value of semaphore
[in] | sem | semaphore handle |
Definition at line 1013 of file krnl.c.
References k_t::cnt1.
Referenced by k_semval().
char ki_send | ( | struct k_msg_t * | pB, |
void * | el | ||
) |
Put data (one element of el_size)in the ringbuffer if there are room for it. Intended for ISR use DONE BY COPY !
[in] | pB | Ref to message buffer |
[in] | el | Reference to data to be put in buffer. Size if already given in k_crt_send |
Definition at line 1088 of file krnl.c.
References k_msg_t::cnt, k_msg_t::el_size, ki_signal(), k_msg_t::lost_msg, k_msg_t::nr, k_msg_t::nr_el, k_msg_t::pBuf, k_msg_t::sem, SEM_MAX_VALUE, and k_msg_t::w.
Referenced by k_send().
int ki_signal | ( | struct k_t * | sem | ) |
Signal a semaphore. Can be called from an ISR when interrupt is disabled. No task shift will occur - only queue manipulation.
[in] | sem | semaphore handle |
Definition at line 831 of file krnl.c.
References k_t::clip, k_t::cnt1, k_t::cnt2, deQ(), k_t::maxv, k_t::next, k_t::nr, pAQ, prio_enQ(), and SEM_MAX_VALUE.
Referenced by ISR(), k_mut_ceil_leave(), k_signal(), and ki_send().
int ki_wait | ( | struct k_t * | sem, |
int | timeout | ||
) |
Like k_wait with the exception interrupt is NOT enabled when leaving
[in] | sem | semaphore handle |
[in] | timeout | "<0" you will be started after timeout ticks, "=0" wait forever "-1" you will not wait |
Definition at line 887 of file krnl.c.
References k_t::cnt1, deQ(), enQ(), ki_task_shift(), k_t::nr, and pRun.
Referenced by k_mut_ceil_enter(), k_receive(), k_wait(), and ki_receive().
Definition at line 353 of file krnl.c.
References k_t::next, k_t::pred, and k_t::prio.
Referenced by ISR(), k_crt_task(), k_init(), k_mut_ceil_enter(), k_mut_ceil_leave(), k_round_robbin(), k_set_prio(), and ki_signal().
int k_config |
volatile char k_err_cnt = 0 |
Definition at line 298 of file krnl.c.
Referenced by k_crt_sem(), k_crt_send_Q(), k_crt_task(), k_init(), and k_start().
unsigned long k_millis_counter = 0 |
Definition at line 306 of file krnl.c.
Referenced by ISR(), k_millis(), and ki_millis().
int k_msg |
Definition at line 295 of file krnl.c.
Referenced by k_crt_send_Q(), and k_init().
volatile char k_running = 0 |
Definition at line 298 of file krnl.c.
Referenced by ISR(), k_crt_sem(), k_crt_send_Q(), k_crt_task(), k_init(), k_mut_ceil_set(), k_set_prio(), k_start(), and k_stop().
int k_sem |
Definition at line 295 of file krnl.c.
Referenced by k_crt_sem(), k_crt_send_Q(), and k_init().
int k_task |
Definition at line 295 of file krnl.c.
Referenced by k_crt_task(), and k_init().
unsigned int k_tick_size |
Definition at line 307 of file krnl.c.
Referenced by ISR(), k_eat_ticks(), and k_start().
char nr_sem = 0 |
Definition at line 296 of file krnl.c.
Referenced by ISR(), k_crt_sem(), and k_crt_send_Q().
char nr_send = 0 |
Definition at line 296 of file krnl.c.
Referenced by k_crt_send_Q(), and k_init().
char nr_task = 0 |
Definition at line 296 of file krnl.c.
Referenced by ISR(), k_crt_task(), and k_init().
int * pAQ |
Definition at line 288 of file krnl.c.
Referenced by ISR(), k_crt_task(), k_init(), k_mut_ceil_enter(), k_mut_ceil_leave(), k_round_robbin(), k_set_prio(), and ki_signal().
int * pmain_el |
int * pRun |
Definition at line 290 of file krnl.c.
Referenced by ISR(), jumper(), k_mut_ceil_enter(), k_mut_ceil_leave(), k_round_robbin(), k_set_prio(), k_start(), k_unused_stak(), and ki_wait().
int * sem_pool |
Definition at line 285 of file krnl.c.
Referenced by ISR(), k_crt_sem(), and k_init().
struct k_msg_t* send_pool |
Definition at line 293 of file krnl.c.
Referenced by k_crt_send_Q(), and k_init().
|
static |
volatile unsigned int tcntValue |
unsigned char timer0_fract |
Referenced by ISR().
volatile unsigned long timer0_millis |
Referenced by ISR().
volatile unsigned long timer0_overflow_count |
Referenced by ISR().