diff --git a/demos/ARM7-LPC214x-GCC/Makefile b/demos/ARM7-LPC214x-GCC/Makefile index b69ae8780..2c8616b80 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile +++ b/demos/ARM7-LPC214x-GCC/Makefile @@ -77,7 +77,7 @@ TSRC = ASMSRC = crt0.s chcore2.s # List all user directories here -UINCDIR = ../../src/include ../../ports/ARM7-LPC214x/GCC +UINCDIR = ../../src/include ../../src/lib ../../ports/ARM7-LPC214x/GCC # List the user directory to look for the libraries here ULIBDIR = diff --git a/demos/ARM7-LPC214x-GCC/main.c b/demos/ARM7-LPC214x-GCC/main.c index 5db6815fb..564c03bfc 100644 --- a/demos/ARM7-LPC214x-GCC/main.c +++ b/demos/ARM7-LPC214x-GCC/main.c @@ -22,6 +22,7 @@ #include "lpc214x.h" #include "lpc214x_serial.h" #include "buzzer.h" +#include "evtimer.h" static BYTE8 waThread1[UserStackSize(32)]; @@ -53,24 +54,36 @@ static t_msg Thread2(void *arg) { return 0; } +static void TimerHandler(t_eventid id) { + + t_msg TestThread(void *p); + + if (!(IO0PIN & 0x00018000)) { // Both buttons + TestThread(&COM1); + PlaySound(500, 100); + } + else { + if (!(IO0PIN & 0x00008000)) // Button 1 + PlaySound(1000, 100); + if (!(IO0PIN & 0x00010000)) // Button 2 + chFDDWrite(&COM1, (BYTE8 *)"Hello World!\r\n", 14); + } +} + static BYTE8 waThread3[UserStackSize(64)]; +static EvTimer evt; +static t_evhandler evhndl[1] = { + TimerHandler +}; static t_msg Thread3(void *arg) { - t_msg TestThread(void *p); + struct EventListener el; - while (TRUE) { - if (!(IO0PIN & 0x00018000)) { - TestThread(&COM1); - PlaySound(500, 100); - } - else { - if (!(IO0PIN & 0x00008000)) // Button 1 - PlaySound(1000, 100); - if (!(IO0PIN & 0x00010000)) // Button 2 - chFDDWrite(&COM1, (BYTE8 *)"Hello World!\r\n", 14); - } - chThdSleep(500); - } + evtInit(&evt, 500); + evtRegister(&evt, &el, 0); + evtStart(&evt); + while (TRUE) + chEvtWait(ALL_EVENTS, evhndl); return 0; } diff --git a/readme.txt b/readme.txt index 3165ad1af..8392f96e2 100644 --- a/readme.txt +++ b/readme.txt @@ -45,6 +45,7 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet. main() procedure are performed before any thread starts. - Added chThdSetPriority() new API. - Added a generic events generator timer to the library code. +- Modified the ARM7-LPC214x-GCC demo to show the use of the event timer. - Added the "#ifdef __cplusplus" stuff to the header files. - Removed an obsolete definition in ./src/templates/chtypes.h. diff --git a/src/lib/evtimer.c b/src/lib/evtimer.c index 212c8f124..1ab384086 100644 --- a/src/lib/evtimer.c +++ b/src/lib/evtimer.c @@ -32,6 +32,7 @@ static void tmrcb(void *p) { EvTimer *etp = p; + chEvtSendI(&etp->et_es); chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp); } diff --git a/src/lib/evtimer.h b/src/lib/evtimer.h index 43b0374ee..dfe09f0be 100644 --- a/src/lib/evtimer.h +++ b/src/lib/evtimer.h @@ -46,9 +46,9 @@ extern "C" { /** * Initializes an \p EvTimer structure. */ -#define evtInit(et, i) (chEvtInit(&(etp)->et_es), \ - (etp)->et_vt.vt_func = NULL, \ - (etp)->et_interval = (i)) +#define evtInit(etp, i) (chEvtInit(&(etp)->et_es), \ + (etp)->et_vt.vt_func = NULL, \ + (etp)->et_interval = (i)) /** * Registers the invoking thread as listener on the timer event.