Skip to content

File syn_port_stubs.c

FileList > port_stubs > syn_port_stubs.c

Go to the source code of this file

Weak default implementations for all port functions. More...

  • #include "../common/syn_compiler.h"
  • #include "../common/syn_defs.h"
  • #include "../util/syn_assert.h"
  • #include "../port/syn_port_spi.h"
  • #include "../port/syn_port_i2c.h"
  • #include "../port/syn_port_flash.h"
  • #include "../port/syn_port_adc.h"
  • #include "../port/syn_port_pwm.h"
  • #include "../system/syn_sleep.h"
  • #include "../port/syn_port_exti.h"
  • #include "../port/syn_port_can.h"
  • #include "../port/syn_port_dma.h"
  • #include "../port/syn_port_i2c_async.h"
  • #include "../port/syn_port_spi_async.h"
  • #include "../common/syn_barrier.h"
  • #include "../port/syn_port_socket.h"
  • #include "../port/syn_port_serial.h"

Public Functions

Type Name
SYN_WEAK SYN_NORETURN void syn_assert_failed (const char * file, int line)
Called when an assertion fails.
SYN_WEAK SYN_Status syn_port_adc_init (uint8_t channel)
Initialize an ADC channel.
SYN_WEAK uint16_t syn_port_adc_read (uint8_t channel)
Read a single ADC sample.
SYN_WEAK uint16_t syn_port_adc_reference_mv (void)
Get the ADC reference voltage in millivolts.
SYN_WEAK uint8_t syn_port_adc_resolution (void)
Get the ADC resolution in bits.
SYN_WEAK bool syn_port_can_init (uint8_t port, uint32_t bitrate)
Initialize CAN peripheral.
SYN_WEAK bool syn_port_can_receive (uint8_t port, uint32_t * id, bool * extended, uint8_t * data, uint8_t * dlc)
Receive a CAN frame (non-blocking).
SYN_WEAK bool syn_port_can_send (uint8_t port, uint32_t id, bool extended, const uint8_t * data, uint8_t dlc)
Send a CAN frame.
SYN_WEAK void syn_port_can_set_filter (uint8_t port, uint32_t id, uint32_t mask)
Set hardware acceptance filter.
SYN_WEAK void syn_port_delay_ms (uint32_t ms)
Blocking delay for the specified number of milliseconds.
SYN_WEAK void syn_port_enter_critical (void)
Enter a critical section (disable interrupts).
SYN_WEAK void syn_port_exit_critical (void)
Exit a critical section (re-enable interrupts).
SYN_WEAK void syn_port_exti_clear_pending (SYN_GPIO_Pin pin)
Clear pending interrupt flag for a pin.
SYN_WEAK SYN_Status syn_port_exti_configure (SYN_GPIO_Pin pin, SYN_EXTI_Edge edge)
Configure a pin for interrupt generation.
SYN_WEAK void syn_port_exti_disable (SYN_GPIO_Pin pin)
Disable interrupt on a pin (without deconfiguring).
SYN_WEAK void syn_port_exti_enable (SYN_GPIO_Pin pin)
Enable interrupt on a configured pin.
SYN_WEAK SYN_Status syn_port_flash_erase (uint32_t addr)
Erase a flash sector.
SYN_WEAK SYN_Status syn_port_flash_read (uint32_t addr, void * buf, size_t len)
Read from flash.
SYN_WEAK uint32_t syn_port_flash_sector_size (uint32_t addr)
Get the sector size for the given address.
SYN_WEAK SYN_Status syn_port_flash_write (uint32_t addr, const void * buf, size_t len)
Write to flash.
SYN_WEAK uint32_t syn_port_get_tick_ms (void)
Return the current system tick in milliseconds.
SYN_WEAK SYN_Status syn_port_gpio_deinit (SYN_GPIO_Pin pin)
De-initialize a GPIO pin, returning it to its reset state.
SYN_WEAK SYN_Status syn_port_gpio_init (SYN_GPIO_Pin pin, SYN_GPIO_Mode mode)
Initialize a GPIO pin with the given mode.
SYN_WEAK SYN_GPIO_State syn_port_gpio_read (SYN_GPIO_Pin pin)
Read the current logical state of a pin.
SYN_WEAK SYN_Status syn_port_gpio_toggle (SYN_GPIO_Pin pin)
Toggle the state of an output pin.
SYN_WEAK SYN_Status syn_port_gpio_write (SYN_GPIO_Pin pin, SYN_GPIO_State state)
Write a logical state to an output pin.
SYN_WEAK uint32_t syn_port_hpclock_freq_hz (void)
Return the timer clock frequency in Hz.
SYN_WEAK volatile uint32_t * syn_port_hpclock_lsb_ptr (void)
Return a pointer to the hardware timer count register.
SYN_WEAK SYN_Status syn_port_i2c_deinit (uint8_t bus)
Deinitialize an I2C bus.
SYN_WEAK SYN_Status syn_port_i2c_init (const SYN_I2C_Config * cfg)
Initialize an I2C bus.
SYN_WEAK SYN_Status syn_port_i2c_read (uint8_t bus, uint8_t addr, uint8_t * data, size_t len)
Read data from an I2C device.
SYN_WEAK SYN_Status syn_port_i2c_write (uint8_t bus, uint8_t addr, const uint8_t * data, size_t len)
Write data to an I2C device.
SYN_WEAK SYN_Status syn_port_i2c_write_read (uint8_t bus, uint8_t addr, const uint8_t * tx_data, size_t tx_len, uint8_t * rx_data, size_t rx_len)
Write then read (register access pattern).
SYN_WEAK void syn_port_memory_barrier (void)
SYN_WEAK void syn_port_pwm_enable (uint8_t channel, bool enable)
Enable/disable PWM output.
SYN_WEAK SYN_Status syn_port_pwm_init (uint8_t channel, uint32_t freq_hz)
Initialize a PWM channel.
SYN_WEAK void syn_port_pwm_set_duty (uint8_t channel, uint8_t duty_pct)
Set PWM duty cycle.
SYN_WEAK void syn_port_pwm_set_duty_raw (uint8_t channel, uint16_t duty_u16)
Set PWM duty cycle with fine resolution.
SYN_WEAK void syn_port_pwm_set_freq (uint8_t channel, uint32_t freq_hz)
Set PWM frequency (runtime change).
SYN_WEAK SYN_Status syn_port_serial_init (uint32_t baudrate)
Initialize the console serial port.
SYN_WEAK int syn_port_serial_read (uint8_t * buf, size_t max_len)
Read available bytes from the console (non-blocking).
SYN_WEAK int syn_port_serial_write (const uint8_t * data, size_t len)
Write bytes to the console.
SYN_WEAK void syn_port_sleep (SYN_SleepMode mode)
Enter low-power mode. Implement for your platform.
SYN_WEAK void syn_port_sleep_until (uint32_t wake_tick_ms)
SYN_WEAK SYN_Socket syn_port_sock_accept (SYN_Socket listener, uint32_t timeout_ms)
Accept an incoming connection on a listener socket.
SYN_WEAK void syn_port_sock_close (SYN_Socket sock)
Close a socket and release resources.
SYN_WEAK SYN_Socket syn_port_sock_connect (const SYN_SockAddr * addr)
Connect to a remote host by IP address.
SYN_WEAK SYN_Socket syn_port_sock_connect_host (const char * host, uint16_t port)
Connect to a remote host by hostname.
SYN_WEAK SYN_Socket syn_port_sock_listen (uint16_t port, int backlog)
Create a listening TCP socket on the given port.
SYN_WEAK int syn_port_sock_recv (SYN_Socket sock, void * buf, size_t max_len, uint32_t timeout_ms)
Receive data from a connected socket.
SYN_WEAK int syn_port_sock_send (SYN_Socket sock, const void * data, size_t len)
Send data over a connected socket.
SYN_WEAK int syn_port_sock_send_all (SYN_Socket sock, const void * data, size_t len)
Send all data over a connected socket.
SYN_WEAK SYN_Status syn_port_spi_cs_assert (uint8_t bus, SYN_GPIO_Pin cs_pin)
Assert (pull low) an SPI chip-select pin.
SYN_WEAK SYN_Status syn_port_spi_cs_deassert (uint8_t bus, SYN_GPIO_Pin cs_pin)
Deassert (release high) an SPI chip-select pin.
SYN_WEAK SYN_Status syn_port_spi_deinit (uint8_t bus)
Deinitialize an SPI bus.
SYN_WEAK SYN_Status syn_port_spi_init (const SYN_SPI_Config * cfg)
Initialize an SPI bus.
SYN_WEAK SYN_Status syn_port_spi_transfer (uint8_t bus, const uint8_t * tx_buf, uint8_t * rx_buf, size_t len)
Full-duplex SPI transfer.
SYN_WEAK SYN_NORETURN void syn_port_system_reset (void)
Perform a system reset.
SYN_WEAK SYN_Status syn_port_uart_deinit (SYN_UARTInstance instance)
De-initialize a UART peripheral.
SYN_WEAK SYN_Status syn_port_uart_init (SYN_UARTInstance instance, uint32_t baudrate)
Initialize a UART peripheral.
SYN_WEAK SYN_Status syn_port_uart_receive (SYN_UARTInstance instance, uint8_t * data, size_t len, size_t * received, uint32_t timeout_ms)
Receive bytes into a buffer (blocking).
SYN_WEAK SYN_Status syn_port_uart_receive_byte (SYN_UARTInstance instance, uint8_t * byte, uint32_t timeout_ms)
Receive a single byte (blocking).
SYN_WEAK SYN_Status syn_port_uart_transmit (SYN_UARTInstance instance, const uint8_t * data, size_t len, uint32_t timeout_ms)
Transmit a buffer of bytes (blocking).
SYN_WEAK SYN_Status syn_port_uart_transmit_byte (SYN_UARTInstance instance, uint8_t byte)
Transmit a single byte (blocking).
SYN_WEAK SYN_Status syn_port_udp_join_multicast (SYN_Socket sock, const char * multicast_ip)
Join a multicast group.
SYN_WEAK SYN_Socket syn_port_udp_open (uint16_t port)
Open a UDP socket bound to the given port.
SYN_WEAK int syn_port_udp_recvfrom (SYN_Socket sock, void * buf, size_t max_len, SYN_SockAddr * from, uint32_t timeout_ms)
Receive a UDP packet.
SYN_WEAK int syn_port_udp_sendto (SYN_Socket sock, const void * data, size_t len, const SYN_SockAddr * to)
Send a UDP packet to a destination address.

