Scott Feldman e7931c6a22 wifinina: fix concurrency issues with multiple sockets
wifinina driver was not handling concurrent socket connections
correctly.  When trying to make multiple socket connections, the sockfd
returned by the first Socket() call would be the same sockfd returned by
subsequent Socket() calls.  The problem is the sockfd returned by
Socket() isn't used until Connect() (or Appect()).  This would result in
Connect() trying to use the same sockfd for multiple connections,
causing wifinina fw to lock up.

The solution in this PR is to create a new sockfd space managed by the
driver that gives the app a unique, safe sockfd for each connection.
The real underlying sock fd returned by fw is set on Connect() (or
Accept()), and mapped back to the apps sockfd using a map:

    sockets map[int]*Socket // keyed by sockfd

Where Socket has a reference to the fw sock:

    type Socket struct {
            protocol        int
            clientConnected bool
            laddr           netip.AddrPort // Set in Bind()
            raddr           netip.AddrPort // Set in Connect()
            sock                           // Device socket, as returned from w.getSocket()
    }
2024-01-22 13:32:57 -08:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2021-05-12 09:21:52 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2021-05-30 22:11:27 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2022-12-19 22:01:39 +01:00
2022-12-21 17:47:14 -05:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-12-19 09:33:54 +01:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2021-03-26 18:10:39 +01:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2023-07-02 18:30:11 +02:00
2023-05-20 15:49:13 +02:00
2023-08-27 11:38:33 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2023-09-20 19:14:17 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2021-05-12 15:29:18 +02:00
2023-10-25 09:57:40 +02:00
2022-09-25 13:23:16 +02:00
2023-09-19 08:31:43 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-07-02 18:30:11 +02:00
2022-09-25 13:23:16 +02:00
2023-05-21 00:32:05 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2022-09-25 13:23:16 +02:00
2021-12-14 09:14:10 +09:00
2021-03-28 12:23:16 +02:00
2022-09-25 13:23:16 +02:00
2023-12-06 20:09:39 +01:00
2023-12-06 20:09:39 +01:00
2023-07-02 18:30:11 +02:00
2023-04-30 01:11:18 +02:00
2023-05-07 12:30:44 +02:00
2021-04-02 17:31:28 +02:00

TinyGo Drivers

PkgGoDev Build

This package provides a collection of 101 different hardware drivers for devices such as sensors and displays that can be used together with TinyGo.

For the complete list, please see: https://tinygo.org/docs/reference/devices/

Installing

go get tinygo.org/x/drivers

How to use

Here is an example in TinyGo that uses the BMP180 digital barometer:

package main

import (
    "time"

    "machine"

    "tinygo.org/x/drivers/bmp180"
)

func main() {
    machine.I2C0.Configure(machine.I2CConfig{})
    sensor := bmp180.New(machine.I2C0)
    sensor.Configure()

    connected := sensor.Connected()
    if !connected {
        println("BMP180 not detected")
        return
    }
    println("BMP180 detected")

    for {
        temp, _ := sensor.ReadTemperature()
        println("Temperature:", float32(temp)/1000, "°C")

        pressure, _ := sensor.ReadPressure()
        println("Pressure", float32(pressure)/100000, "hPa")

        time.Sleep(2 * time.Second)
    }
}

Contributing

Your contributions are welcome!

Please take a look at our CONTRIBUTING.md document for details.

License

This project is licensed under the BSD 3-clause license, just like the Go project itself.

S
Description
TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
Readme BSD-3-Clause 26 MiB
Latest
2026-04-21 08:44:44 +00:00
Languages
Go 99.1%
Shell 0.7%