1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 06:15:16 +03:00

Totally rework software serial to provide tx at the same time as rx using only one timer.

First cut at polymorphic serial port implementation.  Split serialPort_t into uartPort_t and serialPort_t.  Calls to uartWrite() can now be replaced with calls to serialWrite().

Replacing calls to serialWriteByte(softSerial_t*, char) with calls to serialWrite(serialPort_t*, char).  This completes the proof of concept for polymorphic serial port implementations (uartPort and softSerialPort).

Renaming isSerialAvailable to uartTotalBytesWaiting.  Renaming serialAvailable to softSerialTotalBytesWaiting.  Adding serialTotalBytesWaiting to serial API and updating calls to the former methods to use the serial API.

Renaming serialRead to softSerialRead.  Adding serialRead to serial API and updating calls to uartRead and softSerialRead to use the serial API.  Renamed uartPrint to serialPrint which now works on any serialPort implementation.

Replacing calls to isUartTransmitEmpty with isSoftSerialTransmitBufferEmpty.  Replacing remaing calls to uartWrite with serialWrite.  Adding isSoftSerialTransmitBufferEmpty to the serial API.  Adding serialSet/GetBaudRate to the serial API.  Since softSerial does not implement serialSetBaudRate some GPS serial initialisation code has been updated.

At this point it is probably possible to switch around all the ports and use a software serial implementation if desired.

By Dominic Clifton / https://github.com/hydra/baseflight/

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@423 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop@gmail.com 2013-10-01 00:07:44 +00:00
parent 7c595e4110
commit 28d5927836
17 changed files with 523 additions and 265 deletions

View file

@ -12,15 +12,15 @@ extern uint16_t pwmReadRawRC(uint8_t chan);
// gcc/GNU version
static void _putc(void *p, char c)
{
uartWrite(core.mainport, c);
serialWrite(core.mainport, c);
}
#else
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isUartTransmitEmpty(core.mainport));
uartWrite(core.mainport, c);
while (!isSerialTransmitBufferEmpty(core.mainport));
serialWrite(core.mainport, c);
return c;
}
#endif
@ -129,13 +129,11 @@ int main(void)
if (feature(FEATURE_VBAT))
batteryInit();
#ifdef SOFTSERIAL_19200_LOOPBACK
serialInit(19200);
setupSoftSerial1(19200);
uartPrint(core.mainport, "LOOPBACK 19200 ENABLED");
#else
serialInit(mcfg.serial_baudrate);
#ifdef SOFTSERIAL_19200_LOOPBACK
setupSoftSerial1(19200);
serialPort_t* loopbackPort = (serialPort_t*)&(softSerialPorts[0]);
serialPrint(loopbackPort, "LOOPBACK 19200 ENABLED\r\n");
#endif
previousTime = micros();
@ -149,10 +147,11 @@ int main(void)
while (1) {
loop();
#ifdef SOFTSERIAL_19200_LOOPBACK
while (serialAvailable(&softSerialPorts[0])) {
while (serialTotalBytesWaiting(loopbackPort)) {
uint8_t b = serialReadByte(&softSerialPorts[0]);
uartWrite(core.mainport, b);
uint8_t b = serialRead(loopbackPort);
serialWrite(loopbackPort, b);
//serialWrite(core.mainport, b);
};
#endif
}