Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic.

Similar presentations


Presentation on theme: "ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic."— Presentation transcript:

1 ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic

2 ENTC-489 Embedded Real Time Software Development Today’s Agenda Homework Mail Boxes Mail Boxes as Binary Semaphores Fixed Point Arithmetic

3 ENTC-489 Embedded Real Time Software Development Mail Boxes Mechanism to send a single value (usually pointer sized) to a task Receiving task can pend on the posting of a value Can not post 0

4 ENTC-489 Embedded Real Time Software Development Mailbox Functions OSMboxCreate() – Creates a new mailbox OSMboxPost() – Posts a value to a mailbox OSMboxPend() – Waits on a value to be placed in a mailbox, then empties the mailbox OSMboxAccept() – Same as Pend, but does not wait

5 ENTC-489 Embedded Real Time Software Development OSMboxCreate() OS_EVENT *OSMboxCreate(void *msg) – msg is the initial value to go in the box, usually 0 – Returns a pointer to the created mailbox or 0 if there are no more available Event Control Blocks OS_EVENT *my_mbox_ptr; … my_mbox_ptr = OSMboxCreate((void *)0); …

6 ENTC-489 Embedded Real Time Software Development OSMboxPost() INT8U OSMboxPost(OS_EVENT *pevent, void *msg); – *pevent – pointer to the mailbox TCB – *msg – value to be posted, 0 doesn’t post anything – returns the following error codes: OS_ERR_NONE, OS_ERR_FULL, OS_MBOX_FULL, OS_ERR_EVENT_TYPE, OS_ERR_PEVENT_NULL, OS_ERR_POST_NULL_PTR OS_EVENT *my_mbox_ptr; uint8_t recvd_data[100] … if (index == new_index) { … err = OSMboxPost(my_mbox_ptr,(void *)&recvd_data[index]); … }

7 ENTC-489 Embedded Real Time Software Development OSMboxPend() void *OSMboxPend(OS_EVENT *pevent, INT16U timeout, INT8U *err); – *pevent – Pointer to the mailbox TCB – timeout – Max time, in ticks, to pend. 0 waits forever – *err – Pointer to location that will hold the return code from the function OS_ERR_NONE, OS_ERR_TIMEOUT, OS_ERR_EVENT_TYPE, OS_ERR_PEND_ISR, OS_ERR_PEVENT_NULL – Returns the value in the mailbox, (void *)0, if the mailbox is empty OS_EVENT *my_mbox_ptr; UINT8 error_code; uint16_t *next_value; … next_value = OSMboxPend(my_mbox_ptr,0,&error_code); switch (error_code) { case OS_ERR_NONE: return *next_value; … } …

8 ENTC-489 Embedded Real Time Software Development OSMboxAccept() void *OSMboxAccept(OS_EVENT *pevent) – *pevent – Pointer to the mailbox TCB – Returns the value in the mailbox, (void *)0, if the mailbox is empty … OS_EVENT *my_mbox_ptr; uint16_t *next_value; … next_value = OSMboxAccept(my_mbox_ptr); if (next_value != 0) { … return *next_value; … } …

9 ENTC-489 Embedded Real Time Software Development Mail Boxes as Binary Semaphores You do not have to post a pointer, you can post any variable or constant that is the same size or smaller than a pointer. If you “Post” a constant, the behavior of a mailbox is exactly the same as a binary semaphore would be.

10 ENTC-489 Embedded Real Time Software Development Break

11 ENTC-489 Embedded Real Time Software Development Fixed Point Arithmetic The Problem – Floating point math is slower than integer math (even with a Floating Point Unit) – Use of floating point math slows multi-threaded / multi-tasked systems even more (lots of BIG registers to push to save context) – We still need to deal with fractional values The Solution – Fixed point arithmetic

12 ENTC-489 Embedded Real Time Software Development What is a Fixed Point Number?

13 ENTC-489 Embedded Real Time Software Development Whoa! What?

14 ENTC-489 Embedded Real Time Software Development Huh?

15 ENTC-489 Embedded Real Time Software Development Why is this better, I understand floating point?

16 ENTC-489 Embedded Real Time Software Development Facts to Ponder

17 ENTC-489 Embedded Real Time Software Development Tivaware IQMath Library Based on 32 bit values Supports Q30.1 to Q1.30 – Type for Q30.1 is _iq30 – Type for Q29.2 is _iq29 – … – Type for Q1.30 is _iq1 Conversion – To String – To _iq?? From _iq?? – Do not use floating point conversions Multiplication / Division Trig, Sqrt, Exponents, etc. #include “IQmath/IQmathlib.h”

18 ENTC-489 Embedded Real Time Software Development Tivaware IQ Functions Division - _IQNdiv() _iq16 numerator, denominator, result; … result = _IQ16div(numerator,denominator); Multiplication - _IQNmpy() _iq16 mpy1, mpy2, result; … result = _IQ16mpy(mpy1,mpy2); Addition and subtraction _iq16 op1, op2, op3, result; … result = (op1 + op2) – op3; Output Format _iq16 op1; char outstr[16]; … _IQ16toa(op1,”%2.05f”,outstr); Convert from IQn to IQm #define IQtoIQ(Q1,Q2,A) ((_iq ##Q1)(A) >> (Q1 – Q2)) _iq16 val1; _iq24 val2; … val1 = IQtoIQ(16,24,val2);

19 ENTC-489 Embedded Real Time Software Development Creating a Constant π as Q24.7 – Range is -8 to 7.999999996 – Scale is 16,777,216 – π = 3.141592653 * Scale =52707178 (calculator) – #define Q24_SCALE ((int64_t)16777216) – #define PI_9DIGITS ((int64_t)3141592653) – #define TEN_EXP9 ((int64_t)1000000000) – #define PI_Q24 ((_iq24)((PI_9DIGITS*Q24_SCALE)/TEN_EXP9))

20 ENTC-489 Embedded Real Time Software Development You have to design before writing code Working with fixed point numbers you have to think about – Range – Precision – Order of evaluation


Download ppt "ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 5 Mail Boxes / Binary Semaphores Fixed Point Arithmetic."

Similar presentations


Ads by Google