BSB Developer Docs
Loading...
Searching...
No Matches
fkermit.h File Reference

Minimal send-only Kermit file-transfer sender. More...

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  KermitIo
 I/O interface used by the Kermit sender to read the source file and transmit data over the communication channel. More...
 

Typedefs

typedef struct Kermit Kermit
 Opaque Kermit session handle.
 

Functions

Kermit * kermit_alloc (const KermitIo *io, void *context)
 Allocate a new Kermit session in the idle state.
 
void kermit_free (Kermit *kermit)
 Free a Kermit session and release any pending receive buffer.
 
bool kermit_start (Kermit *kermit, const uint8_t timeout_seconds)
 Start a file transfer by transmitting the Send-Init (S) packet.
 
bool kermit_is_active (Kermit *kermit)
 Check whether the transfer has completed.
 
bool kermit_feed_serial_data (Kermit *kermit, const uint8_t *data, size_t length)
 Feed received serial data into the session state machine.
 
void kermit_reset_state (Kermit *kermit)
 Reset the session back to the idle state.
 

Detailed Description

Minimal send-only Kermit file-transfer sender.

Implements the sender side of the Kermit protocol used to push firmware images to a device bootloader over a byte-oriented link (UART). File data is transmitted and the receiver's ACK/NAK packets are consumed; no file data is ever received. The protocol logic is fully decoupled from hardware through the KermitIo interface.

Kermit protocol reference: https://www.kermitproject.org/kpackets.html

Function Documentation

◆ kermit_alloc()

Kermit * kermit_alloc ( const KermitIo * io,
void * context )

Allocate a new Kermit session in the idle state.

Parameters
[in]ioI/O interface used by the sender. Must not be NULL.
[in]contextUser-provided context passed back to every I/O callback.
Returns
Pointer to the newly allocated session.

◆ kermit_feed_serial_data()

bool kermit_feed_serial_data ( Kermit * kermit,
const uint8_t * data,
size_t length )

Feed received serial data into the session state machine.

Typically carries the receiver's ACK/NAK packets. Non-Kermit bytes are skipped until a packet mark is seen, so interleaved bootloader text is tolerated.

Parameters
[in]kermitSession handle.
[in]dataReceived bytes. Must not be NULL.
[in]lengthNumber of bytes. Must be greater than 0.
Returns
true if the data was processed successfully. If false is returned, the session state is invalid and the transfer must be aborted.

◆ kermit_free()

void kermit_free ( Kermit * kermit)

Free a Kermit session and release any pending receive buffer.

Parameters
[in]kermitSession handle. Must not be NULL.

◆ kermit_is_active()

bool kermit_is_active ( Kermit * kermit)

Check whether the transfer has completed.

Parameters
[in]kermitSession handle.
Returns
true if the transfer is still in progress or has not started yet; false once it has completed.

◆ kermit_reset_state()

void kermit_reset_state ( Kermit * kermit)

Reset the session back to the idle state.

Resets the sequence counter, frees any in-progress receive buffer, and moves the file-transfer state machine to idle. Safe to call at any time.

Parameters
[in]kermitSession handle.

◆ kermit_start()

bool kermit_start ( Kermit * kermit,
const uint8_t timeout_seconds )

Start a file transfer by transmitting the Send-Init (S) packet.

Must be called while the session is idle. The transfer is then driven by feeding the receiver's responses with kermit_feed_serial_data().

Parameters
[in]kermitSession handle.
[in]timeout_secondsPer-packet timeout advertised to the receiver (Kermit TIMO field), in seconds.
Returns
true if the Send-Init packet was transmitted, false otherwise.