rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
wifi_bsp.cpp File Reference

Functions

spi_device_e getWifiSpiDevice ()
 
Gpio getWifiCsPin ()
 
Gpio getWifiResetPin ()
 
Gpio getWifiIsrPin ()
 
void nm_bsp_sleep (uint32 u32TimeMsec)
 
static void isrAdapter (void *, efitick_t)
 
void nm_bsp_interrupt_ctrl (uint8 u8Enable)
 
void nm_bsp_register_isr (tpfNmBspIsr pfIsr)
 
sint8 nm_bus_init (void *)
 
sint8 nm_bus_deinit (void)
 
sint8 nm_bus_speed (uint8)
 
void resetSpiDevice (SPIDriver *spi)
 
sint8 nm_spi_rw (uint8 *pu8Mosi, uint8 *pu8Miso, uint16 u16Sz)
 

Variables

static tpfNmBspIsr gpfIsr = nullptr
 
static bool isrEnabled = false
 
static SPIDriver * wifiSpi = nullptr
 
tstrNmBusCapabilities egstrNmBusCapabilities = { .u16MaxTrxSz = 4096 }
 
SPIConfig wifi_spicfg
 
static OutputPin wifiCs
 
static OutputPin wifiReset
 

Function Documentation

◆ getWifiCsPin()

Gpio getWifiCsPin ( )

Definition at line 21 of file board_configuration.cpp.

21 {
22 return Gpio::E4;
23}

Referenced by nm_bus_init().

Here is the caller graph for this function:

◆ getWifiIsrPin()

Gpio getWifiIsrPin ( )

Definition at line 29 of file board_configuration.cpp.

29 {
30 return Gpio::E3;
31}

Referenced by nm_bsp_interrupt_ctrl().

Here is the caller graph for this function:

◆ getWifiResetPin()

Gpio getWifiResetPin ( )

Definition at line 25 of file board_configuration.cpp.

25 {
26 return Gpio::E1;
27}

Referenced by nm_bus_init().

Here is the caller graph for this function:

◆ getWifiSpiDevice()

spi_device_e getWifiSpiDevice ( )

Definition at line 17 of file board_configuration.cpp.

17 {
18 return SPI_DEVICE_4;
19}

Referenced by nm_bus_init().

Here is the caller graph for this function:

◆ isrAdapter()

static void isrAdapter ( void *  ,
efitick_t   
)
static

Definition at line 24 of file wifi_bsp.cpp.

24 {
25 if (gpfIsr) {
26 gpfIsr();
27 }
28}
static tpfNmBspIsr gpfIsr
Definition wifi_bsp.cpp:22

Referenced by nm_bsp_interrupt_ctrl().

Here is the caller graph for this function:

◆ nm_bsp_interrupt_ctrl()

void nm_bsp_interrupt_ctrl ( uint8  u8Enable)

Definition at line 32 of file wifi_bsp.cpp.

32 {
33 if (u8Enable && !isrEnabled) {
34 efiExtiEnablePin("WiFi ISR", getWifiIsrPin(), PAL_EVENT_MODE_FALLING_EDGE, isrAdapter, nullptr);
35 isrEnabled = true;
36 } else if (!u8Enable && isrEnabled) {
38 isrEnabled = false;
39 }
40}
void efiExtiDisablePin(brain_pin_e brainPin)
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
static void isrAdapter(void *, efitick_t)
Definition wifi_bsp.cpp:24
static bool isrEnabled
Definition wifi_bsp.cpp:30
Gpio getWifiIsrPin()

Referenced by nm_bsp_register_isr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nm_bsp_register_isr()

void nm_bsp_register_isr ( tpfNmBspIsr  pfIsr)

Definition at line 42 of file wifi_bsp.cpp.

42 {
43 gpfIsr = pfIsr;
44
46}
void nm_bsp_interrupt_ctrl(uint8 u8Enable)
Definition wifi_bsp.cpp:32
Here is the call graph for this function:

◆ nm_bsp_sleep()

void nm_bsp_sleep ( uint32  u32TimeMsec)

Definition at line 18 of file wifi_bsp.cpp.

18 {
19 chThdSleepMilliseconds(u32TimeMsec);
20}

◆ nm_bus_deinit()

sint8 nm_bus_deinit ( void  )

Definition at line 113 of file wifi_bsp.cpp.

113 {
114 spiReleaseBus(wifiSpi);
115 spiStop(wifiSpi);
116
117 return M2M_SUCCESS;
118}
static SPIDriver * wifiSpi
Definition wifi_bsp.cpp:48

◆ nm_bus_init()

sint8 nm_bus_init ( void *  )

Definition at line 84 of file wifi_bsp.cpp.

