Shinichiro Nakamura
/
TestProgramForBugTopic1074
This is for http://mbed.org/forum/bugs-suggestions/topic/1074/
main.cpp@0:49c0ef6111e6, 2010-09-08 (annotated)
- Committer:
- shintamainjp
- Date:
- Wed Sep 08 12:53:38 2010 +0000
- Revision:
- 0:49c0ef6111e6
- Child:
- 1:70466efca68e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:49c0ef6111e6 | 1 | /** |
shintamainjp | 0:49c0ef6111e6 | 2 | * Test program for a bug. (http://mbed.org/forum/bugs-suggestions/topic/1074/) |
shintamainjp | 0:49c0ef6111e6 | 3 | * |
shintamainjp | 0:49c0ef6111e6 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:49c0ef6111e6 | 5 | * http://shinta.main.jp/ |
shintamainjp | 0:49c0ef6111e6 | 6 | */ |
shintamainjp | 0:49c0ef6111e6 | 7 | |
shintamainjp | 0:49c0ef6111e6 | 8 | #include "mbed.h" |
shintamainjp | 0:49c0ef6111e6 | 9 | #include "Semaphore.h" |
shintamainjp | 0:49c0ef6111e6 | 10 | |
shintamainjp | 0:49c0ef6111e6 | 11 | Serial ser(USBTX, USBRX); |
shintamainjp | 0:49c0ef6111e6 | 12 | Ticker ticker; |
shintamainjp | 0:49c0ef6111e6 | 13 | BusOut led(LED4, LED3, LED2, LED1); |
shintamainjp | 0:49c0ef6111e6 | 14 | Semaphore sem; |
shintamainjp | 0:49c0ef6111e6 | 15 | |
shintamainjp | 0:49c0ef6111e6 | 16 | char shared_resource; // This is a shared resource for example. |
shintamainjp | 0:49c0ef6111e6 | 17 | |
shintamainjp | 0:49c0ef6111e6 | 18 | #define LOCK() sem.take() |
shintamainjp | 0:49c0ef6111e6 | 19 | #define UNLOCK() sem.release() |
shintamainjp | 0:49c0ef6111e6 | 20 | |
shintamainjp | 0:49c0ef6111e6 | 21 | /** |
shintamainjp | 0:49c0ef6111e6 | 22 | * a ticker. |
shintamainjp | 0:49c0ef6111e6 | 23 | */ |
shintamainjp | 0:49c0ef6111e6 | 24 | void func_tick(void) { |
shintamainjp | 0:49c0ef6111e6 | 25 | led = led + 1; |
shintamainjp | 0:49c0ef6111e6 | 26 | } |
shintamainjp | 0:49c0ef6111e6 | 27 | |
shintamainjp | 0:49c0ef6111e6 | 28 | /** |
shintamainjp | 0:49c0ef6111e6 | 29 | * A call back function for serial interrupt. |
shintamainjp | 0:49c0ef6111e6 | 30 | */ |
shintamainjp | 0:49c0ef6111e6 | 31 | void func_serial_interrupt(void) { |
shintamainjp | 0:49c0ef6111e6 | 32 | LOCK(); |
shintamainjp | 0:49c0ef6111e6 | 33 | shared_resource = ser.getc(); |
shintamainjp | 0:49c0ef6111e6 | 34 | UNLOCK(); |
shintamainjp | 0:49c0ef6111e6 | 35 | } |
shintamainjp | 0:49c0ef6111e6 | 36 | |
shintamainjp | 0:49c0ef6111e6 | 37 | /** |
shintamainjp | 0:49c0ef6111e6 | 38 | * Entry point. |
shintamainjp | 0:49c0ef6111e6 | 39 | */ |
shintamainjp | 0:49c0ef6111e6 | 40 | int main() { |
shintamainjp | 0:49c0ef6111e6 | 41 | ticker.attach_us(&func_tick, 100 * 1000); |
shintamainjp | 0:49c0ef6111e6 | 42 | ser.attach(&func_serial_interrupt); |
shintamainjp | 0:49c0ef6111e6 | 43 | while(1) { |
shintamainjp | 0:49c0ef6111e6 | 44 | /* |
shintamainjp | 0:49c0ef6111e6 | 45 | * Hung up your mbed system if you hit keys on console for Serial. |
shintamainjp | 0:49c0ef6111e6 | 46 | */ |
shintamainjp | 0:49c0ef6111e6 | 47 | LOCK(); |
shintamainjp | 0:49c0ef6111e6 | 48 | printf("0x%x\n", shared_resource); |
shintamainjp | 0:49c0ef6111e6 | 49 | UNLOCK(); |
shintamainjp | 0:49c0ef6111e6 | 50 | wait_ms(100); |
shintamainjp | 0:49c0ef6111e6 | 51 | } |
shintamainjp | 0:49c0ef6111e6 | 52 | } |