added debugging
Fork of BLE_nRF8001 by
BLE_nRF8001/utility/hal_aci_tl.h@2:7805a5595aab, 2014-11-10 (annotated)
- Committer:
- jn80842
- Date:
- Mon Nov 10 01:24:23 2014 +0000
- Revision:
- 2:7805a5595aab
- Parent:
- 0:075ea2812998
just added debugging
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RedBearLab | 0:075ea2812998 | 1 | /* Copyright (c) 2014, Nordic Semiconductor ASA |
RedBearLab | 0:075ea2812998 | 2 | * |
RedBearLab | 0:075ea2812998 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
RedBearLab | 0:075ea2812998 | 4 | * of this software and associated documentation files (the "Software"), to deal |
RedBearLab | 0:075ea2812998 | 5 | * in the Software without restriction, including without limitation the rights |
RedBearLab | 0:075ea2812998 | 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
RedBearLab | 0:075ea2812998 | 7 | * copies of the Software, and to permit persons to whom the Software is |
RedBearLab | 0:075ea2812998 | 8 | * furnished to do so, subject to the following conditions: |
RedBearLab | 0:075ea2812998 | 9 | * |
RedBearLab | 0:075ea2812998 | 10 | * The above copyright notice and this permission notice shall be included in all |
RedBearLab | 0:075ea2812998 | 11 | * copies or substantial portions of the Software. |
RedBearLab | 0:075ea2812998 | 12 | * |
RedBearLab | 0:075ea2812998 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
RedBearLab | 0:075ea2812998 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
RedBearLab | 0:075ea2812998 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
RedBearLab | 0:075ea2812998 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
RedBearLab | 0:075ea2812998 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
RedBearLab | 0:075ea2812998 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
RedBearLab | 0:075ea2812998 | 19 | * SOFTWARE. |
RedBearLab | 0:075ea2812998 | 20 | */ |
RedBearLab | 0:075ea2812998 | 21 | |
RedBearLab | 0:075ea2812998 | 22 | /** @file |
RedBearLab | 0:075ea2812998 | 23 | * @brief Interface for hal_aci_tl. |
RedBearLab | 0:075ea2812998 | 24 | */ |
RedBearLab | 0:075ea2812998 | 25 | |
RedBearLab | 0:075ea2812998 | 26 | /** @defgroup hal_aci_tl hal_aci_tl |
RedBearLab | 0:075ea2812998 | 27 | @{ |
RedBearLab | 0:075ea2812998 | 28 | @ingroup hal |
RedBearLab | 0:075ea2812998 | 29 | |
RedBearLab | 0:075ea2812998 | 30 | @brief Module for the ACI Transport Layer interface |
RedBearLab | 0:075ea2812998 | 31 | @details This module is responsible for sending and receiving messages over the ACI interface of the nRF8001 chip. |
RedBearLab | 0:075ea2812998 | 32 | The hal_aci_tl_send_cmd() can be called directly to send ACI commands. |
RedBearLab | 0:075ea2812998 | 33 | |
RedBearLab | 0:075ea2812998 | 34 | |
RedBearLab | 0:075ea2812998 | 35 | The RDYN line is hooked to an interrupt on the MCU when the level is low. |
RedBearLab | 0:075ea2812998 | 36 | The SPI master clocks in the interrupt context. |
RedBearLab | 0:075ea2812998 | 37 | The ACI Command is taken from the head of the command queue is sent over the SPI |
RedBearLab | 0:075ea2812998 | 38 | and the received ACI event is placed in the tail of the event queue. |
RedBearLab | 0:075ea2812998 | 39 | |
RedBearLab | 0:075ea2812998 | 40 | */ |
RedBearLab | 0:075ea2812998 | 41 | |
RedBearLab | 0:075ea2812998 | 42 | #ifndef HAL_ACI_TL_H__ |
RedBearLab | 0:075ea2812998 | 43 | #define HAL_ACI_TL_H__ |
RedBearLab | 0:075ea2812998 | 44 | |
RedBearLab | 0:075ea2812998 | 45 | #include "hal_platform.h" |
RedBearLab | 0:075ea2812998 | 46 | #include "aci.h" |
RedBearLab | 0:075ea2812998 | 47 | #include "boards.h" |
RedBearLab | 0:075ea2812998 | 48 | |
RedBearLab | 0:075ea2812998 | 49 | #ifndef HAL_ACI_MAX_LENGTH |
RedBearLab | 0:075ea2812998 | 50 | #define HAL_ACI_MAX_LENGTH 31 |
RedBearLab | 0:075ea2812998 | 51 | #endif |
RedBearLab | 0:075ea2812998 | 52 | |
RedBearLab | 0:075ea2812998 | 53 | /************************************************************************/ |
RedBearLab | 0:075ea2812998 | 54 | /* Unused nRF8001 pin */ |
RedBearLab | 0:075ea2812998 | 55 | /************************************************************************/ |
RedBearLab | 0:075ea2812998 | 56 | #define UNUSED 255 |
RedBearLab | 0:075ea2812998 | 57 | |
RedBearLab | 0:075ea2812998 | 58 | /** Data type for ACI commands and events */ |
RedBearLab | 0:075ea2812998 | 59 | typedef struct { |
RedBearLab | 0:075ea2812998 | 60 | uint8_t status_byte; |
RedBearLab | 0:075ea2812998 | 61 | uint8_t buffer[HAL_ACI_MAX_LENGTH+1]; |
RedBearLab | 0:075ea2812998 | 62 | } _aci_packed_ hal_aci_data_t; |
RedBearLab | 0:075ea2812998 | 63 | |
RedBearLab | 0:075ea2812998 | 64 | ACI_ASSERT_SIZE(hal_aci_data_t, HAL_ACI_MAX_LENGTH + 2); |
RedBearLab | 0:075ea2812998 | 65 | |
RedBearLab | 0:075ea2812998 | 66 | /** Datatype for ACI pins and interface (polling/interrupt)*/ |
RedBearLab | 0:075ea2812998 | 67 | typedef struct aci_pins_t |
RedBearLab | 0:075ea2812998 | 68 | { |
RedBearLab | 0:075ea2812998 | 69 | uint8_t board_name; //Optional : Use BOARD_DEFAULT if you do not know. See boards.h |
RedBearLab | 0:075ea2812998 | 70 | DigitalInOut *reqn_pin; //Required |
RedBearLab | 0:075ea2812998 | 71 | DigitalInOut *rdyn_pin; //Required |
RedBearLab | 0:075ea2812998 | 72 | |
RedBearLab | 0:075ea2812998 | 73 | DigitalInOut *reset_pin; //Recommended but optional - Set it to UNUSED when not connected |
RedBearLab | 0:075ea2812998 | 74 | DigitalInOut *active_pin; //Optional - Set it to UNUSED when not connected |
RedBearLab | 0:075ea2812998 | 75 | |
RedBearLab | 0:075ea2812998 | 76 | bool interface_is_interrupt; //Required - true = Uses interrupt on RDYN pin. false - Uses polling on RDYN pin |
RedBearLab | 0:075ea2812998 | 77 | |
RedBearLab | 0:075ea2812998 | 78 | uint8_t interrupt_number; //Required when using interrupts, otherwise ignored |
RedBearLab | 0:075ea2812998 | 79 | } aci_pins_t; |
RedBearLab | 0:075ea2812998 | 80 | |
RedBearLab | 0:075ea2812998 | 81 | /** @brief ACI Transport Layer initialization. |
RedBearLab | 0:075ea2812998 | 82 | * @details |
RedBearLab | 0:075ea2812998 | 83 | * This function initializes the transport layer, including configuring the SPI, creating |
RedBearLab | 0:075ea2812998 | 84 | * message queues for Commands and Events and setting up interrupt if required. |
RedBearLab | 0:075ea2812998 | 85 | * @param a_pins Pins on the MCU used to connect to the nRF8001 |
RedBearLab | 0:075ea2812998 | 86 | * @param bool True if debug printing should be enabled on the Serial. |
RedBearLab | 0:075ea2812998 | 87 | */ |
RedBearLab | 0:075ea2812998 | 88 | void hal_aci_tl_init(aci_pins_t *a_pins, bool debug); |
RedBearLab | 0:075ea2812998 | 89 | |
RedBearLab | 0:075ea2812998 | 90 | /** @brief Sends an ACI command to the radio. |
RedBearLab | 0:075ea2812998 | 91 | * @details |
RedBearLab | 0:075ea2812998 | 92 | * This function sends an ACI command to the radio. This queue up the message to send and |
RedBearLab | 0:075ea2812998 | 93 | * lower the request line. When the device lowers the ready line, @ref m_aci_spi_transfer() |
RedBearLab | 0:075ea2812998 | 94 | * will send the data. |
RedBearLab | 0:075ea2812998 | 95 | * @param aci_buffer Pointer to the message to send. |
RedBearLab | 0:075ea2812998 | 96 | * @return True if the data was successfully queued for sending, |
RedBearLab | 0:075ea2812998 | 97 | * false if there is no more space to store messages to send. |
RedBearLab | 0:075ea2812998 | 98 | */ |
RedBearLab | 0:075ea2812998 | 99 | bool hal_aci_tl_send(hal_aci_data_t *aci_buffer); |
RedBearLab | 0:075ea2812998 | 100 | |
RedBearLab | 0:075ea2812998 | 101 | /** @brief Process pending transactions. |
RedBearLab | 0:075ea2812998 | 102 | * @details |
RedBearLab | 0:075ea2812998 | 103 | * The library code takes care of calling this function to check if the nRF8001 RDYN line indicates a |
RedBearLab | 0:075ea2812998 | 104 | * pending transaction. It will send a pending message if there is one and return any receive message |
RedBearLab | 0:075ea2812998 | 105 | * that was pending. |
RedBearLab | 0:075ea2812998 | 106 | * @return Points to data buffer for received data. Length byte in buffer is 0 if no data received. |
RedBearLab | 0:075ea2812998 | 107 | */ |
RedBearLab | 0:075ea2812998 | 108 | hal_aci_data_t * hal_aci_tl_poll_get(void); |
RedBearLab | 0:075ea2812998 | 109 | |
RedBearLab | 0:075ea2812998 | 110 | /** @brief Get an ACI event from the event queue |
RedBearLab | 0:075ea2812998 | 111 | * @details |
RedBearLab | 0:075ea2812998 | 112 | * Call this function from the main context to get an event from the ACI event queue |
RedBearLab | 0:075ea2812998 | 113 | * This is called by lib_aci_event_get |
RedBearLab | 0:075ea2812998 | 114 | */ |
RedBearLab | 0:075ea2812998 | 115 | bool hal_aci_tl_event_get(hal_aci_data_t *p_aci_data); |
RedBearLab | 0:075ea2812998 | 116 | |
RedBearLab | 0:075ea2812998 | 117 | /** @brief Peek an ACI event from the event queue |
RedBearLab | 0:075ea2812998 | 118 | * @details |
RedBearLab | 0:075ea2812998 | 119 | * Call this function from the main context to peek an event from the ACI event queue. |
RedBearLab | 0:075ea2812998 | 120 | * This is called by lib_aci_event_peek |
RedBearLab | 0:075ea2812998 | 121 | */ |
RedBearLab | 0:075ea2812998 | 122 | bool hal_aci_tl_event_peek(hal_aci_data_t *p_aci_data); |
RedBearLab | 0:075ea2812998 | 123 | |
RedBearLab | 0:075ea2812998 | 124 | /** @brief Enable debug printing of all ACI commands sent and ACI events received |
RedBearLab | 0:075ea2812998 | 125 | * @details |
RedBearLab | 0:075ea2812998 | 126 | * when the enable parameter is true. The debug printing is enabled on the Serial. |
RedBearLab | 0:075ea2812998 | 127 | * When the enable parameter is false. The debug printing is disabled on the Serial. |
RedBearLab | 0:075ea2812998 | 128 | * By default the debug printing is disabled. |
RedBearLab | 0:075ea2812998 | 129 | */ |
RedBearLab | 0:075ea2812998 | 130 | void hal_aci_tl_debug_print(bool enable); |
RedBearLab | 0:075ea2812998 | 131 | |
RedBearLab | 0:075ea2812998 | 132 | |
RedBearLab | 0:075ea2812998 | 133 | /** @brief Pin reset the nRF8001 |
RedBearLab | 0:075ea2812998 | 134 | * @details |
RedBearLab | 0:075ea2812998 | 135 | * The reset line of the nF8001 needs to kept low for 200 ns. |
RedBearLab | 0:075ea2812998 | 136 | * Redbearlab shield v1.1 and v2012.07 are exceptions as they |
RedBearLab | 0:075ea2812998 | 137 | * have a Power ON Reset circuit that works differently. |
RedBearLab | 0:075ea2812998 | 138 | * The function handles the exceptions based on the board_name in aci_pins_t |
RedBearLab | 0:075ea2812998 | 139 | */ |
RedBearLab | 0:075ea2812998 | 140 | void hal_aci_tl_pin_reset(void); |
RedBearLab | 0:075ea2812998 | 141 | |
RedBearLab | 0:075ea2812998 | 142 | /** @brief Return full status of transmit queue |
RedBearLab | 0:075ea2812998 | 143 | * @details |
RedBearLab | 0:075ea2812998 | 144 | * |
RedBearLab | 0:075ea2812998 | 145 | */ |
RedBearLab | 0:075ea2812998 | 146 | bool hal_aci_tl_rx_q_full(void); |
RedBearLab | 0:075ea2812998 | 147 | |
RedBearLab | 0:075ea2812998 | 148 | /** @brief Return empty status of receive queue |
RedBearLab | 0:075ea2812998 | 149 | * @details |
RedBearLab | 0:075ea2812998 | 150 | * |
RedBearLab | 0:075ea2812998 | 151 | */ |
RedBearLab | 0:075ea2812998 | 152 | bool hal_aci_tl_rx_q_empty(void); |
RedBearLab | 0:075ea2812998 | 153 | |
RedBearLab | 0:075ea2812998 | 154 | /** @brief Return full status of receive queue |
RedBearLab | 0:075ea2812998 | 155 | * @details |
RedBearLab | 0:075ea2812998 | 156 | * |
RedBearLab | 0:075ea2812998 | 157 | */ |
RedBearLab | 0:075ea2812998 | 158 | bool hal_aci_tl_tx_q_full(void); |
RedBearLab | 0:075ea2812998 | 159 | |
RedBearLab | 0:075ea2812998 | 160 | /** @brief Return empty status of transmit queue |
RedBearLab | 0:075ea2812998 | 161 | * @details |
RedBearLab | 0:075ea2812998 | 162 | * |
RedBearLab | 0:075ea2812998 | 163 | */ |
RedBearLab | 0:075ea2812998 | 164 | bool hal_aci_tl_tx_q_empty(void); |
RedBearLab | 0:075ea2812998 | 165 | |
RedBearLab | 0:075ea2812998 | 166 | /** @brief Flush the ACI command Queue and the ACI Event Queue |
RedBearLab | 0:075ea2812998 | 167 | * @details |
RedBearLab | 0:075ea2812998 | 168 | * Call this function in the main thread |
RedBearLab | 0:075ea2812998 | 169 | */ |
RedBearLab | 0:075ea2812998 | 170 | void hal_aci_tl_q_flush(void); |
RedBearLab | 0:075ea2812998 | 171 | |
RedBearLab | 0:075ea2812998 | 172 | #endif // HAL_ACI_TL_H__ |
RedBearLab | 0:075ea2812998 | 173 | /** @} */ |