MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / spi_event

Function spi_event

core/spi.c:92–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static void spi_event(enum sched_item_id id) {
93 uint8_t bitCount = spi.transferBits < spi.deviceBits ? spi.transferBits : spi.deviceBits;
94 spi.rxFrame <<= bitCount;
95 /* Handle loopback */
96 if (unlikely(spi.cr0 >> 7 & 1)) {
97 spi.rxFrame |= spi.txFrame >> (32 - bitCount);
98 }
99 /* For now, allow only receives from coprocessor */
100 else if (spi.arm) {
101 spi.rxFrame |= spi.deviceFrame >> (32 - bitCount);
102 }
103 spi.deviceFrame <<= bitCount;
104 spi.deviceFrame |= spi.txFrame >> (32 - bitCount);
105 spi.txFrame <<= bitCount;
106
107 spi.deviceBits -= bitCount;
108 if (spi.deviceBits == 0) {
109 uint32_t rxData = 0;
110 spi.deviceBits = spi.device_transfer(spi.deviceFrame, &rxData);
111 spi.deviceFrame = rxData << (32 - spi.deviceBits);
112 }
113
114 spi.transferBits -= bitCount;
115 if (spi.transferBits == 0 && unlikely(spi.cr2 >> 7 & 1)) {
116 /* Note: rfve bound check was performed when starting the transfer */
117 spi.rxFifo[(spi.rfvi + spi.rfve++) & (SPI_RXFIFO_DEPTH - 1)] = spi.rxFrame;
118 spi_update_thresholds();
119 }
120
121 uint32_t ticks = spi_next_transfer();
122 if (ticks) {
123 sched_repeat(id, ticks);
124 }
125}
126
127static void spi_update(void) {
128 spi_update_thresholds();

Callers

nothing calls this directly

Calls 3

spi_update_thresholdsFunction · 0.85
spi_next_transferFunction · 0.85
sched_repeatFunction · 0.85

Tested by

no test coverage detected