Detailed Description

Compile this file into your project to catch unimplemented port functions at runtime. Each stub calls syn_assert_failed() with a descriptive message, making it immediately obvious which function you forgot to implement.

If you provide a strong definition of a function in your platform port file, the linker will silently discard the weak stub.

You can also omit this file entirely and rely on the linker to report unresolved symbols at link time — this is a perfectly valid approach.

Public Functions Documentation

function syn_assert_failed

Called when an assertion fails.

SYN_WEAK  SYN_NORETURN void syn_assert_failed (
    const char * file,
    int line
) 

This function is declared weak so you can provide your own implementation. The default (in syn_port_stubs.c) enters an infinite loop.

Parameters:

  • file Source file name where the assertion failed.
  • line Line number where the assertion failed.

function syn_port_adc_init

Initialize an ADC channel.

SYN_WEAK  SYN_Status syn_port_adc_init (
    uint8_t channel
) 

Parameters:

  • channel ADC channel number.

Returns:

SYN_OK on success.


function syn_port_adc_read

Read a single ADC sample.

SYN_WEAK uint16_t syn_port_adc_read (
    uint8_t channel
) 

Parameters:

  • channel ADC channel number.

Returns:

Raw ADC value (resolution depends on platform).


function syn_port_adc_reference_mv

