Hardware Libraries  20.1
Stratix 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,2017 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/main/embedded/ip/hps/armv8/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 typedef struct ALT_I2C_DEV_s
118 {
119  void * location;
120  alt_freq_t clock_freq;
121  uint32_t last_target;
122 }
123 ALT_I2C_DEV_t;
124 
128 typedef enum ALT_I2C_CTLR_e
129 {
130  ALT_I2C_I2C0 = (int)ALT_I2C0_OFST,
131  ALT_I2C_I2C1 = (int)ALT_I2C1_OFST,
132  /* I2C{2-4] are for general purpose or as control interfaces for connectors
133  * with embedded I2C channels such as SFP. */
134  ALT_I2C_I2C2 = (int)ALT_I2C_EMAC0_OFST,
135  ALT_I2C_I2C3 = (int)ALT_I2C_EMAC1_OFST,
136  ALT_I2C_I2C4 = (int)ALT_I2C_EMAC2_OFST
138 
146 typedef enum ALT_I2C_MODE_e
147 {
148  ALT_I2C_MODE_SLAVE = ALT_I2C_IC_CON_MASTER_MODE_E_DISABLED,
149  ALT_I2C_MODE_MASTER = ALT_I2C_IC_CON_MASTER_MODE_E_ENABLED
151 
165 typedef enum ALT_I2C_SPEED_e
166 {
167  ALT_I2C_SPEED_STANDARD = ALT_I2C_IC_CON_SPEED_E_STANDARD,
169  ALT_I2C_SPEED_FAST = ALT_I2C_IC_CON_SPEED_E_FAST,
171  ALT_I2C_SPEED_HIGH = ALT_I2C_IC_CON_SPEED_E_HIGH
174 
184 {
185  ALT_I2C_ADDR_MODE_7_BIT = ALT_I2C_IC_TAR_IC_10BITADDR_MASTER_E_ADDR_7BITS,
187  ALT_I2C_ADDR_MODE_10_BIT = ALT_I2C_IC_TAR_IC_10BITADDR_MASTER_E_ADDR_10BITS
190 
194 typedef enum ALT_I2C_STATUS_e
195 {
340 
349 {
508 
523 {
528  uint8_t restart_enable;
546  uint16_t ss_scl_hcnt;
550  uint16_t ss_scl_lcnt;
554  uint16_t fs_scl_hcnt;
558  uint16_t fs_scl_lcnt;
562  uint8_t fs_spklen;
569 
575 {
579  uint32_t addr;
583  uint8_t nack_enable;
598 
612 ALT_STATUS_CODE alt_i2c_init(const ALT_I2C_CTLR_t i2c, ALT_I2C_DEV_t *i2c_dev);
613 
623 ALT_STATUS_CODE alt_i2c_reset(ALT_I2C_DEV_t * i2c_dev);
624 
638 ALT_STATUS_CODE alt_i2c_uninit(ALT_I2C_DEV_t *i2c_dev);
639 
659 ALT_STATUS_CODE alt_i2c_disable(ALT_I2C_DEV_t *i2c_dev);
660 
670 ALT_STATUS_CODE alt_i2c_enable(ALT_I2C_DEV_t *i2c_dev);
671 
682 ALT_STATUS_CODE alt_i2c_is_enabled(ALT_I2C_DEV_t *i2c_dev);
683 
698 ALT_STATUS_CODE alt_i2c_master_config_get(ALT_I2C_DEV_t *i2c_dev,
700 
715 ALT_STATUS_CODE alt_i2c_master_config_set(ALT_I2C_DEV_t *i2c_dev,
716  const ALT_I2C_MASTER_CONFIG_t* cfg);
717 
734 ALT_STATUS_CODE alt_i2c_master_config_speed_get(ALT_I2C_DEV_t *i2c_dev,
735  const ALT_I2C_MASTER_CONFIG_t* cfg,
736  uint32_t * speed_in_hz);
737 
754 ALT_STATUS_CODE alt_i2c_master_config_speed_set(ALT_I2C_DEV_t *i2c_dev,
756  uint32_t speed_in_hz);
757 
761 #define alt_i2c_cfg_to_speed(i2c_dev, speed_in_hz, cfg) alt_i2c_master_config_speed_get((i2c_dev), (cfg), (speed_in_hz))
762 
766 #define alt_i2c_speed_to_cfg(i2c_dev, speed_in_hz, cfg) alt_i2c_master_config_speed_set((i2c_dev), (cfg), (speed_in_hz))
767 
782 ALT_STATUS_CODE alt_i2c_slave_config_get(ALT_I2C_DEV_t *i2c_dev,
784 
799 ALT_STATUS_CODE alt_i2c_slave_config_set(ALT_I2C_DEV_t *i2c_dev,
800  const ALT_I2C_SLAVE_CONFIG_t* cfg);
801 
831 ALT_STATUS_CODE alt_i2c_sda_tx_hold_time_get(ALT_I2C_DEV_t *i2c_dev,
832  uint16_t *tx_hold_time);
833 
848 ALT_STATUS_CODE alt_i2c_sda_rx_hold_time_get(ALT_I2C_DEV_t *i2c_dev,
849  uint16_t *rx_hold_time);
864 ALT_STATUS_CODE alt_i2c_sda_tx_hold_time_set(ALT_I2C_DEV_t *i2c_dev,
865  const uint16_t tx_hold_time);
880 ALT_STATUS_CODE alt_i2c_sda_rx_hold_time_set(ALT_I2C_DEV_t *i2c_dev,
881  const uint16_t rx_hold_time);
897 ALT_STATUS_CODE alt_i2c_op_mode_get(ALT_I2C_DEV_t *i2c_dev,
899 
912 ALT_STATUS_CODE alt_i2c_op_mode_set(ALT_I2C_DEV_t *i2c_dev,
913  const ALT_I2C_MODE_t mode);
914 
926 ALT_STATUS_CODE alt_i2c_is_busy(ALT_I2C_DEV_t *i2c_dev);
927 
950 ALT_STATUS_CODE alt_i2c_read(ALT_I2C_DEV_t *i2c_dev, uint8_t *val);
951 
974 ALT_STATUS_CODE alt_i2c_write(ALT_I2C_DEV_t *i2c_dev, const uint8_t val);
975 
995 ALT_STATUS_CODE alt_i2c_slave_receive(ALT_I2C_DEV_t *i2c_dev,
996  uint8_t *data);
997 
1017 ALT_STATUS_CODE alt_i2c_slave_transmit(ALT_I2C_DEV_t *i2c_dev,
1018  const uint8_t data);
1019 
1071 ALT_STATUS_CODE alt_i2c_slave_bulk_transmit(ALT_I2C_DEV_t *i2c_dev,
1072  const void * data,
1073  const size_t size);
1074 
1089 ALT_STATUS_CODE alt_i2c_master_target_get(ALT_I2C_DEV_t * i2c_dev, uint32_t * target_addr);
1090 
1110 ALT_STATUS_CODE alt_i2c_master_target_set(ALT_I2C_DEV_t * i2c_dev, uint32_t target_addr);
1111 
1162 ALT_STATUS_CODE alt_i2c_master_transmit(ALT_I2C_DEV_t *i2c_dev,
1163  const void * data,
1164  const size_t size,
1165  const uint8_t issue_restart,
1166  const uint8_t issue_stop);
1167 
1226 ALT_STATUS_CODE alt_i2c_master_receive(ALT_I2C_DEV_t *i2c_dev,
1227  void * data,
1228  const size_t size,
1229  const uint8_t issue_restart,
1230  const uint8_t issue_stop);
1231 
1273 ALT_STATUS_CODE alt_i2c_issue_read(ALT_I2C_DEV_t *i2c_dev,
1274  const uint8_t issue_restart,
1275  const uint8_t issue_stop);
1276 
1322 ALT_STATUS_CODE alt_i2c_issue_write(ALT_I2C_DEV_t *i2c_dev,
1323  const uint8_t value,
1324  const uint8_t issue_restart,
1325  const uint8_t issue_stop);
1326 
1327 /******************************************************************************/
1403 ALT_STATUS_CODE alt_i2c_master_general_call(ALT_I2C_DEV_t *i2c_dev,
1404  const void * data,
1405  const size_t size,
1406  const uint8_t issue_restart,
1407  const uint8_t issue_stop);
1408 
1420 ALT_STATUS_CODE alt_i2c_general_call_ack_disable(ALT_I2C_DEV_t *i2c_dev);
1421 
1432 ALT_STATUS_CODE alt_i2c_general_call_ack_enable(ALT_I2C_DEV_t *i2c_dev);
1433 
1444 ALT_STATUS_CODE alt_i2c_general_call_ack_is_enabled(ALT_I2C_DEV_t *i2c_dev);
1445 
1448 /******************************************************************************/
1498 ALT_STATUS_CODE alt_i2c_int_status_get(ALT_I2C_DEV_t *i2c_dev,
1499  uint32_t *status);
1500 
1519 ALT_STATUS_CODE alt_i2c_int_raw_status_get(ALT_I2C_DEV_t *i2c_dev,
1520  uint32_t *status);
1521 
1540 ALT_STATUS_CODE alt_i2c_int_clear(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1541 
1566 ALT_STATUS_CODE alt_i2c_int_disable(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1567 
1592 ALT_STATUS_CODE alt_i2c_int_enable(ALT_I2C_DEV_t *i2c_dev, const uint32_t mask);
1593 
1613 ALT_STATUS_CODE alt_i2c_tx_abort_cause_get(ALT_I2C_DEV_t *i2c_dev,
1614  ALT_I2C_TX_ABORT_CAUSE_t *cause);
1615 
1618 /******************************************************************************/
1636 #define ALT_I2C_RX_FIFO_NUM_ENTRIES 64
1637 
1647 ALT_STATUS_CODE alt_i2c_rx_fifo_is_empty(ALT_I2C_DEV_t *i2c_dev);
1648 
1658 ALT_STATUS_CODE alt_i2c_rx_fifo_is_full(ALT_I2C_DEV_t *i2c_dev);
1659 
1672 ALT_STATUS_CODE alt_i2c_rx_fifo_level_get(ALT_I2C_DEV_t *i2c_dev,
1673  uint32_t *num_entries);
1674 
1687 ALT_STATUS_CODE alt_i2c_rx_fifo_threshold_get(ALT_I2C_DEV_t *i2c_dev,
1688  uint8_t *threshold);
1689 
1702 ALT_STATUS_CODE alt_i2c_rx_fifo_threshold_set(ALT_I2C_DEV_t *i2c_dev,
1703  const uint8_t threshold);
1704 
1707 /******************************************************************************/
1725 #define ALT_I2C_TX_FIFO_NUM_ENTRIES 64
1726 
1736 ALT_STATUS_CODE alt_i2c_tx_fifo_is_empty(ALT_I2C_DEV_t *i2c_dev);
1737 
1747 ALT_STATUS_CODE alt_i2c_tx_fifo_is_full(ALT_I2C_DEV_t *i2c_dev);
1748 
1761 ALT_STATUS_CODE alt_i2c_tx_fifo_level_get(ALT_I2C_DEV_t *i2c_dev,
1762  uint32_t *num_entries);
1763 
1776 ALT_STATUS_CODE alt_i2c_tx_fifo_threshold_get(ALT_I2C_DEV_t *i2c_dev,
1777  uint8_t *threshold);
1778 
1791 ALT_STATUS_CODE alt_i2c_tx_fifo_threshold_set(ALT_I2C_DEV_t *i2c_dev,
1792  const uint8_t threshold);
1793 
1796 /******************************************************************************/
1828 ALT_STATUS_CODE alt_i2c_rx_dma_threshold_get(ALT_I2C_DEV_t * i2c_dev, uint8_t * threshold);
1829 
1842 ALT_STATUS_CODE alt_i2c_rx_dma_threshold_set(ALT_I2C_DEV_t * i2c_dev, uint8_t threshold);
1843 
1856 ALT_STATUS_CODE alt_i2c_tx_dma_threshold_get(ALT_I2C_DEV_t * i2c_dev, uint8_t * threshold);
1857 
1870 ALT_STATUS_CODE alt_i2c_tx_dma_threshold_set(ALT_I2C_DEV_t * i2c_dev, uint8_t threshold);
1871 
1876 #ifdef __cplusplus
1877 }
1878 #endif /* __cplusplus */
1879 #endif /* __ALT_I2C_H__ */