source: azure_iot_hub_f767zi/trunk/asp_baseplatform/gdic/ble_shield2.1/utility/hal_aci_tl.h@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 6.6 KB
Line 
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
22/** @file
23 * @brief Interface for hal_aci_tl.
24 */
25
26/** @defgroup hal_aci_tl hal_aci_tl
27@{
28@ingroup hal
29
30@brief Module for the ACI Transport Layer interface
31@details This module is responsible for sending and receiving messages over the ACI interface of the nRF8001 chip.
32 The hal_aci_tl_send_cmd() can be called directly to send ACI commands.
33
34
35The RDYN line is hooked to an interrupt on the MCU when the level is low.
36The SPI master clocks in the interrupt context.
37The ACI Command is taken from the head of the command queue is sent over the SPI
38and the received ACI event is placed in the tail of the event queue.
39
40*/
41
42#ifndef HAL_ACI_TL_H__
43#define HAL_ACI_TL_H__
44
45#include "hal_platform.h"
46#include "aci.h"
47#include "boards.h"
48
49#ifndef HAL_ACI_MAX_LENGTH
50#define HAL_ACI_MAX_LENGTH 31
51#endif
52
53/************************************************************************/
54/* Unused nRF8001 pin */
55/************************************************************************/
56#define UNUSED 255
57
58/** Data type for ACI commands and events */
59typedef struct {
60 uint8_t status_byte;
61 uint8_t buffer[HAL_ACI_MAX_LENGTH+1];
62} _aci_packed_ hal_aci_data_t;
63
64ACI_ASSERT_SIZE(hal_aci_data_t, HAL_ACI_MAX_LENGTH + 2);
65
66/** Datatype for ACI pins and interface (polling/interrupt)*/
67typedef struct aci_pins_t
68{
69 uint8_t board_name; //Optional : Use BOARD_DEFAULT if you do not know. See boards.h
70 uint8_t reqn_pin; //Required
71 uint8_t rdyn_pin; //Required
72// uint8_t mosi_pin; //Required
73// uint8_t miso_pin; //Required
74// uint8_t sck_pin; //Required
75
76// uint8_t spi_clock_divider; //Required : Clock divider on the SPI clock : nRF8001 supports a maximum clock of 3MHz
77 void *spihandle; //Required
78
79 uint8_t reset_pin; //Recommended but optional - Set it to UNUSED when not connected
80 uint8_t active_pin; //Optional - Set it to UNUSED when not connected
81 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
82
83 bool interface_is_interrupt; //Required - true = Uses interrupt on RDYN pin. false - Uses polling on RDYN pin
84
85// uint8_t interrupt_number; //Required when using interrupts, otherwise ignored
86 int event_taskid; //Required event taskid
87} aci_pins_t;
88
89/** @brief ACI Transport Layer initialization.
90 * @details
91 * This function initializes the transport layer, including configuring the SPI, creating
92 * message queues for Commands and Events and setting up interrupt if required.
93 * @param a_pins Pins on the MCU used to connect to the nRF8001
94 * @param bool True if debug printing should be enabled on the Serial.
95 */
96void hal_aci_tl_init(aci_pins_t *a_pins, bool debug);
97
98/** @brief Sends an ACI command to the radio.
99 * @details
100 * This function sends an ACI command to the radio. This queue up the message to send and
101 * lower the request line. When the device lowers the ready line, @ref m_aci_spi_transfer()
102 * will send the data.
103 * @param aci_buffer Pointer to the message to send.
104 * @return True if the data was successfully queued for sending,
105 * false if there is no more space to store messages to send.
106 */
107bool hal_aci_tl_send(hal_aci_data_t *aci_buffer);
108
109/** @brief Process pending transactions.
110 * @details
111 * The library code takes care of calling this function to check if the nRF8001 RDYN line indicates a
112 * pending transaction. It will send a pending message if there is one and return any receive message
113 * that was pending.
114 * @return Points to data buffer for received data. Length byte in buffer is 0 if no data received.
115 */
116hal_aci_data_t * hal_aci_tl_poll_get(void);
117
118/** @brief Get an ACI event from the event queue
119 * @details
120 * Call this function from the main context to get an event from the ACI event queue
121 * This is called by lib_aci_event_get
122 */
123bool hal_aci_tl_event_get(hal_aci_data_t *p_aci_data);
124
125/** @brief Peek an ACI event from the event queue
126 * @details
127 * Call this function from the main context to peek an event from the ACI event queue.
128 * This is called by lib_aci_event_peek
129 */
130bool hal_aci_tl_event_peek(hal_aci_data_t *p_aci_data);
131
132/** @brief Enable debug printing of all ACI commands sent and ACI events received
133 * @details
134 * when the enable parameter is true. The debug printing is enabled on the Serial.
135 * When the enable parameter is false. The debug printing is disabled on the Serial.
136 * By default the debug printing is disabled.
137 */
138void hal_aci_tl_debug_print(bool enable);
139
140
141/** @brief Pin reset the nRF8001
142 * @details
143 * The reset line of the nF8001 needs to kept low for 200 ns.
144 * Redbearlab shield v1.1 and v2012.07 are exceptions as they
145 * have a Power ON Reset circuit that works differently.
146 * The function handles the exceptions based on the board_name in aci_pins_t
147 */
148void hal_aci_tl_pin_reset(void);
149
150/** @brief Return full status of transmit queue
151 * @details
152 *
153 */
154bool hal_aci_tl_rx_q_full(void);
155
156 /** @brief Return empty status of receive queue
157 * @details
158 *
159 */
160bool hal_aci_tl_rx_q_empty(void);
161
162/** @brief Return full status of receive queue
163 * @details
164 *
165 */
166bool hal_aci_tl_tx_q_full(void);
167
168 /** @brief Return empty status of transmit queue
169 * @details
170 *
171 */
172bool hal_aci_tl_tx_q_empty(void);
173
174/** @brief Flush the ACI command Queue and the ACI Event Queue
175 * @details
176 * Call this function in the main thread
177 */
178void hal_aci_tl_q_flush(void);
179
180/**
181 * added aci interrupt function
182 */
183void m_aci_isr(void);
184
185/**
186 * added aci task function
187 */
188void aci_task(int arg);
189
190#endif // HAL_ACI_TL_H__
191/** @} */
Note: See TracBrowser for help on using the repository browser.