|
Firmware
|
A simple serial line framing protocol based on HDLC with 32-bit CRC protection. More...
#include <stdint.h>#include <stdlib.h>#include <stdbool.h>#include <crc32.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <stdio.h>#include <perf/perf_counter.h>#include "hx_stream.h"Classes | |
| struct | hx_stream |
Macros | |
| #define | FBO 0x7e |
| Frame Boundary Octet. | |
| #define | CEO 0x7c |
| Control Escape Octet. | |
Functions | |
| hx_stream_t | hx_stream_init (int fd, hx_stream_rx_callback callback, void *arg) |
| Allocate a new hx_stream object. More... | |
| void | hx_stream_free (hx_stream_t stream) |
| Free a hx_stream object. More... | |
| void | hx_stream_set_counters (hx_stream_t stream, perf_counter_t tx_frames, perf_counter_t rx_frames, perf_counter_t rx_errors) |
| Set performance counters for the stream. More... | |
| void | hx_stream_reset (hx_stream_t stream) |
| Reset a stream. More... | |
| int | hx_stream_start (hx_stream_t stream, const void *data, size_t count) |
| Prepare to send a frame. More... | |
| int | hx_stream_send_next (hx_stream_t stream) |
| Get the next byte to send for a stream. More... | |
| int | hx_stream_send (hx_stream_t stream, const void *data, size_t count) |
| Send a frame. More... | |
| void | hx_stream_rx (hx_stream_t stream, uint8_t c) |
| Handle a byte from the stream. More... | |
A simple serial line framing protocol based on HDLC with 32-bit CRC protection.
| void hx_stream_free | ( | hx_stream_t | stream | ) |
Free a hx_stream object.
| stream | A handle returned from hx_stream_init. |
| hx_stream_t hx_stream_init | ( | int | fd, |
| hx_stream_rx_callback | callback, | ||
| void * | arg | ||
| ) |
Allocate a new hx_stream object.
| fd | The file handle over which the protocol will communicate, or -1 if the protocol will use hx_stream_start/hx_stream_send_next. |
| callback | Called when a frame is received. |
| callback_arg | Passed to the callback. |
| void hx_stream_reset | ( | hx_stream_t | stream | ) |
Reset a stream.
Forces the local stream state to idle.
| stream | A handle returned from hx_stream_init. |
| void hx_stream_rx | ( | hx_stream_t | stream, |
| uint8_t | c | ||
| ) |
Handle a byte from the stream.
| stream | A handle returned from hx_stream_init. |
| c | The character to process. |
| int hx_stream_send | ( | hx_stream_t | stream, |
| const void * | data, | ||
| size_t | count | ||
| ) |
Send a frame.
This function will block until all frame bytes are sent if the descriptor passed to hx_stream_init is marked blocking, otherwise it will return -1 (but may transmit a runt frame at the same time).
| stream | A handle returned from hx_stream_init. |
| data | Pointer to the data to send. |
| count | The number of bytes to send. |
| int hx_stream_send_next | ( | hx_stream_t | stream | ) |
Get the next byte to send for a stream.
This requires that the stream be prepared for sending by calling hx_stream_start first.
| stream | A handle returned from hx_stream_init. |
| void hx_stream_set_counters | ( | hx_stream_t | stream, |
| perf_counter_t | tx_frames, | ||
| perf_counter_t | rx_frames, | ||
| perf_counter_t | rx_errors | ||
| ) |
Set performance counters for the stream.
Any counter may be set to NULL to disable counting that datum.
| stream | A handle returned from hx_stream_init. |
| tx_frames | Counter for transmitted frames. |
| rx_frames | Counter for received frames. |
| rx_errors | Counter for short and corrupt received frames. |
| int hx_stream_start | ( | hx_stream_t | stream, |
| const void * | data, | ||
| size_t | count | ||
| ) |
Prepare to send a frame.
Use this in conjunction with hx_stream_send_next to set the frame to be transmitted.
Use hx_stream_send() to write to the stream fd directly.
| stream | A handle returned from hx_stream_init. |
| data | Pointer to the data to send. |
| count | The number of bytes to send. |
1.8.12