forked from gatsby/df_datalink
99 lines
2.6 KiB
C
99 lines
2.6 KiB
C
/*****************************************************************************/
|
|
/**
|
|
* Description: MPC uart driver implementation file.
|
|
*
|
|
* Date: 2023-05-06 10:59
|
|
* LastEditTime: 2023-05-06 21:48
|
|
* Revisions: Rev 0.0
|
|
* History:
|
|
* [2023-05-06]: Initial version.
|
|
*
|
|
* Copyright(c) 2022 Beijing Institute of Technology.
|
|
*
|
|
******************************************************************************/
|
|
|
|
#ifndef __MPC_HW_H
|
|
#define __MPC_HW_H
|
|
|
|
/**************************** Include Files *****************************/
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "util.h"
|
|
#include "xgpio.h"
|
|
|
|
#define MPC_FRAME_MAX 256
|
|
#define FRAME_PAYLOAD_POFFSET 2 // CheckSum, Dummy and DataLen
|
|
/**************************** Type Definitions *****************************/
|
|
/**
|
|
*
|
|
* Write a value to a SYSTEMBUS_UART register. A 32 bit write is performed.
|
|
* If the component is implemented in a smaller width, only the least
|
|
* significant data is written.
|
|
*
|
|
* @param baseAddr is the base address of the SYSTEMBUS_UARTdevice.
|
|
* @param offset is the register offset from the base to write to.
|
|
* @param data is the data written to the register.
|
|
*
|
|
* @return None.
|
|
*
|
|
* @note
|
|
* C-style signature:
|
|
* void MPC_HW_mWriteReg(uint32_t BaseAddress, unsigned RegOffset, uint32_t Data)
|
|
*
|
|
*/
|
|
#define MPC_HW_mWriteReg(baseAddr, offset, data) \
|
|
IO_Out32((baseAddr) + (offset), (uint32_t)(data))
|
|
|
|
/**
|
|
*
|
|
* Read a value from a SYSTEMBUS_UART register. A 32 bit read is performed.
|
|
* If the component is implemented in a smaller width, only the least
|
|
* significant data is read from the register. The most significant data
|
|
* will be read as 0.
|
|
*
|
|
* @param baseAddr is the base address of the SYSTEMBUS_UART device.
|
|
* @param offset is the register offset from the base to write to.
|
|
*
|
|
* @return Data is the data from the register.
|
|
*
|
|
* @note
|
|
* C-style signature:
|
|
* uint32_t MPC_HW_mReadReg(uint32_t BaseAddress, unsigned RegOffset)
|
|
*
|
|
*/
|
|
#define MPC_HW_mReadReg(baseAddr, offset) \
|
|
IO_In32((baseAddr) + (offset))
|
|
|
|
typedef struct
|
|
{
|
|
uintptr_t txBuffAddr;
|
|
uintptr_t rxBuffAddr;
|
|
uint32_t gpioId;
|
|
} MPC_HW_CONFIG;
|
|
|
|
typedef struct
|
|
{
|
|
MPC_HW_CONFIG config;
|
|
XGpio gpioDesc;
|
|
} MPC_HW;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t len;
|
|
uint8_t checkSum;
|
|
uint8_t isValid;
|
|
uint8_t data[MPC_FRAME_MAX];
|
|
} MPC_HW_FRAME;
|
|
|
|
/************************** Function Prototypes ******************************/
|
|
// Instance initial
|
|
int MpcHw_Init(MPC_HW **instPtr, MPC_HW_CONFIG *config);
|
|
|
|
// Send a MPC frame.
|
|
int MpcHw_Send(MPC_HW *instPtr, MPC_HW_FRAME *frame);
|
|
|
|
// Get last MPC frame.
|
|
int MpcHw_Recv(MPC_HW *instPtr, MPC_HW_FRAME *frame);
|
|
|
|
#endif // __MPC_HW_H
|