Get the ADC reference voltage in millivolts.

SYN_WEAK uint16_t syn_port_adc_reference_mv (
    void
) 

Returns:

Reference voltage (e.g., 3300 for 3.3V).


function syn_port_adc_resolution

Get the ADC resolution in bits.

SYN_WEAK uint8_t syn_port_adc_resolution (
    void
) 

Returns:

Resolution (e.g., 10, 12, 16).


function syn_port_can_init

Initialize CAN peripheral.

SYN_WEAK  bool syn_port_can_init (
    uint8_t port,
    uint32_t bitrate
) 

Parameters:

  • port CAN port number (0, 1, ...).
  • bitrate Bitrate in bits/sec (e.g. 500000 for 500kbps).

Returns:

true on success.


function syn_port_can_receive

Receive a CAN frame (non-blocking).

SYN_WEAK  bool syn_port_can_receive (
    uint8_t port,
    uint32_t * id,
    bool * extended,
    uint8_t * data,
    uint8_t * dlc
) 

Parameters:

  • port CAN port.
  • id [out] CAN identifier.
  • extended [out] true if 29-bit ID.
  • data [out] Frame data buffer (at least 8 bytes).
  • dlc [out] Data length code.

Returns:

true if a frame was received.


function syn_port_can_send

Send a CAN frame.

