krnl 1
Loading...
Searching...
No Matches
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)
 eat milliseconds - to mimik time consuming code
int k_ticksize (void)
void ki_task_shift (void)
 shift running to task in front in AQ
void jumper ()
struct k_tk_crt_task (void(*pTask)(void), char prio, char *pStk, int stkSize)
 create a task - only to be called before k_start creates a task and put it in the active Q
int freeRam (void)
int k_sleep (int time)
 let task sleep for a number of milliseconds
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)
 set ceiling priority on a mutex
struct k_tk_crt_sem (int init_val, int maxvalue)
 change task priority and reinserts it in task Q and do a task shift
int k_set_sem_timer (struct k_t *sem, int val)
 attach a periodic timer to a semaphore, to be used for realtime
int ki_signal (struct k_t *sem)
 signal a semaphore from AN ISR - no task shift , do not enable intr,...
int k_signal (struct k_t *sem)
 Signal a semaphore w eventually task shift.
int ki_wait (struct k_t *sem, int timeout)
 a wait call with no disable - fct might no be usefull
int k_wait (struct k_t *sem, int timeout)
 stand wait on semaphore call with timeout facility
int k_wait2 (struct k_t *sem, int timeout, int *nrClip)
 wait with add info .´- nr of in max limit from signals since last time(saturation)
struct k_tk_crt_mut (char ceiling_prio, int init_val, int maxvalue)
 crt a std semaphore to be used as mutex
int k_mut_ceil (struct k_t *sem, int timeout, void(*fct)(void))
 mutex entet, call fct, leave ceil in one call
int k_mut_ceil_enter (struct k_t *sem, int timeout)
 set ceiling priority on a mutex
int k_mut_ceil_leave (struct k_t *sem)
 leave a "ceiled mutex" enter with k_mut_ceil_enter
int k_sem_signals_lost (struct k_t *sem)
 return signals lost on a sem(saturation) (and reset the saturation counter) Returns how many signals has been lost on semaphore due to saturation
int ki_semval (struct k_t *sem)
 return sem counter value - Its a ki_ fct so intr is not enabled by leave
int k_semval (struct k_t *sem)
 as ki_semval but to enable intr after leave
int k_clear_sem (struct k_t *sem)
 reset sem counter to 0 is no tasks is waiting - usefull ?
int ki_msg_count (struct k_msg_t *m)
 returns no of pending msg on msgf sem - a ki_ fct so no enable of interrupt
int k_msg_count (struct k_msg_t *m)
 return no of pending messages
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)
 returns no msec since start - no DI/EI lock Returns nr of milliseconds since krnl was started by k_start
unsigned long k_millis (void)
 return no of millisec sincs start NB no leap seconds - its clean
int k_tmrInfo (void)
 if (!k_running)
 for (tmr_indx=0;tmr_indx< nr_sem;tmr_indx++)
__asm__ volatile ("reti")
void k_breakout (void)
void k_sem_clip (unsigned char nr, int nrClip)
void k_sem_signal (unsigned char nr, int semVal)
 breakout for k_signal
void k_sem_wait (unsigned char nr, int semVal)
 breakout for k_wait
void k_send_Q_clip (unsigned char nr, int nrClip)
 breakout for k_send
void * k_malloc (int k)
 overruled malloc call malloc protected by DI and EI if dft as weak so you can supply with your own
void k_free (void *m)
 a krnl free which do nothing. call free empty - no function if dft as weak so you can supply with your own
void k_wdt_enable (int i)
 enable HW watchdog Call wdt_enable (AVR lib) DI(); wdt_enable(WDT_PERIOD); EI(); WDT_PERIOD is in KRNL i sec
void k_wdt_disable (void)
 disable HW watchdog disable wdt Disable the watchdog timer

Variables

struct k_ttask_pool
struct k_tsem_pool
struct k_t AQ
struct k_tpmain_el
struct k_tpAQ
struct k_tpRun
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 = sem_pool
 ERROR1
exitt __pad0__

Function Documentation

◆ delayMicroseconds()

void delayMicroseconds ( unsigned int t)

Referenced by k_eat_msec(), and test().

Here is the caller graph for this function:

◆ deQ()

struct k_t * deQ ( struct k_t * el)

Definition at line 208 of file krnl.c.

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

Referenced by if(), 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 199 of file krnl.c.

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

Referenced by ki_wait().

Here is the caller graph for this function:

◆ for()

for ( )

Definition at line 1295 of file krnl.c.

References ki_signal(), nr_sem, pE, and tmr_indx.

Here is the call 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 420 of file krnl.c.

References x.

Referenced by setup().

Here is the caller graph for this function:

◆ if()

if ( ! k_running)

Definition at line 1274 of file krnl.c.

