/*
 * Modbus_periph.h
 *
 *  Created on: 8. 3. 2020
 *      Author: Ondrej Vitoslavsky
 */

#ifndef MODBUS_PERIPH_H_
#define MODBUS_PERIPH_H_

#include "Modbus.h"


//UART

/**
  * @brief  Initialize USART.
  * @note   Is automatically called in Modbus_Init.
  * @param  BaudRate USART Baudrate.
  * @param  Word_Length USART Word length.
  * @param  Parity USART parity.
  * @retval none
  */
void Modbus_Serial_Init(uint32_t BaudRate, uint32_t Word_Length,
		uint32_t Parity );

/**
  * @brief  Enables or disables USART interrupts.
  * @note   Enables or disables USART RXNE and TXE interrupts.
  * 		Also sets DE pin for RS422 to switch receiving/transmitting mode.
  * @param  Rx_Enable Enables RXNE interrupts.
  * @param  Tx_Enable Enables TXE interrupts.
  * @retval none
  */
void Modbus_Serial_Enable( uint8_t Rx_Enable, uint8_t Tx_Enable );

/**
  * @brief  Puts Byte to USART buffer.
  * @note   Puts Byte to USART buffer using non-blocking mode.
  * @param  Byte Byte to send.
  * @retval none
  */
void Modbus_Put_Byte(uint8_t Byte);

/**
  * @brief  Gets Byte from USART buffer.
  * @note   Gets Byte from USART buffer.
  * @param  Byte address where to store received byte.
  * @retval none
  */
void Modbus_Get_Byte(uint8_t* Byte);



/**
  * @brief  USART Interrupt handler.
  * @note  	calls Modbus Finite State Machine.
  * @param  none.
  * @retval none
  */
void USART2_IRQHandler(void);


//TIM

/**
  * @brief  Initialize Timers.
  * @note   Is automatically called in Modbus_Init.
  * @param  Timer_35_value timer 3.5 period value.
  * @param  Timer_15_value timer 1.5 period value.
  * @retval none
  */
void Modbus_Timers_Init(uint16_t Timer_35_value, uint16_t Timer_15_value);

/**
  * @brief  Enables and resets selected timer/timers.
  * @note   Enables and resets selected timer/timers.
  * @param  Timer_35 enables timer 3.5.
  * @param  Timer_15 enables timer 1.5.
  * @retval none
  */
void Modbus_Timers_Enable(uint8_t Timer_35, uint8_t Timer_15);

/**
  * @brief  Disables selected timer/timers.
  * @note   Disables selected timer/timers.
  * @param  Timer_35 disables timer 3.5.
  * @param  Timer_15 disables timer 1.5.
  * @retval none
  */
void Modbus_Timers_Disable(uint8_t Timer_35, uint8_t Timer_15);

/**
  * @brief  Tim 3.5 handler.
  * @note   Calls Modbus_RTU_Timer35_Expired.
  * @param  none
  * @retval none
  */
void TIM3_IRQHandler( void );

/**
  * @brief  Tim 3.5 handler.
  * @note   Calls Modbus_RTU_Timer35_Expired.
  * @param  none
  * @retval none
  */
void TIM4_IRQHandler( void );





#endif /* MODBUS_PERIPH_H_ */
