no-OS
Loading...
Searching...
No Matches
gmsl_reg_access.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file gmsl_reg_access.h
3 * @brief Header file of GMSL Register Access.
4 * @author Automotive Software and Systems team, Bangalore, India
5********************************************************************************
6 * Copyright 2025(c) Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. "AS IS" AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32******************************************************************************/
33#ifndef GMSL_REG_ACCESS_H
34#define GMSL_REG_ACCESS_H
35
36#include <stdint.h>
37#include "no_os_i2c.h"
38
39#define RETURN_ON_ERR(x) if(x != 0) return (x)
40
41#define REG_WRITE_RETURN_ON_ERR(ret, i2c_desc, reg, writeval) {\
42 ret = gmsl_reg_write(i2c_desc, reg, writeval); \
43 if(ret)\
44 return ret;\
45}
46
47#define REG_READ_RETURN_ON_ERR(ret, i2c_desc, reg, mask, readval) {\
48 ret = gmsl_reg_read(i2c_desc, reg, mask, readval); \
49 if(ret)\
50 return ret;\
51}
52
53#define REG_UPDATE_RETURN_ON_ERR(ret, i2c_desc, reg, val, mask) {\
54 ret = gmsl_reg_update(i2c_desc, reg, val, mask); \
55 if(ret)\
56 return ret;\
57}
58
59#define BREAK_ON_ERR(x)\
60if(x != 0)\
61{\
62 break;\
63}
64
65#define REG_WRITE_BREAK_ON_ERR(ret, i2c_desc, reg, writeval)\
66{\
67 ret = gmsl_reg_write(i2c_desc, reg, writeval);\
68 BREAK_ON_ERR(ret);\
69}
70
71#define REG_READ_BREAK_ON_ERR(ret, i2c_desc, reg, mask, readval)\
72{\
73 ret = gmsl_reg_read(i2c_desc, reg, mask, readval);\
74 BREAK_ON_ERR(ret);\
75}
76
77#define REG_UPDATE_BREAK_ON_ERR(ret, i2c_desc, reg, val, mask)\
78{\
79 ret = gmsl_reg_update(i2c_desc, reg, val, mask);\
80 BREAK_ON_ERR(ret);\
81}
82
84int32_t gmsl_reg_read(struct no_os_i2c_desc *i2c_desc,
85 uint16_t reg, uint8_t mask, uint8_t *readval);
86
88int32_t gmsl_reg_write(struct no_os_i2c_desc *i2c_desc,
89 uint16_t reg,
90 uint8_t writeval);
91
93int32_t gmsl_reg_update(struct no_os_i2c_desc *i2c_desc,
94 uint16_t reg,
95 uint8_t val,
96 uint8_t mask);
97
98#endif /* GMSL_REG_ACCESS_H */
int32_t gmsl_reg_update(struct no_os_i2c_desc *i2c_desc, uint16_t reg, uint8_t val, uint8_t mask)
Update a value in a GMSL register.
Definition gmsl_reg_access.c:119
int32_t gmsl_reg_write(struct no_os_i2c_desc *i2c_desc, uint16_t reg, uint8_t writeval)
Write a value to a GMSL register.
Definition gmsl_reg_access.c:90
int32_t gmsl_reg_read(struct no_os_i2c_desc *i2c_desc, uint16_t reg, uint8_t mask, uint8_t *readval)
Read a value from a GMSL register.
Definition gmsl_reg_access.c:51
Header file of I2C Interface.
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89