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_i2c.h"#include "../port/syn_port_spi.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_deinit (uint8_t adc_id) De-initialize the ADC peripheral. |
| SYN_WEAK SYN_Status | syn_port_adc_init (uint8_t adc_id, uint32_t channel_mask) Initialize the ADC peripheral. |
| SYN_WEAK uint16_t | syn_port_adc_read_channel (uint8_t adc_id, uint8_t channel) Read a single analog channel (single-shot polled read). |
| SYN_WEAK SYN_Status | syn_port_adc_start_dma_scan (uint8_t adc_id, uint16_t * dest, size_t num_channels) Start continuous multi-channel background scan via DMA. |
| SYN_WEAK SYN_Status | syn_port_aes_decrypt_block (const uint8_t * round_keys, uint8_t nr, const uint8_t in, uint8_t out) Offload a single 16-byte block decryption to hardware. |
| SYN_WEAK SYN_Status | syn_port_aes_encrypt_block (const uint8_t * round_keys, uint8_t nr, const uint8_t in, uint8_t out) Offload a single 16-byte block encryption to hardware. |
| SYN_WEAK SYN_Status | syn_port_aes_init (void) Initialize the hardware AES/crypto accelerator. |
| SYN_WEAK SYN_Status | syn_port_ble_hci_reset (void) Reset external BLE controller hardware via GPIO reset pin (if present). |
| SYN_WEAK SYN_Status | syn_port_ble_hci_tx (const uint8_t * data, uint16_t len) Transmit raw bytes to external BLE controller via UART/SPI hardware. |
| 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 uint32_t | syn_port_get_tick_us (void) Return the current system tick in microseconds. |
| SYN_WEAK SYN_Status | syn_port_ghash_mult (const uint8_t x, const uint8_t h, uint8_t out) Offload GHASH Galois field GF(2^128) multiplication to hardware. |
| 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 i2c_id) De-initialize an I2C hardware instance. |
| SYN_WEAK SYN_Status | syn_port_i2c_init (uint8_t i2c_id, uint32_t clock_speed_hz, uint8_t role, uint16_t own_addr) Initialize an I2C hardware instance. |
| SYN_WEAK SYN_Status | syn_port_i2c_read (uint8_t bus, uint8_t addr, uint8_t * data, size_t len) |
| SYN_WEAK SYN_Status | syn_port_i2c_transfer (uint8_t i2c_id, uint16_t addr, const uint8_t * tx, size_t tx_len, uint8_t * rx, size_t rx_len) Perform an I2C transaction (Write, Read, or Write-Then-Read restart). |
| 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) |
| 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_deinit (uint8_t spi_id) De-initialize an SPI hardware instance. |
| SYN_WEAK SYN_Status | syn_port_spi_init (uint8_t spi_id, uint32_t baudrate_hz, uint8_t mode, uint8_t role) Initialize an SPI hardware instance. |
| SYN_WEAK SYN_Status | syn_port_spi_transfer (uint8_t spi_id, const uint8_t * tx, uint8_t * rx, size_t len) Perform a full-duplex simultaneous 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.
This function is declared weak so you can provide your own implementation. The default (in syn_port_stubs.c) enters an infinite loop.
Parameters:
fileSource file name where the assertion failed.lineLine number where the assertion failed.
function syn_port_adc_deinit¶
De-initialize the ADC peripheral.
Parameters:
adc_idADC instance index.
Returns:
SYN_OK on success.
function syn_port_adc_init¶
Initialize the ADC peripheral.
Parameters:
adc_idADC instance index (0 = ADC1, 1 = ADC2, etc.).channel_maskBitmask of channels to configure for analog input.
Returns:
SYN_OK on success.
function syn_port_adc_read_channel¶
Read a single analog channel (single-shot polled read).
Parameters:
adc_idADC instance index.channelChannel index (0..18).
Returns:
12-bit raw conversion value (0..4095).
function syn_port_adc_start_dma_scan¶
Start continuous multi-channel background scan via DMA.
SYN_WEAK SYN_Status syn_port_adc_start_dma_scan (
uint8_t adc_id,
uint16_t * dest,
size_t num_channels
)
Parameters:
adc_idADC instance index.destDestination buffer in SRAM.num_channelsNumber of active channels in scan sequence.
Returns:
SYN_OK on success.
function syn_port_aes_decrypt_block¶
Offload a single 16-byte block decryption to hardware.
SYN_WEAK SYN_Status syn_port_aes_decrypt_block (
const uint8_t * round_keys,
uint8_t nr,
const uint8_t in,
uint8_t out
)
Parameters:
round_keysPointer to expanded round keys.nrNumber of rounds (10, 12, or 14).inInput 16-byte ciphertext block.outOutput 16-byte plaintext block.
Returns:
SYN_OK on success, SYN_NOT_IMPLEMENTED to use software AES.
function syn_port_aes_encrypt_block¶
Offload a single 16-byte block encryption to hardware.
SYN_WEAK SYN_Status syn_port_aes_encrypt_block (
const uint8_t * round_keys,
uint8_t nr,
const uint8_t in,
uint8_t out
)
Parameters:
round_keysPointer to expanded round keys.nrNumber of rounds (10, 12, or 14).inInput 16-byte plaintext block.outOutput 16-byte ciphertext block.
Returns:
SYN_OK on success, SYN_NOT_IMPLEMENTED to use software AES.
function syn_port_aes_init¶
Initialize the hardware AES/crypto accelerator.
Returns:
SYN_OK on success, SYN_NOT_IMPLEMENTED if hardware crypto is not available.
function syn_port_ble_hci_reset¶
Reset external BLE controller hardware via GPIO reset pin (if present).
Returns:
SYN_OK on success, or SYN_ERR_NOT_SUPPORTED if unmapped.
function syn_port_ble_hci_tx¶
Transmit raw bytes to external BLE controller via UART/SPI hardware.
Parameters:
dataData buffer pointer.lenData length in bytes.
Returns:
SYN_OK on success.
function syn_port_can_init¶
Initialize CAN peripheral.
Parameters:
portCAN port number (0, 1, ...).bitrateBitrate 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:
portCAN 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:
portCAN port.idCAN identifier (11-bit or 29-bit).extendedtrue for 29-bit ID.dataFrame data (up to 8 bytes).dlcData length code (0-8).
Returns:
true if frame was queued for transmission.
function syn_port_can_set_filter¶
Set hardware acceptance filter.
Parameters:
portCAN port.idFilter ID.maskFilter mask (1 = must match, 0 = don't care).
function syn_port_delay_ms¶
Blocking delay for the specified number of milliseconds.
Parameters:
msDelay duration in milliseconds.
function syn_port_enter_critical¶
Enter a critical section (disable interrupts).
function syn_port_exit_critical¶
Exit a critical section (re-enable interrupts).
function syn_port_exti_clear_pending¶
Clear pending interrupt flag for a pin.
Parameters:
pinGPIO pin.
function syn_port_exti_configure¶
Configure a pin for interrupt generation.
Parameters:
pinGPIO pin number.edgeTrigger edge.
Returns:
SYN_OK on success.
function syn_port_exti_disable¶
Disable interrupt on a pin (without deconfiguring).
Parameters:
pinGPIO pin.
function syn_port_exti_enable¶
Enable interrupt on a configured pin.
Parameters:
pinGPIO pin.
function syn_port_flash_erase¶
Erase a flash sector.
Parameters:
addrStart address of the sector (must be sector-aligned).
Returns:
SYN_OK on success.
function syn_port_flash_read¶
Read from flash.
Parameters:
addrSource address in flash.bufDestination buffer.lenNumber of bytes to read.
Returns:
SYN_OK on success.
function syn_port_flash_sector_size¶
Get the sector size for the given address.
Parameters:
addrAddress within the sector.
Returns:
Sector size in bytes.
function syn_port_flash_write¶
Write to flash.
Flash must be erased before writing (writes can only clear bits). The implementation should handle any alignment requirements.
Parameters:
addrDestination address in flash.bufSource data.lenNumber of bytes to write.
Returns:
SYN_OK on success.
function syn_port_get_tick_ms¶
Return the current system tick in milliseconds.
Returns:
Current system tick count in milliseconds.
function syn_port_get_tick_us¶
Return the current system tick in microseconds.
Returns:
Current system tick count in microseconds.
function syn_port_ghash_mult¶
Offload GHASH Galois field GF(2^128) multiplication to hardware.
Parameters:
xInput 16-byte block.hInput 16-byte subkey block.outOutput 16-byte product block.
Returns:
SYN_OK on success, SYN_NOT_IMPLEMENTED to use software GHASH.
function syn_port_gpio_deinit¶
De-initialize a GPIO pin, returning it to its reset state.
Parameters:
pinPin to de-initialize.
Returns:
SYN_OK on success.
function syn_port_gpio_init¶
Initialize a GPIO pin with the given mode.
Parameters:
pinPlatform-specific pin identifier.modeDesired 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.
Parameters:
pinPin to read.
Returns:
SYN_GPIO_HIGH or SYN_GPIO_LOW.
function syn_port_gpio_toggle¶
Toggle the state of an output pin.
Parameters:
pinPin to toggle.
Returns:
SYN_OK on success.
function syn_port_gpio_write¶
Write a logical state to an output pin.
Parameters:
pinPin to write.stateSYN_GPIO_HIGH or SYN_GPIO_LOW.
Returns:
SYN_OK on success.
function syn_port_hpclock_freq_hz¶
Return the timer clock frequency in Hz.
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.
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¶
De-initialize an I2C hardware instance.
Parameters:
i2c_idInstance index.
Returns:
SYN_OK on success.
function syn_port_i2c_init¶
Initialize an I2C hardware instance.
SYN_WEAK SYN_Status syn_port_i2c_init (
uint8_t i2c_id,
uint32_t clock_speed_hz,
uint8_t role,
uint16_t own_addr
)
Parameters:
i2c_idInstance index (0 = I2C1, 1 = I2C2).clock_speed_hzBus clock frequency in Hz (e.g. 100000, 400000).role0 = Master, 1 = Slave.own_addr7-bit own slave address (used in Slave mode).
Returns:
SYN_OK on success.
function syn_port_i2c_read¶
function syn_port_i2c_transfer¶
Perform an I2C transaction (Write, Read, or Write-Then-Read restart).
SYN_WEAK SYN_Status syn_port_i2c_transfer (
uint8_t i2c_id,
uint16_t addr,
const uint8_t * tx,
size_t tx_len,
uint8_t * rx,
size_t rx_len
)
Parameters:
i2c_idInstance index.addrTarget 7-bit slave address.txTX data buffer (can be NULL if rx_len > 0).tx_lenBytes to transmit.rxRX destination buffer (can be NULL if tx_len > 0).rx_lenBytes to receive.
Returns:
SYN_OK on success.
function syn_port_i2c_write_read¶
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
)
function syn_port_memory_barrier¶
function syn_port_pwm_enable¶
Enable/disable PWM output.
Parameters:
channelPWM channel index.enabletrue to enable, false to disable.
function syn_port_pwm_init¶
Initialize a PWM channel.
Parameters:
channelPWM channel number.freq_hzPWM frequency in Hz.
Returns:
SYN_OK on success.
function syn_port_pwm_set_duty¶
Set PWM duty cycle.
Parameters:
channelPWM channel number.duty_pctDuty cycle 0–100 (percent).
function syn_port_pwm_set_duty_raw¶
Set PWM duty cycle with fine resolution.
Parameters:
channelPWM channel number.duty_u16Duty cycle 0–65535 (0 = off, 65535 = 100%).
function syn_port_pwm_set_freq¶
Set PWM frequency (runtime change).
Parameters:
channelPWM channel number.freq_hzNew frequency in Hz.
function syn_port_serial_init¶
Initialize the console serial port.
Parameters:
baudrateDesired 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).
Returns immediately with however many bytes are available, up to max_len. Returns 0 if no data is available. Never blocks.
Parameters:
bufBuffer to read into.max_lenMaximum 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.
Writes up to len bytes. May briefly block if the transmit buffer is full, but must not spin indefinitely.
Parameters:
dataData to write.lenNumber of bytes.
Returns:
Number of bytes actually written, or -1 on error.
function syn_port_sleep¶
Enter low-power mode. Implement for your platform.
For Cortex-M: SYN_SLEEP_LIGHT → WFI, SYN_SLEEP_DEEP → STOP mode. Must return when an interrupt wakes the MCU.
Note:
The tickless scheduler calls this inside a critical section (interrupts masked). The implementation must use a sleep instruction that wakes on pending-but-masked interrupts (WFI on Cortex-M) and must NOT re-enable interrupts itself.
Parameters:
modeRequested sleep depth.
function syn_port_sleep_until¶
function syn_port_sock_accept¶
Accept an incoming connection on a listener socket.
Blocks until a connection arrives or the timeout expires.
Parameters:
listenerListener socket from syn_port_sock_listen().timeout_msTimeout 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.
Parameters:
sockSocket handle to close.
function syn_port_sock_connect¶
Connect to a remote host by IP address.
Opens a TCP connection. Blocking.
Parameters:
addrRemote 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.
Performs DNS resolution and opens a TCP connection. Blocking.
Parameters:
hostHostname or dotted-decimal IP string.portPort 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.
Binds to all interfaces and begins listening for connections.
Parameters:
portPort number to listen on.backlogMaximum 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:
sockSocket handle.bufReceive buffer.max_lenBuffer capacity.timeout_msTimeout 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.
May send fewer bytes than requested (partial send).
Parameters:
sockSocket handle.dataData to send.lenNumber 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.
Loops internally until all bytes are sent or an error occurs.
Parameters:
sockSocket handle.dataData to send.lenNumber of bytes to send.
Returns:
Number of bytes sent (== len on success), or -1 on error.
function syn_port_spi_deinit¶
De-initialize an SPI hardware instance.
Parameters:
spi_idInstance index.
Returns:
SYN_OK on success.
function syn_port_spi_init¶
Initialize an SPI hardware instance.
SYN_WEAK SYN_Status syn_port_spi_init (
uint8_t spi_id,
uint32_t baudrate_hz,
uint8_t mode,
uint8_t role
)
Parameters:
spi_idInstance index (0 = SPI1, 1 = SPI2).baudrate_hzBaudrate frequency in Hz (e.g. 1000000, 18000000).modeSPI Mode: 0 (CPOL=0, CPHA=0), 1 (CPOL=0, CPHA=1), 2 (CPOL=1, CPHA=0), 3 (CPOL=1, CPHA=1).role0 = Master, 1 = Slave.
Returns:
SYN_OK on success.
function syn_port_spi_transfer¶
Perform a full-duplex simultaneous SPI transfer.
SYN_WEAK SYN_Status syn_port_spi_transfer (
uint8_t spi_id,
const uint8_t * tx,
uint8_t * rx,
size_t len
)
Parameters:
spi_idInstance index.txTX data buffer (can be NULL, transmits 0xFF dummy bytes).rxRX destination buffer (can be NULL).lenTransfer byte count.
Returns:
SYN_OK on success.
function syn_port_system_reset¶
Perform a system reset.
function syn_port_uart_deinit¶
De-initialize a UART peripheral.
Parameters:
instanceUART instance to de-initialize.
Returns:
SYN_OK on success.
function syn_port_uart_init¶
Initialize a UART peripheral.
Parameters:
instanceUART instance number (0, 1, 2, …).baudrateDesired 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:
instanceUART instance.dataBuffer to receive into.lenMaximum number of bytes to receive.received[out] Actual number of bytes received.timeout_msTimeout 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:
instanceUART instance.byte[out] Received byte.timeout_msTimeout 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:
instanceUART instance.dataPointer to data to transmit.lenNumber of bytes to transmit.timeout_msTimeout 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).
Parameters:
instanceUART instance.byteByte to transmit.
Returns:
SYN_OK on success.
function syn_port_udp_join_multicast¶
Join a multicast group.
Parameters:
sockUDP socket handle.multicast_ipMulticast 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.
Parameters:
portLocal 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:
sockSocket handle.bufReceive buffer.max_lenBuffer capacity.from[out] Source address.timeout_msReceive 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:
sockSocket handle.dataPayload to send.lenPayload length.toDestination 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