84 {
85 auto spi = getWifiSpiDevice();
86 if (spi == SPI_NONE) {
87 return M2M_ERR_BUS_FAIL;
88 }
89
90 // Set up chip select, reset
91 wifiCs.initPin("WiFi CS", getWifiCsPin());
93 wifiReset.initPin("WiFi RST", getWifiResetPin());
94
95 // Reset the chip
97 chThdSleepMilliseconds(10);
99 chThdSleepMilliseconds(10);
100
101 // Set up SPI
103 wifi_spicfg.ssport = wifiCs.m_port;
104 wifi_spicfg.sspad = wifiCs.m_pin;
105 spiStart(wifiSpi, &wifi_spicfg);
106
107 // Take exclusive access of the bus for WiFi use, don't release it until the bus is de-init.
108 spiAcquireBus(wifiSpi);
109
110 return M2M_SUCCESS;
111}
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition efi_gpio.cpp:711
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
ioportid_t m_port
Definition efi_output.h:71
uint8_t m_pin
Definition efi_output.h:72
SPIDriver * getSpiDevice(spi_device_e spiDevice)
Definition hardware.cpp:149
SPIConfig wifi_spicfg
Definition wifi_bsp.cpp:55
spi_device_e getWifiSpiDevice()
static OutputPin wifiCs
Definition wifi_bsp.cpp:81
static OutputPin wifiReset
Definition wifi_bsp.cpp:82
Gpio getWifiResetPin()
Gpio getWifiCsPin()
Here is the call graph for this function:

◆ nm_bus_speed()

sint8 nm_bus_speed ( uint8  )

Definition at line 120 of file wifi_bsp.cpp.

120 {
121 // Do we even need to do anything here?
122 return M2M_SUCCESS;
123}

◆ nm_spi_rw()

sint8 nm_spi_rw ( uint8 *  pu8Mosi,
uint8 *  pu8Miso,
uint16  u16Sz 
)

Definition at line 127 of file wifi_bsp.cpp.

127 {
128 spiSelectI(wifiSpi);
129
130 if (u16Sz < 16) {
131 for (size_t i = 0; i < u16Sz; i++) {
132 uint8 tx = pu8Mosi ? pu8Mosi[i] : 0;
133
134 uint8 rx = spiPolledExchange(wifiSpi, tx);
135
136 if (pu8Miso) {
137 pu8Miso[i] = rx;
138 }
139 }
140 } else {
141 // #if CORTEX_MODEL == 7
142 // if (pu8Mosi) {
143 // SCB_CleanDCache_by_Addr((uint32_t*)pu8Mosi, u16Sz);
144 // }
145 // #endif
146
147 // #ifdef STM32H7XX
148 // /* workaround for silicon errata */
149 // /* see https://github.com/rusefi/rusefi/issues/2395 */
150 // resetSpiDevice(wifiSpi);
151 // spiStart(wifiSpi, &wifi_spicfg);
152 // #endif
153
154 if (pu8Mosi && pu8Miso) {
155 spiExchange(wifiSpi, u16Sz, pu8Mosi, pu8Miso);
156 } else if (pu8Mosi) {
157 spiSend(wifiSpi, u16Sz, pu8Mosi);
158 } else if (pu8Miso) {
159 spiReceive(wifiSpi, u16Sz, pu8Miso);
160 } else {
161 // Neither MISO nor MOSI???
162 osalSysHalt("wifi neither mosi nor miso");
163 }
164
165 // #if CORTEX_MODEL == 7
166 // if (pu8Miso) {
167 // SCB_InvalidateDCache_by_Addr((uint32_t*)pu8Miso, u16Sz);
168 // }
169 // #endif
170 }
171
172 spiUnselectI(wifiSpi);
173
174 return M2M_SUCCESS;
175}

◆ resetSpiDevice()

void resetSpiDevice ( SPIDriver *  spi)

Variable Documentation

◆ egstrNmBusCapabilities

tstrNmBusCapabilities egstrNmBusCapabilities = { .u16MaxTrxSz = 4096 }

Definition at line 50 of file wifi_bsp.cpp.

50{ .u16MaxTrxSz = 4096 };

◆ gpfIsr

tpfNmBspIsr gpfIsr = nullptr
static

Definition at line 22 of file wifi_bsp.cpp.

Referenced by isrAdapter(), and nm_bsp_register_isr().

◆ isrEnabled

bool isrEnabled = false
static

Definition at line 30 of file wifi_bsp.cpp.

Referenced by nm_bsp_interrupt_ctrl().

◆ wifi_spicfg

static SPIConfig wifi_spicfg
Initial value:
= {
.circular = false,
.end_cb = NULL,
.ssport = NULL,
.sspad = 0,
.cfg1 = 7
| 2 << 28 ,
.cfg2 = 0
}

Definition at line 55 of file wifi_bsp.cpp.

55 {
56 .circular = false,
57 .end_cb = NULL,
58 .ssport = NULL,
59 .sspad = 0,
60 .cfg1 = 7 // 8 bits per byte
61 | 2 << 28 /* MBR = 2, divider = 8 */,
62 .cfg2 = 0
63};

Referenced by nm_bus_init().

◆ wifiCs

OutputPin wifiCs
static

Definition at line 81 of file wifi_bsp.cpp.

Referenced by nm_bus_init().

◆ wifiReset

OutputPin wifiReset
static

Definition at line 82 of file wifi_bsp.cpp.

Referenced by nm_bus_init().

◆ wifiSpi

SPIDriver* wifiSpi = nullptr
static

Definition at line 48 of file wifi_bsp.cpp.

Referenced by nm_bus_deinit(), nm_bus_init(), and nm_spi_rw().

Go to the source code of this file.