source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/wl_spi.h @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 6.4 KB
Line 
1/*!
2 *  \file wl_spi.h
3 *  \brief SPI interface for wl_api.
4 *  Copyright (C) 2010 HD Wireless AB
5 *
6 *  You should have received a copy of the license along with this library.
7 */
8
9#ifndef WL_SPI_H
10#define WL_SPI_H
11
12#ifndef WITHOUT_STDINT
13#include <stdint.h>
14#endif
15
16/** \defgroup wl_spi SPI Interface
17 *
18 * These functions implement the interface that the wl_api library
19 * needs to work with a SPI transport layer.
20 *
21 * The functions prototyped here must be implemented when porting the
22 * wl_api library to a new platform with a different SPI configuration
23 *
24 * On platforms supported by H&D Wireless these functions are
25 * implemented in the file avr32_spi.c
26 *
27 *  @{
28 */
29
30/**
31 * Maximum transfer size. This will set an upper limit on the len parameter
32 * passed to owl_spi_txrx().
33 *
34 *
35 */ 
36#define MAX_BLOCK_LEN                 512
37
38
39/**
40 * Indicates that the spi driver needs to be polled in order to make
41 * forward progress, i.e. it does not support interrupts through SD pin 8.
42 *
43 * The actual polling will result in owl_spi_txrx() being call to
44 * request status information from the device.
45 *
46 * To activate polling, this flag should be set in owl_spi_init().
47 *
48 * See wl_poll() and wl_register_rx_isr() for more information regarding
49 * polled and interrupt modes.
50 *
51 */
52#define SPI_FLAG_POLL (1 << 0)
53
54
55/**
56 * This function will be invoked when wlan device initialization should be
57 * performed, this happens when the wl_fw_download() function in the transport
58 * group of wl_api is invoked.
59 *
60 * The wifi device requires spi mode 3, i.e. clock polarity high and sample
61 * on second phase. This corresponds to CPOL=1, CPHA=1. Maximum frequency on
62 * spi clock is 30 MHz.
63 *
64 * The function is also responsible for doing any necessary spi initialization
65 * such as allocating gpio's, setting up the SPI master, one time allocations of
66 * dma buffers etc.
67 *
68 *
69 * If the SPB105 device is used, two signals; POWER (pin 10 on SPB105) and
70 * SHUTDOWN (pin 4 on SPB105) might be connected to gpio's on the host.
71 * The GPIO_POWER_PIN is the main power supply to the device. The
72 * GPIO_SHUTDOWN_PIN (active low) should be defined as an input.
73 *
74 * After GPIO_POWER_PIN is pulled high by the host, the device will pull the
75 * GPIO_SHUTDOWN_PIN high once the device is properly powered.
76 *
77 * However, if pin 4 (GPIO_SHUTDOWN_PIN) is not connected to the host, a delay
78 * of up to 250 ms must be added after GPIO_POWER_PIN is pulled high to ensure
79 * that startup is completed. The actual time is usually much shorter, therefore
80 * one might try to reduce the delay for a particualar hardware design.
81 *
82 * On SPB104, the GPIO_POWER_PIN will be connected to VCC and GPIO_SHUTDOWN_PIN
83 * will be unconnected; hence we have to make sure that we have enough delay
84 * after powering on the host. Since the device power-on usually happens at the
85 * same time as the host power-on, the startup time of the host can be
86 * subtracted from any delay put into owl_spi_init().
87 *
88 * @param flags is an out parameter that should hold any spi flags upon return.
89 *        The avaible flags are prefixed with SPI_FLAG_
90 *
91 * @return 0 on success
92 *         -1 if any error occurs
93 *
94 */
95int owl_spi_init(uint8_t *flags);
96
97
98/**
99 * Invoked when a spi transfer should be performed.
100 *
101 * All buffers that are allocated by the wl library will have a size that is
102 * aligned to 4. If size-unaligned data is passed to this function, it is
103 * always allocated by the ip stack. If 4-byte size alignment (e.g. for DMA)
104 * is required, 1-3 extra padding bytes can be transmitted after the in buffer.
105 * These bytes must be 0xff.
106 *
107 * Since size-unaligned data always comes from the ip stack, the out ptr is
108 * always NULL for such data.
109 *
110 * @param in points a buffer which holds the data to be transmitted. If NULL,
111 *        then \a len bytes with the value 0xff should be transmitted on the
112 *        bus.
113 * @param out points a buffer should hold the data received from the device. If
114 *        NULL, any received data can be discarded.
115 * @param len is the length of the in and out buffers.
116 *
117 */
118void owl_spi_txrx(const uint8_t *in, uint8_t* out, uint16_t len);
119
120
121/**
122 * Invoked when spi rx interrupts from the device should be enabled or disabled.
123 * Note that the spi interrupts are obtained from pin 8 on SPB104 or pin 3 from
124 * SPB105. This pin can be be connected to a gpio on the host. The irq line
125 * will signal an interrupt on both edges.
126 *
127 * In general, the wifi device will not issue a new interrupt unless the
128 * last interrupt has been handled. Also, during normal operation (i.e after
129 * the complete callback registered in wl_init() has been invoked),
130 * owl_spi_irq() will never be invoked so interrupts will be enabled all
131 * the time. For the SPI-mode, the purpose of owl_spi_irq() is basically to
132 * make sure that the first interrupt (coming after the reset performed in
133 * owl_spi_init()) is ignored.
134 *
135 * If SPI_FLAG_POLL was set in owl_spi_init(), then this function can be
136 * left empty and the wifi device will be used in polled mode. In polled mode,
137 * the interrupt line is not used. Regardless of polled or interrupt-mode,
138 * wl_poll() must be called to ensure progress of the driver.
139 *
140 * @param enable specifies if interrupts should be enabled or disabled.
141 *
142 */
143void owl_spi_irq(uint8_t enable);
144
145
146/**
147 * Invoked when the spi cs for the wifi device should be enabled. Note that
148 * multiple calls to owl_spi_txrx() might be done during a 'single' chip
149 * select.
150 *
151 * @param enable specifies whether chip select should be asserted or deasserted,
152 *        The chip select signal is active low, so if enable is '1' then the
153 *        chip select connected to the wifi device should be set to '0'.
154 *       
155 */
156void owl_spi_cs(uint8_t enable);
157
158
159/**
160 * Delay executiom for the specified number of ms. This function will be called
161 * with delays in the 10-20 ms range during fw download and startup of the
162 * Wi-Fi device. This function can be implemented with a simple for-loop if
163 * desired (beware of optimization). The timing does not have to be accurate as
164 * long as the actual delay becomes at least the specified number of ms.
165 *
166 * @param ms is the minimal amount of time to wait [ms].
167 *
168 */
169void owl_spi_mdelay(uint32_t ms);
170
171
172/**
173 * This function should be called whenever an interrupt is detected. It can
174 * be called from an interrupt context.
175 *
176 * If SPI_FLAG_POLL was set in owl_spi_init(), then wl_spi_irq()
177 * should never be called.
178 *
179 */
180extern void wl_spi_irq(void);
181
182
183/*!  @} */
184
185#endif
Note: See TracBrowser for help on using the repository browser.