diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2013-06-04 10:20:53 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2013-06-04 10:20:53 +0900 |
commit | 7a09ac9a10ece38ec11c9d8588f198eea5c422b1 (patch) | |
tree | 262637b6745bfe0270c31301e393632be6f81241 /example-cdc/sample.c | |
parent | ca47da23f1f65fe86eef3ced72cbf2d750a17ff7 (diff) |
Now, it works with svc holding lock.
Diffstat (limited to 'example-cdc/sample.c')
-rw-r--r-- | example-cdc/sample.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/example-cdc/sample.c b/example-cdc/sample.c index 3cc87dc..fbb7bac 100644 --- a/example-cdc/sample.c +++ b/example-cdc/sample.c @@ -1,5 +1,6 @@ #include <stdint.h> #include <stdlib.h> +#include <string.h> #include <chopstx.h> #include "sys.h" /* for set_led */ #include "usb_lld.h" /* for set_led */ @@ -9,8 +10,7 @@ static chopstx_cond_t cnd0; static chopstx_cond_t cnd1; chopstx_mutex_t usb_mtx; -chopstx_cond_t cnd_usb_connection; -chopstx_cond_t cnd_usb_buffer_ready; +chopstx_cond_t cnd_usb; static uint8_t u, v; static uint8_t m; /* 0..100 */ @@ -102,12 +102,23 @@ const size_t __stacksize_blk = (size_t)&__process2_stack_size__; const uint32_t __stackaddr_intr = (uint32_t)&__process3_stack_base__; const size_t __stacksize_intr = (size_t)&__process3_stack_size__; +static char hexchar (uint8_t x) +{ + if (x <= 0x09) + return '0' + x; + else if (x <= 0x0f) + return 'a' + x - 10; + else + return '?'; +} + int main (int argc, const char *argv[]) { chopstx_t thd; chopstx_attr_t attr; + uint8_t count; (void)argc; (void)argv; @@ -117,8 +128,7 @@ main (int argc, const char *argv[]) chopstx_cond_init (&cnd1); chopstx_mutex_init (&usb_mtx); - chopstx_cond_init (&cnd_usb_connection); - chopstx_cond_init (&cnd_usb_buffer_ready); + chopstx_cond_init (&cnd_usb); m = 10; @@ -149,21 +159,33 @@ main (int argc, const char *argv[]) { extern uint8_t connected; + count= 0; + u = 1; /* waiting USB connection */ chopstx_mutex_lock (&usb_mtx); if (!connected) - chopstx_cond_wait (&cnd_usb_connection, &usb_mtx); + chopstx_cond_wait (&cnd_usb, &usb_mtx); chopstx_mutex_unlock (&usb_mtx); while (1) { + char s[32]; + u ^= 1; chopstx_usec_wait (200*1000*6); - usb_lld_write (ENDP1, "Hello, World with Chopstx!\r\n", 28); + memcpy (s, "xx: Hello, World with Chopstx!\r\n", 32); + s[0] = hexchar (count >> 4); + s[1] = hexchar (count & 0x0f); + count++; + chopstx_mutex_lock (&usb_mtx); - chopstx_cond_wait (&cnd_usb_buffer_ready, &usb_mtx); - if (!connected) + if (connected) + { + usb_lld_write (ENDP1, s, 32); + chopstx_cond_wait (&cnd_usb, &usb_mtx); + } + else break; chopstx_mutex_unlock (&usb_mtx); } |