/******************************************************************************* * Function Name : EP1_OUT_Callback. * Description : EP1 OUT Callback Routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP1_OUT_Callback(void) { BitAction Led_State; /* Read received data (2 bytes) */ USB_SIL_Read(EP1_OUT, Receive_Buffer); if (Receive_Buffer[1] == 0) { Led_State = Bit_RESET; } else { Led_State = Bit_SET; } switch (Receive_Buffer[0]) { /*case 1: if (Led_State != Bit_RESET) { GPIO_SetBits(LED_PORT,LED1_PIN); } else { GPIO_ResetBits(LED_PORT,LED1_PIN); } break; case 2: if (Led_State != Bit_RESET) { GPIO_SetBits(LED_PORT,LED2_PIN); } else { GPIO_ResetBits(LED_PORT,LED2_PIN); } break; case 3: Buffer[4]=Receive_Buffer[1]; break;*/ } SetEPRxStatus(ENDP1, EP_RX_VALID); }
/******************************************************************************* * Function Name : EP3_OUT_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) { uint16_t USB_Rx_Cnt; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the USART Xfer */ USB_To_USART_Send_Data(USB_Rx_Buffer, USB_Rx_Cnt); #ifndef STM32F10X_CL /* Enable the receive of data on EP3 */ SetEPRxValid(ENDP3); #endif /* STM32F10X_CL */ }
/******************************************************************************* * Function Name : EP3_OUT_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) { uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE]; int USB_Rx_Cnt; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the USART Xfer */ int i=0; for (i=0;i<USB_Rx_Cnt;i++) jshPushIOCharEvent(EV_USBSERIAL, USB_Rx_Buffer[i]); /* Enable the receive of data on EP3 */ SetEPRxStatus(ENDP3, jshHasEventSpaceForChars(VIRTUAL_COM_PORT_DATA_SIZE) ? EP_RX_VALID : EP_RX_NAK); }
/******************************************************************************* * Function Name : EP3_OUT_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) { uint16_t USB_Rx_Cnt; int i; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the USART Xfer */ USB_To_USART_Send_Data(USB_Rx_Buffer, USB_Rx_Cnt); if( USB_Rx_Cnt >= 4 ) { uint8_t cmpBuf[4] = {0x43,0x4D,0x39,0x58};//{0x31, 0x45, 0x41, 0x46}; if (reset_state == DTR_NEGEDGE) { reset_state = DTR_LOW; bool cmpMatch = TRUE; for (i=0; i<4; i++) { if (USB_Rx_Buffer[i] != cmpBuf[i]) { cmpMatch = FALSE; } } if( cmpMatch == TRUE ) { IWDG->PR = 0; // divider / 4 IWDG->RLR = 1; IWDG->KR = 0xCCCC; // Start } } } //dbg_print("USB Rx\r\n"); /* Enable the receive of data on EP3 */ SetEPRxValid(ENDP3); }
/******************************************************************************* * Function Name : EP3_IN_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) { char *end; int i; int count; // if we are near buffer overrun, discard all packets if (count_out + 64 > sizeof(buffer_out)) { printf("buffer full\n"); count_out = 0; } // Get the received data buffer and update the counter count = USB_SIL_Read(EP3_OUT, buffer_out+count_out); // replace '\r' into '\n" for(i=count_out; i<count_out+count; i++) buffer_out[i] = buffer_out[i] == '\r' ? '\n' : buffer_out[i]; count_out += count; buffer_out[count_out] = NULL; #ifndef STM32F10X_CL // Enable the receive of data on EP3 SetEPRxValid(ENDP3); #endif /* STM32F10X_CL */ // line handling and coping left to head of buffer end = parse_command((char*)buffer_out); if (end > (char*)buffer_out) { int left = strlen(end); memmove(buffer_out, end, left+1); count_out = left; // one command each line... //printf("cmd handled\n"); //count_out = 0; } count_out = 0; }
void EP6_OUT_Callback(void) { uint16_t USB_Rx_Cnt; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = USB_SIL_Read(EP6_OUT, USB_Rx_Buffer); /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the USART Xfer */ ringbuf_put(&rx_rb, USB_Rx_Buffer, USB_Rx_Cnt); /* Enable the receive of data on EP4 */ SetEPRxValid(ENDP6); if (rx_cb != NULL) { rx_cb(ringbuf_available(&rx_rb), NULL); } }
/******************************************************************************* * Function Name : EP3_OUT_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) { rt_uint32_t level; rt_uint16_t size; /* receive data from USB VCOM */ level = rt_hw_interrupt_disable(); size = USB_SIL_Read(EP3_OUT, rx_buf); rt_ringbuffer_put(&rx_ringbuffer, rx_buf, size); rt_hw_interrupt_enable(level); /* Enable the receive of data on EP3 */ SetEPRxValid(ENDP3); /* notify receive data */ rt_hw_serial_isr(&vcom_serial); //return RT_EOK; }
/******************************************************************************* * Function Name : EP1_OUT_Callback. * Description : EP1 OUT Callback Routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP1_OUT_Callback(void) { BitAction Led_State; /* Read received data (2 bytes) */ uint32_t len = USB_SIL_Read(EP1_OUT, Receive_Buffer); if (Receive_Buffer[1] == 0) { Led_State = Bit_RESET; } else { Led_State = Bit_SET; } #ifndef STM32F10X_CL SetEPRxStatus(ENDP1, EP_RX_VALID); #endif /* STM32F10X_CL */ usb_get_data(Receive_Buffer, len); }
/******************************************************************************* * Function Name : EP3_OUT_Callback * Description : * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP3_OUT_Callback(void) //EP3 OUT的回调函数,当EP3接收到数据时候中断调用该函数 { uint16_t USB_Rx_Cnt; /* Get the received data buffer and update the counter */ USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); /* USB data will be immediately processed, this allow next USB traffic beeing NAKed till the end of the USART Xfet */ if(USB_Rx_Cnt > 0) { BSP_PushinFIFO(&(USBDEVICE.ReadFIFO),USB_Rx_Buffer,USB_Rx_Cnt); //通知新的数据来到 BSP_USBNewRecv(); } #ifndef STM32F10X_CL /* Enable the receive of data on EP3 */ SetEPRxValid(ENDP3); #endif /* STM32F10X_CL */ }
void EP3_OUT_Callback(void) { portBASE_TYPE hpta = false; xQueueHandle queue = serial_get_rx_queue(usb_state.serial); uint8_t *buff = usb_state.USB_Rx_Buffer; /* Get the received data buffer and clear the counter */ const size_t len = USB_SIL_Read(EP3_OUT, buff); for (size_t i = 0; i < len; ++i) xQueueSendFromISR(queue, buff + i, &hpta); /* * STIEG HACK * For now just assume that all the data made it into the queue. This * is what we do in MK2. Probably shouldn't go out the door like this. */ SetEPRxValid(ENDP3); if (usb_state.rx_isr_cb) usb_state.rx_isr_cb(); portEND_SWITCHING_ISR(hpta); }