amiro-lld / source / AT24C01B / v1 / alld_AT24C01B_v1.c @ c4db2363
History | View | Annotate | Download (6.638 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file alld_AT24C01B_v1.c
|
21 |
* @brief EEPROM function implementations.
|
22 |
*
|
23 |
* @addtogroup lld_eeprom
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <alld_AT24C01B.h> |
28 |
|
29 |
#if (defined(AMIROLLD_CFG_AT24C01B) && (AMIROLLD_CFG_AT24C01B == 1)) || defined(__DOXYGEN__) |
30 |
|
31 |
#include <string.h> |
32 |
|
33 |
/******************************************************************************/
|
34 |
/* LOCAL DEFINITIONS */
|
35 |
/******************************************************************************/
|
36 |
|
37 |
/******************************************************************************/
|
38 |
/* EXPORTED VARIABLES */
|
39 |
/******************************************************************************/
|
40 |
|
41 |
/******************************************************************************/
|
42 |
/* LOCAL TYPES */
|
43 |
/******************************************************************************/
|
44 |
|
45 |
/******************************************************************************/
|
46 |
/* LOCAL VARIABLES */
|
47 |
/******************************************************************************/
|
48 |
|
49 |
/******************************************************************************/
|
50 |
/* LOCAL FUNCTIONS */
|
51 |
/******************************************************************************/
|
52 |
|
53 |
/******************************************************************************/
|
54 |
/* EXPORTED FUNCTIONS */
|
55 |
/******************************************************************************/
|
56 |
|
57 |
/**
|
58 |
* @brief Acknowledgement polling to check if a write operation finished.
|
59 |
* @param[in] at24c01b The eeprom driver to use.
|
60 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
61 |
*
|
62 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
63 |
*/
|
64 |
apalExitStatus_t at24c01b_lld_poll_ack(const AT24C01BDriver* const at24c01b, const apalTime_t timeout) |
65 |
{ |
66 |
apalDbgAssert(at24c01b != NULL);
|
67 |
|
68 |
uint8_t tmp = 0;
|
69 |
return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), &tmp, 1, timeout); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* @brief Read the data from the eeprom starting at the current address.
|
74 |
* @param[in] at24c01b The eeprom driver to use.
|
75 |
* @param[out] data The data read from the AT24C01B.
|
76 |
* @param[in] num The amount of bytes to read.
|
77 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
78 |
*
|
79 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
80 |
*/
|
81 |
apalExitStatus_t at24c01b_lld_read_current_address(const AT24C01BDriver* const at24c01b, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
82 |
{ |
83 |
apalDbgAssert(at24c01b != NULL);
|
84 |
apalDbgAssert(data != NULL);
|
85 |
|
86 |
return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), data, num, timeout);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* @brief Read the data from the eeprom starting at a given address.
|
91 |
* @param[in] at24c01b The eeprom driver to use.
|
92 |
* @param[in] addr The address to read.
|
93 |
* @param[out] data The data read from the AT24C01B.
|
94 |
* @param[in] num The amount of bytes to read.
|
95 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
96 |
*
|
97 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
98 |
*/
|
99 |
apalExitStatus_t at24c01b_lld_read(const AT24C01BDriver* const at24c01b, const uint8_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
100 |
{ |
101 |
apalDbgAssert(at24c01b != NULL);
|
102 |
apalDbgAssert(data != NULL);
|
103 |
apalDbgAssert(addr + num <= AT24C01B_LLD_SIZE_BYTES); |
104 |
|
105 |
apalExitStatus_t status = apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), &addr, 1, NULL, 0, timeout); |
106 |
if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
|
107 |
return apalI2CMasterReceive(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), data, num, timeout);
|
108 |
} else {
|
109 |
return status;
|
110 |
} |
111 |
} |
112 |
|
113 |
/**
|
114 |
* @brief Write a byte to the eeprom.
|
115 |
* @param[in] at24c01b The eeprom driver to use.
|
116 |
* @param[in] addr The address to start writing.
|
117 |
* @param[out] data The data to be written to the AT24C01BN.
|
118 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
119 |
*
|
120 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
121 |
*/
|
122 |
apalExitStatus_t at24c01b_lld_write_byte(const AT24C01BDriver* const at24c01b, const uint8_t addr, const uint8_t data, const apalTime_t timeout) |
123 |
{ |
124 |
apalDbgAssert(at24c01b != NULL);
|
125 |
|
126 |
const uint8_t writedata[2] = {addr, data}; |
127 |
return apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), writedata, 2, NULL, 0, timeout); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* @brief Write a page to the eeprom.
|
132 |
* @param[in] at24c01b The eeprom driver to use.
|
133 |
* @param[in] addr The address to start writing.
|
134 |
* @param[in] data The data to be written to the AT24C01BN.
|
135 |
* @param[in] num The amount of bytes to write.
|
136 |
* @param[in] timeout Timeout for the function to return (in microseconds)
|
137 |
*
|
138 |
* @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
139 |
*/
|
140 |
apalExitStatus_t at24c01b_lld_write_page(const AT24C01BDriver* const at24c01b, const uint8_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
141 |
{ |
142 |
apalDbgAssert(at24c01b != NULL);
|
143 |
apalDbgAssert(data != NULL);
|
144 |
|
145 |
uint8_t writedata[num+1];
|
146 |
writedata[0] = addr;
|
147 |
memcpy(&writedata[1], data, num);
|
148 |
return apalI2CMasterTransmit(at24c01b->i2cd, (AT24C01B_LLD_I2C_ADDR_FIXED | at24c01b->addr), writedata, num+1, NULL, 0, timeout); |
149 |
} |
150 |
|
151 |
#endif /* defined(AMIROLLD_CFG_AT24C01B) && (AMIROLLD_CFG_AT24C01B == 1) */ |
152 |
|
153 |
/** @} */
|