OSDN Git Service

Update lejos_osek to nxtOSEK_v205b0.zip
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples / usbtest / usbtest.c
1 /* usbtest.c */\r
2 #include <string.h>\r
3 \r
4 #include "kernel.h"\r
5 #include "kernel_id.h"\r
6 #include "ecrobot_interface.h"\r
7 \r
8 /* OSEK declarations */\r
9 DeclareTask(Task1); \r
10 \r
11 /* below macro enables run-time USB connection */\r
12 #define RUNTIME_CONNECTION\r
13 \r
14 /* LEJOS OSEK hooks */\r
15 void ecrobot_device_initialize()\r
16 {\r
17 #ifndef RUNTIME_CONNECTION\r
18         ecrobot_init_usb(); /* init USB */\r
19 #endif\r
20 }\r
21 \r
22 void ecrobot_device_terminate()\r
23 {\r
24         ecrobot_term_usb();\r
25 }\r
26 \r
27 /* LEJOS OSEK hook to be invoked from an ISR in category 2 */\r
28 void user_1ms_isr_type2(void){}\r
29 \r
30 #define MAX_NUM_OF_CHAR 16\r
31 #define MAX_NUM_OF_LINE 8\r
32 \r
33 static void display_usb_data(U8 *data, int len)\r
34 {\r
35         int i;\r
36         static int pos_x = 0;\r
37         static int pos_y = 0;\r
38 \r
39         /* set LCD postion in x, y */\r
40         if (pos_x >= MAX_NUM_OF_CHAR)\r
41         {\r
42                 pos_x = 0;\r
43                 pos_y++;\r
44         }\r
45 \r
46         if (pos_y >= MAX_NUM_OF_LINE)\r
47         {\r
48                 pos_x = 0;\r
49                 pos_y = 0;\r
50         }\r
51                         \r
52         if (pos_x == 0 && pos_y == 0)\r
53         {\r
54                 display_clear(0);\r
55         }\r
56         display_goto_xy(pos_x, pos_y);\r
57 \r
58         for (i = 0; i < len; i++)\r
59         {\r
60                 if (data[i] == '\n')\r
61                 {\r
62                         pos_x = 0;\r
63                         pos_y++;\r
64                         break;\r
65                 }\r
66                 else\r
67                 {\r
68                         display_string((char *)&data[i]);\r
69                         display_update();\r
70                         if (i == (len - 1))\r
71                         {\r
72                                 pos_x += len;\r
73                                 break;\r
74                         }\r
75                 }\r
76         }\r
77 }\r
78 \r
79 TASK(Task1)\r
80 {\r
81         int len;\r
82         U8 data[MAX_USB_DATA_SIZE];\r
83 \r
84 #ifdef RUNTIME_CONNECTION\r
85         ecrobot_init_usb(); /* init USB */\r
86 #endif\r
87 \r
88         display_clear(0);\r
89         display_goto_xy(0, 0);\r
90         display_string("USB TEST");\r
91         display_goto_xy(0, 1);\r
92         display_string("Run usbhost.exe");\r
93         display_update();\r
94         while(1)\r
95         {\r
96                 memset(data, 0, MAX_USB_DATA_SIZE);\r
97                 len = ecrobot_read_usb(data, MAX_USB_DATA_SIZE); /* read USB data */\r
98                 \r
99                 if (len > 0)\r
100                 {\r
101                         ecrobot_send_usb(data, len);    /* send USB data */\r
102                         display_usb_data(data, len);\r
103                 }\r
104         }\r
105   \r
106         TerminateTask();\r
107 }\r