/*
 * njj29c2_drv.h
 *
 *  Created on: 2020Äê12ÔÂ4ÈÕ
 *      Author: nxa16228
 */

#ifndef PEPS_DRV_NJJ29C2_DRV_H_
#define PEPS_DRV_NJJ29C2_DRV_H_

#include "Mcal.h"
#include "status.h"
#include "Crc_Ip.h"

/********************************************************************
 * MACRO definition for NJJ29C2 Driver
 *******************************************************************/
#define NJJ_SPI_INST		4U
#define NJJ_CRC_INST		0U
#define NJJ_CRC_SEED		0xFFFFFFFFu
#define NJJ_CRC_POLY		0x1021u

#define NJJ_CS_PORT_INST	5
#define NJJ_CS_PIN_IDX		26
#define NJJ_BUSY_PORT_INST	5
#define NJJ_BUSY_PIN_IDX	27
#define NJJ_IRQ_PORT_INST	2
#define NJJ_IRQ_PIN_IDX		7
#define NJJ_RST_PORT_INST	5
#define NJJ_RST_PIN_IDX		30

#define NJJ_SPI_FRAME_LEN	32U
#define NJJ_SPI_TIMEOUT		1000U
/* delay 20us to release CS signal, fit for 2MHz data rate */
#define NJJ_SPI_CS_DELAY	10U

/**********************************************************************************
 * Global Variables
 **********************************************************************************/
extern uint8_t txBufNjj[32];
extern uint8_t rxBufNjj[32];

/**********************************************************************************
 * API Functions
 **********************************************************************************/
void cenDelayUs(uint32_t usec);
void cenDelayMs(uint32_t msec);
void cenCrcInit(void);
void cenPortInit(void);
void cenWaitForIrqLine(void);
void cenWaitForBusyLine(void);
void cenGenSpiCrc(uint8_t *data, uint8_t len);
void cenResetPin(void);
status_t cenSpiTxRx(uint8_t *txBuf, uint8_t *rxBuf);
status_t cenSendNopCmd(void);
status_t cenSendStopCmd(void);
status_t cenResetCmd(void);
status_t cenRespParse(const uint8_t respData[]);
status_t cenInitialCheck(void);
status_t cenCheckResp(void);


#endif /* PEPS_DRV_NJJ29C2_DRV_H_ */
