Code: Select all
static WORKING_AREA(waUSB, 128);
static msg_t USB_thread(void *arg)
{
(void)arg;
chRegSetThreadName("USB");
EventListener el1;
flagsmask_t flags=0;
uint8_t cmd_res[2];
uint8_t clear_buff[64], buff[64];
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1500);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
chEvtRegisterMask(chnGetEventSource(&SDU1), &el1, ALL_EVENTS);
while(SDU1.state != USB_READY)
chThdSleepMilliseconds(10);
while(GPIOA->IDR&GPIO_IDR_IDR9)
{
chEvtWaitAny(ALL_EVENTS);
chSysLock();
flags = chEvtGetAndClearFlagsI(&el1);
chSysUnlock();
if(flags & CHN_INPUT_AVAILABLE)
{
chnReadTimeout( &SDU1, cmd_res, 1, MS2ST(1500) );
switch(cmd_res[0])
{
case cmd_GSM_nr:
chnWrite(&SDU1, "000000000", 9);
break;
case cmd_IMEI:
chnWrite(&SDU1, "0123456789ABCDE", 15);
break;
case cmd_Signal:
chmWrite(&SDU1, "00", 2 );
break;
case cmd_FV_state:
chnWrite(&SDU1, __DATE__, 12);
break;
case cmd_RLY_read:
break;
case Phone_list_long_read:
break;
case cmd_USART_cnt:
LED_green_ON;
cmd_res[0] = 2;
cmd_res[1] = 3;
chnWriteTimeout((BaseChannel *)&SDU1, cmd_res, 2, MS2ST(10) );
break;
case cmd_USART_buf:
LED_green_ON;
cmd_res[0] = 10;
cmd_res[1] = 11;
chnWriteTimeout((BaseChannel *)&SDU1, cmd_res, 2, MS2ST(10) );
break;
}
if(SDU1.iqueue.q_counter)
LED_green_tog;
}
}
usbStop(serusbcfg.usbp);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(100);
extChannelEnable(&EXTD1, 9);
}At PIN9 I have USB supply connection detect. When I plugin USB, then EXI create USB thread, when plugout, then while loot is ending and thread is going down.
I modified code, but still it's the same problem.
PC program show me how much elements incomming.
Should be:
GSM number: 9
IMEI: 15
Signal: 2
Firmware: 12
When I first ask, then:
All next:
All value are shifted, I think it's something wrong with queue.
I trying found problem with debugind, but I nothing see.