Modified event_t structure to make it castable to void *

replace/83a39432f16a95b80c20934918c1c8f8c6655b5a
Silvano Seva 2020-12-05 22:14:58 +01:00 zatwierdzone przez Federico Amedeo Izzo
rodzic 94b37d9137
commit 014262f4df
2 zmienionych plików z 16 dodań i 8 usunięć

Wyświetl plik

@ -40,10 +40,15 @@ enum eventType_t
* But if we keep the size under 32 bits, we can sent the
* entire message, casting it to a void * pointer.
*/
typedef struct
typedef union
{
uint32_t type : 3;
uint32_t payload : 29;
struct
{
uint32_t type : 3,
payload : 29;
};
void *value;
}event_t;
#endif /* EVENT_H */

Wyświetl plik

@ -103,9 +103,12 @@ static void ui_task(void *arg)
while(1)
{
// Wait to receive an event message
event_t event = (event_t)OSQPend(&ui_queue, 0u, OS_OPT_PEND_BLOCKING,
&msg_size, 0u, &os_err);
// Read from the keyboard queue (returns 0 if no message is present)
// Copy keyboard_t keys from received void * pointer msg
void *msg = OSQPend(&ui_queue, 0u, OS_OPT_PEND_BLOCKING,
&msg_size, 0u, &os_err);
event_t event = ((event_t) msg);
// Lock mutex, read and write state
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
// React to keypresses and update FSM inside state
@ -152,9 +155,9 @@ static void kbd_task(void *arg)
event_t kbd_msg;
kbd_msg.type = EVENT_KBD;
kbd_msg.payload = keys;
void * msg = (void *) kbd_msg;
// Send keyboard status in queue
OSQPost(&ui_queue, msg, sizeof(event_t),
OSQPost(&ui_queue, (void *)kbd_msg.value, sizeof(event_t),
OS_OPT_POST_FIFO + OS_OPT_POST_NO_SCHED, &os_err);
}
// Read keyboard state at 5Hz