upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
hal_aci_tl.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, Nordic Semiconductor ASA
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all
11  * copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19  * SOFTWARE.
20  */
21 
43 #ifndef HAL_ACI_TL_H__
44 #define HAL_ACI_TL_H__
45 
46 #include "hal_platform.h"
47 #include "aci.h"
48 #include "boards.h"
49 
50 #include <mraa/aio.h>
51 #include <mraa/gpio.h>
52 #include <mraa/spi.h>
53 
54 #ifndef HAL_ACI_MAX_LENGTH
55 #define HAL_ACI_MAX_LENGTH 31
56 #endif
57 
58 /************************************************************************/
59 /* Unused nRF8001 pin */
60 /************************************************************************/
61 #define UNUSED 255
62 
64 typedef struct {
65  uint8_t status_byte;
66  uint8_t buffer[HAL_ACI_MAX_LENGTH+1];
67 } _aci_packed_ hal_aci_data_t;
68 
69 ACI_ASSERT_SIZE(hal_aci_data_t, HAL_ACI_MAX_LENGTH + 2);
70 
72 typedef struct aci_pins_t
73 {
74  mraa_spi_context m_spi;
75  mraa_gpio_context m_rdy_ctx;
76  mraa_gpio_context m_req_ctx;
77  mraa_gpio_context m_rst_ctx;
78 
79  uint8_t board_name; //Optional : Use BOARD_DEFAULT if you do not know. See boards.h
80  uint8_t reqn_pin; //Required
81  uint8_t rdyn_pin; //Required
82  uint8_t mosi_pin; //Required
83  uint8_t miso_pin; //Required
84  uint8_t sck_pin; //Required
85 
86  uint8_t spi_clock_divider; //Required : Clock divider on the SPI clock : nRF8001 supports a maximum clock of 3MHz
87 
88  uint8_t reset_pin; //Recommended but optional - Set it to UNUSED when not connected
89  uint8_t active_pin; //Optional - Set it to UNUSED when not connected
90  uint8_t optional_chip_sel_pin; //Optional - Used only when the reqn line is required to be separate from the SPI chip select. Eg. Arduino DUE
91 
92  bool interface_is_interrupt; //Required - true = Uses interrupt on RDYN pin. false - Uses polling on RDYN pin
93 
94  uint8_t interrupt_number; //Required when using interrupts, otherwise ignored
95 } aci_pins_t;
96 
104 void hal_aci_tl_init(aci_pins_t *a_pins, bool debug);
105 
115 bool hal_aci_tl_send(hal_aci_data_t *aci_buffer);
116 
124 hal_aci_data_t * hal_aci_tl_poll_get(void);
125 
131 bool hal_aci_tl_event_get(hal_aci_data_t *p_aci_data);
132 
138 bool hal_aci_tl_event_peek(hal_aci_data_t *p_aci_data);
139 
146 void hal_aci_tl_debug_print(bool enable);
147 
148 
156 void hal_aci_tl_pin_reset(void);
157 
162  bool hal_aci_tl_rx_q_full(void);
163 
168  bool hal_aci_tl_rx_q_empty(void);
169 
174  bool hal_aci_tl_tx_q_full(void);
175 
180  bool hal_aci_tl_tx_q_empty(void);
181 
186 void hal_aci_tl_q_flush(void);
187 
188 #endif // HAL_ACI_TL_H__
189 
bool hal_aci_tl_rx_q_full(void)
Return full status of transmit queue.
Definition: hal_aci_tl.cpp:441
bool hal_aci_tl_tx_q_empty(void)
Return empty status of transmit queue.
Definition: hal_aci_tl.cpp:446
bool hal_aci_tl_event_peek(hal_aci_data_t *p_aci_data)
Peek an ACI event from the event queue.
Definition: hal_aci_tl.cpp:277
bool hal_aci_tl_event_get(hal_aci_data_t *p_aci_data)
Get an ACI event from the event queue.
Definition: hal_aci_tl.cpp:292
void hal_aci_tl_init(aci_pins_t *a_pins, bool debug)
ACI Transport Layer initialization.
Definition: hal_aci_tl.cpp:329
HAL specific macros.
bool hal_aci_tl_tx_q_full(void)
Return full status of receive queue.
Definition: hal_aci_tl.cpp:451
Defines for the different Bluetooth low energy boards.
void hal_aci_tl_debug_print(bool enable)
Enable debug printing of all ACI commands sent and ACI events received.
Definition: hal_aci_tl.cpp:248
bool hal_aci_tl_send(hal_aci_data_t *aci_buffer)
Sends an ACI command to the radio.
Definition: hal_aci_tl.cpp:405
hal_aci_data_t * hal_aci_tl_poll_get(void)
Process pending transactions.
void hal_aci_tl_pin_reset(void)
Pin reset the nRF8001.
Definition: hal_aci_tl.cpp:253
#define HAL_ACI_MAX_LENGTH
Module for the ACI Transport Layer interface.
Definition: hal_aci_tl.h:55
bool hal_aci_tl_rx_q_empty(void)
Return empty status of receive queue.
Definition: hal_aci_tl.cpp:436
Structure for the ACI_CMD_SET_LOCAL_DATA ACI command parameters.
Definition: aci.h:271
void hal_aci_tl_q_flush(void)
Flush the ACI command Queue and the ACI Event Queue.
Definition: hal_aci_tl.cpp:456