Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/uart.h
mmi e54e15da18 Added all required GPIOs
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@242 05563f52-14a8-4384-a975-3d1654cca0fa
2017-10-06 12:08:24 +00:00

170 lines
5.8 KiB
C

// -----------------------------------------------------------------------------
/// @file uart.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file uart.h
/// @ingroup {group_name}
#ifndef MISC_INC_UART_H_
#define MISC_INC_UART_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "FreeRTOS.h"
#include "semphr.h"
#include "platform.h"
#include "IODevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define UART_DEF_BAUDRATE (9600)
#define UART_DEF_WORDLENGTH (USART_WordLength_8b)
#define UART_DEF_STOPBITS (USART_StopBits_1)
#define UART_DEF_PARITY (USART_Parity_No)
#define UART_DEF_MODE (USART_Mode_Tx | USART_Mode_Rx)
#define UART_DEF_HW_FLOW_CONTROL (USART_HardwareFlowControl_None)
#define UART_DEF_RX_QUEUE (32)
#define UART_DEF_TX_QUEUE (32)
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct usartQueueItem
{
char byte;
};
struct UartParameters
{
uint32_t baudrate;
uint16_t wordlength;
uint16_t stopbits;
uint16_t parity;
uint16_t mode;
uint16_t hwFlowControl;
UBaseType_t txQueueSize;
UBaseType_t rxQueueSize;
};
struct Uart
{
struct IODevice device;
USART_TypeDef* USART_TypeDef;
USART_InitTypeDef USART_InitStruct;
USART_ClockInitTypeDef* USART_ClockInitStruct;
T_PL_GPIO USART_RX;
T_PL_GPIO USART_TX;
T_PL_GPIO USART_CTS;
T_PL_GPIO USART_RTS;
SemaphoreHandle_t txSemaphore; //! Semaphore for transmit handler
xQueueHandle txQueue; //! USART Transfer queue identifier
xQueueHandle rxQueue; //! USART Receive queue identifier
bool initialized;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* Uart_construct
* Description of function
*
* @param _self The UART object to initialize
* @param baudrate Baudrate to use
* @param wordlength Wordlength for the UART
* @param stopbits Number of stopbits to use
* @param parity Parity of the UART
* @param mode Mode (TX, RX, Both)
* @param hwFlowControl Control of hardware flow control
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus Uart_construct(struct Uart* self, struct UartParameters* parameters);
/** ----------------------------------------------------------------------------
* Uart_getDefaultParameters
* Function that assigns default parameters to the uart struct
*
* @param parameters
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters);
/** ----------------------------------------------------------------------------
* 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
* @param length Message length
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
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);
#endif /* MISC_INC_UART_H_ */