Browse Source

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.

master
Dominic Clifton 11 years ago
parent
commit
a6f6a5e28b
  1. 2
      src/cli.c
  2. 7
      src/drv_serial.h
  3. 7
      src/drv_softserial.c
  4. 2
      src/drv_softserial.h
  5. 6
      src/drv_uart.c
  6. 2
      src/drv_uart.h
  7. 2
      src/main.c
  8. 4
      src/serial.c

2
src/cli.c

@ -931,7 +931,7 @@ void cliProcess(void)
cliPrompt();
}
while (isUartAvailable((uartPort_t *)core.mainport)) {
while (serialTotalBytesWaiting(core.mainport)) {
uint8_t c = uartRead((uartPort_t *)core.mainport);
if (c == '\t' || c == '?') {
// do tab completion

7
src/drv_serial.h

@ -28,9 +28,16 @@ typedef struct serialPort {
struct serialPortVTable {
void (*serialWrite)(serialPort_t *instance, uint8_t ch);
uint8_t (*serialTotalBytesWaiting)(serialPort_t *instance);
};
static inline void serialWrite(serialPort_t *instance, uint8_t ch)
{
instance->vTable->serialWrite(instance, ch);
}
static inline uint8_t serialTotalBytesWaiting(serialPort_t *instance)
{
return instance->vTable->serialTotalBytesWaiting(instance);
}

7
src/drv_softserial.c

@ -255,8 +255,9 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture)
}
uint8_t serialAvailable(softSerial_t *softSerial)
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
{
softSerial_t *softSerial = (softSerial_t *)instance;
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
return 0;
}
@ -281,7 +282,7 @@ static void moveHeadToNextByte(softSerial_t *softSerial)
uint8_t serialReadByte(softSerial_t *softSerial)
{
if (serialAvailable(softSerial) == 0) {
if (softSerialTotalBytesWaiting((serialPort_t*)softSerial) == 0) {
return 0;
}
@ -299,7 +300,7 @@ void serialWriteByte(serialPort_t *s, uint8_t ch)
}
const struct serialPortVTable softSerialVTable[] = {
{ serialWriteByte }
{ serialWriteByte, softSerialTotalBytesWaiting }
};
void serialPrint(softSerial_t *softSerial, const char *str)

2
src/drv_softserial.h

@ -36,7 +36,7 @@ extern const struct serialPortVTable softSerialVTable[];
void setupSoftSerial1(uint32_t baud);
uint8_t serialReadByte(softSerial_t *softSerial);
uint8_t serialAvailable(softSerial_t *softSerial);
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance);
void softSerialWriteByte(serialPort_t *instance, uint8_t ch);
void serialPrint(softSerial_t *softSerial, const char *str);

6
src/drv_uart.c

@ -210,8 +210,10 @@ static void uartStartTxDMA(uartPort_t *s)
DMA_Cmd(s->txDMAChannel, ENABLE);
}
bool isUartAvailable(uartPort_t *s)
uint8_t uartTotalBytesWaiting(serialPort_t *instance)
{
uartPort_t *s = (uartPort_t*)instance;
// FIXME always returns 1 or 0, not the amount of bytes waiting
if (s->rxDMAChannel)
return s->rxDMAChannel->CNDTR != s->rxDMAPos;
else
@ -258,7 +260,7 @@ void uartWrite(serialPort_t *instance, uint8_t ch)
}
const struct serialPortVTable uartVTable[] = {
{ uartWrite }
{ uartWrite, uartTotalBytesWaiting }
};
void uartPrint(uartPort_t *s, const char *str)

2
src/drv_uart.h

@ -30,7 +30,7 @@ extern const struct serialPortVTable uartVTable[];
serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode);
void uartChangeBaud(uartPort_t *s, uint32_t baudRate);
bool isUartAvailable(uartPort_t *s);
uint8_t uartTotalBytesWaiting(serialPort_t *instance);
bool isUartTransmitEmpty(uartPort_t *s);
uint8_t uartRead(uartPort_t *s);
void uartWrite(serialPort_t *instance, uint8_t ch);

2
src/main.c

@ -146,7 +146,7 @@ int main(void)
while (1) {
loop();
#ifdef SOFTSERIAL_19200_LOOPBACK
while (serialAvailable(&softSerialPorts[0])) {
while (serialTotalBytesWaiting((serialPort_t *)&softSerialPorts[0])) {
uint8_t b = serialReadByte(&softSerialPorts[0]);
serialWrite((serialPort_t*)&softSerialPorts[0], b);

4
src/serial.c

@ -678,7 +678,7 @@ void serialCom(void)
return;
}
while (isUartAvailable((uartPort_t *)core.mainport)) {
while (serialTotalBytesWaiting(core.mainport)) {
c = uartRead((uartPort_t *)core.mainport);
if (c_state == IDLE) {
@ -715,7 +715,7 @@ void serialCom(void)
c_state = IDLE;
}
}
if (!cliMode && !isUartAvailable((uartPort_t *)core.telemport) && feature(FEATURE_TELEMETRY) && f.ARMED) { // The first 2 conditions should never evaluate to true but I'm putting it here anyway - silpstream
if (!cliMode && !serialTotalBytesWaiting(core.telemport) && feature(FEATURE_TELEMETRY) && f.ARMED) { // The first 2 conditions should never evaluate to true but I'm putting it here anyway - silpstream
sendTelemetry();
return;
}

Loading…
Cancel
Save