diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/uart.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/uart.h index 2614fe4..2eac7dc 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/uart.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/uart.h @@ -126,8 +126,8 @@ extern ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* para extern ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters); /** ---------------------------------------------------------------------------- - * Uart_Write - * Description of function + * Uart_write + * Writes length number of bytes from buffer to Uart object self * * @param self The UART class object * @param buffer Message string to send @@ -139,7 +139,27 @@ extern ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters); * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length); +extern ErrorStatus Uart_write(struct Uart* self, const char* buffer, int length); + + +/** ---------------------------------------------------------------------------- + * Uart_read + * Reads length number of bytes from Uart object self into buffer. The actual + * number of read bytes are put in actualLength. Ususally they should be equal + * but in some cases less bytes are read than requested. + * + * @param self The UART class object + * @param buffer Message string to send + * @param length Message length + * @param actualLength THe actual number of bytes read + * + * @return ErrorStatus SUCCESS if writing message was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus Uart_read(struct Uart* self, char* buffer, size_t length, size_t* actualLength); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/IODevice.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/IODevice.c index a7226a8..40828e0 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/IODevice.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/IODevice.c @@ -76,3 +76,16 @@ ErrorStatus IODevice_write(const struct IODevice* self, const char* buffer, size return returnValue; } + + +ErrorStatus IODevice_read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->_read != NULL) + { + returnValue = self->_read(self, buffer, length, actualLength); + } + + return returnValue; +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c index f70df14..d3e48a7 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c @@ -455,36 +455,39 @@ static ErrorStatus initIO (void) gpio.GPIO_Typedef = GPIOA; gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN; gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; + adc1->channel[ADC_Channel_0].input = gpio; GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); - adc1->channel[ADC_Channel_0].input = gpio; // Channel 1 - PA1 gpio.GPIO_Typedef = GPIOA; gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN; gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1; + adc1->channel[ADC_Channel_1].input = gpio; GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); - adc1->channel[ADC_Channel_1].input = gpio; // Channel 2 - PA2 gpio.GPIO_Typedef = GPIOA; gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN; gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2; + adc1->channel[ADC_Channel_2].input = gpio; GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); - adc1->channel[ADC_Channel_2].input = gpio; /* USART1 initialisation -------------------------------------------------*/ // Init TX line - _uart1.USART_TX.GPIO_Typedef = GPIOB; - _uart1.USART_TX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; - _uart1.USART_TX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6; - _uart1.USART_TX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(_uart1.USART_TX.GPIO_Typedef, &_uart1.USART_TX.GPIO_InitStruct); + gpio.GPIO_Typedef = GPIOB; + gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; + gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6; + gpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + uart1->USART_TX = gpio; + GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); + // Init RX line - _uart1.USART_RX.GPIO_Typedef = GPIOB; - _uart1.USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; - _uart1.USART_RX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7; - _uart1.USART_RX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(_uart1.USART_RX.GPIO_Typedef, &_uart1.USART_RX.GPIO_InitStruct); + gpio.GPIO_Typedef = GPIOB; + gpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; + gpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7; + uart1->USART_RX = gpio; + GPIO_Init(gpio.GPIO_Typedef, &gpio.GPIO_InitStruct); + // Apply pin-remapping for UART1 I/Os (alternative I/Os usage) GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE); @@ -498,7 +501,7 @@ static ErrorStatus initIO (void) // Init RX line uart3->USART_RX.GPIO_Typedef = GPIOB; - uart3->USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; + uart3->USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; uart3->USART_RX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; uart3->USART_RX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(uart3->USART_RX.GPIO_Typedef, &uart3->USART_RX.GPIO_InitStruct); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/uart.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/uart.c index 92126ab..10df3de 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/uart.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/uart.c @@ -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; +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c index 5997361..49a3f1c 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Logger.c @@ -327,6 +327,12 @@ static void loggerTask(void* parameters) IODevice_write(loggerDevice, str, strlen(str)); #endif + char buffer[5] = {0,}; + size_t actualLength = 0; + IODevice_read(loggerDevice, buffer, 5, &actualLength); + + snprintf(str, sizeof(str) / sizeof(str[0]), "%d - %x %x %x %x %x", actualLength, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]); + IODevice_write(loggerDevice, str, strlen(str)); } } } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c index 021d3fd..18416aa 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c @@ -170,7 +170,7 @@ static void initTask(void* parameters) xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 40, &ledTaskArguments, 0, &ledTaskHandle); - Logger_construct(&uart1->device); + Logger_construct(&uart3->device); NHD0420_construct(&nhd0420, &spiDisplay->device); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c index b111881..2f64919 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c @@ -142,11 +142,8 @@ void USART1_IRQHandler(void) //! Transmission register empty interrupt if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { - //! Receive element from usart transmission queue - struct usartQueueItem usartTxItem; - xQueueReceiveFromISR(uart1->txQueue, &usartTxItem, &higherPriorityTaskWoken); //! Write one byte to the transmit data register USART_SendData(USART1, usartTxItem.byte); @@ -163,11 +160,10 @@ void USART1_IRQHandler(void) if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { //! Read one byte from the receive data register - struct usartQueueItem usartRxItem; //! Reading from reception register automatically clears the RXNE interrupt - usartRxItem.byte = (unsigned char) 0xFF & USART_ReceiveData(USART1); - //! Add the byte to the bluetooth RX queue + usartRxItem.byte = USART_ReceiveData(USART1); + //! Add the byte to the USART RX queue //! In case of a full queue, the data is dumped (void)xQueueSendFromISR(uart1->rxQueue, &usartRxItem, &higherPriorityTaskWoken); } @@ -195,11 +191,8 @@ void USART3_IRQHandler(void) //! Transmission register empty interrupt if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET) { - //! Receive element from usart transmission queue - struct usartQueueItem usartTxItem; - xQueueReceiveFromISR(uart3->txQueue, &usartTxItem, &higherPriorityTaskWoken); //! Write one byte to the transmit data register USART_SendData(USART3, usartTxItem.byte); @@ -216,11 +209,10 @@ void USART3_IRQHandler(void) if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) { //! Read one byte from the receive data register - struct usartQueueItem usartRxItem; //! Reading from reception register automatically clears the RXNE interrupt - usartRxItem.byte = (unsigned char) 0xFF & USART_ReceiveData(USART3); - //! Add the byte to the bluetooth RX queue + usartRxItem.byte = (char)USART_ReceiveData(USART3); + //! Add the byte to the USART RX queue //! In case of a full queue, the data is dumped (void)xQueueSendFromISR(uart3->rxQueue, &usartRxItem, &higherPriorityTaskWoken); } @@ -387,14 +379,6 @@ void RTC_IRQHandler(void) xSemaphoreGiveFromISR(rtc->secondSync, &higherPriorityTaskWoken); Display_feedRefreshCounter(display); - if (ledGreen->status) - { - LED_turnOff(ledGreen); - } - else - { - LED_turnOn(ledGreen); - } /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();