TASKSk_crt_taskRet values
#define STK 100 char s1[STK]; // your are stack supplier struct k_t * p_t1; void t1() { while (1) { } } ... p_t1 = k_crt_task(t1, 10, s1, STK); // code, 0 < prio < DMY_PRIO, s1: array of bytes, STK: 60 < nrofbytes k_set_prio:Ret values
k_sleep:Parm tp int - Legal 0 < val < 32000 Ret values
.. K_sleep(34); // sleep for 34 ticks k_round_robbink_round_robbin(); // reinsert caller so a round robbin situation is issued k_releaseIn non preemptive setup k_release switch running to the task in front of activeQ k_unused_stakRet values
int unusedStak; unusedStak = k_unused_stak(NULL); // myself or struct k_t *anotherTask; unusedStak = k_unused_stak(anotherTask); SEMAPHORESk_crt_semRet values
struct k_t *sem1; ... sem1 = k_crt_sem(1, 10); // 1: start value, 10: max value (clipping) k_signal, ki_signalRet values
struct k_t *sem; ... if (0 <= ksignal(sem) ) { // signal went ok } k_wait,ki_waitRet values0: ok - has been block bef signal arrived at semaphore
struct k_t *sem; int res; res = k_wait(sem,0); //0: we will wait forever until we get a signal or res = k_wait(sem,10); //0: we will wait max 10 krnl ticks for a signal or res = k_wait(sem,-1); //0: we will not wait if no signal is present k_set_sem_timer:Ret values
struct k_t * sem; k_set_sem_timer(sem,10); // now krnl will signal every 10 krnl tick to semaphore // krnl must be running before it will work k_sem_val, ki_sem_val
struct k_t * sem; int semVal; semVal = k_semval(sem); k_wait_lostRet values
struct k_t * sem; int nrLost; nrLost = k_wait_lost(sem); MESSAGE PASSINGk_crt_send_QRet values
struct k_msg_t *pMsg,*pMsg2; char mar[10*2]; ... pMsg = k_crt_send_Q(10,2,mar); // 10: nr elem, 2: size in bytes, mar 10*2 "bytes" ki_send,k_sendstruct k_msg_t *pMsg; char mar[10*2]; ... before k_start pMsg = k_crt_send_Q(10,2,mar); // crt a buffer with 10 elements each 2 byte size (std int in Arduino) ... after k_start .. sender int value=3 k_send(pMsg,(void *)&value); .. receiver int destVar; int lostMesg; if (0 <= k_receive(pMsg,&destVar,10,&lostMsg) ) { // third parm 10 = timeout which is forever //got it // lostMsg hold number of lost messages since last call with this parm NOT eq NULL. Counter is reset } ... or k_receive(pMsg,&destVar,0,NULL) ) { // third parm 0 = timeout which is forever // we know we will be in receive until data arrives. NULL says we dont want to have info about lost messages ki_receive,k_receivesee above k_msg_count, ki_msg_countReturns nr of messages waiting int count; ... struct k_msg_t *m; count = k_msg_count(m); Ceiling Mutexk_mut_ceil_setSets priority in semaphore for immediate ceiling protocol (critical region) returns
struct k_t *mutex; -- before k_start ! mutex = k_crt_sem(1,10); // initalvalue(1) and max clip value k_mut_ceil_set(sem,50); // semaphore and max prio for ceil protocol k_mut_ceil_enterpendant to k_wait just with immediate ceiling protocol
struct k_t * mut; if ( 0 <= k_mut_ceil_enter(mut,10)) { // max 10 tick wating in Q ! // yes we are now inside // mutex region code k_mut_leave(mut); } else { // did not get mutex bq of timeout } ... k_mut_ceil_leavependant to signal
freeRamreturn nr of unused bytes (between heap and orginal stack - they are growing towards each other) int memoryleft memoryleft = freeRam(); |