References deQ(), K_CHG_STAK, k_coopFlag, k_running, pAQ, prio_enQ(), and pRun.

Here is the call graph for this function:

◆ jumper()

void jumper ( )

Definition at line 310 of file krnl.c.

References k_set_prio(), pRun, 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_breakout()

void k_breakout ( void )

Definition at line 1341 of file krnl.c.

◆ 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 900 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)

reset sem counter to 0 is no tasks is waiting - usefull ?

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 814 of file krnl.c.

References DI, EI, and sem.

◆ k_crt_mut()

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

crt a std semaphore to be used as mutex

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

Parameters
[in]ceiling_priopriority - task ceiling prio
[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
you can use a normale semaphore - its the same

Definition at line 703 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 )

change task priority and reinserts it in task Q and do a task shift

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 544 of file krnl.c.

References k_err_cnt, k_running, k_sem, MAX_SEM_VAL, nr_sem, QHD_PRIO, sem, and sem_pool.

Referenced by initSemaphores(), k_crt_mut(), k_crt_send_Q(), k_init(), rdWrLockInit(), 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 841 of file krnl.c.

References k_msg_t::el_size, k_crt_sem(), k_err_cnt, k_msg, k_running, k_sem, k_msg_t::nr_el, nr_sem, nr_send, k_msg_t::pBuf, pMsg, and send_pool.

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(* pTask )(void),
char prio,
char * pS,
int stkSize )

create a task - only to be called before k_start creates a task and put it in the active Q

Parameters
[in]pTaskpointer to function for code ( void task(void) ...)
[in]prio- task prio max: 1 lowest < DUMMY_PRIO
[in]pS- ptr to bye to be used as stack
[in]stkSizesize of data area(in bytes) to be used for stak
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 328 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, s, k_t::sp_hi, k_t::sp_lo, STAK_HASH, and task_pool.

Referenced by initTasks(), and 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 milliseconds - to mimik time consuming code

Eat time in milliseconds starting from now but not from next tick (1 msec)

Parameters
[in]eatTimenumber of ticks to eat

Definition at line 246 of file krnl.c.

References delayMicroseconds().

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

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

◆ k_free()

void k_free ( void * m)

a krnl free which do nothing. call free empty - no function if dft as weak so you can supply with your own

Remarks
do no free mem bq we do not want fragmented memory

Definition at line 1363 of file krnl.c.

References m.

◆ 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 1108 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().

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

◆ k_malloc()

void * k_malloc ( int k)

overruled malloc call malloc protected by DI and EI if dft as weak so you can supply with your own

Definition at line 1355 of file krnl.c.

References DI, EI, k, and m.

◆ k_millis()

unsigned long k_millis ( void )

return no of millisec sincs start NB no leap seconds - its clean

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 1247 of file krnl.c.

References DI, EI, k_millis_counter, and l.

Referenced by setup(), t2(), task1(), and wr().

Here is the caller graph for this function:

◆ k_msg_count()

int k_msg_count ( struct k_msg_t * m)

return no of pending messages

Parameters
[in]mmsg Q handle
Returns
positive nr of pending or -1
Remarks
only to be called after start of KRNL

Definition at line 833 of file krnl.c.

References EI, ki_msg_count(), and m.

Here is the call graph for this function:

◆ k_mut_ceil()

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

mutex entet, call fct, leave ceil in one call

Mutex enter and leave w imm priority ceiling in one operation

Parameters
semmutex with ceiling
timeout0 == forever
fctvoid 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 726 of file krnl.c.

References k_mut_ceil_enter(), k_mut_ceil_leave(), and sem.

Here is the call graph for this function:

◆ k_mut_ceil_enter()

int k_mut_ceil_enter ( struct k_t * sem,
int timeout )

set ceiling priority on a mutex

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 739 of file krnl.c.

References CEILINGFAILNOTCEIL, CEILINGFAILPRIO, deQ(), DI, EI, ki_task_shift(), ki_wait(), pAQ, prio_enQ(), pRun, and sem.

Referenced by controlTask(), getDataInCritRegion(), k_mut_ceil(), lowTask(), saveDataInCritRegion(), task1(), and task2().

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 a "ceiled mutex" enter with k_mut_ceil_enter

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 771 of file krnl.c.

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

Referenced by controlTask(), getDataInCritRegion(), k_mut_ceil(), lowTask(), saveDataInCritRegion(), task1(), and task2().

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 )

set ceiling priority on a mutex

Parameters
[in]semsemaphore
[in]prio
Returns
0 if ok otherwise neg

Definition at line 529 of file krnl.c.

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

Referenced by setup().

Here is the caller graph for this function:

◆ 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 991 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 t1(), t2(), task1(), and 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 1084 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 1073 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_clip()

void k_sem_clip ( unsigned char nr,
int nrClip )

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)

