hal_aci_data_t * hal_aci_tl_poll_get(void) { uint8_t byte_cnt; uint8_t byte_sent_cnt; uint8_t max_bytes; hal_aci_data_t data_to_send; digitalWrite(a_pins_local_ptr->reqn_pin, 0); // Receive from queue if (m_aci_q_dequeue(&aci_tx_q, &data_to_send) == false) { /* queue was empty, nothing to send */ data_to_send.status_byte = 0; data_to_send.buffer[0] = 0; } //Change this if your mcu has DMA for the master SPI // Send length, receive header byte_sent_cnt = 0; //Byte at index 0 sent, byte from slave is the status byte received_data.status_byte = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); // Send first byte, receive length from slave received_data.buffer[0] = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); if (0 == data_to_send.buffer[0]) { max_bytes = received_data.buffer[0]; } else { // Set the maximum to the biggest size. One command byte is already sent max_bytes = (received_data.buffer[0] > (data_to_send.buffer[0] - 1)) ? received_data.buffer[0] : (data_to_send.buffer[0] - 1); } if (max_bytes > HAL_ACI_MAX_LENGTH) { max_bytes = HAL_ACI_MAX_LENGTH; } // Transmit/receive the rest of the packet for (byte_cnt = 0; byte_cnt < max_bytes; byte_cnt++) { received_data.buffer[byte_cnt+1] = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); } //REQN/SS is set to high digitalWrite(a_pins_local_ptr->reqn_pin, 1); //RDYN should automatically follow the REQN line in approx 100ns //sleep_enable(); if (a_pins_local_ptr->interface_is_interrupt) { attachInterrupt(a_pins_local_ptr->interrupt_number, m_rdy_line_handle, LOW); } if (false == m_aci_q_is_empty(&aci_tx_q)) { //Lower the REQN line to start a new ACI transaction digitalWrite(a_pins_local_ptr->reqn_pin, 0); } /* valid Rx available or transmit finished*/ return (&received_data); }
bool lib_aci_event_get(aci_state_t *aci_stat, hal_aci_evt_t *p_aci_evt_data) { bool status = false; if (false == aci_stat->aci_pins.interface_is_interrupt) { /* Check the RDYN line When the RDYN line goes low Run the SPI master place the returned ACI Event in the p_aci_evt_data */ /* When the RDYN goes low it means the nRF8001 is ready for the SPI transaction */ if (0 != digitalRead(aci_stat->aci_pins.rdyn_pin)) { /* RDYN line was not low */ /*when there are commands in the Command queue. place the REQN line low, so the RDYN line will go low later*/ if ((false == m_aci_q_is_empty(&aci_tx_q)) && (false == m_aci_q_is_full(&aci_rx_q))) { digitalWrite(aci_stat->aci_pins.reqn_pin, 0); } /* Master SPI cannot be run , no event to process */ } else { /* Now process the Master SPI */ m_rdy_line_handle(); } } status = hal_aci_tl_event_get((hal_aci_data_t *)p_aci_evt_data); /** Update the state of the ACI witn the ACI Events -> Pipe Status, Disconnected, Connected, Bond Status, Pipe Error */ if (true == status) { aci_evt_t * aci_evt; aci_evt = &p_aci_evt_data->evt; switch(aci_evt->evt_opcode) { case ACI_EVT_PIPE_STATUS: { uint8_t i=0; for (i=0; i < PIPES_ARRAY_SIZE; i++) { aci_stat->pipes_open_bitmap[i] = aci_evt->params.pipe_status.pipes_open_bitmap[i]; aci_stat->pipes_closed_bitmap[i] = aci_evt->params.pipe_status.pipes_closed_bitmap[i]; } } break; case ACI_EVT_DISCONNECTED: { uint8_t i=0; for (i=0; i < PIPES_ARRAY_SIZE; i++) { aci_stat->pipes_open_bitmap[i] = 0; aci_stat->pipes_closed_bitmap[i] = 0; } aci_stat->confirmation_pending = false; aci_stat->data_credit_available = aci_stat->data_credit_total; } break; case ACI_EVT_TIMING: aci_stat->connection_interval = aci_evt->params.timing.conn_rf_interval; aci_stat->slave_latency = aci_evt->params.timing.conn_slave_rf_latency; aci_stat->supervision_timeout = aci_evt->params.timing.conn_rf_timeout; break; } } return status; }
hal_aci_data_t * hal_aci_tl_poll_get(void) { uint8_t byte_cnt; uint8_t byte_sent_cnt; uint8_t max_bytes; hal_aci_data_t data_to_send; //SPI.begin(); HAL_IO_SET_STATE(HAL_IO_RADIO_REQN, 0); // Receive from queue if (m_aci_q_dequeue(&aci_tx_q, &data_to_send) == false) { /* queue was empty, nothing to send */ data_to_send.status_byte = 0; data_to_send.buffer[0] = 0; } //Change this if your mcu has DMA for the master SPI // Send length, receive header byte_sent_cnt = 0; received_data.status_byte = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); // Send first byte, receive length from slave received_data.buffer[0] = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); if (0 == data_to_send.buffer[0]) { max_bytes = received_data.buffer[0]; } else { // Set the maximum to the biggest size. One command byte is already sent max_bytes = (received_data.buffer[0] > (data_to_send.buffer[0] - 1)) ? received_data.buffer[0] : (data_to_send.buffer[0] - 1); } if (max_bytes > HAL_ACI_MAX_LENGTH) { max_bytes = HAL_ACI_MAX_LENGTH; } // Transmit/receive the rest of the packet for (byte_cnt = 0; byte_cnt < max_bytes; byte_cnt++) { received_data.buffer[byte_cnt+1] = spi_readwrite(data_to_send.buffer[byte_sent_cnt++]); } HAL_IO_SET_STATE(HAL_IO_RADIO_REQN, 1); //SPI.end(); //RDYN should follow the REQN line in approx 100ns sleep_enable(); attachInterrupt(HAL_IO_RADIO_IRQ, m_rdy_line_handle, LOW); if (false == m_aci_q_is_empty(&aci_tx_q)) { //Lower the REQN line to start a new ACI transaction HAL_IO_SET_STATE(HAL_IO_RADIO_REQN, 0); } /* valid Rx available or transmit finished*/ return (&received_data); }