Fixed UART RX problems
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@232 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "uart.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include "led.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -55,6 +55,7 @@
|
||||
|
||||
|
||||
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
@@ -65,20 +66,20 @@ ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
IODevice_construct(&self->device, NULL, write);
|
||||
IODevice_construct(&self->device, read, write);
|
||||
|
||||
//! Create semaphore to synchronize with USART interrupt handler
|
||||
vSemaphoreCreateBinary(self->txSemaphore);
|
||||
|
||||
USART_DeInit(self->USART_TypeDef);
|
||||
|
||||
self->USART_ClockInitStruct->USART_Clock = USART_Clock_Enable;
|
||||
self->USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
self->USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
self->USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
|
||||
|
||||
//! Enable USART clock
|
||||
USART_ClockInit(self->USART_TypeDef, self->USART_ClockInitStruct);
|
||||
// self->USART_ClockInitStruct->USART_Clock = USART_Clock_Enable;
|
||||
// self->USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
||||
// self->USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
||||
// self->USART_ClockInitStruct->USART_LastBit = USART_LastBit_Enable;
|
||||
//
|
||||
// //! Enable USART clock
|
||||
// USART_ClockInit(self->USART_TypeDef, self->USART_ClockInitStruct);
|
||||
|
||||
// Initialise the UART
|
||||
self->USART_InitStruct.USART_BaudRate = parameters->baudrate;
|
||||
@@ -117,6 +118,14 @@ ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* parameters)
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
struct usartQueueItem tmp;
|
||||
tmp.byte = 0x01;
|
||||
xQueueSend(self->rxQueue, &tmp, 0);
|
||||
tmp.byte++;
|
||||
xQueueSend(self->rxQueue, &tmp, 0);
|
||||
tmp.byte++;
|
||||
xQueueSend(self->rxQueue, &tmp, 0);
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
//! Enable the UART RX not empty interrupt
|
||||
@@ -146,11 +155,16 @@ ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters)
|
||||
|
||||
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
|
||||
{
|
||||
return Uart_Write((struct Uart*)self, buffer, length);
|
||||
return Uart_write((struct Uart*)self, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length)
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||
{
|
||||
return Uart_read((struct Uart*)self, buffer, length, actualLength);
|
||||
}
|
||||
|
||||
ErrorStatus Uart_write(struct Uart* self, const char* buffer, int length)
|
||||
{
|
||||
struct usartQueueItem usartTxItem;
|
||||
ErrorStatus returnValue = SUCCESS; //! Define return variable
|
||||
@@ -202,8 +216,32 @@ ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length)
|
||||
{
|
||||
//! Do nothing
|
||||
}
|
||||
|
||||
|
||||
return (returnValue); //! Return result to caller
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus Uart_read (struct Uart* self, char* buffer, size_t length, size_t* actualLength)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
int loopCounter = 0;
|
||||
*actualLength = 0;
|
||||
struct usartQueueItem usartRxItem;
|
||||
|
||||
|
||||
for (loopCounter = 0; loopCounter < length; loopCounter++)
|
||||
{
|
||||
if (xQueueReceive(self->rxQueue, &usartRxItem, 0) != pdFALSE)
|
||||
{
|
||||
// Item successfully fetched from Queue
|
||||
buffer[loopCounter] = usartRxItem.byte;
|
||||
*actualLength = *actualLength + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user