Presentation is loading. Please wait.

Presentation is loading. Please wait.

Queues Asynchronous data transfer between tasks

Similar presentations


Presentation on theme: "Queues Asynchronous data transfer between tasks"— Presentation transcript:

1 Queues Asynchronous data transfer between tasks
Avoid live lock as with semaphore based solutions Usefull as internal (light)thread communication and between programs even between machines

2 Direct (a)synchronous

3 Indirect Q/mailbox (asynchronous)

4 Direct thread -> thread
Synchronous

5 Synchronous Advantage you will know when message is received
no need for extra ack/nack protocol no need for buffering (save of RAM9 can be by copying or just memory ref handover easy to understand easy to debug Disadvantage you will be blocked until receiver receives (maybe with timeout- but still) will potential destroy real time capabilities cant be used from ISR (ISR cant wait on thread...)

6 Asynchronous Advantage
You are not aware if and when message is received Your are not blocked until receiver is present real time - - high prio task will not wait on low prio can be used from ISR Disadvantage Buffering of messages may take RAM please no malloc/free !! Difficult to debug / track down behaviour

7 An example - Asynchronous Q
void t1(void) { int i; while (1) { if (0 == k_receive(pMsg,&i,10,NULL) ) { doBlink(); Serial.println(i); } else Serial.println("-"); void t2(void) { int i=0; i++; k_sleep(20); k_send(pMsg,&i); char mar[10*2]; struct k_msg_t *pMsg; pMsg = k_crt_send_Q(10,2,mar); you may fill Q you may empty Q

8 ISR example you may fill Q you may empty Q
#if defined (__AVR_ATmega2560__) || defined (__AVR_ATmega1280__) ISR(INT4_vect,ISR_NAKED) { #else ISR(INT0_vect, ISR_NAKED) { #endif // no local vars ?!? ! I think PUSHREGS(); if (!k_running) goto exitt ; icnt++; ki_send(pMsg,(void *)&icnt); K_CHG_STAK(); exitt: POPREGS(); RETI(); } char mar[10*2]; struct k_msg_t *pMsg; pMsg = k_crt_send_Q(10,2,mar); void t2(void) { int i; i = 0; while (1) { if (0 == k_receive(pMsg,&i,0,NULL) ) { Serial.println(i); k_send(pMsg2,&i); } else Serial.println("-1"); you may fill Q you may empty Q

9 ISR example II you may fill Q you may empty Q
#if defined (__AVR_ATmega2560__) || defined (__AVR_ATmega1280__) ISR(INT4_vect,ISR_NAKED) { #else ISR(INT0_vect, ISR_NAKED) { #endif // no local vars ?!? ! I think PUSHREGS(); if (!k_running) goto exitt ; if (ki_receive(pMsg,(void *)&icnt,&lost) == 0) { // yep got data from user space } K_CHG_STAK(); exitt: POPREGS(); RETI(); char mar[10*2]; struct k_msg_t *pMsg; pMsg = k_crt_send_Q(10,2,mar); void t2(void) { int i; i = 0; while (1) { i++; if (0 == k_send(pMsg,&i,0,NULL) ) { k_sleep(100); } you may fill Q you may empty Q

10 Async II Asynchronous thread->thread ISR->thread
ki_receive + k_send Variant No Q but each task has own message Q 5 min modification on SNOT

11 Sync message passing Direct handover task -> task EXERCISE :-)

12 MEASURE for today can do Arduino SNOT can do tasks and semaphores
with ISR interface message Queues with ISR have implemented synchronous message system Understand real time and IPC problems

13 to discuss Async versus sync communication buffering scheme / needed
Real time issues in async and sync case Interrupt handling time with interrupt disabled < > system responsiveness Cascade interrupts System timer heart beat And exercises on web


Download ppt "Queues Asynchronous data transfer between tasks"

Similar presentations


Ads by Google