v2.0.0
cyw43_configport.h
1/*
2 * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7// This header is included by cyw43_driver to setup its environment
8
9#ifndef _CYW43_CONFIGPORT_H
10#define _CYW43_CONFIGPORT_H
11
12#include "pico.h"
13#include "hardware/gpio.h"
14#include "pico/time.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifndef CYW43_HOST_NAME
21#define CYW43_HOST_NAME "PicoW"
22#endif
23
24#ifndef CYW43_GPIO
25#define CYW43_GPIO 1
26#endif
27
28#ifndef CYW43_LOGIC_DEBUG
29#define CYW43_LOGIC_DEBUG 0
30#endif
31
32#ifndef CYW43_USE_OTP_MAC
33#define CYW43_USE_OTP_MAC 1
34#endif
35
36#ifndef CYW43_NO_NETUTILS
37#define CYW43_NO_NETUTILS 1
38#endif
39
40#ifndef CYW43_IOCTL_TIMEOUT_US
41#define CYW43_IOCTL_TIMEOUT_US 1000000
42#endif
43
44#ifndef CYW43_USE_STATS
45#define CYW43_USE_STATS 0
46#endif
47
48// todo should this be user settable?
49#ifndef CYW43_HAL_MAC_WLAN0
50#define CYW43_HAL_MAC_WLAN0 0
51#endif
52
53#ifndef STATIC
54#define STATIC static
55#endif
56
57#ifndef CYW43_USE_SPI
58#define CYW43_USE_SPI 1
59#endif
60
61#ifndef CYW43_SPI_PIO
62#define CYW43_SPI_PIO 1
63#endif
64
65#ifndef CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE
66#if CYW43_ENABLE_BLUETOOTH
67#define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "wb43439A0_7_95_49_00_combined.h"
68#else
69#define CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE "w43439A0_7_95_49_00_combined.h"
70#endif
71#endif
72
73#ifndef CYW43_WIFI_NVRAM_INCLUDE_FILE
74#define CYW43_WIFI_NVRAM_INCLUDE_FILE "wifi_nvram_43439.h"
75#endif
76
77// Note, these are negated, because cyw43_driver negates them before returning!
78#define CYW43_EPERM (-PICO_ERROR_NOT_PERMITTED) // Operation not permitted
79#define CYW43_EIO (-PICO_ERROR_IO) // I/O error
80#define CYW43_EINVAL (-PICO_ERROR_INVALID_ARG) // Invalid argument
81#define CYW43_ETIMEDOUT (-PICO_ERROR_TIMEOUT) // Connection timed out
82
83#define CYW43_NUM_GPIOS CYW43_WL_GPIO_COUNT
84
85#define cyw43_hal_pin_obj_t uint
86
87// get the number of elements in a fixed-size array
88#define CYW43_ARRAY_SIZE(a) count_of(a)
89
90static inline uint32_t cyw43_hal_ticks_us(void) {
91 return time_us_32();
92}
93
94static inline uint32_t cyw43_hal_ticks_ms(void) {
95 return to_ms_since_boot(get_absolute_time());
96}
97
98static inline int cyw43_hal_pin_read(cyw43_hal_pin_obj_t pin) {
99 return gpio_get(pin);
100}
101
102static inline void cyw43_hal_pin_low(cyw43_hal_pin_obj_t pin) {
103 gpio_clr_mask(1 << pin);
104}
105
106static inline void cyw43_hal_pin_high(cyw43_hal_pin_obj_t pin) {
107 gpio_set_mask(1 << pin);
108}
109
110#define CYW43_HAL_PIN_MODE_INPUT (GPIO_IN)
111#define CYW43_HAL_PIN_MODE_OUTPUT (GPIO_OUT)
112
113#define CYW43_HAL_PIN_PULL_NONE (0)
114#define CYW43_HAL_PIN_PULL_UP (1)
115#define CYW43_HAL_PIN_PULL_DOWN (2)
116
117static inline void cyw43_hal_pin_config(cyw43_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, __unused uint32_t alt) {
118 assert((mode == CYW43_HAL_PIN_MODE_INPUT || mode == CYW43_HAL_PIN_MODE_OUTPUT) && alt == 0);
119 gpio_set_dir(pin, mode);
120 gpio_set_pulls(pin, pull == CYW43_HAL_PIN_PULL_UP, pull == CYW43_HAL_PIN_PULL_DOWN);
121}
122
123void cyw43_hal_get_mac(int idx, uint8_t buf[6]);
124
125void cyw43_hal_generate_laa_mac(int idx, uint8_t buf[6]);
126
127
128void cyw43_thread_enter(void);
129
130void cyw43_thread_exit(void);
131
132#define CYW43_THREAD_ENTER cyw43_thread_enter();
133#define CYW43_THREAD_EXIT cyw43_thread_exit();
134#ifndef NDEBUG
135
136void cyw43_thread_lock_check(void);
137
138#define cyw43_arch_lwip_check() cyw43_thread_lock_check()
139#define CYW43_THREAD_LOCK_CHECK cyw43_arch_lwip_check();
140#else
141#define cyw43_arch_lwip_check() ((void)0)
142#define CYW43_THREAD_LOCK_CHECK
143#endif
144
145void cyw43_await_background_or_timeout_us(uint32_t timeout_us);
146// todo not 100% sure about the timeouts here; MP uses __WFI which will always wakeup periodically
147#define CYW43_SDPCM_SEND_COMMON_WAIT cyw43_await_background_or_timeout_us(1000);
148#define CYW43_DO_IOCTL_WAIT cyw43_await_background_or_timeout_us(1000);
149
150void cyw43_delay_ms(uint32_t ms);
151
152void cyw43_delay_us(uint32_t us);
153
154void cyw43_schedule_internal_poll_dispatch(void (*func)(void));
155
156void cyw43_post_poll_hook(void);
157
158#define CYW43_POST_POLL_HOOK cyw43_post_poll_hook();
159
160// Allow malloc and free to be changed
161#ifndef cyw43_malloc
162#define cyw43_malloc malloc
163#endif
164#ifndef cyw43_free
165#define cyw43_free free
166#endif
167
168#ifdef __cplusplus
169}
170#endif
171
172
173#endif
time.h
gpio.h
gpio_set_dir
static void gpio_set_dir(uint gpio, bool out)
Set a single GPIO direction.
Definition: gpio.h:1340
gpio_clr_mask
static void gpio_clr_mask(uint32_t mask)
Drive low every GPIO appearing in mask.
Definition: gpio.h:955
gpio_set_pulls
void gpio_set_pulls(uint gpio, bool up, bool down)
Select up and down pulls on specific GPIO.
Definition: gpio.c:63
gpio_get
static bool gpio_get(uint gpio)
Get state of a single specified GPIO.
Definition: gpio.h:859
gpio_set_mask
static void gpio_set_mask(uint32_t mask)
Drive high every GPIO appearing in mask.
Definition: gpio.h:908
time_us_32
static uint32_t time_us_32(void)
Return a 32 bit timestamp value in microseconds for the default timer instance.
Definition: timer.h:215
get_absolute_time
static absolute_time_t get_absolute_time(void)
Return a representation of the current time.
Definition: time.h:66
to_ms_since_boot
static uint32_t to_ms_since_boot(absolute_time_t t)
Convert a timestamp into a number of milliseconds since boot.
Definition: time.h:87
pico.h