/**************************************************************************//** \brief Transmit byte to usb FIFO. \param[in] len - number of bytes to transmit; \param[in] p - pointer to byte memory; ******************************************************************************/ void setByteUsbFifo(uint16_t len, uint8_t *p) { wdt_reset(); // set PORTA as output USB_DATA_DDR = 0xFF; while (len--) { while (GPIO_TXE_read()); USB_DATA_PORT = *p++; // prepare transmission GPIO_WR_clr(); GPIO_WR_set(); } // set PORTA as input USB_DATA_DDR = 0; }
/**************************************************************************//** \brief Reads byte from tx buffer and sends it to fifo. ******************************************************************************/ static void usbfifoTxBufferCleaner(void) { HalUsartService_t *control; uint16_t poW; uint16_t poR; if (!usbfifoPointDescrip) { // unregistered intrrupt is occurred HAL_DisableIrq(IRQ_6); return; } control = &usbfifoPointDescrip->service; poW = control->txPointOfWrite; poR = control->txPointOfRead; if (poW != poR) { // set port as output USB_DATA_DDR = 0xFF; NOP; USB_DATA_PORT = usbfifoPointDescrip->txBuffer[poR++]; GPIO_WR_clr(); GPIO_WR_set(); USB_DATA_DDR = 0; if (poR == usbfifoPointDescrip->txBufferLength) poR = 0; control->txPointOfRead = poR; } else { // tx buffer is empty HAL_DisableIrq(IRQ_6); usbfifoPostTask(USB_FIFO_TASK_TX); } }