[457] | 1 | /*
|
---|
| 2 | * TOPPERS/ASP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Advanced Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | * Copyright (C) 2004-2012 by Embedded and Real-Time Systems Laboratory
|
---|
| 9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 10 | *
|
---|
| 11 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 12 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 13 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 14 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 15 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 16 | * スコード中に含まれていること.
|
---|
| 17 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 18 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 19 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 20 | * の無保証規定を掲載すること.
|
---|
| 21 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 22 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 23 | * と.
|
---|
| 24 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 25 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 26 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 27 | * 報告すること.
|
---|
| 28 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 29 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 30 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 31 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 32 | * 免責すること.
|
---|
| 33 | *
|
---|
| 34 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 35 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 36 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 37 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 38 | * の責任を負わない.
|
---|
| 39 | *
|
---|
| 40 | * $Id$
|
---|
| 41 | */
|
---|
| 42 |
|
---|
| 43 | /*
|
---|
| 44 | * USB OTGテストの本体
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | #include <kernel.h>
|
---|
| 48 | #include <t_syslog.h>
|
---|
| 49 | #include <t_stdlib.h>
|
---|
| 50 | #include <sil.h>
|
---|
| 51 | #include "syssvc/serial.h"
|
---|
| 52 | #include "syssvc/syslog.h"
|
---|
| 53 | #include "kernel_cfg.h"
|
---|
| 54 | #include <target_syssvc.h>
|
---|
| 55 | #include "device.h"
|
---|
| 56 | #include "usb_otg.h"
|
---|
| 57 |
|
---|
| 58 | #include "usbotest.h"
|
---|
| 59 |
|
---|
| 60 | #include "tusbd_base.h"
|
---|
| 61 | #if USB_OTG_MODE != USB_OTG_MODE_HOST
|
---|
| 62 | #include "tusbd_device.h"
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | /*
|
---|
| 66 | * サービスコールのエラーのログ出力
|
---|
| 67 | */
|
---|
| 68 | Inline void
|
---|
| 69 | svc_perror(const char *file, int_t line, const char *expr, ER ercd)
|
---|
| 70 | {
|
---|
| 71 | if (ercd < 0) {
|
---|
| 72 | t_perror(LOG_ERROR, file, line, expr, ercd);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | #define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
|
---|
| 77 |
|
---|
| 78 | #define CURSOR_STEP 5
|
---|
| 79 |
|
---|
| 80 | USBH_HandleTypeDef hUSBHost;
|
---|
| 81 | USBD_HandleTypeDef USBD_Device;
|
---|
| 82 |
|
---|
| 83 | uint8_t ukey;
|
---|
| 84 | uint8_t device_state[16];
|
---|
| 85 | Line_Coding_t CDC_Info = {
|
---|
| 86 | 115200,
|
---|
| 87 | 0,
|
---|
| 88 | 0,
|
---|
| 89 | 8
|
---|
| 90 | };
|
---|
| 91 | uint8_t send_buffer[] = "help\r\nhelp\r\n";
|
---|
| 92 | uint8_t receive_buffer[512] __attribute__ ((aligned (32)));
|
---|
| 93 | uint8_t scratch[512];
|
---|
| 94 |
|
---|
| 95 | uint8_t HID_Buffer[4];
|
---|
| 96 |
|
---|
| 97 | static uint32_t heap_area[4*1024];
|
---|
| 98 |
|
---|
| 99 | uint32_t heap_param[2] = {
|
---|
| 100 | (uint32_t)heap_area,
|
---|
| 101 | (4*4*1024)
|
---|
| 102 | };
|
---|
| 103 |
|
---|
| 104 | /*
|
---|
| 105 | * SW1割込み
|
---|
| 106 | */
|
---|
| 107 | void sw_int(void)
|
---|
| 108 | {
|
---|
| 109 | ukey = 1;
|
---|
| 110 | syslog_0(LOG_NOTICE, "## sw_int() ##");
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | #if USB_OTG_MODE != USB_OTG_MODE_DEVICE
|
---|
| 115 | /*
|
---|
| 116 | * USB HOST USER CALLBACK関数
|
---|
| 117 | */
|
---|
| 118 | static void USBH_UserProcess(USBH_HandleTypeDef *phost, TUSBH_Device_t *pdevice, uint8_t id)
|
---|
| 119 | {
|
---|
| 120 | device_state[pdevice->type] = id;
|
---|
| 121 | if(pdevice->pClass != NULL){
|
---|
| 122 | syslog_3(LOG_NOTICE, "## CLASS[%s](%d)(%d) ##", pdevice->pClass->Name, pdevice->type, id);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /*
|
---|
| 127 | * MSC SECTOR READ
|
---|
| 128 | */
|
---|
| 129 | static void MSC_Read_Operations(void){
|
---|
| 130 | TUSBH_ERCODE status = TUSBH_E_OK;
|
---|
| 131 | char pdrv = 0;
|
---|
| 132 |
|
---|
| 133 | if(tusbhMscUnitIsReady (&hUSBHost, pdrv)){
|
---|
| 134 | syslog_0(LOG_NOTICE, "READY");
|
---|
| 135 | }
|
---|
| 136 | else{
|
---|
| 137 | syslog_0(LOG_NOTICE, "NOT READY");
|
---|
| 138 | }
|
---|
| 139 | status = tusbhMscRead(&hUSBHost, pdrv, 0, (uint8_t *)scratch, 1);
|
---|
| 140 | syslog_1(LOG_NOTICE, "## status(%d) ##", status);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /*
|
---|
| 144 | * HID CALLBACK関数
|
---|
| 145 | */
|
---|
| 146 | static void HID_Callback(TUSBH_Device_t *pdevice, uint8_t length, uint8_t *buffer)
|
---|
| 147 | {
|
---|
| 148 | void *phandle = pdevice->pData;
|
---|
| 149 | uint8_t type = tusbhHidGetType(pdevice);
|
---|
| 150 | if(length == 0){
|
---|
| 151 | if(type == HID_KEYBOARD_TYPE)
|
---|
| 152 | HidKeyboardInit(phandle);
|
---|
| 153 | else if(type == HID_MOUSE_TYPE)
|
---|
| 154 | HidMouseInit(phandle);
|
---|
| 155 | }
|
---|
| 156 | else{
|
---|
| 157 | #if 1 /* ROI DEBUG */
|
---|
| 158 | uint8_t *p = buffer;
|
---|
| 159 | syslog_5(LOG_NOTICE, "## HID_Callback len(%d) [%02x][%02x][%02x][%02x] ##", length, p[0], p[1], p[2], p[3]);
|
---|
| 160 | #endif /* ROI DEBUG */
|
---|
| 161 |
|
---|
| 162 | if(type == HID_KEYBOARD_TYPE){
|
---|
| 163 | KEYBOARD_Info_t k_info;
|
---|
| 164 | if(HidGetKeyboardInfo(phandle, &k_info, buffer, length) == TUSBH_E_OK){
|
---|
| 165 | char c = HidGetASCIICode(&k_info);
|
---|
| 166 | if(c != 0){
|
---|
| 167 | syslog_1(LOG_NOTICE, "## KEY[%02x] ##", c);
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 | else if(type == HID_MOUSE_TYPE){
|
---|
| 172 | MOUSE_Info_t m_info;
|
---|
| 173 | if(HidMouseInfo(phandle, &m_info, buffer, length) == TUSBH_E_OK){
|
---|
| 174 | syslog_3(LOG_NOTICE, "button left(%d) right(%d) middle(%d)", m_info.button_left, m_info.button_right, m_info.button_middle);
|
---|
| 175 | syslog_3(LOG_NOTICE, "position x (%d) y (%d) z (%d)", m_info.x, m_info.y, m_info.z);
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | /*
|
---|
| 182 | * CDC CALLBACK関数
|
---|
| 183 | */
|
---|
| 184 | static void CDC_Callback(TUSBH_Device_t *pdevice, uint8_t type)
|
---|
| 185 | {
|
---|
| 186 | syslog_2(LOG_NOTICE, "## CDC_Callback[%08x](%d) ##", pdevice, type);
|
---|
| 187 | }
|
---|
| 188 | #endif
|
---|
| 189 |
|
---|
| 190 | #if USB_OTG_MODE != USB_OTG_MODE_HOST
|
---|
| 191 | #if USB_DEVICE_ID == 0
|
---|
| 192 |
|
---|
| 193 | uint8_t HID_Buffer[4];
|
---|
| 194 |
|
---|
| 195 | /*
|
---|
| 196 | * HID MOUSE DEVICE CLASS REQUEST
|
---|
| 197 | * parameter1: pbuf データ設定バッファ
|
---|
| 198 | */
|
---|
| 199 | static void GetPointerData(uint8_t *pbuf)
|
---|
| 200 | {
|
---|
| 201 | static int8_t cnt = 0;
|
---|
| 202 | int8_t x = 0, y = 0 ;
|
---|
| 203 |
|
---|
| 204 | if(cnt++ > 0)
|
---|
| 205 | {
|
---|
| 206 | x = CURSOR_STEP;
|
---|
| 207 | }
|
---|
| 208 | else
|
---|
| 209 | {
|
---|
| 210 | x = -CURSOR_STEP;
|
---|
| 211 | }
|
---|
| 212 | pbuf[0] = 0;
|
---|
| 213 | pbuf[1] += x;
|
---|
| 214 | pbuf[2] += y;
|
---|
| 215 | pbuf[3] = 0;
|
---|
| 216 | }
|
---|
| 217 | #else
|
---|
| 218 |
|
---|
| 219 | #define APP_TX_DATA_SIZE 2048
|
---|
| 220 |
|
---|
| 221 | #define FLG_CDC_SET_LINE_CODING 0x0001
|
---|
| 222 | #define FLG_CDC_GET_LINE_CODING 0x0002
|
---|
| 223 | #define FLG_CDC_SET_CONTROL_LINE_STATE 0x0004
|
---|
| 224 | #define FLG_CDC_SEND_BREAK 0x0008
|
---|
| 225 | #define FLG_CDC_RECEIVE_DATA 0x0010
|
---|
| 226 | #define FLG_CDC_SEND_FLUSH 0x0100
|
---|
| 227 |
|
---|
| 228 | static uint8_t txBuffer[APP_TX_DATA_SIZE] __attribute__ ((aligned (32)));/* Received Data over UART (CDC interface) are stored in this buffer */
|
---|
| 229 | static uint8_t *pTransRxBuffer;
|
---|
| 230 | static uint16_t TransRxLength;
|
---|
| 231 | static uint16_t TransRxCount;
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 | Line_Coding_t LineCoding =
|
---|
| 235 | {
|
---|
| 236 | 115200, /* baud rate*/
|
---|
| 237 | 0x00, /* stop bits-1*/
|
---|
| 238 | 0x00, /* parity - none*/
|
---|
| 239 | 0x08 /* nb. of bits 8*/
|
---|
| 240 | };
|
---|
| 241 |
|
---|
| 242 | /*
|
---|
| 243 | * CDC DEVICE CLASS REQUEST
|
---|
| 244 | * parameter1: hcdc CDCハンドラ
|
---|
| 245 | * parameter2: cmd 要求コマンド
|
---|
| 246 | * parameter3: length データ長
|
---|
| 247 | */
|
---|
| 248 | static void CdcDeviceRequest(TUSBD_CDC_Handle_t *hcdc, uint8_t cmd, uint32_t length)
|
---|
| 249 | {
|
---|
| 250 | switch (cmd){
|
---|
| 251 | case CDC_SEND_ENCAPSULATED_COMMAND:
|
---|
| 252 | syslog_2(LOG_NOTICE, "## CdcDeviceRequest CDC_SEND_ENCAPSULATED_COMMAND hcdc[%08x] length(%d) ##", hcdc, length);
|
---|
| 253 | break;
|
---|
| 254 |
|
---|
| 255 | case CDC_GET_ENCAPSULATED_RESPONSE:
|
---|
| 256 | syslog_2(LOG_NOTICE, "## CdcDeviceRequest CDC_GET_ENCAPSULATED_RESPONSE hcdc[%08x] length(%d) ##", hcdc, length);
|
---|
| 257 | break;
|
---|
| 258 |
|
---|
| 259 | case CDC_SET_COMM_FEATURE:
|
---|
| 260 | syslog_2(LOG_NOTICE, "## CdcDeviceRequest CDC_SET_COMM_FEATURE hcdc[%08x] length(%d) ##", hcdc, length);
|
---|
| 261 | break;
|
---|
| 262 |
|
---|
| 263 | case CDC_GET_COMM_FEATURE:
|
---|
| 264 | syslog_2(LOG_NOTICE, "## CDC_GET_COMM_FEATURE hcdc[%08x] length(%d) ##", hcdc, length);
|
---|
| 265 | break;
|
---|
| 266 |
|
---|
| 267 | case CDC_CLEAR_COMM_FEATURE:
|
---|
| 268 | syslog_2(LOG_NOTICE, "## CDC_CLEAR_COMM_FEATURE hcdc[%08x] length(%d) ##", hcdc, length);
|
---|
| 269 | break;
|
---|
| 270 |
|
---|
| 271 | case CDC_SET_LINE_CODING:
|
---|
| 272 | memcpy(&LineCoding, hcdc->cmddata, sizeof(Line_Coding_t));
|
---|
| 273 | iset_flg(USBCDC_FLG, FLG_CDC_SET_LINE_CODING);
|
---|
| 274 | break;
|
---|
| 275 |
|
---|
| 276 | case CDC_GET_LINE_CODING:
|
---|
| 277 | memcpy(hcdc->cmddata, &LineCoding, sizeof(Line_Coding_t));
|
---|
| 278 | break;
|
---|
| 279 |
|
---|
| 280 | case CDC_SET_CONTROL_LINE_STATE:
|
---|
| 281 | iset_flg(USBCDC_FLG, FLG_CDC_SET_CONTROL_LINE_STATE);
|
---|
| 282 | break;
|
---|
| 283 |
|
---|
| 284 | case CDC_SEND_BREAK:
|
---|
| 285 | iset_flg(USBCDC_FLG, FLG_CDC_SEND_BREAK);
|
---|
| 286 | break;
|
---|
| 287 |
|
---|
| 288 | case CDC_RECEIVED:
|
---|
| 289 | pTransRxBuffer = hcdc->rxdata;
|
---|
| 290 | TransRxLength = length;
|
---|
| 291 | TransRxCount = 0;
|
---|
| 292 | iset_flg(USBCDC_FLG, FLG_CDC_RECEIVE_DATA);
|
---|
| 293 | break;
|
---|
| 294 |
|
---|
| 295 | default:
|
---|
| 296 | syslog_3(LOG_NOTICE, "## CdcDeviceRequest cmd[%02x] hcdc[%08x] length(%d) ##", cmd, hcdc, length);
|
---|
| 297 | break;
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 | #endif
|
---|
| 301 | #endif
|
---|
| 302 |
|
---|
| 303 | /*
|
---|
| 304 | * メインタスク
|
---|
| 305 | */
|
---|
| 306 | void main_task(intptr_t exinf)
|
---|
| 307 | {
|
---|
| 308 | USB_OTG_Init_t USB_Data_Init;
|
---|
| 309 | USB_OTG_Handle_t *husb;
|
---|
| 310 | ER_UINT ercd;
|
---|
| 311 | TUSBH_ERCODE result;
|
---|
| 312 | #if USB_OTG_MODE != USB_OTG_MODE_DEVICE
|
---|
| 313 | Line_Coding_t CDC_data;
|
---|
| 314 | uint32_t length;
|
---|
| 315 | uint32_t count = 0;
|
---|
| 316 | #endif
|
---|
| 317 |
|
---|
| 318 | SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)));
|
---|
| 319 | syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);
|
---|
| 320 |
|
---|
| 321 | /*
|
---|
| 322 | * シリアルポートの初期化
|
---|
| 323 | *
|
---|
| 324 | * システムログタスクと同じシリアルポートを使う場合など,シリアル
|
---|
| 325 | * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は
|
---|
| 326 | * ない.
|
---|
| 327 | */
|
---|
| 328 | ercd = serial_opn_por(TASK_PORTID);
|
---|
| 329 | if (ercd < 0 && MERCD(ercd) != E_OBJ) {
|
---|
| 330 | syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.",
|
---|
| 331 | itron_strerror(ercd), SERCD(ercd));
|
---|
| 332 | }
|
---|
| 333 | SVC_PERROR(serial_ctl_por(TASK_PORTID,
|
---|
| 334 | (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
|
---|
| 335 |
|
---|
| 336 | /*
|
---|
| 337 | * USB OTG初期化
|
---|
| 338 | */
|
---|
| 339 | USB_Data_Init.usb_otg_mode = USB_OTG_MODE;
|
---|
| 340 | USB_Data_Init.host_channels = 11; /* HOST */
|
---|
| 341 | USB_Data_Init.dev_endpoints = 4; /* DEV */
|
---|
| 342 | USB_Data_Init.use_dedicated_ep1 = 0; /* DEV */
|
---|
| 343 | USB_Data_Init.dma_enable = 0;
|
---|
| 344 | USB_Data_Init.low_power_enable = 0;
|
---|
| 345 | USB_Data_Init.phy_itface = USB_PHY_EMBEDDED;
|
---|
| 346 | USB_Data_Init.sof_enable = 0;
|
---|
| 347 | USB_Data_Init.speed = USB_SPEED_FULL;
|
---|
| 348 | #if USB_OTG_MODE != USB_OTG_MODE_HOST
|
---|
| 349 | USB_Data_Init.vbus_sensing_enable = 1; /* HOST/DEV */
|
---|
| 350 | #else
|
---|
| 351 | USB_Data_Init.vbus_sensing_enable = 0; /* HOST */
|
---|
| 352 | #endif
|
---|
| 353 | USB_Data_Init.lpm_enable = 0;
|
---|
| 354 | USB_Data_Init.use_external_vbus = 0;
|
---|
| 355 | husb = usbo_init(USB1_PORTID, &USB_Data_Init);
|
---|
| 356 | #if 1 /* ROI DEBUG */
|
---|
| 357 | if(husb == NULL){
|
---|
| 358 | syslog_0(LOG_NOTICE, "## usbo_init error STOP ##");
|
---|
| 359 | slp_tsk();
|
---|
| 360 | }
|
---|
| 361 | #endif /* ROI DEBUG */
|
---|
| 362 |
|
---|
| 363 | #if USB_OTG_MODE != USB_OTG_MODE_HOST
|
---|
| 364 | /*
|
---|
| 365 | * USB DEVICEミドルウェア初期化
|
---|
| 366 | */
|
---|
| 367 | USBD_Device.pSysData = husb;
|
---|
| 368 | result = tusbdInit(&USBD_Device, USB_DEVICE_ID);
|
---|
| 369 | syslog_1(LOG_NOTICE, "## tusbdInit result(%d) ##", result);
|
---|
| 370 | MakeUsbDescriptor(&USBD_Device);
|
---|
| 371 |
|
---|
| 372 | #if USB_DEVICE_ID != 0
|
---|
| 373 | USBD_Device.pUsrData = CdcDeviceRequest;
|
---|
| 374 | #endif
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 | * USB DEVICEスタート
|
---|
| 378 | */
|
---|
| 379 | result = tusbdStart(&USBD_Device);
|
---|
| 380 | syslog_1(LOG_NOTICE, "## tusbdStart result(%d) ##", result);
|
---|
| 381 | act_tsk(USBD_TASK);
|
---|
| 382 | #endif
|
---|
| 383 |
|
---|
| 384 | #if USB_OTG_MODE != USB_OTG_MODE_DEVICE
|
---|
| 385 | /*
|
---|
| 386 | * USB HOSTミドルウェア設定
|
---|
| 387 | */
|
---|
| 388 | hUSBHost.pSysData = husb;
|
---|
| 389 | tusbhInit(&hUSBHost, USBH_UserProcess, 0);
|
---|
| 390 |
|
---|
| 391 | tusbhSetHidCallBack(&hUSBHost, HID_Callback);
|
---|
| 392 | tusbhSetCdcCallBack(&hUSBHost, CDC_Callback);
|
---|
| 393 |
|
---|
| 394 | /*
|
---|
| 395 | * USB HOSTスタート
|
---|
| 396 | */
|
---|
| 397 | result = tusbhStart(&hUSBHost);
|
---|
| 398 | syslog_1(LOG_NOTICE, "## tusbhStart result(%d) ##", result);
|
---|
| 399 |
|
---|
| 400 | /*
|
---|
| 401 | * USB HOSTアプリ処理
|
---|
| 402 | */
|
---|
| 403 | while (1){
|
---|
| 404 | if(device_state[MSC_CLASS] == HOST_USER_CLASS_ACTIVE){
|
---|
| 405 | syslog_0(LOG_NOTICE, "Press User button to start");
|
---|
| 406 | syslog_0(LOG_NOTICE, "read and write operations");
|
---|
| 407 | /* KEY待ち */
|
---|
| 408 | ukey = 0;
|
---|
| 409 | while((ukey != 1) && (device_state[MSC_CLASS] != HOST_USER_DISCONNECTION)){
|
---|
| 410 | dly_tsk(1);
|
---|
| 411 | }
|
---|
| 412 | MSC_Read_Operations();
|
---|
| 413 | dly_tsk(400);
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | if(device_state[MSC_CLASS] == HOST_USER_DISCONNECTION){
|
---|
| 417 | device_state[MSC_CLASS] = 0;
|
---|
| 418 | syslog_0(LOG_ERROR, "MSC device disconnected!\n");
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | /*
|
---|
| 422 | * CDC SERIAL処理
|
---|
| 423 | */
|
---|
| 424 | if(device_state[CDC_CLASS] == HOST_USER_CLASS_ACTIVE){
|
---|
| 425 | static bool_t cdc_init = true;
|
---|
| 426 | if(cdc_init){
|
---|
| 427 | syslog_1(LOG_NOTICE, "## device_state(%d) ##", device_state[CDC_CLASS]);
|
---|
| 428 | tusbhCdcSetLineCoding(&hUSBHost, 0, &CDC_Info);
|
---|
| 429 | dly_tsk(100);
|
---|
| 430 | tusbhCdcGetLineCoding(&hUSBHost, 0, &CDC_data);
|
---|
| 431 | result = tusbhCdcSend(&hUSBHost, 0, send_buffer, sizeof(send_buffer));
|
---|
| 432 | syslog_4(LOG_NOTICE, "CDC INFO baud(%d) format(%d) parity(%d) data(%d)", CDC_data.baudrate, CDC_data.stop_bits, CDC_data.parity, CDC_data.data_bits);
|
---|
| 433 | syslog_1(LOG_NOTICE, "## send result(%d) ##", result);
|
---|
| 434 | cdc_init = false;
|
---|
| 435 | }
|
---|
| 436 | length = 512;
|
---|
| 437 | result = tusbhCdcReceive(&hUSBHost, 0, receive_buffer, &length, 500);
|
---|
| 438 | syslog_3(LOG_NOTICE, "## tusbhCdcReceive status(%d) length(%d) buffer[%08x] ##", result, length, receive_buffer);
|
---|
| 439 | if(length > 0){
|
---|
| 440 | syslog_4(LOG_NOTICE, "## 00[%02x] 01[%02x] 02[%02x] 03[%02x] ##", receive_buffer[0], receive_buffer[1], receive_buffer[2], receive_buffer[3]);
|
---|
| 441 | syslog_4(LOG_NOTICE, "## 04[%02x] 05[%02x] 06[%02x] 07[%02x] ##", receive_buffer[4], receive_buffer[5], receive_buffer[6], receive_buffer[7]);
|
---|
| 442 | syslog_4(LOG_NOTICE, "## 08[%02x] 09[%02x] 10[%02x] 11[%02x] ##", receive_buffer[8], receive_buffer[9], receive_buffer[10], receive_buffer[11]);
|
---|
| 443 | syslog_4(LOG_NOTICE, "## 12[%02x] 13[%02x] 14[%02x] 15[%02x] ##", receive_buffer[12], receive_buffer[13], receive_buffer[14], receive_buffer[15]);
|
---|
| 444 | }
|
---|
| 445 | if(length != 0 && count == 0){
|
---|
| 446 | dly_tsk(1000);
|
---|
| 447 | cdc_init = true;
|
---|
| 448 | }
|
---|
| 449 | count++;
|
---|
| 450 | }
|
---|
| 451 | #if 1 /* ROI DEBUG */
|
---|
| 452 | /*
|
---|
| 453 | * PRINTER処理
|
---|
| 454 | */
|
---|
| 455 | if(device_state[PRT_CLASS] == HOST_USER_CLASS_ACTIVE){
|
---|
| 456 | static bool_t prt_init = true;
|
---|
| 457 | if(prt_init){
|
---|
| 458 | syslog_1(LOG_NOTICE, "## [PRT]device_state(%d) ##", device_state[PRT_CLASS]);
|
---|
| 459 | dly_tsk(1000);
|
---|
| 460 | syslog_0(LOG_NOTICE, "## SEND EOJ ##");
|
---|
| 461 | tusbhPrtEOJ(&hUSBHost, 0, 1, 2, 3);
|
---|
| 462 | tusbhPrtPortID(&hUSBHost, 0, receive_buffer);
|
---|
| 463 | syslog_1(LOG_NOTICE, "## PORTID(%d) ##", receive_buffer[0]);
|
---|
| 464 | prt_init = false;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | #endif /* ROI DEBUG */
|
---|
| 468 |
|
---|
| 469 | dly_tsk(500);
|
---|
| 470 | }
|
---|
| 471 | #endif
|
---|
| 472 | #if 1 /* ROI DEBUG */
|
---|
| 473 | syslog_0(LOG_NOTICE, "## STOP ##");
|
---|
| 474 | slp_tsk();
|
---|
| 475 | #endif /* ROI DEBUG */
|
---|
| 476 |
|
---|
| 477 | syslog(LOG_NOTICE, "Sample program ends.");
|
---|
| 478 | // SVC_PERROR(ext_ker());
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | #if USB_OTG_MODE != USB_OTG_MODE_HOST
|
---|
| 482 | void usbd_task(intptr_t exinf)
|
---|
| 483 | {
|
---|
| 484 | FLGPTN crcflag;
|
---|
| 485 | ER ercd;
|
---|
| 486 |
|
---|
| 487 | while (1){
|
---|
| 488 | ercd = twai_flg(USBCDC_FLG, 0xffff, TWF_ORW, &crcflag, 1000);
|
---|
| 489 | #if USB_DEVICE_ID == 0
|
---|
| 490 | GetPointerData(HID_Buffer);
|
---|
| 491 | if(USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4) == TUSBD_E_OK)
|
---|
| 492 | memset(&HID_Buffer, 0, sizeof(HID_Buffer));
|
---|
| 493 | #else
|
---|
| 494 | if(ercd == E_OK){
|
---|
| 495 | if((crcflag & FLG_CDC_RECEIVE_DATA) != 0 && TransRxLength > TransRxCount){
|
---|
| 496 | pTransRxBuffer[TransRxLength] = 0;
|
---|
| 497 | syslog_2(LOG_NOTICE, "## revlen(%d)[%s] ##", TransRxLength, pTransRxBuffer);
|
---|
| 498 | memcpy(txBuffer, pTransRxBuffer, TransRxLength);
|
---|
| 499 | tusbdCdcStartTransmit(&USBD_Device, txBuffer, TransRxLength);
|
---|
| 500 | TransRxLength = 0;
|
---|
| 501 | tusbdCdcSetReceivePacket(&USBD_Device);
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 | #endif
|
---|
| 505 | syslog_1(LOG_NOTICE, "## dev_state(%d) ##", USBD_Device.dev_state);
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 | #endif
|
---|
| 509 |
|
---|