Skip to content
jhalmen edited this page Dec 4, 2018 · 3 revisions

Frames API

A simple embedded C API for the frame layer is defined. This is a non-blocking.

The standard header file that contains MIN API definitions is min.h.

Calls from the application

A context is used to store the internal MIN state machine information. This approach allows multiple ports to be supported. The call is:

void min_init_context(min_context_t *self, uint8_t port);

The port parameter indicates the port that the connection is for. There is no special meaning attached to the port: it is set by the programmer as desired (e.g. it might be an index into an array of port descriptor structs).

The self parameter is the context structure. The user must allocate the memory for this structure.

void min_send_frame(min_context_t *self, uint8_t min_id, uint8_t *payload, uint8_t payload_len);

This sends a MIN frame as a datagram. The min_id must be a value 0..63. The payload can be up to 255 bytes.

The following call queues a MIN frame into the transport FIFO:

bool min_queue_frame(min_context_t *self, uint8_t min_id, uint8_t *payload, uint8_t payload_len);

It returns true if the frame was queued OK, and false otherwise.

The following call sends bytes of data from the port into the MIN protocol:

void min_poll(min_context_t *self, uint8_t *buf, uint32_t buf_len);

The programmer is responsible for obtaining the data from the port and passing in a pointer to the data and its length. If there is no data to send then the call should still be made in order to operate the transport protocol timeouts.

Callbacks to the application

The MIN layer will make callbacks into the application to indicate certain events must be handled. The following call obtains the time and is called if the transport protocol is running:

uint32_t min_time_ms(void);

This call is made by MIN to pass a successfully received frame to the application:

void min_application_handler(uint8_t min_id, uint8_t *min_payload, uint8_t len_payload, uint8_t port);

The port parameter is passed back to allow the programmer to determine the source of the frame.

The following call is the interface between the MIN implementation and the serial drivers:

void min_tx_byte(uint8_t port, uint8_t byte);

It is called to put a byte into the given port.

Clone this wiki locally