11/* ****************************************************************************
2- * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
2+ * Copyright (C) 2022 Maxim Integrated Products, Inc., All Rights Reserved.
33 *
44 * Permission is hereby granted, free of charge, to any person obtaining a
55 * copy of this software and associated documentation files (the "Software"),
3131 *
3232 *************************************************************************** */
3333
34- #ifndef _I2C_REVA_H_
35- #define _I2C_REVA_H_
34+ #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_I2C_I2C_REVA_H_
35+ #define LIBRARIES_PERIPHDRIVERS_SOURCE_I2C_I2C_REVA_H_
3636
3737#include <stdio.h>
3838#include <stddef.h>
4646#include "i2c_reva_regs.h"
4747#include "dma.h"
4848
49-
5049/* **** Definitions **** */
51- #define MXC_I2C_REVA_MAX_ADDR_WIDTH 0x7F
52- #define MXC_I2C_REVA_STD_MODE 100000
53- #define MXC_I2C_REVA_FAST_SPEED 400000
54- #define MXC_I2C_REVA_FASTPLUS_SPEED 1000000
55- #define MXC_I2C_REVA_HS_MODE 3400000
50+ #define MXC_I2C_REVA_MAX_ADDR_WIDTH 0x7F
51+ #define MXC_I2C_REVA_STD_MODE 100000
52+ #define MXC_I2C_REVA_FAST_SPEED 400000
53+ #define MXC_I2C_REVA_FASTPLUS_SPEED 1000000
54+ #define MXC_I2C_REVA_HS_MODE 3400000
5655
57- #define MXC_I2C_REVA_INTFL0_MASK 0x00FFFFFF
58- #define MXC_I2C_REVA_INTFL1_MASK 0x00000007
56+ #define MXC_I2C_REVA_INTFL0_MASK 0x00FFFFFF
57+ #define MXC_I2C_REVA_INTFL1_MASK 0x00000007
5958
60- #define MXC_I2C_REVA_MAX_FIFO_TRANSACTION 256
59+ #define MXC_I2C_REVA_MAX_FIFO_TRANSACTION 256
6160
62- #define MXC_I2C_REVA_ERROR (MXC_F_I2C_REVA_INTFL0_ARB_ERR | MXC_F_I2C_REVA_INTFL0_TO_ERR | MXC_F_I2C_REVA_INTFL0_ADDR_NACK_ERR | \
63- MXC_F_I2C_REVA_INTFL0_DATA_ERR | MXC_F_I2C_REVA_INTFL0_DNR_ERR | MXC_F_I2C_REVA_INTFL0_START_ERR | \
64- MXC_F_I2C_REVA_INTFL0_STOP_ERR)
61+ #define MXC_I2C_REVA_ERROR \
62+ (MXC_F_I2C_REVA_INTFL0_ARB_ERR | MXC_F_I2C_REVA_INTFL0_TO_ERR | \
63+ MXC_F_I2C_REVA_INTFL0_ADDR_NACK_ERR | MXC_F_I2C_REVA_INTFL0_DATA_ERR | \
64+ MXC_F_I2C_REVA_INTFL0_DNR_ERR | MXC_F_I2C_REVA_INTFL0_START_ERR | \
65+ MXC_F_I2C_REVA_INTFL0_STOP_ERR)
6566
6667typedef struct _i2c_reva_req_t mxc_i2c_reva_req_t ;
67- typedef int (* mxc_i2c_reva_getAck_t ) (mxc_i2c_reva_regs_t * i2c , unsigned char byte );
68- typedef void (* mxc_i2c_reva_complete_cb_t ) (mxc_i2c_reva_req_t * req , int result );
69- typedef void (* mxc_i2c_reva_dma_complete_cb_t ) (int len , int result );
68+ typedef int (* mxc_i2c_reva_getAck_t )(mxc_i2c_reva_regs_t * i2c , unsigned char byte );
69+ typedef void (* mxc_i2c_reva_complete_cb_t )(mxc_i2c_reva_req_t * req , int result );
70+ typedef void (* mxc_i2c_reva_dma_complete_cb_t )(int len , int result );
7071struct _i2c_reva_req_t {
71- mxc_i2c_reva_regs_t * i2c ;
72+ mxc_i2c_reva_regs_t * i2c ;
7273 unsigned int addr ;
73- unsigned char * tx_buf ;
74+ unsigned char * tx_buf ;
7475 unsigned int tx_len ;
75- unsigned char * rx_buf ;
76+ unsigned char * rx_buf ;
7677 unsigned int rx_len ;
7778 int restart ;
7879 mxc_i2c_reva_complete_cb_t callback ;
@@ -86,72 +87,86 @@ typedef enum {
8687 MXC_I2C_REVA_EVT_UNDERFLOW ,
8788 MXC_I2C_REVA_EVT_OVERFLOW ,
8889} mxc_i2c_reva_slave_event_t ;
89- typedef int (* mxc_i2c_reva_slave_handler_t ) (mxc_i2c_reva_regs_t * i2c ,
90- mxc_i2c_reva_slave_event_t event , void * data );
90+ typedef int (* mxc_i2c_reva_slave_handler_t )(mxc_i2c_reva_regs_t * i2c ,
91+ mxc_i2c_reva_slave_event_t event , void * data );
9192/* **** Variable Declaration **** */
9293
94+ extern void * AsyncRequests [MXC_I2C_INSTANCES ];
95+
9396/* **** Function Prototypes **** */
9497
9598/* ************************************************************************* */
9699/* Control/Configuration functions */
97100/* ************************************************************************* */
98- int MXC_I2C_RevA_Init (mxc_i2c_reva_regs_t * i2c , int masterMode , unsigned int slaveAddr );
99- int MXC_I2C_RevA_SetSlaveAddr (mxc_i2c_reva_regs_t * i2c , unsigned int slaveAddr , int idx );
100- int MXC_I2C_RevA_Shutdown (mxc_i2c_reva_regs_t * i2c );
101- int MXC_I2C_RevA_SetFrequency (mxc_i2c_reva_regs_t * i2c , unsigned int hz );
102- unsigned int MXC_I2C_RevA_GetFrequency (mxc_i2c_reva_regs_t * i2c );
103- int MXC_I2C_RevA_ReadyForSleep (mxc_i2c_reva_regs_t * i2c );
104- int MXC_I2C_RevA_SetClockStretching (mxc_i2c_reva_regs_t * i2c , int enable );
105- int MXC_I2C_RevA_GetClockStretching (mxc_i2c_reva_regs_t * i2c );
101+ int MXC_I2C_RevA_Init (mxc_i2c_reva_regs_t * i2c , int masterMode , unsigned int slaveAddr );
102+ int MXC_I2C_RevA_SetSlaveAddr (mxc_i2c_reva_regs_t * i2c , unsigned int slaveAddr , int idx );
103+ int MXC_I2C_RevA_Shutdown (mxc_i2c_reva_regs_t * i2c );
104+ int MXC_I2C_RevA_SetFrequency (mxc_i2c_reva_regs_t * i2c , unsigned int hz );
105+ unsigned int MXC_I2C_RevA_GetFrequency (mxc_i2c_reva_regs_t * i2c );
106+ int MXC_I2C_RevA_ReadyForSleep (mxc_i2c_reva_regs_t * i2c );
107+ int MXC_I2C_RevA_SetClockStretching (mxc_i2c_reva_regs_t * i2c , int enable );
108+ int MXC_I2C_RevA_GetClockStretching (mxc_i2c_reva_regs_t * i2c );
106109
107110/* ************************************************************************* */
108111/* Low-level functions */
109112/* ************************************************************************* */
110- int MXC_I2C_RevA_Start (mxc_i2c_reva_regs_t * i2c );
111- int MXC_I2C_RevA_Stop (mxc_i2c_reva_regs_t * i2c );
112- int MXC_I2C_RevA_WriteByte (mxc_i2c_reva_regs_t * i2c , unsigned char byte );
113- int MXC_I2C_RevA_ReadByte (mxc_i2c_reva_regs_t * i2c , unsigned char * byte , int ack );
114- int MXC_I2C_RevA_ReadByteInteractive (mxc_i2c_reva_regs_t * i2c , unsigned char * byte , mxc_i2c_reva_getAck_t getAck );
115- int MXC_I2C_RevA_Write (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int * len );
116- int MXC_I2C_RevA_Read (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int * len , int ack );
117- int MXC_I2C_RevA_ReadRXFIFO (mxc_i2c_reva_regs_t * i2c , volatile unsigned char * bytes , unsigned int len );
118- int MXC_I2C_RevA_ReadRXFIFODMA (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int len , mxc_i2c_reva_dma_complete_cb_t callback , mxc_dma_config_t config , mxc_dma_regs_t * dma );
119- int MXC_I2C_RevA_GetRXFIFOAvailable (mxc_i2c_reva_regs_t * i2c );
120- int MXC_I2C_RevA_WriteTXFIFO (mxc_i2c_reva_regs_t * i2c , volatile unsigned char * bytes , unsigned int len );
121- int MXC_I2C_RevA_WriteTXFIFODMA (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int len , mxc_i2c_reva_dma_complete_cb_t callback , mxc_dma_config_t config , mxc_dma_regs_t * dma );
122- int MXC_I2C_RevA_GetTXFIFOAvailable (mxc_i2c_reva_regs_t * i2c );
123- void MXC_I2C_RevA_ClearRXFIFO (mxc_i2c_reva_regs_t * i2c );
124- void MXC_I2C_RevA_ClearTXFIFO (mxc_i2c_reva_regs_t * i2c );
125- int MXC_I2C_RevA_GetFlags (mxc_i2c_reva_regs_t * i2c , unsigned int * flags0 , unsigned int * flags1 );
126- void MXC_I2C_RevA_ClearFlags (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
127- void MXC_I2C_RevA_EnableInt (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
128- void MXC_I2C_RevA_DisableInt (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
129- void MXC_I2C_RevA_EnablePreload (mxc_i2c_reva_regs_t * i2c );
130- void MXC_I2C_RevA_DisablePreload (mxc_i2c_reva_regs_t * i2c );
131- void MXC_I2C_RevA_EnableGeneralCall (mxc_i2c_reva_regs_t * i2c );
132- void MXC_I2C_RevA_DisableGeneralCall (mxc_i2c_reva_regs_t * i2c );
133- void MXC_I2C_RevA_SetTimeout (mxc_i2c_reva_regs_t * i2c , unsigned int timeout );
134- unsigned int MXC_I2C_RevA_GetTimeout (mxc_i2c_reva_regs_t * i2c );
135- int MXC_I2C_RevA_Recover (mxc_i2c_reva_regs_t * i2c , unsigned int retries );
113+ int MXC_I2C_RevA_Start (mxc_i2c_reva_regs_t * i2c );
114+ int MXC_I2C_RevA_Stop (mxc_i2c_reva_regs_t * i2c );
115+ int MXC_I2C_RevA_WriteByte (mxc_i2c_reva_regs_t * i2c , unsigned char byte );
116+ int MXC_I2C_RevA_ReadByte (mxc_i2c_reva_regs_t * i2c , unsigned char * byte , int ack );
117+ int MXC_I2C_RevA_ReadByteInteractive (mxc_i2c_reva_regs_t * i2c , unsigned char * byte ,
118+ mxc_i2c_reva_getAck_t getAck );
119+ int MXC_I2C_RevA_Write (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int * len );
120+ int MXC_I2C_RevA_Read (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int * len , int ack );
121+ int MXC_I2C_RevA_ReadRXFIFO (mxc_i2c_reva_regs_t * i2c , volatile unsigned char * bytes ,
122+ unsigned int len );
123+ int MXC_I2C_RevA_ReadRXFIFODMA (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int len ,
124+ mxc_i2c_reva_dma_complete_cb_t callback , mxc_dma_config_t config ,
125+ mxc_dma_regs_t * dma );
126+ int MXC_I2C_RevA_GetRXFIFOAvailable (mxc_i2c_reva_regs_t * i2c );
127+ int MXC_I2C_RevA_WriteTXFIFO (mxc_i2c_reva_regs_t * i2c , volatile unsigned char * bytes ,
128+ unsigned int len );
129+ int MXC_I2C_RevA_WriteTXFIFODMA (mxc_i2c_reva_regs_t * i2c , unsigned char * bytes , unsigned int len ,
130+ mxc_i2c_reva_dma_complete_cb_t callback , mxc_dma_config_t config ,
131+ mxc_dma_regs_t * dma );
132+ int MXC_I2C_RevA_GetTXFIFOAvailable (mxc_i2c_reva_regs_t * i2c );
133+ void MXC_I2C_RevA_ClearRXFIFO (mxc_i2c_reva_regs_t * i2c );
134+ void MXC_I2C_RevA_ClearTXFIFO (mxc_i2c_reva_regs_t * i2c );
135+ int MXC_I2C_RevA_GetFlags (mxc_i2c_reva_regs_t * i2c , unsigned int * flags0 , unsigned int * flags1 );
136+ void MXC_I2C_RevA_ClearFlags (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
137+ void MXC_I2C_RevA_EnableInt (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
138+ void MXC_I2C_RevA_DisableInt (mxc_i2c_reva_regs_t * i2c , unsigned int flags0 , unsigned int flags1 );
139+ void MXC_I2C_RevA_EnablePreload (mxc_i2c_reva_regs_t * i2c );
140+ void MXC_I2C_RevA_DisablePreload (mxc_i2c_reva_regs_t * i2c );
141+ void MXC_I2C_RevA_EnableGeneralCall (mxc_i2c_reva_regs_t * i2c );
142+ void MXC_I2C_RevA_DisableGeneralCall (mxc_i2c_reva_regs_t * i2c );
143+ void MXC_I2C_RevA_SetTimeout (mxc_i2c_reva_regs_t * i2c , unsigned int timeout );
144+ unsigned int MXC_I2C_RevA_GetTimeout (mxc_i2c_reva_regs_t * i2c );
145+ int MXC_I2C_RevA_Recover (mxc_i2c_reva_regs_t * i2c , unsigned int retries );
136146
137147/* ************************************************************************* */
138148/* Transaction level functions */
139149/* ************************************************************************* */
140- int MXC_I2C_RevA_MasterTransaction (mxc_i2c_reva_req_t * req );
141- int MXC_I2C_RevA_MasterTransactionAsync (mxc_i2c_reva_req_t * req );
142- int MXC_I2C_RevA_MasterTransactionDMA (mxc_i2c_reva_req_t * req , mxc_dma_regs_t * dma );
143- int MXC_I2C_RevA_SlaveTransaction (mxc_i2c_reva_regs_t * i2c , mxc_i2c_reva_slave_handler_t callback , uint32_t interruptCheck );
144- int MXC_I2C_RevA_SlaveTransactionAsync (mxc_i2c_reva_regs_t * i2c , mxc_i2c_reva_slave_handler_t callback , uint32_t interruptCheck );
145- int MXC_I2C_RevA_SetRXThreshold (mxc_i2c_reva_regs_t * i2c , unsigned int numBytes );
146- unsigned int MXC_I2C_RevA_GetRXThreshold (mxc_i2c_reva_regs_t * i2c );
147- int MXC_I2C_RevA_SetTXThreshold (mxc_i2c_reva_regs_t * i2c , unsigned int numBytes );
148- unsigned int MXC_I2C_RevA_GetTXThreshold (mxc_i2c_reva_regs_t * i2c );
149- void MXC_I2C_RevA_AsyncCallback (mxc_i2c_reva_regs_t * i2c , int retVal );
150- void MXC_I2C_RevA_AsyncStop (mxc_i2c_reva_regs_t * i2c );
151- void MXC_I2C_RevA_AbortAsync (mxc_i2c_reva_regs_t * i2c );
152- void MXC_I2C_RevA_MasterAsyncHandler (int i2cNum );
153- unsigned int MXC_I2C_RevA_SlaveAsyncHandler (mxc_i2c_reva_regs_t * i2c , mxc_i2c_reva_slave_handler_t callback , unsigned int interruptEnables , int * retVal );
154- void MXC_I2C_RevA_AsyncHandler (mxc_i2c_reva_regs_t * i2c , uint32_t interruptCheck );
155- void MXC_I2C_RevA_DMACallback (int ch , int error );
150+ int MXC_I2C_RevA_MasterTransaction (mxc_i2c_reva_req_t * req );
151+ int MXC_I2C_RevA_MasterTransactionAsync (mxc_i2c_reva_req_t * req );
152+ int MXC_I2C_RevA_MasterTransactionDMA (mxc_i2c_reva_req_t * req , mxc_dma_regs_t * dma );
153+ int MXC_I2C_RevA_SlaveTransaction (mxc_i2c_reva_regs_t * i2c , mxc_i2c_reva_slave_handler_t callback ,
154+ uint32_t interruptCheck );
155+ int MXC_I2C_RevA_SlaveTransactionAsync (mxc_i2c_reva_regs_t * i2c ,
156+ mxc_i2c_reva_slave_handler_t callback ,
157+ uint32_t interruptCheck );
158+ int MXC_I2C_RevA_SetRXThreshold (mxc_i2c_reva_regs_t * i2c , unsigned int numBytes );
159+ unsigned int MXC_I2C_RevA_GetRXThreshold (mxc_i2c_reva_regs_t * i2c );
160+ int MXC_I2C_RevA_SetTXThreshold (mxc_i2c_reva_regs_t * i2c , unsigned int numBytes );
161+ unsigned int MXC_I2C_RevA_GetTXThreshold (mxc_i2c_reva_regs_t * i2c );
162+ void MXC_I2C_RevA_AsyncCallback (mxc_i2c_reva_regs_t * i2c , int retVal );
163+ void MXC_I2C_RevA_AsyncStop (mxc_i2c_reva_regs_t * i2c );
164+ void MXC_I2C_RevA_AbortAsync (mxc_i2c_reva_regs_t * i2c );
165+ void MXC_I2C_RevA_MasterAsyncHandler (int i2cNum );
166+ unsigned int MXC_I2C_RevA_SlaveAsyncHandler (mxc_i2c_reva_regs_t * i2c ,
167+ mxc_i2c_reva_slave_handler_t callback ,
168+ unsigned int interruptEnables , int * retVal );
169+ void MXC_I2C_RevA_AsyncHandler (mxc_i2c_reva_regs_t * i2c , uint32_t interruptCheck );
170+ void MXC_I2C_RevA_DMACallback (int ch , int error );
156171
157- #endif /* _I2C_REVA_H_ */
172+ #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_I2C_I2C_REVA_H_
0 commit comments