amiro-lld / source / alld_at24c01bn-sh-b.c @ 1d4fc180
History | View | Annotate | Download (5.236 KB)
1 | d6728c5b | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | f0ca400f | Thomas Schöpping | it under the terms of the GNU Lesser General Public License as published by
|
7 | d6728c5b | Thomas Schöpping | 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 | f0ca400f | Thomas Schöpping | GNU Lesser General Public License for more details.
|
14 | d6728c5b | Thomas Schöpping | |
15 | f0ca400f | Thomas Schöpping | You should have received a copy of the GNU Lesser General Public License
|
16 | d6728c5b | Thomas Schöpping | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | */
|
||
18 | |||
19 | 5e2f673b | Marc Rothmann | /**
|
20 | * @file alld_at24c01bn-sh-b.c
|
||
21 | * @brief EEPROM function implementations.
|
||
22 | *
|
||
23 | * @addtogroup lld_eeprom
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | d6728c5b | Thomas Schöpping | #include <alld_at24c01bn-sh-b.h> |
28 | |||
29 | #if defined(AMIROLLD_CFG_USE_AT24C01BN) || defined(__DOXYGEN__)
|
||
30 | |||
31 | #include <string.h> |
||
32 | |||
33 | /**
|
||
34 | * @brief Acknowledgement polling to check if a write operation finished.
|
||
35 | * @param[in] at24c01bn The eeprom driver to use.
|
||
36 | * @param[in] timeout Timeout for the function to return (in microseconds)
|
||
37 | *
|
||
38 | * @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
||
39 | */
|
||
40 | inline apalExitStatus_t
|
||
41 | at24c01bn_lld_poll_ack(const AT24C01BNDriver* const at24c01bn, const apalTime_t timeout) |
||
42 | { |
||
43 | apalDbgAssert(at24c01bn != NULL);
|
||
44 | |||
45 | uint8_t tmp = 0;
|
||
46 | return apalI2CMasterReceive(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), &tmp, 1, timeout); |
||
47 | } |
||
48 | |||
49 | /**
|
||
50 | * @brief Read the data from the eeprom starting at the current address.
|
||
51 | * @param[in] at24c01bn The eeprom driver to use.
|
||
52 | * @param[out] data The data read from the AT24C01BN.
|
||
53 | * @param[in] num The amount of bytes to read.
|
||
54 | * @param[in] timeout Timeout for the function to return (in microseconds)
|
||
55 | *
|
||
56 | * @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
||
57 | */
|
||
58 | inline apalExitStatus_t
|
||
59 | at24c01bn_lld_read_current_address(const AT24C01BNDriver* const at24c01bn, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
||
60 | { |
||
61 | apalDbgAssert(at24c01bn != NULL);
|
||
62 | apalDbgAssert(data != NULL);
|
||
63 | |||
64 | return apalI2CMasterReceive(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), data, num, timeout);
|
||
65 | } |
||
66 | |||
67 | /**
|
||
68 | * @brief Read the data from the eeprom starting at a given address.
|
||
69 | * @param[in] at24c01bn The eeprom driver to use.
|
||
70 | * @param[in] addr The address to read.
|
||
71 | * @param[out] data The data read from the AT24C01BN.
|
||
72 | * @param[in] num The amount of bytes to read.
|
||
73 | * @param[in] timeout Timeout for the function to return (in microseconds)
|
||
74 | *
|
||
75 | * @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
||
76 | */
|
||
77 | inline apalExitStatus_t
|
||
78 | at24c01bn_lld_read(const AT24C01BNDriver* const at24c01bn, const uint8_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
||
79 | { |
||
80 | apalDbgAssert(at24c01bn != NULL);
|
||
81 | apalDbgAssert(data != NULL);
|
||
82 | apalDbgAssert(addr + num <= AT24C01BN_LLD_SIZE_BYTES); |
||
83 | |||
84 | apalExitStatus_t status = apalI2CMasterTransmit(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), &addr, 1, NULL, 0, timeout); |
||
85 | if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
|
||
86 | return apalI2CMasterReceive(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), data, num, timeout);
|
||
87 | } else {
|
||
88 | return status;
|
||
89 | } |
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * @brief Write a byte to the eeprom.
|
||
94 | * @param[in] at24c01bn The eeprom driver to use.
|
||
95 | * @param[in] addr The address to start writing.
|
||
96 | * @param[out] data The data to be written to the AT24C01BN.
|
||
97 | * @param[in] timeout Timeout for the function to return (in microseconds)
|
||
98 | *
|
||
99 | * @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
||
100 | */
|
||
101 | inline apalExitStatus_t
|
||
102 | at24c01bn_lld_write_byte(const AT24C01BNDriver* const at24c01bn, const uint8_t addr, const uint8_t data, const apalTime_t timeout) |
||
103 | { |
||
104 | apalDbgAssert(at24c01bn != NULL);
|
||
105 | |||
106 | const uint8_t writedata[2] = {addr, data}; |
||
107 | return apalI2CMasterTransmit(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), writedata, 2, NULL, 0, timeout); |
||
108 | } |
||
109 | |||
110 | /**
|
||
111 | * @brief Write a page to the eeprom.
|
||
112 | * @param[in] at24c01bn The eeprom driver to use.
|
||
113 | * @param[in] addr The address to start writing.
|
||
114 | * @param[in] data The data to be written to the AT24C01BN.
|
||
115 | * @param[in] num The amount of bytes to write.
|
||
116 | * @param[in] timeout Timeout for the function to return (in microseconds)
|
||
117 | *
|
||
118 | * @return The return status indicates whether the function call was succesfull or a timeout occurred.
|
||
119 | */
|
||
120 | inline apalExitStatus_t
|
||
121 | at24c01bn_lld_write_page(const AT24C01BNDriver* const at24c01bn, const uint8_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
||
122 | { |
||
123 | apalDbgAssert(at24c01bn != NULL);
|
||
124 | apalDbgAssert(data != NULL);
|
||
125 | |||
126 | uint8_t writedata[num+1];
|
||
127 | writedata[0] = addr;
|
||
128 | memcpy(&writedata[1], data, num);
|
||
129 | return apalI2CMasterTransmit(at24c01bn->i2cd, (AT24C01BN_LLD_I2C_ADDR_FIXED | at24c01bn->addr), writedata, num+1, NULL, 0, timeout); |
||
130 | } |
||
131 | |||
132 | #endif /* defined(AMIROLLD_CFG_USE_AT24C01BN) */ |
||
133 | 5e2f673b | Marc Rothmann | |
134 | /** @} */ |