Definition at line 1343 of file krnl.c.

Referenced by ki_signal().

Here is the caller graph for this function:

◆ k_sem_signal()

void k_sem_signal ( unsigned char nr,
int val )

breakout for k_signal

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] val
[in]valsem val also in message queues. So it may be diff to find the semaphore...

Definition at line 1345 of file krnl.c.

Referenced by ki_signal().

Here is the caller graph for this function:

◆ k_sem_signals_lost()

int k_sem_signals_lost ( struct k_t * sem)

return signals lost on a sem(saturation) (and reset the saturation counter) 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 789 of file krnl.c.

References DI, EI, sem, and x.

◆ k_sem_wait()

void k_sem_wait ( unsigned char nr,
int val )

breakout for k_wait

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

Definition at line 1347 of file krnl.c.

◆ k_semval()

int k_semval ( struct k_t * sem)

as ki_semval but to enable intr after leave

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 807 of file krnl.c.

References EI, ki_semval(), and sem.

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 944 of file krnl.c.

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

Referenced by t2(), and task1().

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

◆ k_send_Q_clip()

void k_send_Q_clip ( unsigned char nr,
int nrClip )

breakout for k_send

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)

Definition at line 1349 of file krnl.c.

Referenced by ki_send().

Here is the caller graph for this function:

◆ k_set_coop_multitask()

void k_set_coop_multitask ( unsigned char onn)

Definition at line 1236 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 503 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 periodic timer to a semaphore, to be used for realtime

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 586 of file krnl.c.

References DI, EI, and sem.

Referenced by controlTask(), highprio(), initSemaphores(), lowprio(), medprio(), t1(), t1(), t2(), t2(), task(), task1(), task2(), task2Body(), task3(), and tperiodic().

Here is the caller graph for this function:

◆ k_signal()

int k_signal ( struct k_t * sem)

Signal a semaphore w eventually task shift.

Signal and has higher priority than you. Task shift will task place if a task is started by the signal has higher prio 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 636 of file krnl.c.

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

Referenced by controlTask(), getDataInCritRegion(), lowTask(), rdEnter(), rdLeave(), saveDataInCritRegion(), saveDataInCritRegionNoWait(), t1(), t1Code(), t2(), t2(), t2Code(), task(), task1(), task2(), task2Body(), wrEnter(), and wrLeave().

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

◆ k_sleep()

int k_sleep ( int time)

let task sleep for a number of milliseconds

Set task asleep for a number of msec.

Parameters
[in]timemillisec to sleep
Returns
: 0 is ok - has sleept, error - did you sleep or did someone signal your sleepSem is less than 0
Remarks
only to be called after start of KRNL

Definition at line 445 of file krnl.c.

References k_wait(), and pSleepSem.

Referenced by code(), lowTask(), rd(), t1(), t1(), t2(), t2(), task(), task2(), tgeneric(), tnoise(), and wr().

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 1149 of file krnl.c.

References DI, EI, k_err_cnt, k_running, 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 1212 of file krnl.c.

References DI, EI, and k_running.

Referenced by t1().

Here is the caller graph for this function:

◆ k_ticksize()

int k_ticksize ( void )

Definition at line 283 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 1256 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 493 of file krnl.c.

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

Referenced by t1().

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

◆ k_wait()

int k_wait ( struct k_t * sem,
int timeout )

stand wait on semaphore call with timeout facility

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 683 of file krnl.c.

References DI, EI, ki_wait(), and sem.

Referenced by controlTask(), getDataInCritRegion(), highprio(), k_sleep(), lowprio(), lowTask(), medprio(), rdEnter(), rdLeave(), saveDataInCritRegion(), saveDataInCritRegionNoWait(), t1(), t1(), t1Code(), t2(), t2(), t2Code(), task(), task1(), task1Body(), task2(), task2Body(), task3(), taskBody(), tperiodic(), wrEnter(), and wrLeave().

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 with add info .´- nr of in max limit from signals since last time(saturation)

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 691 of file krnl.c.

References DI, EI, ki_wait(), and sem.

Referenced by task1().

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

◆ k_wdt_disable()

void k_wdt_disable ( void )

disable HW watchdog disable wdt Disable the watchdog timer

Definition at line 1376 of file krnl.c.

References DI, EI, and k_wdt_enabled.

◆ k_wdt_enable()

void k_wdt_enable ( int t)

enable HW watchdog Call wdt_enable (AVR lib) DI(); wdt_enable(WDT_PERIOD); EI(); WDT_PERIOD is in KRNL i sec

Parameters
[t]watchdog timout WDT_PERIOD is 1 sec See avrlib docu for more info The watchdog is reset in krnls timer ISR when active

Definition at line 1369 of file krnl.c.

