execute all tests just once
[Arduino] / c2_ulx3s_test / spi.cpp
1
2 #if (_BYTE_ORDER == _LITTLE_ENDIAN)
3 #define SPI_READY_MASK (1 << 8)
4 #else
5 #define SPI_READY_MASK (1 << 16)
6 #endif
7
8 uint8_t spi_start_tx(volatile uint16_t *port)
9 {
10   uint32_t in;
11
12   ((uint8_t *)port)[1] = 0x80;
13   do {
14     in = *port;
15   } while ((in & SPI_READY_MASK) == 0);
16
17 #if (_BYTE_ORDER == _LITTLE_ENDIAN)
18   return (in & 0xff);
19 #else
20   return (in >> 24);
21 #endif
22 }
23
24
25 uint8_t spi_rxtx(volatile uint16_t *port, uint8_t _data)
26 {
27   uint32_t in;
28
29   *(uint8_t *)port = _data;
30   do {
31     in = *port;
32   } while ((in & SPI_READY_MASK) == 0);
33
34 #if (_BYTE_ORDER == _LITTLE_ENDIAN)
35   return (in & 0xff);
36 #else
37   return (in >> 24);
38 #endif
39 }