You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.0 KiB
150 lines
4.0 KiB
/**
|
|
**************************************************************************************************
|
|
* @file usart.h
|
|
* @author Kerem Yollu & Edwin Koch
|
|
* @date 02.11.2021
|
|
* @version 1.0
|
|
**************************************************************************************************
|
|
* @brief USART functionalities description and implementation template
|
|
*
|
|
* **Detailed Description :**
|
|
*
|
|
* This header file for pin control is based on the most common configuation options
|
|
* curenty awailable for modern hardware.
|
|
* Depending of the used Chip, some function may vary or be unawailable.
|
|
* Please take a minute to go and explore the according Chips pin.c file to see woh each function
|
|
* is implmented.
|
|
*
|
|
* @todo
|
|
* - 03.11.2021 : MAybe find a way to link the awalabe uart channnels with the awailable pins for that USART channel
|
|
**************************************************************************************************
|
|
*/
|
|
#ifndef _USART_H_
|
|
#define _USART_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
#include "pin.h"
|
|
|
|
#define NO_PARITY_CTRL 0
|
|
#define PARITY_CTRL 1
|
|
|
|
/*! Enum of USART Word Lenght Options */
|
|
typedef enum
|
|
{
|
|
seven, /*!< **7 bits** word Lenght */
|
|
eight, /*!< **8 bits** word Lenght */
|
|
nine /*!< **9 bits** word Lenght */
|
|
}usartWordLength_t;
|
|
|
|
/*! Enum of USART Word Lenght Options */
|
|
typedef enum
|
|
{
|
|
usart1 = USART1_BASE , /*!< USART Channel 1 */
|
|
usart2 = USART2_BASE /*!< USART Channel 2 */
|
|
}usartNo_t;
|
|
|
|
/*! Enum of USART Parity Even or Odd */
|
|
typedef enum
|
|
{
|
|
even, /*!< **Even** Parity */
|
|
odd /*!< **Odd** Parity */
|
|
}usartParity_t;
|
|
|
|
/*! Enum of USART Hardware flow control options */
|
|
typedef enum
|
|
{
|
|
noFlowControl, /*!< **Disabeled** */
|
|
cts, /*!< **CTS** Only */
|
|
rts, /*!< **RTS** Only */
|
|
ctsRts /*!< **CTS & RTS** Enabled */
|
|
}usartHwFlowCtrl_t;
|
|
|
|
|
|
/**
|
|
* \brief Enable the USART with the most commment settings
|
|
* \param usartNo_t channel Uart **Channel** to be used
|
|
* \param pinNo_t pinTx Pin to be used for **Transmit**
|
|
* \param pinNo_t pinRx Pin to be used for **Recieve**
|
|
* \retval none
|
|
*/
|
|
void usartInit( usartNo_t channel,
|
|
pinNo_t pinTx,
|
|
pinNo_t pinRx,
|
|
uint32_t baud,
|
|
usartWordLength_t lenght,
|
|
uint8_t parity,
|
|
usartHwFlowCtrl_t flowCtrl);
|
|
|
|
/**
|
|
* \brief Enable the USART Transmission pin, be carefull this function will not link the right pin to the right UART channel.
|
|
* \param pinNo_t pinTx Pin to be used for **Transmit**
|
|
* \retval none
|
|
*/
|
|
void usartInitTx(pinNo_t pinTx);
|
|
|
|
/**
|
|
* \brief Enable the USART Recieve pin, be carefull this function will not link the right pin to the right UART channel.
|
|
* \param pinNo_t pinRx Pin to be used for **Transmit**
|
|
* \retval none
|
|
*/
|
|
void usartInitRx(pinNo_t pinRx);
|
|
|
|
/**
|
|
* \brief Sets the word lenght of the Usart channel.
|
|
* \param usartNo_t channel,
|
|
* \param usartWordLength_t lenght
|
|
* \retval none
|
|
*/
|
|
void usartSetWordLenght(usartNo_t channel, usartWordLength_t lenght);
|
|
|
|
/**
|
|
* \brief Sets the Baud Rate of the Usart channel.
|
|
* \param usartNo_t channel,
|
|
* \param uint32_t baud
|
|
* \retval none
|
|
*/
|
|
void usartSetBaudRate(usartNo_t channel, uint32_t baud);
|
|
|
|
/**
|
|
* \brief Stups Hardware Flow control
|
|
* \param usartNo_t channel,
|
|
* \param usartHwFlowCtrl_t flowCtrl
|
|
* \retval none
|
|
*/
|
|
void usartSetHwFlowCtrl(usartNo_t channel, usartHwFlowCtrl_t flowCtrl);
|
|
|
|
/**
|
|
* \brief Sends a char array until \0 is detected.
|
|
* \param usartNo_t channel,
|
|
* \param *ptr pointer to char array
|
|
* \retval none
|
|
*/
|
|
void print_Usart(usartNo_t channel,char *ptr);
|
|
|
|
/**
|
|
* \brief Cheks if the send buffer is empty an than Sends one Char
|
|
* \param usartNo_t channel,
|
|
* \param uint8_t ch one Character.
|
|
* \retval none
|
|
*/
|
|
void usartSendChar(usartNo_t channel, uint8_t ch);
|
|
|
|
|
|
/**
|
|
* \brief Cheks if the recieve buffer is NOT empty an than Rreturns the recieved Char
|
|
* \param usartNo_t channel,
|
|
* \param uint8_t ch one Character.
|
|
* \retval none
|
|
*/
|
|
uint8_t usartGetChar(usartNo_t channel);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // _USART_H_
|