📄 mbusman.h
字号:
#ifndef MBUSMAN_H
#define MBUSMAN_H
#include "bastype.h"
#include "mbuspack.h"
#define MBAR_ADDR MCF5206::MBAR
//MCF5206 MBUS module registers address define
#define MADR (MBAR_ADDR + 0x1e0)
#define MFDR (MBAR_ADDR + 0x1e4)
#define MBCR (MBAR_ADDR + 0x1e8)
#define MBSR (MBAR_ADDR + 0x1ec)
#define MBDR (MBAR_ADDR + 0x1F0)
#define MBUS_ICR (MBAR_ADDR + 0x1e)
#define UART1_UOP1 (MBAR_ADDR + 0x1b8)
#define UART1_UOP0 (MBAR_ADDR + 0x1bc)
// Three I2C chip slave address define
#define CAT24C021_SLAVE_ADDR 0xa0
// the maximal number of data that CAT24C021 can write one time
#define CAT24C021_PAGE_SIZE 16
#define EEPROM_SIZE 2048
// repeat times define
#define CAT24C021_READ_REPEAT 100
#define CAT24C021_WRITE_REPEAT 500
#define PACKQUE_NUMBER 2
/**
* PCF8591 control byte define:
* bit7: unused
* bit6: Analogue output: enable - (1) or disable - (0)
* bit5~bit4: Analogue input: four single ended inputs - (00)
* three differential inputs - (01)
* single ended and differential mixed - (10)
* two differential inputs - (11)
* bit3: unused
* bit2: A/D channel autoincrement: enable - (1) or disable - (0)
* bit1~bit0: A/D channel number: channel 0 - (00)
* channel 1 - (01)
* channel 2 - (10)
* channel 3 - (11)
*/
#define PCF8591_CONTROL_BYTE 0x45
enum OperationType{OP_WRITE = 0, OP_READ = 1};
enum MBUSCmd{ CMD_TRANSMIT, // normal transmit
CMD_TRANSMIT_STOP, // a stop after transmitting
CMD_TRANSMIT_RECEIVE, // change to receive mode after transmit
CMD_RESTART_TRANSMIT, // restart then transmit
CMD_RECEIVE_ACK, // receive with acknowledge
CMD_RECEIVE_NOACK, // receive without acknowledge
CMD_RECEIVE_STOP // receive then stop
};
// function prototype define
VOID MBusInit(VOID);
//extern "C" VOID MBusMixedLisr(VOID);
extern "C" VOID Mbus_Lisr(int vector);
//static INT16 ProcessNext(VOID);
static INT16 RepeatTransfer(VOID);
static VOID ConstructSequence(MBusPackType *pack);
static VOID StartTransfer(VOID);
//static VOID EnterInterrupt(VOID);
CHAR CAT24C021Initialize(VOID);
CHAR CAT24C021WritePage(UINT16 baseAddr, UINT16 byteNum, UCHAR *data);
CHAR CAT24C021WriteSeqByte(UINT16 baseAddr, UINT16 byteNum, UCHAR *data);
CHAR CAT24C021ReadSeqByte(UINT16 baseAddr, UINT16 byteNum, UCHAR *dataAddr);
VOID ResetWatchdog( VOID );
static CHAR MBusTransferByQuery(MBusPackType *thePack);
static UCHAR WaitForMBusFree(VOID);
static UCHAR WaitForMIF(VOID);
static VOID UpdateCheckSum(UINT16 baseAddr, UINT16 byteNum, UCHAR *data);
static CHAR CAT24C021LoadMemoryMap(UCHAR *memoryMap);
CHAR CAT24C021WritePageWithCheck(UINT16 baseAddr, UINT16 byteNum, UCHAR *data);
CHAR CAT24C021WriteSeqByteWithCheck(UINT16 baseAddr, UINT16 byteNum, UCHAR *data);
INT IsMBusInQueryMode( VOID );
BOOL WriteEeprom(UINT32 addr, UINT32 count, UCHAR* data);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -