/******************************************************************************/
/* Williams Advanced Engineering Limited                     Copyright(C) 2021*/
/* Grove                                                  All rights reserved */
/*                                                                            */
/******************************************************************************/

#ifndef MAINSOURCES_INCLUDE_IOS_CANCONFIG_H_
#define MAINSOURCES_INCLUDE_IOS_CANCONFIG_H_

#include "hal_stdtypes.h"
#include "sys_common.h"
#include "reg_spi.h"
#include "spi.h"
#include "gio.h"

//SPI Controller
#define SPI2_CS0_PIN    1

// CAN Controller Register Address
#define MODE_CONTROL_REG    0x01
#define MAIN_STATUS_REG     0x03
#define CAN_CONTROL_REG     0x20
#define TRANSCEIVER_REG     0x22
#define LOCK_CONTROL_REG    0x0A
#define TRANSCEIVER_EVNT_REG 0x63
#define SYSEVNT_STAT_REG    0x61
#define ID_UNIT_REG         0x7E

//CAN Controller Read Register Address
#define READ_REG_COMMAND 0x01

//CAN Controller Register Config
#define CAN_SLEEP_MODE          0x01
#define CAN_STANDBY_MODE        0x04
#define CAN_NORMAL_MODE         0x07
#define CAN_ACTIVE_MODE         0x02
#define CAN_OFFLINE_MODE        0x00
#define CAN_EXPECTED_ID         0x70

#define CAN_READ_MASK           0xFF

/*----------------------------------------------------------------------------*/
/* FUNCTION PROTOTYPES                                                         */
/*----------------------------------------------------------------------------*/
extern uint32   fnIosCANWakeUpPolledTransfer( uint16 *ptbSendBuffer, uint16 *ptbReceiveBuffer, uint32 uByteCount);
extern uint8    fnIosCANWakeUpModeControl(void);
extern uint8    fnIosCANWakeUpModeActive(void);
extern uint8    fnIosCANWakeUpRegRead(void);
extern uint8    fnIosCANWakeUpIDAcquire(void);
extern void     fnIosCANConfigWakeUp(void);
extern uint8    fnIosCANWakeUpSpiCtrlInitialise(void);
extern void     fnIosCANWakeUpMainStatusAcquire(void);



#endif /* MAINSOURCES_INCLUDE_IOS_CANCONFIG_H_ */
