hello everyone
I have some questions with the following function in the hal_aci_tl.cpp file
static bool m_aci_spi_transfer(hal_aci_data_t * data_to_send, hal_aci_data_t * received_data)
what is happening between line 9 and 13? Is the receiving packet an event on what has ben sent?
And why is the sending en receiving separated because on line 31 the rest of the packet fallows.
Any and all help is much appreciated
1 static bool m_aci_spi_transfer(hal_aci_data_t * data_to_send, hal_aci_data_t * received_data)
2 {
3 uint8_t byte_cnt;
4 uint8_t byte_sent_cnt;
5 uint8_t max_bytes;
6
7 m_aci_reqn_enable();
8
9 // Send length, receive header
10 byte_sent_cnt = 0;
11 received_data->status_byte = spi_readwrite(data_to_send->buffer[byte_sent_cnt++]);
12 // Send first byte, receive length from slave
13 received_data->buffer[0] = spi_readwrite(data_to_send->buffer[byte_sent_cnt++]);
14 if (0 == data_to_send->buffer[0])
15 {
16 max_bytes = received_data->buffer[0];
17 }
18 else
19 {
20 // Set the maximum to the biggest size. One command byte is already sent
21 max_bytes = (received_data->buffer[0] > (data_to_send->buffer[0] - 1))
22 ? received_data->buffer[0]
23 : (data_to_send->buffer[0] - 1);
24 }
25
26 if (max_bytes > HAL_ACI_MAX_LENGTH)
27 {
28 max_bytes = HAL_ACI_MAX_LENGTH;
29 }
30
31 // Transmit/receive the rest of the packet
32 for (byte_cnt = 0; byte_cnt < max_bytes; byte_cnt++)
33 {
34 received_data->buffer[byte_cnt+1] = spi_readwrite(data_to_send->buffer[byte_sent_cnt++]);
35 }
36
37 // RDYN should follow the REQN line in approx 100ns
38 m_aci_reqn_disable();
39
40 return (max_bytes > 0);
41}