diff options
Diffstat (limited to 'Projects/XPLAINBridge/XPLAINBridge.c')
-rw-r--r-- | Projects/XPLAINBridge/XPLAINBridge.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/Projects/XPLAINBridge/XPLAINBridge.c b/Projects/XPLAINBridge/XPLAINBridge.c index ef311d060..ce23862dd 100644 --- a/Projects/XPLAINBridge/XPLAINBridge.c +++ b/Projects/XPLAINBridge/XPLAINBridge.c @@ -62,7 +62,7 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = .NotificationEndpointDoubleBank = false, }, }; - + /** Circular buffer to hold data from the host before it is sent to the device via the serial port. */ RingBuff_t USBtoUART_Buffer; @@ -77,9 +77,11 @@ int main(void) { SetupHardware(); - Buffer_Initialize(&USBtoUART_Buffer); - Buffer_Initialize(&UARTtoUSB_Buffer); - + USBtoUART_Buffer.In = USBtoUART_Buffer.Buffer; + USBtoUART_Buffer.Out = USBtoUART_Buffer.Buffer; + UARTtoUSB_Buffer.In = UARTtoUSB_Buffer.Buffer; + UARTtoUSB_Buffer.Out = UARTtoUSB_Buffer.Buffer; + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); @@ -123,23 +125,35 @@ void USARTBridge_Task(void) /* Read bytes from the USB OUT endpoint into the UART transmit buffer */ for (uint8_t DataBytesRem = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); DataBytesRem != 0; DataBytesRem--) { - if (!(BUFF_STATICSIZE - USBtoUART_Buffer.Elements)) - break; - - Buffer_StoreElement(&USBtoUART_Buffer, CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface)); + *USBtoUART_Buffer.In = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); + + if (++USBtoUART_Buffer.In == &USBtoUART_Buffer.Buffer[128]) + USBtoUART_Buffer.In = USBtoUART_Buffer.Buffer; } /* Read bytes from the UART receive buffer into the USB IN endpoint */ - if (UARTtoUSB_Buffer.Elements) - CDC_Device_SendByte(&VirtualSerial_CDC_Interface, Buffer_GetElement(&UARTtoUSB_Buffer)); + if (UARTtoUSB_Buffer.In != UARTtoUSB_Buffer.Out) + { + CDC_Device_SendByte(&VirtualSerial_CDC_Interface, *UARTtoUSB_Buffer.Out); + if (++UARTtoUSB_Buffer.Out == &UARTtoUSB_Buffer.Buffer[128]) + UARTtoUSB_Buffer.Out = UARTtoUSB_Buffer.Buffer; + } /* Load bytes from the UART transmit buffer into the UART */ - if ((USBtoUART_Buffer.Elements) && SoftUART_IsReady()) - SoftUART_TxByte(Buffer_GetElement(&USBtoUART_Buffer)); + if ((USBtoUART_Buffer.In != USBtoUART_Buffer.Out) && SoftUART_IsReady()) + { + SoftUART_TxByte(*USBtoUART_Buffer.Out); + if (++USBtoUART_Buffer.Out == &USBtoUART_Buffer.Buffer[128]) + USBtoUART_Buffer.Out = USBtoUART_Buffer.Buffer; + } /* Load bytes from the UART into the UART receive buffer */ if (SoftUART_IsReceived()) - Buffer_StoreElement(&UARTtoUSB_Buffer, SoftUART_RxByte()); + { + *UARTtoUSB_Buffer.In = SoftUART_RxByte(); + if (++UARTtoUSB_Buffer.In == &UARTtoUSB_Buffer.Buffer[128]) + UARTtoUSB_Buffer.In = UARTtoUSB_Buffer.Buffer; + } CDC_Device_USBTask(&VirtualSerial_CDC_Interface); } @@ -169,7 +183,7 @@ void SetupHardware(void) _delay_ms(10); /* Select the firmware mode based on the JTD pin's value */ - CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER; + CurrentFirmwareMode = MODE_USART_BRIDGE; // TEMP (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER; /* Re-enable JTAG debugging */ MCUCR &= ~(1 << JTD); |