References DI, EI, i, and k_wdt_enabled.

◆ 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 882 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 no msec since start - no DI/EI lock 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 1240 of file krnl.c.

References DI, k_millis_counter, and l.

Referenced by if(), myISR_Debounce(), myISR_No_Debounce(), and wr().

Here is the caller graph for this function:

◆ ki_msg_count()

int ki_msg_count ( struct k_msg_t * msgbuffer)

returns no of pending msg on msgf sem - a ki_ fct so no enable of interrupt

Parameters
[in]msgbufferhandle
Returns
no of pending messages or -1

Definition at line 828 of file krnl.c.

References DI, and m.

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 455 of file krnl.c.

References 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 959 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)

return sem counter value - Its a ki_ fct so intr is not enabled by leave

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 801 of file krnl.c.

References DI, and sem.

Referenced by k_semval(), and rdEnter().

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 908 of file krnl.c.

References k_msg_t::cnt, k_msg_t::el_size, i, k_send_Q_clip(), 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 ISR(), ISR(), k_send(), myISR_Debounce(), and myISR_No_Debounce().

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 from AN ISR - no task shift , do not enable intr,...

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 605 of file krnl.c.

References deQ(), DI, k_sem_clip(), k_sem_signal(), MAX_SEM_VAL, pAQ, prio_enQ(), and sem.

Referenced by for(), if(), ISR(), k_mut_ceil_leave(), k_signal(), ki_send(), myISR(), myISR_Debounce(), myISR_No_Debounce(), and xxx().

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

◆ ki_task_shift()

void ki_task_shift ( void )

shift running to task in front in AQ

HERE

Definition at line 302 of file krnl.c.

References K_CHG_STAK, PUSHREGS(), and RETI.

Referenced by k_mut_ceil_enter(), k_mut_ceil_leave(), k_release(), k_round_robbin(), k_send(), k_set_prio(), k_signal(), k_start(), and ki_wait().

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 472 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 )

a wait call with no disable - fct might no be usefull

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 653 of file krnl.c.

References deQ(), DI, enQ(), ki_task_shift(), pRun, and sem.

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 217 of file krnl.c.

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

Referenced by if(), 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:

◆ volatile()

__asm__ volatile ( "reti" )

Variable Documentation

◆ __pad0__

exitt __pad0__

Definition at line 1330 of file krnl.c.

◆ AQ

struct k_t AQ

Definition at line 145 of file krnl.c.

Referenced by k_init().

◆ ERROR1

ERROR1
Initial value:
{
PUSHREGS()

Definition at line 1268 of file krnl.c.

◆ k_coopFlag

unsigned char k_coopFlag = 0

Definition at line 166 of file krnl.c.

Referenced by if(), and k_set_coop_multitask().

◆ k_err_cnt

volatile char k_err_cnt = 0

Definition at line 156 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

k_millis_counter = 0

Definition at line 161 of file krnl.c.

Referenced by if(), k_breakout(), k_millis(), ki_millis(), and wr().

◆ k_msg

int k_msg

Definition at line 153 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ k_running

◆ k_sem

int k_sem

Definition at line 153 of file krnl.c.

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

◆ k_task

int k_task

Definition at line 153 of file krnl.c.

Referenced by k_crt_task(), and k_init().

◆ k_tick_size

unsigned int k_tick_size

Definition at line 162 of file krnl.c.

Referenced by k_start(), and k_ticksize().

◆ nr_sem

char nr_sem = 0

Definition at line 154 of file krnl.c.

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

◆ nr_send

char nr_send = 0

Definition at line 154 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ nr_task

char nr_task = 0

Definition at line 154 of file krnl.c.

Referenced by k_crt_task(), and k_init().

◆ pAQ

struct k_t * pAQ

◆ pE

pE = sem_pool

Definition at line 1260 of file krnl.c.

Referenced by for().

◆ pmain_el

struct k_t * pmain_el

Definition at line 146 of file krnl.c.

Referenced by k_init(), and k_start().

◆ pRun

◆ pSleepSem

struct k_t * pSleepSem

Definition at line 149 of file krnl.c.

Referenced by k_init(), and k_sleep().

◆ sem_pool

struct k_t * sem_pool

Definition at line 144 of file krnl.c.

Referenced by k_crt_sem(), and k_init().

◆ send_pool

struct k_msg_t* send_pool

Definition at line 151 of file krnl.c.

Referenced by k_crt_send_Q(), and k_init().

◆ task_pool

struct k_t* task_pool

Definition at line 143 of file krnl.c.

Referenced by k_crt_task(), and k_init().

◆ tcntValue

volatile unsigned char tcntValue

Definition at line 158 of file krnl.c.

◆ tmr_indx

int tmr_indx

Definition at line 168 of file krnl.c.

Referenced by for().