Hardware Libraries  20.1
Arria 10 SoC Hardware Manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
alt_i2c.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright 2013 Altera Corporation. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 ******************************************************************************/
32 
33 /*
34  * $Id: //acds/rel/20.1/embedded/ip/hps/altera_hps/hwlib/include/alt_i2c.h#1 $
35  */
36 
41 #ifndef __ALT_I2C_H__
42 #define __ALT_I2C_H__
43 
44 #include "hwlib.h"
45 #include "alt_clock_manager.h"
46 #include "socal/alt_i2c.h"
47 #include "socal/alt_rstmgr.h"
48 #include "socal/hps.h"
49 #include "socal/socal.h"
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif /* __cplusplus */
55 
56 /******************************************************************************/
96 /******************************************************************************/
102 {
108 }
110 
111 
112 /*
113  * A pointer or handle to the I2C controller device instance. The ALT_I2C_DEV_t is
114  * initialized by a call to alt_i2c_init() and subsequently used by the other I2C
115  * controller API functions as a reference to a specific device.
116  *
117  * \internal
118  * ALT_I2C_DEV_t may be a struct or reference to an opaque data
119  * structure. Whatever "internal" type is suited to the needs of the
120  * implementation.
121  * \endinternal
122  */
123 typedef struct ALT_I2C_DEV_s
124 {
125  void * location;
126  alt_freq_t clock_freq;
127  uint32_t last_target;
128 }
129 ALT_I2C_DEV_t;
130 
134 typedef enum ALT_I2C_CTLR_e
135 {
136  ALT_I2C_I2C0 = (int)ALT_I2C0_OFST,
137  ALT_I2C_I2C1 = (int)ALT_I2C1_OFST,
138 #if defined(soc_cv_av)
139  ALT_I2C_I2C2 = (int)ALT_I2C2_OFST,
140  ALT_I2C_I2C3 = (int)ALT_I2C3_OFST
141 #elif defined(soc_a10)
142  /* I2C{2-4] are for general purpose or as control interfaces for connectors
143  * with embedded I2C channels such as SFP. */
144  ALT_I2C_I2C2 = (int)ALT_I2C_EMAC_0_I2C_OFST,
145  ALT_I2C_I2C3 = (int)ALT_I2C_EMAC_1_I2C_OFST,
146  ALT_I2C_I2C4 = (int)ALT_I2C_EMAC_2_I2C_OFST
147 #endif
149 
157 typedef enum ALT_I2C_MODE_e
158 {
159  ALT_I2C_MODE_SLAVE = ALT_I2C_CON_MST_MOD_E_DIS,
160  ALT_I2C_MODE_MASTER = ALT_I2C_CON_MST_MOD_E_EN
162 
176 typedef enum ALT_I2C_SPEED_e
177 {
178  ALT_I2C_SPEED_STANDARD = ALT_I2C_CON_SPEED_E_STANDARD,
180  ALT_I2C_SPEED_FAST = ALT_I2C_CON_SPEED_E_FAST
183 
193 {
194  ALT_I2C_ADDR_MODE_7_BIT = ALT_I2C_TAR_IC_10BITADDR_MST_E_START7,
196  ALT_I2C_ADDR_MODE_10_BIT = ALT_I2C_TAR_IC_10BITADDR_MST_E_START10
199 
203 typedef enum ALT_I2C_STATUS_e
204 {
349 
362 {
521 
536 {
541  uint8_t restart_enable;
559  uint16_t ss_scl_hcnt;
563  uint16_t ss_scl_lcnt;
567  uint16_t fs_scl_hcnt;
571  uint16_t fs_scl_lcnt;
575  uint8_t fs_spklen;
582 
588 {
592  uint32_t addr;
596  uint8_t nack_enable;
611 
634 ALT_STATUS_CODE alt_i2c_init(const ALT_I2C_CTLR_t i2c, ALT_I2C_DEV_t *i2c_dev);
635 
656 ALT_STATUS_CODE alt_i2c_reset(ALT_I2C_DEV_t * i2c_dev);
657 
674 ALT_STATUS_CODE alt_i2c_uninit(ALT_I2C_DEV_t *i2c_dev);
675 
700 ALT_STATUS_CODE alt_i2c_disable(ALT_I2C_DEV_t *i2c_dev);
701 
715 ALT_STATUS_CODE alt_i2c_enable(ALT_I2C_DEV_t *i2c_dev);
716 
730 ALT_STATUS_CODE alt_i2c_is_enabled(ALT_I2C_DEV_t *i2c_dev);
731 
749 ALT_STATUS_CODE alt_i2c_master_config_get(ALT_I2C_DEV_t *i2c_dev,
751 
769 ALT_STATUS_CODE alt_i2c_master_config_set(ALT_I2C_DEV_t *i2c_dev,
770  const ALT_I2C_MASTER_CONFIG_t* cfg);
771 
788 ALT_STATUS_CODE alt_i2c_master_config_speed_get(ALT_I2C_DEV_t *i2c_dev,
789  const ALT_I2C_MASTER_CONFIG_t* cfg,
790  uint32_t * speed_in_hz);
791 
811 ALT_STATUS_CODE alt_i2c_master_config_speed_set(ALT_I2C_DEV_t *i2c_dev,
813  uint32_t speed_in_hz);
814 
818 #define alt_i2c_cfg_to_speed(i2c_dev, speed_in_hz, cfg) alt_i2c_master_config_speed_get((i2c_dev), (cfg), (speed_in_hz))
819 
823 #define alt_i2c_speed_to_cfg(i2c_dev, speed_in_hz, cfg) alt_i2c_master_config_speed_set((i2c_dev), (cfg), (speed_in_hz))
824 
842 ALT_STATUS_CODE alt_i2c_slave_config_get(ALT_I2C_DEV_t *i2c_dev,
844 
862 ALT_STATUS_CODE alt_i2c_slave_config_set(ALT_I2C_DEV_t *i2c_dev,
863  const ALT_I2C_SLAVE_CONFIG_t* cfg);
864 
880 #if defined (soc_cv_av)
881 
898 ALT_STATUS_CODE alt_i2c_sda_hold_time_get(ALT_I2C_DEV_t *i2c_dev,
899  uint16_t *hold_time);
900 
918 ALT_STATUS_CODE alt_i2c_sda_hold_time_set(ALT_I2C_DEV_t *i2c_dev,
919  const uint16_t hold_time);
920 #elif defined (soc_a10)
921 
938 ALT_STATUS_CODE alt_i2c_sda_tx_hold_time_get(ALT_I2C_DEV_t *i2c_dev,
939  uint16_t *tx_hold_time);
940 
958 ALT_STATUS_CODE alt_i2c_sda_rx_hold_time_get(ALT_I2C_DEV_t *i2c_dev,
959  uint16_t *rx_hold_time);
977 ALT_STATUS_CODE alt_i2c_sda_tx_hold_time_set(ALT_I2C_DEV_t *i2c_dev,
978  const uint16_t tx_hold_time);
996 ALT_STATUS_CODE alt_i2c_sda_rx_hold_time_set(ALT_I2C_DEV_t *i2c_dev,
997  const uint16_t rx_hold_time);
998 #endif
999 
1018 ALT_STATUS_CODE alt_i2c_op_mode_get(ALT_I2C_DEV_t *i2c_dev,
1019  ALT_I2C_MODE_t* mode);
1020 
1036 ALT_STATUS_CODE alt_i2c_op_mode_set(ALT_I2C_DEV_t *i2c_dev,
1037  const ALT_I2C_MODE_t mode);
1038 
1056 ALT_STATUS_CODE alt_i2c_is_busy(ALT_I2C_DEV_t *i2c_dev);
1057 
1083 ALT_STATUS_CODE alt_i2c_read(ALT_I2C_DEV_t *i2c_dev, uint8_t *val);
1084 
1110 ALT_STATUS_CODE alt_i2c_write(ALT_I2C_DEV_t *i2c_dev, const uint8_t val);
1111 
1134 ALT_STATUS_CODE alt_i2c_slave_receive(ALT_I2C_DEV_t *i2c_dev,
1135  uint8_t *data);
1136 
1159 ALT_STATUS_CODE alt_i2c_slave_transmit(ALT_I2C_DEV_t *i2c_dev,
1160  const uint8_t data);
1161 
1218 ALT_STATUS_CODE alt_i2c_slave_bulk_transmit(ALT_I2C_DEV_t *i2c_dev,
1219  const void * data,
1220  const size_t size);
1221 
1236 ALT_STATUS_CODE alt_i2c_master_target_get(ALT_I2C_DEV_t * i2c_dev, uint32_t * target_addr);
1237 
1257 ALT_STATUS_CODE alt_i2c_master_target_set(ALT_I2C_DEV_t * i2c_dev, uint32_t target_addr);
1258 
1312 ALT_STATUS_CODE alt_i2c_master_transmit(ALT_I2C_DEV_t *i2c_dev,
1313  const void * data,
1314  const size_t size,
1315  const uint8_t issue_restart,
1316  const uint8_t issue_stop);
1317 
1379 ALT_STATUS_CODE alt_i2c_master_receive(ALT_I2C_DEV_t *i2c_dev,
1380  void * data,
1381  const size_t size,
1382  const uint8_t issue_restart,
1383  const uint8_t issue_stop);
1384 
1432 ALT_STATUS_CODE alt_i2c_issue_read(ALT_I2C_DEV_t *i2c_dev,
1433  const uint8_t issue_restart,
1434  const uint8_t issue_stop);
1435 
1485 ALT_STATUS_CODE alt_i2c_issue_write(ALT_I2C_DEV_t *i2c_dev,
1486  const uint8_t value,
1487  const uint8_t issue_restart,
1488  const uint8_t issue_stop);
1489 
1490 /******************************************************************************/
1569 ALT_STATUS_CODE alt_i2c_master_general_call(ALT_I2C_DEV_t *i2c_dev,
1570  const void * data,
1571  const size_t size,
1572  const uint8_t issue_restart,
1573  const uint8_t issue_stop);
1574 
1590 ALT_STATUS_CODE alt_i2c_general_call_ack_disable(ALT_I2C_DEV_t *i2c_dev);
1591 
1606 ALT_STATUS_CODE alt_i2c_general_call_ack_enable(ALT_I2C_DEV_t *i2c_dev);
1607 
1622 ALT_STATUS_CODE alt_i2c_general_call_ack_is_enabled(ALT_I2C_DEV_t *i2c_dev);
1623 
1626 /******************************************************************************/
1680 ALT_STATUS_CODE alt_i2c_int_status_get(ALT_I2C_DEV_t *i2c_dev,
1681  uint32_t *status);
1682 
1705 ALT_STATUS_CODE alt_i2c_int_raw_status_get(ALT_I2C_DEV_t *i2c_dev,
1706  uint32_t *status);
1707 
1729 ALT_STATUS_CODE alt_i2c_int_clear(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1730 
1758 ALT_STATUS_CODE alt_i2c_int_disable(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1759 
1787 ALT_STATUS_CODE alt_i2c_int_enable(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1788 
1812 ALT_STATUS_CODE alt_i2c_tx_abort_cause_get(ALT_I2C_DEV_t *i2c_dev,
1813  ALT_I2C_TX_ABORT_CAUSE_t *cause);
1814 
1817 /******************************************************************************/
1835 #define ALT_I2C_RX_FIFO_NUM_ENTRIES 64
1836 
1850 ALT_STATUS_CODE alt_i2c_rx_fifo_is_empty(ALT_I2C_DEV_t *i2c_dev);
1851 
1865 ALT_STATUS_CODE alt_i2c_rx_fifo_is_full(ALT_I2C_DEV_t *i2c_dev);
1866 
1883 ALT_STATUS_CODE alt_i2c_rx_fifo_level_get(ALT_I2C_DEV_t *i2c_dev,
1884  uint32_t *num_entries);
1885 
1902 ALT_STATUS_CODE alt_i2c_rx_fifo_threshold_get(ALT_I2C_DEV_t *i2c_dev,
1903  uint8_t *threshold);
1904 
1921 ALT_STATUS_CODE alt_i2c_rx_fifo_threshold_set(ALT_I2C_DEV_t *i2c_dev,
1922  const uint8_t threshold);
1923 
1926 /******************************************************************************/
1944 #define ALT_I2C_TX_FIFO_NUM_ENTRIES 64
1945 
1959 ALT_STATUS_CODE alt_i2c_tx_fifo_is_empty(ALT_I2C_DEV_t *i2c_dev);
1960 
1974 ALT_STATUS_CODE alt_i2c_tx_fifo_is_full(ALT_I2C_DEV_t *i2c_dev);
1975 
1992 ALT_STATUS_CODE alt_i2c_tx_fifo_level_get(ALT_I2C_DEV_t *i2c_dev,
1993  uint32_t *num_entries);
1994 
2011 ALT_STATUS_CODE alt_i2c_tx_fifo_threshold_get(ALT_I2C_DEV_t *i2c_dev,
2012  uint8_t *threshold);
2013 
2030 ALT_STATUS_CODE alt_i2c_tx_fifo_threshold_set(ALT_I2C_DEV_t *i2c_dev,
2031  const uint8_t threshold);
2032 
2035 /******************************************************************************/
2067 ALT_STATUS_CODE alt_i2c_rx_dma_threshold_get(ALT_I2C_DEV_t * i2c_dev, uint8_t * threshold);
2068 
2081 ALT_STATUS_CODE alt_i2c_rx_dma_threshold_set(ALT_I2C_DEV_t * i2c_dev, uint8_t threshold);
2082 
2095 ALT_STATUS_CODE alt_i2c_tx_dma_threshold_get(ALT_I2C_DEV_t * i2c_dev, uint8_t * threshold);
2096 
2109 ALT_STATUS_CODE alt_i2c_tx_dma_threshold_set(ALT_I2C_DEV_t * i2c_dev, uint8_t threshold);
2110 
2115 #ifdef __cplusplus
2116 }
2117 #endif /* __cplusplus */
2118 #endif /* __ALT_I2C_H__ */