VSF Documented
i2c.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
19#define __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_I2C == ENABLED
26
27// HW/IPCore
32// HW/IPCore end
33
34/*\note Refer to template/README.md for usage cases.
35 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
36 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
37 * For emulated drivers, **** No reimplementation ****.
38 */
39
40/*\note Includes CAN ONLY be put here. */
41/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
42
43// IPCore
44#if defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT)
45# define __VSF_CLASS_IMPLEMENT__
46#elif defined(__VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__)
47# define __VSF_CLASS_INHERIT__
48#endif
49
50#include "utilities/ooc_class.h"
51// IPCore end
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/*============================ MACROS ========================================*/
58
59/*\note VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
60 * while VSF_HW_I2C_CFG_MULTI_CLASS should be in i2c.c.
61 */
62
63// IPCore
64#ifndef VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS
65# define VSF_${I2C_IP}_I2C_CFG_MULTI_CLASS VSF_I2C_CFG_MULTI_CLASS
66#endif
67// IPCore end
68
69// HW
70/*\note hw I2C driver can reimplement following types:
71 * To enable reimplementation, please enable macro below:
72 * VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE for vsf_i2c_mode_t
73 * VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS for vsf_i2c_status_t
74 * VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_i2c_irq_mask_t
75 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD for vsf_i2c_cmd_t
76 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL for vsf_i2c_ctrl_t
77 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG for vsf_i2c_cfg_t
78 * VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_i2c_capability_t
79 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
80 * *** DO NOT reimplement these in emulated drivers. ***
81 */
82
83#define VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE ENABLED
84#define VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
85#define VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
86#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD ENABLED
87#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
88#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG ENABLED
89#define VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
90// HW end
91
92/*============================ TYPES =========================================*/
93
94// IPCore
95vsf_class(vsf_${i2c_ip}_i2c_t) {
96#if VSF_${I2C_IP}_CFG_MULTI_CLASS == ENABLED
97 public_member(
98 vsf_i2c_t vsf_i2c;
99 )
100#endif
101
102/*\note You can add more member in vsf_${i2c_ip}_i2c_t instance.
103 * For members accessible from child, put in protected_member.
104 * Else, put in private_member.
105 */
106
107 protected_member(
108 vsf_${i2c_ip}_iwc_reg_t *reg;
111};
112// IPCore end
113
114// HW/IPCore, not for emulated drivers
115#if VSF_I2C_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
116typedef enum vsf_i2c_mode_t {
117 VSF_I2C_MODE_MASTER = (0x1ul << 28),
118 VSF_I2C_MODE_SLAVE = (0x0ul << 28),
119
121 VSF_I2C_SPEED_FAST_MODE = (0x1ul << 29),
124
125 VSF_I2C_ADDR_7_BITS = (0x0ul << 31),
126 VSF_I2C_ADDR_10_BITS = (0x1ul << 31),
127
128 // more vendor specified irq_mask can be added here
130#endif
131
132#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CMD == ENABLED
133typedef enum vsf_i2c_cmd_t {
134 VSF_I2C_CMD_WRITE = (0x00ul << 0),
135 VSF_I2C_CMD_READ = (0x01ul << 0),
136
137 VSF_I2C_CMD_START = (0x00ul << 28),
138 VSF_I2C_CMD_NO_START = (0x01ul << 28),
139
140 VSF_I2C_CMD_STOP = (0x00ul << 29),
141 VSF_I2C_CMD_RESTART = (0x01ul << 30),
143
144 VSF_I2C_CMD_7_BITS = (0x00ul << 31),
145 VSF_I2C_CMD_10_BITS = (0x01ul << 31),
146
147 // more vendor specified commands can be added here
149#endif
150
151#if VSF_I2C_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
152typedef enum vsf_i2c_irq_mask_t {
168
169 // more vendor specified irq_masks can be added here
171#endif
172
173#if VSF_I2C_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
174/*\note It's not obligated to inherit from vsf_peripheral_status_t.
175 * If not, there MUST be a is_busy bit in vsf_i2c_status_t.
176 */
177
178typedef struct vsf_i2c_status_t {
179 union {
181 struct {
182 uint32_t is_busy : 1;
183 };
185 };
187#endif
188
189#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
190typedef enum vsf_i2c_ctrl_t {
193#endif
194
195#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
196typedef struct vsf_i2c_t vsf_i2c_t;
197typedef void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask);
198typedef struct vsf_i2c_isr_t {
200 void *target_ptr;
203typedef struct vsf_i2c_cfg_t {
209#endif
210
211#if VSF_I2C_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
212typedef struct vsf_i2c_capability_t {
213#if VSF_I2C_CFG_INHERIT_HAL_CAPABILITY == ENABLED
215#endif
222
223 // more vendor specified capability can be added here
225#endif
226// HW/IPCore end
227
228/*============================ GLOBAL VARIABLES ==============================*/
229/*============================ PROTOTYPES ====================================*/
230
231// IPCore
232/*\note Extern APIs for ip core diriver.
233 * There is no requirement about how APIs of IPCore drivers should be implemented.
234 * Just consider the simplicity for actual peripheral drivers.
235 */
236// IPCore end
237
238#ifdef __cplusplus
239}
240#endif
241
242// IPCore
243#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_IMPLEMENT
244#undef __VSF_HAL_${I2C_IP}_I2C_CLASS_INHERIT__
245// IPCore end
246
247#endif // VSF_HAL_USE_I2C
248#endif // __HAL_DRIVER_${SERIES/I2C_IP}_I2C_H__
249/* EOF */
Definition adc.h:92
vsf_arch_prio_t
Definition cortex_a_generic.h:88
vsf_i2c_cmd_t
Definition i2c.h:32
@ VSF_I2C_CMD_10_BITS
Definition i2c.h:40
@ VSF_I2C_CMD_7_BITS
Definition i2c.h:39
@ VSF_I2C_CMD_NO_START
Definition i2c.h:47
@ VSF_I2C_CMD_STOP
Definition i2c.h:48
@ VSF_I2C_CMD_NO_STOP_RESTART
Definition i2c.h:49
@ VSF_I2C_CMD_RESTART
Definition i2c.h:37
@ VSF_I2C_CMD_WRITE
Definition i2c.h:33
@ VSF_I2C_CMD_READ
Definition i2c.h:34
@ VSF_I2C_CMD_START
Definition i2c.h:36
struct vsf_i2c_cfg_t vsf_i2c_cfg_t
struct vsf_i2c_status_t vsf_i2c_status_t
vsf_i2c_mode_t
Definition i2c.h:80
@ VSF_I2C_MODE_MASTER
Definition i2c.h:81
@ VSF_I2C_SPEED_HIGH_SPEED_MODE
Definition i2c.h:87
@ VSF_I2C_MODE_SLAVE
Definition i2c.h:82
@ VSF_I2C_SPEED_STANDARD_MODE
Definition i2c.h:84
@ VSF_I2C_ADDR_7_BITS
Definition i2c.h:89
@ VSF_I2C_SPEED_FAST_MODE_PLUS
Definition i2c.h:86
@ VSF_I2C_SPEED_FAST_MODE
Definition i2c.h:85
@ VSF_I2C_ADDR_10_BITS
Definition i2c.h:90
struct vsf_i2c_capability_t vsf_i2c_capability_t
struct vsf_i2c_isr_t vsf_i2c_isr_t
vsf_i2c_ctrl_t
Definition i2c.h:154
@ __VSF_I2C_CTRL_DUMMP
Definition i2c.h:155
vsf_i2c_irq_mask_t
Definition i2c.h:116
@ VSF_I2C_IRQ_MASK_MASTER_STOP_DETECT
Definition i2c.h:125
@ VSF_I2C_IRQ_MASK_SLAVE_TX
Definition i2c.h:128
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:119
@ VSF_I2C_IRQ_MASK_SLAVE_START_OR_RESTART_DETECT
Definition i2c.h:126
@ VSF_I2C_IRQ_MASK_MASTER_TX
Definition i2c.h:117
@ VSF_I2C_IRQ_MASK_MASTER_ERR
Definition i2c.h:123
@ VSF_I2C_IRQ_MASK_MASTER_RX
Definition i2c.h:118
@ VSF_I2C_IRQ_MASK_SLAVE_TRANSFER_COMPLETE
Definition i2c.h:130
@ VSF_I2C_IRQ_MASK_MASTER_START_OR_RESTART_DETECT
Definition i2c.h:124
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:121
@ VSF_I2C_IRQ_MASK_SLAVE_ERR
Definition i2c.h:131
@ VSF_I2C_IRQ_MASK_SLAVE_STOP_DETECT
Definition i2c.h:127
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:120
@ VSF_I2C_IRQ_MASK_MASTER_TX_NACK_DETECT
Definition i2c.h:122
@ VSF_I2C_IRQ_MASK_SLAVE_RX
Definition i2c.h:129
void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
Definition i2c.h:161
class vsf_$ * reg
vsf_i2c_isr_t isr
Definition i2c.h:110
vsf_i2c_irq_mask_t
Definition i2c.h:152
void vsf_i2c_isr_handler_t(void *target_ptr, vsf_i2c_t *i2c_ptr, vsf_i2c_irq_mask_t irq_mask)
Definition i2c.h:197
#define vsf_class(__name)
Definition ooc_class.h:48
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned short uint_fast16_t
Definition stdint.h:25
unsigned char uint8_t
Definition stdint.h:5
Predefined I2C capability structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_i2c.h:778
uint8_t support_restart
Definition vsf_template_i2c.h:796
uint8_t support_no_stop
Definition vsf_template_i2c.h:792
inherit(vsf_peripheral_capability_t) vsf_i2c_irq_mask_t irq_mask
uint_fast16_t max_transfer_size
Definition vsf_template_i2c.h:800
uint_fast16_t min_transfer_size
Definition vsf_template_i2c.h:804
uint8_t support_no_start
Definition vsf_template_i2c.h:788
I2C configuration.
Definition vsf_template_i2c.h:882
vsf_i2c_mode_t mode
Definition vsf_template_i2c.h:885
uint_fast16_t slave_addr
Definition vsf_template_i2c.h:897
vsf_i2c_isr_t isr
Definition vsf_template_i2c.h:893
uint32_t clock_hz
Definition vsf_template_i2c.h:889
I2C interrupt configuration.
Definition vsf_template_i2c.h:861
vsf_i2c_isr_handler_t * handler_fn
Definition vsf_template_i2c.h:864
void * target_ptr
Definition vsf_template_i2c.h:868
vsf_arch_prio_t prio
Definition vsf_template_i2c.h:872
Predefined VSF I2C status that can be reimplemented in specific hal drivers.
Definition vsf_template_i2c.h:758
uint32_t value
Definition vsf_template_i2c.h:764
I2C instance structure for multi-class support.
Definition vsf_template_i2c.h:977
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
vsf_i2c_mode_t
Predefined VSF I2C modes that can be reimplemented in specific HAL drivers.If we want to add optional...
Definition vsf_template_i2c.h:238
vsf_i2c_ctrl_t
I2C control commands for hardware-specific operations.
Definition vsf_template_i2c.h:910
vsf_i2c_irq_mask_t
Predefined VSF I2C interrupt masks that can be reimplemented in specific HAL drivers....
Definition vsf_template_i2c.h:538
Generated from commit: vsfteam/vsf@74aa6ce