|
SGDK
A free and open development kit for the Sega Mega Drive
|
Local Symmetric Data-link. Implements an extremely simple protocol to link two full-duplex devices, multiplexing the data link. More...
Typedefs | |
| typedef void(* | lsd_send_cb) (enum lsd_status stat, void *ctx) |
| Callback for the asynchronous lsd_send() function. | |
| typedef void(* | lsd_recv_cb) (enum lsd_status stat, uint8_t ch, char *data, uint16_t len, void *ctx) |
| Callback for the asynchronous lsd_recv() function. | |
Enumerations | |
| enum | lsd_status { LSD_STAT_ERR_FRAMING = -5 , LSD_STAT_ERR_INVALID_CH = -4 , LSD_STAT_ERR_FRAME_TOO_LONG = -3 , LSD_STAT_ERR_IN_PROGRESS = -2 , LSD_STAT_ERROR = -1 , LSD_STAT_COMPLETE = 0 , LSD_STAT_BUSY = 1 } |
| Return status codes for LSD functions. More... | |
Functions | |
| void | lsd_init (void) |
| Module initialization. | |
| int | lsd_ch_enable (uint8_t ch) |
| Enables a channel to start reception and be able to send data. | |
| int | lsd_ch_disable (uint8_t ch) |
| Disables a channel to stop reception and prohibit sending data. | |
| enum lsd_status | lsd_send (uint8_t ch, const char *data, int16_t len, void *ctx, lsd_send_cb send_cb) |
| Asynchronously sends data through a previously enabled channel. | |
| enum lsd_status | lsd_send_sync (uint8_t ch, const char *data, int16_t len) |
| Synchronously sends data through a previously enabled channel. | |
| enum lsd_status | lsd_recv (char *buf, int16_t len, void *ctx, lsd_recv_cb recv_cb) |
| Asyncrhonously Receives a frame using LSD protocol. | |
| enum lsd_status | lsd_recv_sync (char *buf, uint16_t *len, uint8_t *ch) |
| Syncrhonously Receives a frame using LSD protocol. | |
| void | lsd_process (void) |
| Processes sends/receives pending data. | |
| void | lsd_line_sync (void) |
| Sends syncrhonization frame. | |
Local Symmetric Data-link. Implements an extremely simple protocol to link two full-duplex devices, multiplexing the data link.
The multiplexing facility allows having up to LSD_MAX_CH simultaneous channels on the serial link.
The module has synchronous functions to send/receive data (easy to use, but due to polling hang the console until transfer is complete) and their asyncronous counterparts. The asynchronous functions return immediately, but require calling frequently lsd_process() to actually send/receive data. Once the asynchronous functions complete sending/receiving data, the specified callback is run.
| enum lsd_status |
Return status codes for LSD functions.
| int lsd_ch_disable | ( | uint8_t | ch | ) |
Disables a channel to stop reception and prohibit sending data.
| [in] | ch | Channel number. |
| int lsd_ch_enable | ( | uint8_t | ch | ) |
Enables a channel to start reception and be able to send data.
| [in] | ch | Channel number. |
| void lsd_line_sync | ( | void | ) |
Sends syncrhonization frame.
This function sends a chunk of 0x55 bytes to help physical layer to synchronize. It is usually not necessary to use this function, but might help some UART chips to compute an accurate clock.
| void lsd_process | ( | void | ) |
Processes sends/receives pending data.
Call this function as much as possible when using the asynchronous lsd_send() and lsd_receive() functions.
| enum lsd_status lsd_recv | ( | char * | buf, |
| int16_t | len, | ||
| void * | ctx, | ||
| lsd_recv_cb | recv_cb ) |
Asyncrhonously Receives a frame using LSD protocol.
| [in] | buf | Buffer for reception. |
| [in] | len | Buffer length. |
| [in] | ctx | Context for the receive callback function. |
| [in] | recv_cb | Callback to run when receive completes or errors. |
| enum lsd_status lsd_recv_sync | ( | char * | buf, |
| uint16_t * | len, | ||
| uint8_t * | ch ) |
Syncrhonously Receives a frame using LSD protocol.
| [out] | buf | Buffer for received data. |
| [in,out] | len | On input: buffer length. On output: received frame length. |
| [out] | ch | Channel on which the data has been received. |
| enum lsd_status lsd_send | ( | uint8_t | ch, |
| const char * | data, | ||
| int16_t | len, | ||
| void * | ctx, | ||
| lsd_send_cb | send_cb ) |
Asynchronously sends data through a previously enabled channel.
| [in] | ch | Channel number to use. |
| [in] | data | Buffer to send. |
| [in] | len | Length of the buffer to send. |
| [in] | ctx | Context for the send callback function. |
| [in] | send_cb | Callback to run when send completes or errors. |
| enum lsd_status lsd_send_sync | ( | uint8_t | ch, |
| const char * | data, | ||
| int16_t | len ) |
Synchronously sends data through a previously enabled channel.
| [in] | ch | Channel number to use. |
| [in] | data | Buffer to send. |
| [in] | len | Length of the buffer to send. |