dit projekt
Functions | Variables
krnl.c File Reference
#include "krnl.h"
#include <stdlib.h>
#include <avr/interrupt.h>
Include dependency graph for krnl.c:

Go to the source code of this file.

Functions

void enQ (struct k_t *Q, struct k_t *el)
 
struct k_tdeQ (struct k_t *el)
 
void prio_enQ (struct k_t *Q, struct k_t *el)
 
void delayMicroseconds (unsigned int t)
 
void k_eat_msec (unsigned int eatTime)
 
int k_ticksize (void)
 
void __attribute__ ((naked, noinline))
 
void jumper ()
 
struct k_tk_crt_task (void(*pTask)(void), char prio, char *pStk, int stkSize)
 
int freeRam (void)
 
int k_sleep (int time)
 
int ki_my_unused_stak ()
 
int ki_unused_stak (struct k_t *t)
 
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_tk_crt_sem (int 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_wait2 (struct k_t *sem, int timeout, int *nrClip)
 
struct k_tk_crt_mut (char ceiling_prio, int init_val, int maxvalue)
 
int k_mut_ceil (struct k_t *sem, int timeout, void(*fct)(void))
 
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 k_clear_sem (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_tk_crt_send_Q (int nr_el, int el_size, void *pBuf)
 
int ki_clear_msg_Q (struct k_msg_t *pB)
 
int k_clear_msg_Q (struct k_msg_t *pB)
 
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 k_stop ()
 
void k_set_coop_multitask (unsigned char onn)
 
unsigned long ki_millis (void)
 
unsigned long k_millis (void)
 
int k_tmrInfo (void)
 
 ISR (KRNLTMRVECTOR, ISR_NAKED)
 
void __attribute__ ((weak))
 

Variables

JDN SIGER NOGO IN SIMPLIFY VRS struct k_ttask_pool
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_tsem_pool
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_t AQ
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_tpmain_el
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_tpAQ
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_tpRun
 
JDN SIGER NOGO IN SIMPLIFY VRS struct k_tpSleepSem
 
struct k_msg_tsend_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 char tcntValue
 
unsigned long k_millis_counter = 0
 
unsigned int k_tick_size
 
unsigned char k_coopFlag = 0
 
int tmr_indx
 
struct k_tpE
 

Function Documentation

◆ __attribute__() [1/2]

void __attribute__ ( (naked, noinline)  )

HERE

Definition at line 348 of file krnl.c.

References K_CHG_STAK(), and RETI().

Here is the call graph for this function:

◆ __attribute__() [2/2]

void __attribute__ ( (weak)  )

disable wdt Disable the watchdog timer

a function for overloading on usersite which is called when a semaphore is overflooding no 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

Parameters
[in]nrid of semaphore 1,2,3,...
[in]nrClipnumber 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

Parameters
[out]nrnumber of semaphore. Semaphores are allocated by user buth also in message queues. So it may be diff to find the semaphore...

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

Parameters
[out]nr: id of send Q 0,1,2,...
[out]nrClipnumber of times clip has occured (may be reset by call k_receive and lost parm not eq NULL)

Breakout function called from scheduler You can use to examine who is runnning and who is next NB NB should be fast code and remember interrupt is and must be disables pRun->nr Nr of running. dummy has nr == 0 then task is numbered 1.. in acc with order of creation of tasks k_breakout is defined as weak function so you can write your own k_breakout The builtin k_breakout has no code and just a placeholder to be subst with your code. setting led8-12 on uno as task number PORTB = (1 << pRun->nr) | led13

Definition at line 1412 of file krnl.c.

◆ delayMicroseconds()

void delayMicroseconds ( unsigned int  t)

Referenced by k_eat_msec().

Here is the caller graph for this function:

◆ deQ()

struct k_t* deQ ( struct k_t el)

Definition at line 260 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().

Here is the caller graph for this function:

◆ enQ()

void enQ ( struct k_t Q,
struct k_t el 
)

Definition at line 251 of file krnl.c.

References k_t::next, and k_t::pred.

Referenced by ki_wait().

Here is the caller graph for this function:

◆ freeRam()

int freeRam ( void  )

returns amount of free memory in your system (free size of heap) se docu in krnl.c

Definition at line 466 of file krnl.c.

References x.

◆ ISR()

ISR ( KRNLTMRVECTOR  ,
ISR_NAKED   
)

Definition at line 1337 of file krnl.c.

References k_t::cnt1, k_t::cnt2, k_t::cnt3, deQ(), K_CHG_STAK(), k_coopFlag, k_millis_counter, k_running, k_tick_size, k_wdt_enabled, ki_signal(), nr_sem, nr_task, pAQ, pE, prio_enQ(), pRun, RETI(), sem_pool, task_pool, and tmr_indx.

Here is the call graph for this function:

◆ jumper()

void jumper ( )

Definition at line 356 of file krnl.c.

References k_set_prio(), pRun, k_t::pt, and ZOMBI_PRIO.

Referenced by k_crt_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_clear_msg_Q()

int k_clear_msg_Q ( struct k_msg_t pB)

Empty sendQ See ki_clear_msg-Q for description

Definition at line 945 of file krnl.c.

References DI, EI, ki_clear_msg_Q(), and k_msg_t::r.

Here is the call graph for this function:

◆ k_clear_sem()

int k_clear_sem ( struct k_t sem)

Clear semaphore if possible. Will set semaphore vallue 0 if possible (if no tasks is waiting)

Parameters
[in]sempointer ref to semaphore
Returns
semValue - if negative it indicates task are waiting and no clear

Definition at line 859 of file krnl.c.

References k_t::clip, k_t::cnt1, DI, and EI.

◆ k_crt_mut()

struct k_t* k_crt_mut ( char  ceiling_prio,
int  init_val,
int  maxvalue 
)

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

Parameters
[in]semreference to sem used for mutex - no check
[in]prioCeiling pirority
Returns
0: ok , otherwise bad bad
Remarks
only to be called before start of KRNL creates a standard mutex. It can be initialized to values in range [0..maxvalue]
Parameters
[in]init_valstartvalue of semaphore 0,1,2,... maxvalue
[in]maxvaluewhich is maxvalue semaphore can reach
Returns
handle to semaphore or NULL pointer
Remarks
only to be called before start of KRNL

Definition at line 748 of file krnl.c.

References k_t::ceiling_prio, k_crt_sem(), k_err_cnt, and k_running.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_crt_sem()

struct k_t* k_crt_sem ( int  init_val,
int  maxvalue 
)

creates a standard Dijkstra semaphore. It can be initialized to values in range [0..maxvalue]

Parameters
[in]init_valstartvalue of semaphore 0,1,2,... maxvalue
[in]maxvaluewhich is maxvalue semaphore can reach
Returns
handle to semaphore or NULL pointer
Remarks
only to be called before start of KRNL

Definition at line 589 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, MAX_SEM_VAL, k_t::maxv, k_t::next, k_t::nr, nr_sem, k_t::pred, k_t::prio, QHD_PRIO, k_t::saved_prio, and sem_pool.

Referenced by k_crt_mut(), k_crt_send_Q(), k_init(), and setup().

Here is the caller graph for this function:

◆ k_crt_send_Q()

struct k_msg_t* k_crt_send_Q ( int  nr_el,
int  el_size,
void *  pBuf 
)

Definition at line 886 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.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_crt_task()

struct k_t* k_crt_task ( void(*)(void)  pTask,
char  prio,
char *  pS,
int  stkSize 
)

creates a task and put it in the active Q

Parameters
[in]pTaskpointer to function for code ( void task(void) ...)
[in]stkSizesize of data area(in bytes) to be used for stak
[in]prio- task prio max: 1 lowest < DUMMY_PRIO
Returns
: pointer to task handle or NULL if no success
Remarks
only to be called before start of KRNL but after k_init

Definition at line 374 of file krnl.c.

References k_t::cnt1, k_t::cnt2, k_t::cnt3, DMY_PRIO, hi8, i, 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, pTask, k_t::sp_hi, k_t::sp_lo, STAK_HASH, and task_pool.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_eat_msec()

void k_eat_msec ( unsigned int  eatTime)

Eat time in quant of krnl ticks starting from now but not from next tick Eats CPU time in k_tick quants

Parameters
[in]tyicknumber of ticks to eat

Definition at line 292 of file krnl.c.

References delayMicroseconds().

Referenced by t1(), t2(), task1(), task2(), tgeneric(), tnoise(), and tperiodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_init()

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

Parameters
[in]nrTask...
[in]nrSem...
[in]nrMsg...

Definition at line 1152 of file krnl.c.

References AQ, k_t::cnt2, k_t::cnt3, DMY_PRIO, k_crt_sem(), k_err_cnt, k_msg, k_running, k_sem, k_task, k_t::next, k_t::nr, nr_send, nr_task, pAQ, pmain_el, k_t::pred, k_t::prio, prio_enQ(), pSleepSem, QHD_PRIO, sem_pool, send_pool, and task_pool.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_millis()

unsigned long k_millis ( void  )

Returns nr of milliseconds since krnl was started by k_start

Returns
: unsigned long is returned
Remarks
only to be called after start of KRNL
Interrupt is disabled when reading krnl time and is enabled afterwards

Definition at line 1322 of file krnl.c.

References DI, EI, and k_millis_counter.

Referenced by t2().

Here is the caller graph for this function:

◆ k_msg_count()

int k_msg_count ( struct k_msg_t m)

returns nr of pending messages

Parameters
[in]msgbufferhandle
Returns
1: ok not suspended, 0: ok you have been suspended
-1 no wait maybe bq no timeout was allowed
Remarks
only to be called after start of KRNL

Definition at line 878 of file krnl.c.

References EI, and ki_msg_count().

Here is the call graph for this function:

◆ k_mut_ceil()

int k_mut_ceil ( struct k_t sem,
int  timeout,
void(*)(void)  fct 
)

Mutex enter and leave w imm priority ceiling in one operation

Parameters
smmutex with ceiling
timeout0 == forever @fct void fct(void) the function w critical code
Returns
0: ok ,waited, 1 straight through; -1 timeout, -3 CEILINGFAILNOTCEIL not a semaphore w ceiling, -4 CEILINGFAIL my priority is above ceil max prio

Definition at line 771 of file krnl.c.

References k_mut_ceil_enter(), and k_mut_ceil_leave().

Here is the call graph for this function:

◆ k_mut_ceil_enter()

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

Parameters
[in]semaka mutex
[in]timeouttimeout value
Returns
0: if you have been waiting, 1 if you just went through, -1 for timeout, -3 if your priority was higher than ceiling priority

Definition at line 784 of file krnl.c.

References k_t::ceiling_prio, CEILINGFAILNOTCEIL, CEILINGFAILPRIO, deQ(), DI, EI, ki_task_shift(), ki_wait(), pAQ, k_t::prio, prio_enQ(), pRun, and k_t::saved_prio.

Referenced by getDataInCritRegion(), and k_mut_ceil().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_mut_ceil_leave()

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

Parameters
[in]semused as mutex
Returns
0: ok otherwise bad bad

Definition at line 816 of file krnl.c.

References deQ(), DI, EI, ki_signal(), ki_task_shift(), pAQ, k_t::prio, prio_enQ(), pRun, and k_t::saved_prio.

Referenced by getDataInCritRegion(), and k_mut_ceil().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_mut_ceil_set()

int k_mut_ceil_set ( struct k_t sem,
char  prio 
)

Definition at line 574 of file krnl.c.

References k_t::ceiling_prio, DMY_PRIO, k_running, and k_t::prio.

◆ k_receive()

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 !

Parameters
[in]pBRef to message buffer
[out]elReference to where data shall be copied to at your site
[in]timeoutMax time you want to wait on data, -1: never, 0: forever, positive: nr of KRNL timer quants
[out]lost_msgnr of lost messages since last receive. will clip at
  1. If lost_msg ptr is NULL then overrun counter is not reset to 0.
Returns
1: ok no suspension, 0: operation did succed, -1: no data in ringbuffer
Remarks
only to be called after start of KRNL

Definition at line 1036 of file krnl.c.

References k_msg_t::cnt, DI, EI, k_msg_t::el_size, i, 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.

Referenced by task2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_release()

void k_release ( void  )

release switch running to task in front of Active Q calls ki_task_shift (); enveloped by a DI and EI no round robbin

Definition at line 1129 of file krnl.c.

References DI, EI, and ki_task_shift().

Here is the call graph for this function:

◆ k_round_robbin()

void k_round_robbin ( void  )

round robbin reinsert running task in activeQ. so running will be inserted after other tasks with same or higher priority

Definition at line 1118 of file krnl.c.

References deQ(), DI, EI, ki_task_shift(), pAQ, prio_enQ(), and pRun.

Here is the call graph for this function:

◆ k_sem_signals_lost()

int k_sem_signals_lost ( struct k_t sem)

Returns how many signals has been lost on semaphore due to saturation

Parameters
[in]semsemaphore handle
Returns
nr of signals lost
Remarks
only to be called after start of KRNL

Definition at line 834 of file krnl.c.

References k_t::clip, DI, EI, and x.

◆ k_semval()

int k_semval ( struct k_t sem)

returns value of semaphore

Parameters
[in]semsemaphore handle
Returns
1: ok not suspended, 0: ok you have been suspended
-1 no wait maybe bq no timeout was allowed
Remarks
only to be called after start of KRNL

Definition at line 852 of file krnl.c.

References EI, and ki_semval().

Here is the call graph for this function:

◆ k_send()

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 !

Parameters
[in]pBRef to message buffer
[in]elReference to data to be put in buffer. Size if already given in k_crt_send
Returns
0: operation did succed, -1: no room in ringbuffer
Remarks
only to be called after start of KRNL
k_send does not block if no space in buffer. Instead -1 is returned

Definition at line 989 of file krnl.c.

References DI, EI, ki_send(), and ki_task_shift().

Referenced by task1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_set_coop_multitask()

void k_set_coop_multitask ( unsigned char  onn)

Definition at line 1311 of file krnl.c.

References k_coopFlag.

◆ k_set_prio()

int k_set_prio ( char  prio)

change priority of calling task)

Parameters
[in]prionew prio, Priority 1: highest (QHEAD_PRIO-1): lowest
Returns
: 0: ok, -1: KRNL not running, -2: illegal value
Remarks
only to be called after start of KRNL

Definition at line 548 of file krnl.c.

References deQ(), DI, DMY_PRIO, EI, i, k_running, ki_task_shift(), pAQ, k_t::prio, prio_enQ(), and pRun.

Referenced by jumper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_set_sem_timer()

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.

Parameters
[in]semsemaphore handle
[in]valinterval in quant of KRNL ticks (0: disable cyclic timer, 1,2,3... cyclic quant)
Returns
-1: negative val, 0. ok
Remarks
only to be called after start of KRNL

Definition at line 631 of file krnl.c.

References k_t::cnt1, k_t::cnt2, k_t::cnt3, DI, EI, and val.

Referenced by t1(), task1(), task2(), and tperiodic().

Here is the caller graph for this function:

◆ k_signal()

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.

Parameters
[in]semsemaphore handle
Returns
0: ok , -1: max value of semaphore reached
Remarks
The ki_ indicates that interrups is NOT enabled when leaving ki_signal
only to be called after start of KRNL

Definition at line 681 of file krnl.c.

References DI, EI, ki_signal(), and ki_task_shift().

Referenced by getDataInCritRegion(), saveDataInCritRegion(), task1(), and task2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_sleep()

int k_sleep ( int  time)

Set task asleep for a number of ticks.

Parameters
[in]timenr of ticks to sleep < 0
Returns
: 0 is ok(has been suspended), 1(is not suspended), -1 is wait time is less than 0
Remarks
only to be called after start of KRNL

Definition at line 491 of file krnl.c.

References k_wait(), and pSleepSem.

Referenced by t1(), t2(), task2(), tgeneric(), and tnoise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_start()

int k_start ( void  )

Starts krnl is possible If there has been ciritcal errors between k_init and k_start (like no more task descriptors) k_start will return a negative number indicatin how many errors

If k_start starts you will not return from k_start

Definition at line 1192 of file krnl.c.

References DI, EI, k_err_cnt, k_running, K_TICK, k_tick_size, ki_task_shift(), pmain_el, and pRun.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_stop()

int k_stop ( )

stop KRNL parm can be 1 or 10 can only run 1 og 10 msec tick speed If krnl is not yet running you will return with a -1 as return value If krnl is running interrupt will be disabled and k_stop ends in an infinite loop

Definition at line 1292 of file krnl.c.

References DI, EI, and k_running.

◆ k_ticksize()

int k_ticksize ( void  )

Return krnl ticksize As for now it can be 1 (msec) or 10(msec) BEWARE All delays are in quants of tick_size..

Definition at line 329 of file krnl.c.

References k_tick_size.

◆ k_tmrInfo()

int k_tmrInfo ( void  )

returns which timer is used

Returns
0,1,2,3,4,5 ...

Definition at line 1331 of file krnl.c.

◆ k_unused_stak()

int k_unused_stak ( struct k_t t)

Returns amount of unused stak

Parameters
[in]tPtr to taskdescriptor. If NULL it is yourself
Returns
: amount of unused stak(in bytes)
Remarks
: a watermark philosophy is used

Definition at line 538 of file krnl.c.

References DI, EI, i, and ki_unused_stak().

Here is the call graph for this function:

◆ k_wait()

int k_wait ( struct k_t sem,
int  timeout 
)

Wait on a semaphore. Task shift will task place if you are blocked.

Parameters
[in]semsemaphore handle
[in]timeout"<0" you will be started after timeout ticks, "=0" wait forever "-1" you will not wait
Returns
1: ok there was a signal hanging - so no suspension
0: ok- you have been suspended
-1: timeout has occured, -2 no wait bq timeout was -1 and semaphore was negative
Remarks
only to be called after start of KRNL

Definition at line 728 of file krnl.c.

References DI, EI, and ki_wait().

Referenced by getDataInCritRegion(), k_sleep(), saveDataInCritRegion(), t1(), task1(), task2(), and tperiodic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ k_wait2()

int k_wait2 ( struct k_t sem,
int  timeout,
int *  nrClip 
)

Wait on a semaphore. Task shift will task place if you are blocked.

Parameters
[in]semsemaphore handle
[in]timeout"<0" you will be started after timeout ticks, "=0" wait forever "-1" you will not wait
[out]nrClipIf not NULL you will get in return nr of clip on signals on sem and clip counter will be set to 0
Returns
1: ok there was a signal hanging - so no suspension
0: ok- you have been suspended
-1: timeout has occured, -2 no wait bq timeout was -1 and semaphore was negative
Remarks
only to be called after start of KRNL

Definition at line 736 of file krnl.c.

References k_t::clip, DI, EI, ki_wait(), and nrClip.

Referenced by task1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ki_clear_msg_Q()

int ki_clear_msg_Q ( struct k_msg_t pB)

Empty sendQ

Returns
given no of deleted messages
-1 if its no a msg q
-2 if krnl is not running
0 or positive gives no of messages deleted

Definition at line 927 of file krnl.c.

References k_msg_t::cnt, k_t::cnt1, k_running, k_msg_t::lost_msg, k_msg_t::r, k_msg_t::sem, and k_msg_t::w.

Referenced by k_clear_msg_Q().

Here is the caller graph for this function:

◆ ki_millis()

unsigned long ki_millis ( void  )

Returns nr of milliseconds since krnl was started by k_start

Returns
: unsigned long is returned
Remarks
only to be called after start of KRNL and only when interrupt is disabled
To be called within an ISR so interrupts is no disabled

Definition at line 1315 of file krnl.c.

References DI, and k_millis_counter.

◆ ki_msg_count()

int ki_msg_count ( struct k_msg_t msgbuffer)

returns nr of pending messages

Parameters
[in]msgbufferhandle xxx

Definition at line 873 of file krnl.c.

References k_msg_t::cnt, and DI.

Referenced by k_msg_count().

Here is the caller graph for this function:

◆ ki_my_unused_stak()

int ki_my_unused_stak ( )

Returns amount of unused stak for running task

Returns
: amount of unused stak(in bytes)
Remarks
: a watermark philosophy is used
can be called from ISR . iif userapce you must disable intr

Definition at line 500 of file krnl.c.

References k_t::cnt1, i, pRun, and STAK_HASH.

◆ ki_receive()

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 and intr must be blocked prior to call

Parameters
[in]pBRef to message buffer
[out]elReference to where data shall be copied to at your site
[out]lost_msgnr of lost messages since last receive. will clip at
  1. If lost_msg ptr is NULL then overrun counter is not reset to 0
Returns
1: data was rdy no suspension, 0: ok you have been suspended , -1: no data in ringbuffer
Remarks
can be used from ISR
only to be called after start of KRNL

Definition at line 1004 of file krnl.c.

References k_msg_t::cnt, DI, k_msg_t::el_size, i, 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.

Here is the call graph for this function:

◆ ki_semval()

int ki_semval ( struct k_t sem)

returns value of semaphore

Parameters
[in]semsemaphore handle
Returns
1: ok not suspended, 0: ok you have been suspended
-1 no wait maybe bq no timeout was allowed
Remarks
only to be called after start of KRNL
do not enable interrupt upon leaving

Definition at line 846 of file krnl.c.

References k_t::cnt1, and DI.

Referenced by k_semval().

Here is the caller graph for this function:

◆ ki_send()

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 !

Parameters
[in]pBRef to message buffer
[in]elReference to data to be put in buffer. Size if already given in k_crt_send
Returns
0: operation did succed, -1: no room in ringbuffer
Remarks
Interrupt will not enabled upon leaving, so ki_send is intended to be used from an ISR
only to be called before start of KRNL

Definition at line 953 of file krnl.c.

References k_msg_t::cnt, k_msg_t::el_size, i, ki_signal(), k_msg_t::lost_msg, MAX_SEM_VAL, k_msg_t::nr, k_msg_t::nr_el, k_msg_t::pBuf, k_msg_t::sem, and k_msg_t::w.

Referenced by k_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ki_signal()

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.

Parameters
[in]semsemaphore handle
Returns
0: ok , -1: max value of semaphore reached
Remarks
only to be called after start of KRNL

Definition at line 650 of file krnl.c.

References k_t::clip, k_t::cnt1, k_t::cnt2, deQ(), DI, k_sem_clip(), MAX_SEM_VAL, k_t::maxv, k_t::next, k_t::nr, pAQ, and prio_enQ().

Referenced by ISR(), k_mut_ceil_leave(), k_signal(), and ki_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ki_unused_stak()

int ki_unused_stak ( struct k_t t)

Returns amount of unused stak

Parameters
[in]tPtr to taskdescriptor. If NULL it is yourself
Returns
: amount of unused stak(in bytes)
Remarks
: a watermark philosophy is used
can be called from ISR . iif userapce you must disable intr

Definition at line 517 of file krnl.c.

References k_t::cnt1, i, pRun, and STAK_HASH.

Referenced by k_unused_stak().

Here is the caller graph for this function:

◆ ki_wait()

int ki_wait ( struct k_t sem,
int  timeout 
)

Like k_wait with the exception interrupt is NOT enabled when leaving

Parameters
[in]semsemaphore handle
[in]timeout"<0" you will be started after timeout ticks, "=0" wait forever "-1" you will not wait
Returns
0: ok , -1: could do wait bw blocking would have taken place
Remarks
The ki_ indicates that interrups is NOT enabled when leaving ki_wait
only to be called after start of KRNL
normally not to be used by users !!! BEWARE

Definition at line 698 of file krnl.c.

References k_t::cnt1, k_t::cnt2, k_t::cnt3, deQ(), DI, enQ(), ki_task_shift(), and pRun.

Referenced by k_mut_ceil_enter(), k_receive(), k_wait(), k_wait2(), and ki_receive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prio_enQ()

void prio_enQ ( struct k_t Q,
struct k_t el 
)

Definition at line 269 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().

Here is the caller graph for this function:

Variable Documentation

◆ AQ

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t AQ

Definition at line 197 of file krnl.c.

Referenced by k_init().

◆ k_coopFlag

unsigned char k_coopFlag = 0

Definition at line 218 of file krnl.c.

Referenced by ISR(), and k_set_coop_multitask().

◆ k_err_cnt

volatile char k_err_cnt = 0

Definition at line 208 of file krnl.c.

Referenced by k_crt_mut(), k_crt_sem(), k_crt_send_Q(), k_crt_task(), k_init(), and k_start().

◆ k_millis_counter

unsigned long k_millis_counter = 0

Definition at line 213 of file krnl.c.

Referenced by ISR(), k_millis(), and ki_millis().

◆ k_msg

int k_msg

Definition at line 205 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ k_running

volatile char k_running = 0

◆ k_sem

int k_sem

Definition at line 205 of file krnl.c.

Referenced by k_crt_sem(), k_crt_send_Q(), and k_init().

◆ k_task

int k_task

Definition at line 205 of file krnl.c.

Referenced by k_crt_task(), and k_init().

◆ k_tick_size

unsigned int k_tick_size

Definition at line 214 of file krnl.c.

Referenced by ISR(), k_start(), and k_ticksize().

◆ nr_sem

char nr_sem = 0

Definition at line 206 of file krnl.c.

Referenced by ISR(), k_crt_sem(), and k_crt_send_Q().

◆ nr_send

char nr_send = 0

Definition at line 206 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ nr_task

char nr_task = 0

Definition at line 206 of file krnl.c.

Referenced by ISR(), k_crt_task(), and k_init().

◆ pAQ

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t * pAQ

◆ pE

struct k_t* pE

Definition at line 1335 of file krnl.c.

Referenced by ISR().

◆ pmain_el

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t * pmain_el

Definition at line 198 of file krnl.c.

Referenced by k_init(), and k_start().

◆ pRun

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t * pRun

◆ pSleepSem

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t * pSleepSem

Definition at line 201 of file krnl.c.

Referenced by k_init(), and k_sleep().

◆ sem_pool

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t * sem_pool

Definition at line 196 of file krnl.c.

Referenced by ISR(), k_crt_sem(), and k_init().

◆ send_pool

struct k_msg_t* send_pool

Definition at line 203 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ task_pool

JDN SIGER NOGO IN SIMPLIFY VRS struct k_t* task_pool

Definition at line 195 of file krnl.c.

Referenced by ISR(), k_crt_task(), and k_init().

◆ tcntValue

volatile unsigned char tcntValue

Definition at line 210 of file krnl.c.

◆ tmr_indx

int tmr_indx

Definition at line 220 of file krnl.c.

Referenced by ISR().