84 uint8_t *data = readData;
85 uint32_t count = nrBytes;
87 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
89 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
90 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
91 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
92 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
93 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
95 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
96 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
97 i2cSetSlaveAdd(i2cREG1, slaveAddress);
98 i2cSetCount(i2cREG1, 1u);
100 i2cREG1->DXR = (uint32_t)readAddress;
104 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
105 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
114 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
118 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
124 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
125 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
126 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
127 i2cSetCount(i2cREG1, nrBytes);
128 i2cSetStart(i2cREG1);
134 while (((i2cREG1->STR & (uint32_t)I2C_RX_INT) == 0u) && (timeout > 0u)) {
135 if ((i2cREG1->STR & (uint32_t)I2C_NACK_INT) != 0u) {
141 if ((nack ==
true) || (timeout == 0u)) {
144 *data = ((uint8)i2cREG1->DRR);
148 if ((nack ==
true) || (timeout == 0u)) {
150 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
154 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
161 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
167 i2cClearSCD(i2cREG1);
189 uint8_t *data = readData;
190 uint32_t count = nrBytes;
192 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
194 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
195 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
196 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
197 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
198 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
199 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
200 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
202 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
203 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
204 i2cSetSlaveAdd(i2cREG1, slaveAddress);
205 i2cSetCount(i2cREG1, nrBytes);
206 i2cSetStart(i2cREG1);
212 while (((i2cREG1->STR & (uint32_t)I2C_RX_INT) == 0u) && (timeout > 0u)) {
213 if ((i2cREG1->STR & (uint32_t)I2C_NACK_INT) != 0u) {
219 if ((nack ==
true) || (timeout == 0u)) {
222 *data = ((uint8)i2cREG1->DRR);
226 if ((nack ==
true) || (timeout == 0u)) {
228 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
232 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
239 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
245 i2cClearSCD(i2cREG1);
262 uint8_t *data = writeData;
263 uint32_t count = nrBytes;
265 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
267 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
268 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
269 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
270 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
271 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
273 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
274 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
275 i2cSetSlaveAdd(i2cREG1, slaveAddress);
277 i2cSetCount(i2cREG1, nrBytes + 1u);
278 i2cSetStart(i2cREG1);
281 i2cREG1->DXR = (uint32_t)writeAddress;
284 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
285 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
293 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
297 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
303 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
308 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
309 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
315 if ((nack ==
true) || (timeout == 0u)) {
318 i2cREG1->DXR = (uint32_t)*data;
322 if ((nack ==
true) || (timeout == 0u)) {
323 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
327 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
334 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
340 i2cClearSCD(i2cREG1);
362 uint8_t *data = writeData;
363 uint32_t count = nrBytes;
365 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
367 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
368 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
369 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
370 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
371 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
373 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
374 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
375 i2cSetSlaveAdd(i2cREG1, slaveAddress);
377 i2cSetCount(i2cREG1, nrBytes);
378 i2cSetStart(i2cREG1);
381 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
386 while (((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) && (timeout > 0u)) {
387 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
393 if ((nack ==
true) || (timeout == 0u)) {
396 i2cREG1->DXR = (uint32_t)*data;
400 if ((nack ==
true) || (timeout == 0u)) {
401 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
405 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
412 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
418 i2cClearSCD(i2cREG1);
439 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
458 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
459 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
460 i2cSetSlaveAdd(i2cREG1, slaveAddress);
461 i2cSetCount(i2cREG1, 1u);
462 i2cSetStart(i2cREG1);
463 i2cSendByte(i2cREG1, readAddress);
466 while ((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) {
467 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
472 if ((i2cREG1->STR & (uint32_t)I2C_NACK) == 0u) {
473 i2cSetDirection(i2cREG1, (uint32_t)I2C_RECEIVER);
474 i2cSetCount(i2cREG1, nrBytes);
475 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
477 i2cSetStart(i2cREG1);
479 i2cREG1->STR |= (uint32_t)I2C_NACK;
480 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
485 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
489 i2cClearSCD(i2cREG1);
500 uint32_t slaveAddress,
501 uint8_t writeAddress,
503 uint8_t *writeData) {
509 if ((i2cREG1->STR & (uint32_t)I2C_BUSBUSY) == 0u) {
526 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
527 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
528 i2cSetSlaveAdd(i2cREG1, slaveAddress);
530 i2cSetCount(i2cREG1, nrBytes + 1u);
531 i2cSendByte(i2cREG1, writeAddress);
533 i2cSetStart(i2cREG1);
536 while ((i2cREG1->STR & (uint32_t)I2C_TX_INT) == 0u) {
537 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
542 if ((i2cREG1->STR & (uint32_t)I2C_NACK) != 0u) {
543 i2cREG1->STR |= (uint32_t)I2C_NACK;
544 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
548 while ((i2cIsStopDetected(i2cREG1) == 0u) && (timeout > 0u)) {
552 i2cClearSCD(i2cREG1);
553 i2cREG1->STR &= ~(uint32_t)I2C_REPEATMODE;
565 i2cREG1->MDR &= ~((uint32_t)I2C_STOP_COND);
566 i2cREG1->MDR &= ~((uint32_t)I2C_START_COND);
567 i2cREG1->MDR &= ~((uint32_t)I2C_REPEATMODE);
568 i2cREG1->STR |= (uint32_t)I2C_TX_INT;
569 i2cREG1->STR |= (uint32_t)I2C_RX_INT;
571 i2cREG1->MDR |= (uint32_t)I2C_REPEATMODE;
572 i2cSetMode(i2cREG1, (uint32_t)I2C_MASTER);
573 i2cSetDirection(i2cREG1, (uint32_t)I2C_TRANSMITTER);
576 while (i2cIsStopDetected(i2cREG1) == 0u) {
579 i2cREG1->MDR &= ~(uint32_t)I2C_REPEATMODE;
580 i2cClearSCD(i2cREG1);
584 #ifdef UNITY_UNIT_TEST
Headers for the driver for the DMA module.
#define DMA_CHANNEL_I2C_TX
#define DMA_CHANNEL_I2C_RX
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define NULL_PTR
Null pointer.
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
Function to switch between user mode and privilege mode.
#define FSYS_SwitchToUserMode()
Switch back to user mode.
long FSYS_RaisePrivilege(void)
raise privilege
STD_RETURN_TYPE_e I2C_WriteDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, no register address written first, blocking.
void I2C_SetStopNow(void)
sets stop condition.
STD_RETURN_TYPE_e I2C_ReadDma(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, using DMA.
STD_RETURN_TYPE_e I2C_Write(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, blocking.
STD_RETURN_TYPE_e I2C_ReadDirect(uint32_t slaveAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, no register address written first, blocking.
void I2C_Initialize(void)
STD_RETURN_TYPE_e I2C_WriteDma(uint32_t slaveAddress, uint8_t writeAddress, uint32_t nrBytes, uint8_t *writeData)
writes to an I2C slave, using DMA.
STD_RETURN_TYPE_e I2C_Read(uint32_t slaveAddress, uint8_t readAddress, uint32_t nrBytes, uint8_t *readData)
reads from an I2C slave, blocking.
Header for the driver for the I2C module.
#define I2C_TIMEOUT_ITERATIONS
Headers for the driver for the MCU module.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.