SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
lsd.h
1/************************************************************************/
32
33/*
34 * Frame format is:
35 *
36 * STX : CH-LENH : LENL : DATA : ETX
37 *
38 * - STX and ETX are the start/end of transmission characters (1 byte each).
39 * - CH-LENH is the channel number (first 4 bits) and the 4 high bits of the
40 * data length.
41 * - LENL is the low 8 bits of the data length.
42 * - DATA is the payload, of the previously specified length.
43 */
44#ifndef _LSD_H_
45#define _LSD_H_
46
47#include "config.h"
48#include "types.h"
49
50#if (MODULE_EVERDRIVE != 0)
51 // use the everdrive uart
52 #include "ext/mw/ssf.h"
53#else
54 // use the default 16c550 uart
55 #include "ext/mw/16c550.h"
56#endif
57#include "ext/mw/mw-msg.h"
58
60#define LSD_OVERHEAD 4
61
63#define LSD_MAX_CH 4
64
66#define LSD_MAX_LEN 4095
67
69#define LSD_BUF_FRAMES 2
70
81
83typedef void (*lsd_send_cb)(enum lsd_status stat, void *ctx);
85typedef void (*lsd_recv_cb)(enum lsd_status stat, uint8_t ch,
86 char *data, uint16_t len, void *ctx);
87
88/************************************************************************/
91void lsd_init(void);
92
93/************************************************************************/
100int lsd_ch_enable(uint8_t ch);
101
102/************************************************************************/
109int lsd_ch_disable(uint8_t ch);
110
111
112/************************************************************************/
126enum lsd_status lsd_send(uint8_t ch, const char *data, int16_t len,
127 void *ctx, lsd_send_cb send_cb);
128
129/************************************************************************/
139enum lsd_status lsd_send_sync(uint8_t ch, const char *data, int16_t len);
140
141/************************************************************************/
151enum lsd_status lsd_recv(char *buf, int16_t len, void *ctx,
152 lsd_recv_cb recv_cb);
153
154/************************************************************************/
166enum lsd_status lsd_recv_sync(char *buf, uint16_t *len, uint8_t *ch);
167
168/************************************************************************/
174void lsd_process(void);
175
176/************************************************************************/
183void lsd_line_sync(void);
184
186
187#endif //_LSD_H_
188
Basic SGDK library configuration file.
void lsd_init(void)
Module initialization.
lsd_status
Return status codes for LSD functions.
Definition lsd.h:72
void(* lsd_send_cb)(enum lsd_status stat, void *ctx)
Callback for the asynchronous lsd_send() function.
Definition lsd.h:83
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_recv_sync(char *buf, uint16_t *len, uint8_t *ch)
Syncrhonously Receives a frame using LSD protocol.
int lsd_ch_enable(uint8_t ch)
Enables a channel to start reception and be able to send data.
void lsd_process(void)
Processes sends/receives pending data.
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_send_sync(uint8_t ch, const char *data, int16_t len)
Synchronously sends data through a previously enabled channel.
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.
Definition lsd.h:85
void lsd_line_sync(void)
Sends syncrhonization frame.
int lsd_ch_disable(uint8_t ch)
Disables a channel to stop reception and prohibit sending data.
@ LSD_STAT_ERR_FRAMING
Frame format error.
Definition lsd.h:73
@ LSD_STAT_COMPLETE
No error.
Definition lsd.h:78
@ LSD_STAT_BUSY
Doing requested operation.
Definition lsd.h:79
@ LSD_STAT_ERR_IN_PROGRESS
Operation in progress.
Definition lsd.h:76
@ LSD_STAT_ERR_FRAME_TOO_LONG
Frame is too long.
Definition lsd.h:75
@ LSD_STAT_ERROR
General error.
Definition lsd.h:77
@ LSD_STAT_ERR_INVALID_CH
Invalid channel.
Definition lsd.h:74
MegaWiFi command message definitions.
Types definition.