SYN_WEAK  bool syn_port_can_send (
    uint8_t port,
    uint32_t id,
    bool extended,
    const uint8_t * data,
    uint8_t dlc
) 

Parameters:

  • port CAN port.
  • id CAN identifier (11-bit or 29-bit).
  • extended true for 29-bit ID.
  • data Frame data (up to 8 bytes).
  • dlc Data length code (0-8).

Returns:

true if frame was queued for transmission.


function syn_port_can_set_filter

Set hardware acceptance filter.

SYN_WEAK void syn_port_can_set_filter (
    uint8_t port,
    uint32_t id,
    uint32_t mask
) 

Parameters:

  • port CAN port.
  • id Filter ID.
  • mask Filter mask (1 = must match, 0 = don't care).

function syn_port_delay_ms

Blocking delay for the specified number of milliseconds.

SYN_WEAK void syn_port_delay_ms (
    uint32_t ms
) 

The implementation may busy-wait or yield to an RTOS. The delay must be at least ms milliseconds.

Parameters:

  • ms Number of milliseconds to delay.

function syn_port_enter_critical

Enter a critical section (disable interrupts).

SYN_WEAK void syn_port_enter_critical (
    void
) 

Calls may be nested; the implementation must track nesting depth and only re-enable interrupts when the outermost critical section exits.


function syn_port_exit_critical

Exit a critical section (re-enable interrupts).

SYN_WEAK void syn_port_exit_critical (
    void
) 

Must be called once for each corresponding syn_port_enter_critical().


function syn_port_exti_clear_pending

Clear pending interrupt flag for a pin.

SYN_WEAK void syn_port_exti_clear_pending (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin GPIO pin.

function syn_port_exti_configure

Configure a pin for interrupt generation.

SYN_WEAK  SYN_Status syn_port_exti_configure (
    SYN_GPIO_Pin pin,
    SYN_EXTI_Edge edge
) 

Parameters:

  • pin GPIO pin number.
  • edge Trigger edge.

Returns:

SYN_OK on success.


function syn_port_exti_disable

Disable interrupt on a pin (without deconfiguring).

SYN_WEAK void syn_port_exti_disable (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin GPIO pin.

function syn_port_exti_enable

Enable interrupt on a configured pin.

SYN_WEAK void syn_port_exti_enable (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin GPIO pin.

function syn_port_flash_erase

Erase a flash sector.

SYN_WEAK  SYN_Status syn_port_flash_erase (
    uint32_t addr
) 

Parameters:

  • addr Start address of the sector (must be sector-aligned).

Returns:

SYN_OK on success.


function syn_port_flash_read

Read from flash.

SYN_WEAK  SYN_Status syn_port_flash_read (
    uint32_t addr,
    void * buf,
    size_t len
) 

Parameters:

  • addr Source address in flash.
  • buf Destination buffer.
  • len Number of bytes to read.

Returns:

SYN_OK on success.


function syn_port_flash_sector_size

Get the sector size for the given address.

SYN_WEAK uint32_t syn_port_flash_sector_size (
    uint32_t addr
) 

Parameters:

  • addr Address within the sector.

Returns:

Sector size in bytes.


function syn_port_flash_write

Write to flash.

SYN_WEAK  SYN_Status syn_port_flash_write (
    uint32_t addr,
    const void * buf,
    size_t len
) 

Flash must be erased before writing (writes can only clear bits). The implementation should handle any alignment requirements.

Parameters:

  • addr Destination address in flash.
  • buf Source data.
  • len Number of bytes to write.

Returns:

SYN_OK on success.


function syn_port_get_tick_ms

Return the current system tick in milliseconds.

SYN_WEAK uint32_t syn_port_get_tick_ms (
    void
) 

This value must be monotonically increasing and should wrap naturally at UINT32_MAX. Typical sources: SysTick, a hardware timer, or an RTOS tick.

Returns:

Milliseconds since system start (or last wrap).


function syn_port_gpio_deinit

De-initialize a GPIO pin, returning it to its reset state.

SYN_WEAK  SYN_Status syn_port_gpio_deinit (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin Pin to de-initialize.

Returns:

SYN_OK on success.


function syn_port_gpio_init

Initialize a GPIO pin with the given mode.

SYN_WEAK  SYN_Status syn_port_gpio_init (
    SYN_GPIO_Pin pin,
    SYN_GPIO_Mode mode
) 

Parameters:

  • pin Platform-specific pin identifier.
  • mode Desired pin mode (input, output, etc.).

Returns:

SYN_OK on success, or an error code.


function syn_port_gpio_read

Read the current logical state of a pin.

SYN_WEAK  SYN_GPIO_State syn_port_gpio_read (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin Pin to read.

Returns:

SYN_GPIO_HIGH or SYN_GPIO_LOW.


function syn_port_gpio_toggle

Toggle the state of an output pin.

SYN_WEAK  SYN_Status syn_port_gpio_toggle (
    SYN_GPIO_Pin pin
) 

Parameters:

  • pin Pin to toggle.

Returns:

SYN_OK on success.


function syn_port_gpio_write

Write a logical state to an output pin.

SYN_WEAK  SYN_Status syn_port_gpio_write (
    SYN_GPIO_Pin pin,
    SYN_GPIO_State state
) 

Parameters:

  • pin Pin to write.
  • state SYN_GPIO_HIGH or SYN_GPIO_LOW.

Returns:

SYN_OK on success.


function syn_port_hpclock_freq_hz

Return the timer clock frequency in Hz.

SYN_WEAK uint32_t syn_port_hpclock_freq_hz (
    void
) 

Used for tick-to-nanosecond conversion. Must be a compile-time constant or a value that does not change after initialization.

Returns:

Timer frequency in Hz (e.g. 16000000 for 16 MHz).


function syn_port_hpclock_lsb_ptr

Return a pointer to the hardware timer count register.

SYN_WEAK volatile uint32_t * syn_port_hpclock_lsb_ptr (
    void
) 

The returned pointer must be volatile and point to a memory-mapped register that increments at the rate returned by syn_port_hpclock_freq_hz().

Returns:

Pointer to the timer counter register.


function syn_port_i2c_deinit

Deinitialize an I2C bus.

SYN_WEAK  SYN_Status syn_port_i2c_deinit (
    uint8_t bus
) 

Parameters:

  • bus I2C bus index.

Returns:

SYN_OK on success.


function syn_port_i2c_init

Initialize an I2C bus.

SYN_WEAK  SYN_Status syn_port_i2c_init (
    const SYN_I2C_Config * cfg
) 

Parameters:

  • cfg I2C configuration.

Returns:

SYN_OK on success.


function syn_port_i2c_read

Read data from an I2C device.

SYN_WEAK  SYN_Status syn_port_i2c_read (
    uint8_t bus,
    uint8_t addr,
    uint8_t * data,
    size_t len
) 

Parameters:

  • bus I2C bus index.
  • addr 7-bit device address.
  • data Buffer to receive data.
  • len Number of bytes to read.

Returns:

SYN_OK on ACK, SYN_ERROR on NACK/timeout.


function syn_port_i2c_write

Write data to an I2C device.

SYN_WEAK  SYN_Status syn_port_i2c_write (
    uint8_t bus,
    uint8_t addr,
    const uint8_t * data,
    size_t len
) 

Parameters:

  • bus I2C bus index.
  • addr 7-bit device address.
  • data Data to write.
  • len Number of bytes.

Returns:

SYN_OK on ACK, SYN_ERROR on NACK/timeout.


function syn_port_i2c_write_read

Write then read (register access pattern).

SYN_WEAK  SYN_Status syn_port_i2c_write_read (
    uint8_t bus,
    uint8_t addr,
    const uint8_t * tx_data,
    size_t tx_len,
    uint8_t * rx_data,
    size_t rx_len
) 

Sends a write (typically a register address) followed by a repeated start and read. This is the most common I2C transaction pattern.

Parameters:

  • bus I2C bus index.
  • addr 7-bit device address.
  • tx_data Data to write (e.g., register address).
  • tx_len Write length.
  • rx_data Buffer for read data.
  • rx_len Read length.

Returns:

SYN_OK on success.


function syn_port_memory_barrier

SYN_WEAK void syn_port_memory_barrier (
    void
) 

function syn_port_pwm_enable

Enable/disable PWM output.

SYN_WEAK void syn_port_pwm_enable (
    uint8_t channel,
    bool enable
) 

Parameters:

  • channel PWM channel index.
  • enable true to enable, false to disable.

function syn_port_pwm_init

Initialize a PWM channel.

SYN_WEAK  SYN_Status syn_port_pwm_init (
    uint8_t channel,
    uint32_t freq_hz
) 

Parameters:

  • channel PWM channel number.
  • freq_hz PWM frequency in Hz.

Returns:

SYN_OK on success.


function syn_port_pwm_set_duty

Set PWM duty cycle.

SYN_WEAK void syn_port_pwm_set_duty (
    uint8_t channel,
    uint8_t duty_pct
) 

Parameters:

  • channel PWM channel number.
  • duty_pct Duty cycle 0–100 (percent).

function syn_port_pwm_set_duty_raw

Set PWM duty cycle with fine resolution.

SYN_WEAK void syn_port_pwm_set_duty_raw (
    uint8_t channel,
    uint16_t duty_u16
) 

Parameters:

  • channel PWM channel number.
  • duty_u16 Duty cycle 0–65535 (0 = off, 65535 = 100%).

function syn_port_pwm_set_freq

Set PWM frequency (runtime change).

SYN_WEAK void syn_port_pwm_set_freq (
    uint8_t channel,
    uint32_t freq_hz
) 

Parameters:

  • channel PWM channel number.
  • freq_hz New frequency in Hz.

function syn_port_serial_init

Initialize the console serial port.

SYN_WEAK  SYN_Status syn_port_serial_init (
    uint32_t baudrate
) 

Parameters:

  • baudrate Desired baud rate. Pass 0 for default (or if the underlying transport ignores baud rate, e.g. USB CDC).

Returns:

SYN_OK on success.


function syn_port_serial_read

Read available bytes from the console (non-blocking).

SYN_WEAK int syn_port_serial_read (
    uint8_t * buf,
    size_t max_len
) 

Returns immediately with however many bytes are available, up to max_len. Returns 0 if no data is available. Never blocks.

Parameters:

  • buf Buffer to read into.
  • max_len Maximum bytes to read.

Returns:

Number of bytes read (0 if nothing available), or -1 on error.


function syn_port_serial_write

Write bytes to the console.

SYN_WEAK int syn_port_serial_write (
    const uint8_t * data,
    size_t len
) 

Writes up to len bytes. May briefly block if the transmit buffer is full, but must not spin indefinitely.

Parameters:

  • data Data to write.
  • len Number of bytes.

Returns:

Number of bytes actually written, or -1 on error.


function syn_port_sleep

Enter low-power mode. Implement for your platform.

SYN_WEAK void syn_port_sleep (
    SYN_SleepMode mode
) 

For Cortex-M: SYN_SLEEP_LIGHT → WFI, SYN_SLEEP_DEEP → STOP mode. Must return when an interrupt wakes the MCU.

Parameters:

  • mode Requested sleep depth.

function syn_port_sleep_until

SYN_WEAK void syn_port_sleep_until (
    uint32_t wake_tick_ms
) 

function syn_port_sock_accept

Accept an incoming connection on a listener socket.

SYN_WEAK  SYN_Socket syn_port_sock_accept (
    SYN_Socket listener,
    uint32_t timeout_ms
) 

Blocks until a connection arrives or the timeout expires.

Parameters:

  • listener Listener socket from syn_port_sock_listen().
  • timeout_ms Timeout in milliseconds (0 = block indefinitely).

Returns:

Connected socket handle, or SYN_SOCKET_INVALID on timeout/error.


function syn_port_sock_close

Close a socket and release resources.

SYN_WEAK void syn_port_sock_close (
    SYN_Socket sock
) 

Parameters:

  • sock Socket handle to close.

function syn_port_sock_connect

Connect to a remote host by IP address.

SYN_WEAK  SYN_Socket syn_port_sock_connect (
    const SYN_SockAddr * addr
) 

Opens a TCP connection. Blocking.

Parameters:

  • addr Remote address (IPv4 + port).

Returns:

Socket handle on success, SYN_SOCKET_INVALID on failure.


function syn_port_sock_connect_host

Connect to a remote host by hostname.

SYN_WEAK  SYN_Socket syn_port_sock_connect_host (
    const char * host,
    uint16_t port
) 

Performs DNS resolution and opens a TCP connection. Blocking.

Parameters:

  • host Hostname or dotted-decimal IP string.
  • port Port number.

Returns:

Socket handle on success, SYN_SOCKET_INVALID on failure.


function syn_port_sock_listen

Create a listening TCP socket on the given port.

SYN_WEAK  SYN_Socket syn_port_sock_listen (
    uint16_t port,
    int backlog
) 

Binds to all interfaces and begins listening for connections.

Parameters:

  • port Port number to listen on.
  • backlog Maximum pending connections (typically 1–5).

Returns:

Listener socket handle, or SYN_SOCKET_INVALID on failure.


function syn_port_sock_recv

Receive data from a connected socket.

SYN_WEAK int syn_port_sock_recv (
    SYN_Socket sock,
    void * buf,
    size_t max_len,
    uint32_t timeout_ms
) 

Returns available data up to max_len. Blocks up to timeout_ms.

Parameters:

  • sock Socket handle.
  • buf Receive buffer.
  • max_len Buffer capacity.
  • timeout_ms Timeout in milliseconds (0 = non-blocking).

Returns:

Number of bytes received, 0 if connection closed, -1 on error/timeout.


function syn_port_sock_send

Send data over a connected socket.

SYN_WEAK int syn_port_sock_send (
    SYN_Socket sock,
    const void * data,
    size_t len
) 

May send fewer bytes than requested (partial send).

Parameters:

  • sock Socket handle.
  • data Data to send.
  • len Number of bytes to send.

Returns:

Number of bytes sent, or -1 on error.


function syn_port_sock_send_all

Send all data over a connected socket.

SYN_WEAK int syn_port_sock_send_all (
    SYN_Socket sock,
    const void * data,
    size_t len
) 

Loops internally until all bytes are sent or an error occurs.

Parameters:

  • sock Socket handle.
  • data Data to send.
  • len Number of bytes to send.

Returns:

Number of bytes sent (== len on success), or -1 on error.


function syn_port_spi_cs_assert

Assert (pull low) an SPI chip-select pin.

SYN_WEAK  SYN_Status syn_port_spi_cs_assert (
    uint8_t bus,
    SYN_GPIO_Pin cs_pin
) 

Parameters:

  • bus SPI bus index.
  • cs_pin Chip-select GPIO pin.

Returns:

SYN_OK on success.


function syn_port_spi_cs_deassert

Deassert (release high) an SPI chip-select pin.

SYN_WEAK  SYN_Status syn_port_spi_cs_deassert (
    uint8_t bus,
    SYN_GPIO_Pin cs_pin
) 

Parameters:

  • bus SPI bus index.
  • cs_pin Chip-select GPIO pin.

Returns:

SYN_OK on success.


function syn_port_spi_deinit

Deinitialize an SPI bus.

SYN_WEAK  SYN_Status syn_port_spi_deinit (
    uint8_t bus
) 

Parameters:

  • bus SPI bus index.

Returns:

SYN_OK on success.


function syn_port_spi_init

Initialize an SPI bus.

SYN_WEAK  SYN_Status syn_port_spi_init (
    const SYN_SPI_Config * cfg
) 

Parameters:

  • cfg SPI configuration.

Returns:

SYN_OK on success.


function syn_port_spi_transfer

Full-duplex SPI transfer.

SYN_WEAK  SYN_Status syn_port_spi_transfer (
    uint8_t bus,
    const uint8_t * tx_buf,
    uint8_t * rx_buf,
    size_t len
) 

Simultaneously transmits from tx_buf and receives into rx_buf. Either buffer can be NULL for half-duplex operation.

Parameters:

  • bus SPI bus index.
  • tx_buf Transmit buffer (NULL to send 0x00/0xFF).
  • rx_buf Receive buffer (NULL to discard received data).
  • len Number of bytes to transfer.

Returns:

SYN_OK on success.


function syn_port_system_reset

Perform a system reset.

SYN_WEAK  SYN_NORETURN void syn_port_system_reset (
    void
) 

This function should not return. On Cortex-M, this is typically NVIC_SystemReset().


function syn_port_uart_deinit

De-initialize a UART peripheral.

SYN_WEAK  SYN_Status syn_port_uart_deinit (
    SYN_UARTInstance instance
) 

Parameters:

  • instance UART instance to de-initialize.

Returns:

SYN_OK on success.


function syn_port_uart_init

Initialize a UART peripheral.

SYN_WEAK  SYN_Status syn_port_uart_init (
    SYN_UARTInstance instance,
    uint32_t baudrate
) 

Parameters:

  • instance UART instance number (0, 1, 2, …).
  • baudrate Desired baud rate.

Returns:

SYN_OK on success.


function syn_port_uart_receive

Receive bytes into a buffer (blocking).

SYN_WEAK  SYN_Status syn_port_uart_receive (
    SYN_UARTInstance instance,
    uint8_t * data,
    size_t len,
    size_t * received,
    uint32_t timeout_ms
) 

Parameters:

  • instance UART instance.
  • data Buffer to receive into.
  • len Maximum number of bytes to receive.
  • received [out] Actual number of bytes received.
  • timeout_ms Timeout in milliseconds (0 = no timeout).

Returns:

SYN_OK on success, SYN_TIMEOUT if the timeout elapsed.


function syn_port_uart_receive_byte

Receive a single byte (blocking).

SYN_WEAK  SYN_Status syn_port_uart_receive_byte (
    SYN_UARTInstance instance,
    uint8_t * byte,
    uint32_t timeout_ms
) 

Parameters:

  • instance UART instance.
  • byte [out] Received byte.
  • timeout_ms Timeout in milliseconds (0 = no timeout).

Returns:

SYN_OK if a byte was received, SYN_TIMEOUT otherwise.


function syn_port_uart_transmit

Transmit a buffer of bytes (blocking).

SYN_WEAK  SYN_Status syn_port_uart_transmit (
    SYN_UARTInstance instance,
    const uint8_t * data,
    size_t len,
    uint32_t timeout_ms
) 

Parameters:

  • instance UART instance.
  • data Pointer to data to transmit.
  • len Number of bytes to transmit.
  • timeout_ms Timeout in milliseconds (0 = no timeout).

Returns:

SYN_OK on success, SYN_TIMEOUT if the timeout elapsed.


function syn_port_uart_transmit_byte

Transmit a single byte (blocking).

SYN_WEAK  SYN_Status syn_port_uart_transmit_byte (
    SYN_UARTInstance instance,
    uint8_t byte
) 

Parameters:

  • instance UART instance.
  • byte Byte to transmit.

Returns:

SYN_OK on success.


function syn_port_udp_join_multicast

Join a multicast group.

SYN_WEAK  SYN_Status syn_port_udp_join_multicast (
    SYN_Socket sock,
    const char * multicast_ip
) 

Parameters:

  • sock UDP socket handle.
  • multicast_ip Multicast IP string (e.g. "224.0.0.251").

Returns:

SYN_OK on success, SYN_ERROR on failure.


function syn_port_udp_open

Open a UDP socket bound to the given port.

SYN_WEAK  SYN_Socket syn_port_udp_open (
    uint16_t port
) 

Parameters:

  • port Local port to bind to, or 0 for ephemeral.

Returns:

Socket handle on success, SYN_SOCKET_INVALID on failure.


function syn_port_udp_recvfrom

Receive a UDP packet.

SYN_WEAK int syn_port_udp_recvfrom (
    SYN_Socket sock,
    void * buf,
    size_t max_len,
    SYN_SockAddr * from,
    uint32_t timeout_ms
) 

Parameters:

  • sock Socket handle.
  • buf Receive buffer.
  • max_len Buffer capacity.
  • from [out] Source address.
  • timeout_ms Receive timeout in milliseconds. If 0, must return immediately (non-blocking poll). Cooperative tasks (protothreads) rely on this to avoid blocking the scheduler. Port implementations MUST NOT treat 0 as "block forever."

Returns:

Number of bytes received, 0 if no data available (non-blocking), or -1 on error.


function syn_port_udp_sendto

Send a UDP packet to a destination address.

SYN_WEAK int syn_port_udp_sendto (
    SYN_Socket sock,
    const void * data,
    size_t len,
    const SYN_SockAddr * to
) 

Parameters:

  • sock Socket handle.
  • data Payload to send.
  • len Payload length.
  • to Destination address (IP + port).

Returns:

Number of bytes sent, or -1 on error.



The documentation for this class was generated from the following file src/syntropic/port_stubs/syn_port_stubs.c