rtos signal test program

Dependencies:   RTOS-errstr mbed-rtos mbed

Committer:
YasuhiroKawai
Date:
Sun Jul 23 02:36:45 2017 +0000
Revision:
1:79cd2642890c
Parent:
0:8cc0dbb478dc
Child:
3:1b9c07fe623b
Change type of signal from uint32_t to int32_t.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YasuhiroKawai 0:8cc0dbb478dc 1 /**
YasuhiroKawai 0:8cc0dbb478dc 2 *
YasuhiroKawai 0:8cc0dbb478dc 3 */
YasuhiroKawai 0:8cc0dbb478dc 4
YasuhiroKawai 0:8cc0dbb478dc 5 #include <mbed.h>
YasuhiroKawai 0:8cc0dbb478dc 6 #include <rtos.h>
YasuhiroKawai 0:8cc0dbb478dc 7 #include "RTOSerrstr.h"
YasuhiroKawai 0:8cc0dbb478dc 8
YasuhiroKawai 0:8cc0dbb478dc 9 typedef struct {
YasuhiroKawai 1:79cd2642890c 10 int32_t wait_signal;
YasuhiroKawai 1:79cd2642890c 11 int32_t signal_flag;
YasuhiroKawai 0:8cc0dbb478dc 12 } sig_table_t;
YasuhiroKawai 0:8cc0dbb478dc 13
YasuhiroKawai 0:8cc0dbb478dc 14 Serial pc(SERIAL_TX, SERIAL_RX);
YasuhiroKawai 0:8cc0dbb478dc 15 DigitalOut myled(LED1);
YasuhiroKawai 0:8cc0dbb478dc 16 Thread thread;
YasuhiroKawai 0:8cc0dbb478dc 17 Semaphore sem;
YasuhiroKawai 0:8cc0dbb478dc 18
YasuhiroKawai 0:8cc0dbb478dc 19 volatile uint32_t signal;
YasuhiroKawai 0:8cc0dbb478dc 20
YasuhiroKawai 0:8cc0dbb478dc 21 static const sig_table_t tbl[] = {
YasuhiroKawai 0:8cc0dbb478dc 22 { 0x0000, 0x0000, },
YasuhiroKawai 0:8cc0dbb478dc 23 { 0x0000, 0x0001, },
YasuhiroKawai 0:8cc0dbb478dc 24 { 0x0000, 0x0002, },
YasuhiroKawai 0:8cc0dbb478dc 25 { 0x0000, 0x0007, },
YasuhiroKawai 0:8cc0dbb478dc 26 { 0x0000, 0x0080, },
YasuhiroKawai 0:8cc0dbb478dc 27 { 0x0000, 0x10000, },
YasuhiroKawai 0:8cc0dbb478dc 28 { 0x0001, 0x0001, },
YasuhiroKawai 0:8cc0dbb478dc 29 { 0x0003, 0x0003, },
YasuhiroKawai 0:8cc0dbb478dc 30 { 0x0003, 0x0001, },
YasuhiroKawai 0:8cc0dbb478dc 31 { 0x0003, 0x0002, },
YasuhiroKawai 0:8cc0dbb478dc 32 };
YasuhiroKawai 0:8cc0dbb478dc 33
YasuhiroKawai 0:8cc0dbb478dc 34 void
YasuhiroKawai 0:8cc0dbb478dc 35 signal_wait_thread(void const *argument)
YasuhiroKawai 0:8cc0dbb478dc 36 {
YasuhiroKawai 0:8cc0dbb478dc 37 static uint32_t i = 0;
YasuhiroKawai 0:8cc0dbb478dc 38 osEvent evt;
YasuhiroKawai 0:8cc0dbb478dc 39
YasuhiroKawai 0:8cc0dbb478dc 40 while (true) {
YasuhiroKawai 0:8cc0dbb478dc 41 signal = tbl[i].signal_flag;
YasuhiroKawai 0:8cc0dbb478dc 42 pc.printf("sig = 0x%08x 0x%03x\n", tbl[i].wait_signal, signal);
YasuhiroKawai 0:8cc0dbb478dc 43 sem.release();
YasuhiroKawai 0:8cc0dbb478dc 44 evt = Thread::signal_wait(tbl[i].wait_signal, 1000);
YasuhiroKawai 0:8cc0dbb478dc 45 if (evt.status != osOK) {
YasuhiroKawai 0:8cc0dbb478dc 46 pc.printf("%s\n", getOsStatusStr(evt.status));
YasuhiroKawai 0:8cc0dbb478dc 47 }
YasuhiroKawai 0:8cc0dbb478dc 48 //thread.signal_clr(signal);
YasuhiroKawai 0:8cc0dbb478dc 49 i++;
YasuhiroKawai 0:8cc0dbb478dc 50 if (i >= sizeof(tbl) / sizeof(sig_table_t)) {
YasuhiroKawai 0:8cc0dbb478dc 51 i = 0;
YasuhiroKawai 0:8cc0dbb478dc 52 }
YasuhiroKawai 0:8cc0dbb478dc 53 }
YasuhiroKawai 0:8cc0dbb478dc 54 }
YasuhiroKawai 0:8cc0dbb478dc 55
YasuhiroKawai 0:8cc0dbb478dc 56
YasuhiroKawai 0:8cc0dbb478dc 57
YasuhiroKawai 0:8cc0dbb478dc 58 int main()
YasuhiroKawai 0:8cc0dbb478dc 59 {
YasuhiroKawai 1:79cd2642890c 60 int32_t status;
YasuhiroKawai 0:8cc0dbb478dc 61
YasuhiroKawai 0:8cc0dbb478dc 62 pc.baud(115200);
YasuhiroKawai 0:8cc0dbb478dc 63 pc.printf("signal test[%s %s]\n", __DATE__, __TIME__);
YasuhiroKawai 0:8cc0dbb478dc 64
YasuhiroKawai 0:8cc0dbb478dc 65 thread.start(callback(signal_wait_thread, (void const *)NULL)); // start thread
YasuhiroKawai 0:8cc0dbb478dc 66 while(1) {
YasuhiroKawai 0:8cc0dbb478dc 67 sem.wait();
YasuhiroKawai 0:8cc0dbb478dc 68 myled = !myled;
YasuhiroKawai 0:8cc0dbb478dc 69 Thread::wait(1000);
YasuhiroKawai 0:8cc0dbb478dc 70 status = thread.signal_set(signal);
YasuhiroKawai 0:8cc0dbb478dc 71 if (status == 0x80000000) {
YasuhiroKawai 0:8cc0dbb478dc 72 pc.printf("signal_set(0x%04x) failed.\n", status);
YasuhiroKawai 0:8cc0dbb478dc 73 } else if (status != 0) {
YasuhiroKawai 0:8cc0dbb478dc 74 pc.printf("signal_set() returns 0x%08x.\n", status);
YasuhiroKawai 0:8cc0dbb478dc 75 }
YasuhiroKawai 0:8cc0dbb478dc 76 }
YasuhiroKawai 0:8cc0dbb478dc 77 }