Download presentation
Presentation is loading. Please wait.
Published byOscar Arnold Modified over 9 years ago
1
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 6 Review I2C Communication, review fixed point arithmetic, message queues, event flags
2
ENTC-489 Embedded Real Time Software Development Today’s Agenda Review – I2C Communication – Fixed Point Arithmetic – Semaphores / Mutexes Message Queues Event Flags
3
ENTC-489 Embedded Real Time Software Development I2C Configuration
4
ENTC-489 Embedded Real Time Software Development I2C Library Interrupt Calls Register an interrupt to be called when I2C operation is complete – I2CIntRegister(I2C3_BASE,my_i2c_irq); Clear the I2C Interrupt (must use in irq handler) – ROM_I2CMasterIntClear(I2C3_BASE); Enable the I2C Interrupts – ROM_I2CMasterIntEnable(I2C3_BASE);
5
ENTC-489 Embedded Real Time Software Development I2C Library Operation Write ROM_I2CMasterSlaveAddrSet(I2C3_BASE, address, false); ROM_I2CMasterDataPut(I2C3_BASE, data); ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START) Additional bytes sent with: – ROM_I2CMasterDataPut(I2C3_BASE,data); – ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_CONT); ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_ERROR_STOP) = Interrupt
6
ENTC-489 Embedded Real Time Software Development I2C Library Read 1 Byte Operation ROM_I2CMasterSlaveAddrSet(I2C3_BASE, address, true); ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE); data = ROM_I2CMasterDataGet(I2C3_BASE);
7
ENTC-489 Embedded Real Time Software Development I2C Library Read Multiple Byte Operation ROM_I2CMasterSlaveAddrSet(I2C3_BASE, address, true); ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); data = ROM_I2CMasterDataGet(I2C3_BASE); Additional Bytes: – ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT); – data = ROM_I2CMasterDataGet(I2C3_BASE); ROM_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP);
8
ENTC-489 Embedded Real Time Software Development Fixed Point Arithmetic
9
ENTC-489 Embedded Real Time Software Development Fixed Point Arithmetic
10
ENTC-489 Embedded Real Time Software Development Fixed Point Arithmetic Note the datasheet says the low order 2 bits are flags and must be discarded. Computation Shortcut: IQ15_SCALE is 2^15 so we could have just divided read_value by 2: e.g. temp_calc = read_value >> 1;
11
ENTC-489 Embedded Real Time Software Development Making Globals that Aren’t Global
12
ENTC-489 Embedded Real Time Software Development Message Queues Message queues are similar to mail boxes except they can buffer messages A message queue has at any given time 0 to N pointer sized messages in a FIFO (or LIFO) container. Pending on an empty message queue suspends the task until the message queue has a new message Pending on a message queue that is not empty removes the oldest message in the queue and gives it to the pending task
13
ENTC-489 Embedded Real Time Software Development Message Queues
14
ENTC-489 Embedded Real Time Software Development Key Message Queue Functions OS_EVENT *OSQCreate(void **start, INT16U size) Creates the queue, start points to the array that will hold the queue elements. You have to allocate the memory yourself. void *OSQPend(OS_EVENT *pevent, INT16U timeout, INT8U *err) Removes and returns the next element from the queue, Pends until there is an element available INT8U OSQPost(OS_EVENT *pevent, void *msg) Posts (FIFO) message in Queue INT8U OSQPostFront(OS_EVENT *pevent, void *msg) Posts (LIFO) message in Queue void *OSQAccept(OS_EVENT *pevent) Like OSQPend() but does not pause INT8U OSQQuery(OS_EVENT *pevent, OS_Q_DATA *pdata) Allows a task to view the status of the queue INT8U OSQFlush(OS_EVENT *pevent) Empties the queue
15
ENTC-489 Embedded Real Time Software Development Common Use for A Queue Message Logging – Use two queues, buf_q and msg_q. – buf_q is initially filled with pointers to a fixed number of buffers that will hold messages to be logged – Task wants to log a message Pend on buf_q to obtain a buffer to write in Use sprintf to format a message into the buffer Post the buffer to msg_q – Logging task Pen on msg_q Perform logging magic on the buffer received Post the used (now free) buffer to buf_q
16
ENTC-489 Embedded Real Time Software Development Event Flags Event flags are not available in all kernels In uC/OS they are an 8,16 or 32 bit value that is treated as a group of individual bits Can Pend on a set of bits as follows: – OS_FLAG_WAIT_CLEAR_ALL – OS_FLAG_WAIT CLEAR_ANY – OS_FLAG_WAIT_SET_ALL – OS_FLAG_WAIT_SET_ANY
17
ENTC-489 Embedded Real Time Software Development Event Flag Functions OS_FLAG_GRP *OSFlagCreate(OS_FLAGS flags, INT8U *err) Creates a flag group and initializes it to the value in flags OS_FLAGS OS_FlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U, timeout, INT8U *err) Pends on the flags (masked by “flags”) being any clear, all clear, any set, or all set (based on wait_type). Adding OS_FLAG_CONSUME to the wait_type resets the flags that were used to set the condition.
18
ENTC-489 Embedded Real Time Software Development Event Flag Functions OS_FLAGS OSFlagPost(OS_FLAG_GRP *pgrp, OS_FAGS flags, INT8U opt, INT8U *err) Sets or clears the flags masked by “flags” based on whether opt is OS_FLAG_SET or OS_FLAG_CLEAR OS_FLAGS OSFlagAccept(OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT8U *err) Identical to OSFlagPend() but does not pause
19
ENTC-489 Embedded Real Time Software Development Semaphores The players – Timer Keep track of time Writes down wakeup requests When an alarm occurs takes the “Running” flag from whoever has it and gives that task the “Interrupted” flag – Tells task waiting on alarm, to be “Ready” again – Takes “Interrupted” flag back (that task now uses its “Ready” flag) – Hands “Running” to the kernel – Kernel When holding the “Running” flag gives it to the highest priority task that is ready
20
ENTC-489 Embedded Real Time Software Development Semaphores The Players (cont) – Serial Input When given a character puts it in a stack If there is a “Dibs” sign, in the semaphore holder – Tells the task with “Dibs” they can go from pending to ready – Otherwise, puts a piece of chalk in the semaphore holder When asked for a character hands the one off the bottom. If no characters available takes the “running” sign from the task until given a character
21
ENTC-489 Embedded Real Time Software Development Semaphores The Players (cont) – Idle Task (lowest priority) Hums War Hymn when holding “Running” – Task Flashlight (second lowest priority) Toggles flashlight Pends for a 5 tick delay Hands running sign to kernel
22
ENTC-489 Embedded Real Time Software Development Semaphores The Players (cont) – Task Print (highest priority) Looks in the semaphore holder for a piece of chalk – If no chalk » puts in “Dibs” sign » Goes to Pending » Hands “running” sign to kernel – Otherwise, takes out one piece of chalk and asks Serial Input for a character » If character is a “!” yell Howdy damn it! » Any other character say “Howdy” » No character, hand input routine the “running” sign and wait
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.