openMMC
Open Source Modular MMC for AMCs
Loading...
Searching...
No Matches
i2c.h
Go to the documentation of this file.
1/*
2 * openMMC -- Open Source modular IPM Controller firmware
3 *
4 * Copyright (C) 2015-2016 Henrique Silva <henrique.silva@lnls.br>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
20 */
21
22#ifndef I2C_H_
23#define I2C_H_
24
25#include "FreeRTOS.h"
26#include "semphr.h"
27#include <stdint.h>
28#include <stdbool.h>
29
39
43typedef struct i2c_bus_mapping {
44 uint8_t i2c_interface;
45 int8_t mux_bus;
46 uint8_t enabled;
48
52typedef struct i2c_mux_state {
53 uint8_t i2c_interface;
54 int8_t state;
55 SemaphoreHandle_t semaphore;
57
63void i2c_init( void );
64
75bool i2c_set_mux_bus( uint8_t bus_id, i2c_mux_state_t *i2c_mux, int8_t new_state );
76
85uint8_t i2c_get_mux_bus( uint8_t bus_id, i2c_mux_state_t *i2c_mux );
86
97bool i2c_take_by_busid( uint8_t bus_id, uint8_t *i2c_interface, uint32_t timeout );
98
110bool i2c_take_by_chipid( uint8_t chip_id, uint8_t *i2c_address, uint8_t * i2c_interface, TickType_t timeout );
111
117void i2c_give( uint8_t i2c_interface );
118
119#endif
i2c_mux_state_t i2c_mux[I2C_MUX_CNT]
Definition i2c_mapping.c:5
bool i2c_set_mux_bus(uint8_t bus_id, i2c_mux_state_t *i2c_mux, int8_t new_state)
Change I2C bus mux state.
Definition i2c_mapping.c:52
struct i2c_mux_state i2c_mux_state_t
I2C Mux state.
void i2c_init(void)
Initialize peripheral I2C buses.
Definition i2c.c:32
bool i2c_take_by_busid(uint8_t bus_id, uint8_t *i2c_interface, uint32_t timeout)
Take control over an I2C bus given a bus id.
struct i2c_bus_mapping i2c_bus_mapping_t
I2C Bus description.
bool i2c_take_by_chipid(uint8_t chip_id, uint8_t *i2c_address, uint8_t *i2c_interface, TickType_t timeout)
Take control over an I2C bus given a chip id.
struct i2c_chip_mapping i2c_chip_mapping_t
I2C Chips information regarding the bus and slave address.
uint8_t i2c_get_mux_bus(uint8_t bus_id, i2c_mux_state_t *i2c_mux)
Read I2C bus mux state.
Definition i2c_mapping.c:72
void i2c_give(uint8_t i2c_interface)
Release the previously gained I2C bus.
Definition i2c.c:124
I2C Bus description.
Definition i2c.h:43
uint8_t enabled
Definition i2c.h:46
int8_t mux_bus
Definition i2c.h:45
uint8_t i2c_interface
Definition i2c.h:44
I2C Chips information regarding the bus and slave address.
Definition i2c.h:33
uint8_t i2c_address
Definition i2c.h:37
uint8_t bus_id
Definition i2c.h:34
I2C Mux state.
Definition i2c.h:52
uint8_t i2c_interface
Definition i2c.h:53
int8_t state
Definition i2c.h:54
SemaphoreHandle_t semaphore
Definition i2c.h:55