Could you review my usart driver wrapper please?
It contains the C language Xilinx usart driver, but I write C++ programs and need to C++ usart driver. How it was designed correctly and what I have to chage or add in the one on your view?
I will be thankful for your the strictest appraisal.
Thank you.
//**********************************************************************
// name: usart.hpp
//
// test: non.
//
// description: a usart driver wrapper.
//
// author: Artyom Shimko
//
// contact: [email protected]
//
// created: 28.12.19
//
// release: 28.12.19
//
// changes: non.
//
#ifndef USART_HPP
#define USART_HPP
#include "platform.h" // Platform depending settings.
#include "xuartps_hw.h" // The Xilinx header file for XUartPs device.
namespace UsartSapce {
enum usartNumber { usart0 = XPAR_PS7_UART_0_BASEADDR,
usart1 = XPAR_PS7_UART_1_BASEADDR};
}
template <typename T>
class Usart : public Platform {
private:
u32 usartNumber;
public:
Usart(u32 usartNumber); // The set usart number method.
status transmit(T *pData, u32 dataValue);
status receive (T *pData, u32 dataValue);
void reset(void);
};
//**********************************************************************
// The class constructor definition, it sets the usart number.
//**********************************************************************
// id: A required usart number.
//
template <typename T>
Usart<T>::Usart (u32 usartNumber ) {
this->usartNumber = usartNumber;
}
//**********************************************************************
// The usart reset method.
//**********************************************************************
// parameters: non.
//
// return: non.
//
template <typename T>
void Usart<T>::reset(void) {
XUartPs_ResetHw(usartNumber);
}
//**********************************************************************
// The data transmit usart method.
//**********************************************************************
// pData: The pointer to transmited data.
//
// dataValue: Value of transmited data.
//
// return: ok aka 0 or error aka -1. The error occurs then pData
// is equal to nullptr or/and dataValue is equal to null.
//
template <typename T>
status Usart<T>::transmit(T *pData, u32 dataValue) {
u8 *pByteData = nullptr;
if(parameterCheck_(pData,dataValue) != StatusSpace::ok) {
return StatusSpace::error;
}
pByteData = reinterpret_cast<u8*>(pData);
for(u32 byteCounter = 0; byteCounter < dataValue; ++byteCounter) {
XUartPs_SendByte(usartNumber, *(pByteData + byteCounter));
}
return StatusSpace::ok;
}
//**********************************************************************
// The data receive usart method.
//**********************************************************************
// pData: The pointer to an array for received data.
//
// dataValue: Value of received data.
//
// return: ok aka 0 or error aka -1. The error occurs then pData
// is equal to nullptr or/and dataValue is equal to null.
//
template <typename T>
status Usart<T>::receive(T *pData, u32 dataValue) {
u8 *pByteData = nullptr;
if(parameterCheck_(pData,dataValue) != StatusSpace::ok) {
return StatusSpace::error;
}
pByteData = reinterpret_cast<u8*>(pData);
for(u32 byteCounter = 0; byteCounter < dataValue; ++byteCounter) {
*(pByteData + byteCounter) = XUartPs_RecvByte(usartNumber);
}
return StatusSpace::ok;
}
#endif