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#include "ext/mw/comm.h"
50#include "ext/mw/mw-msg.h"
51
53#define LSD_OVERHEAD 4
54
56#define LSD_MAX_CH 4
57
59#define LSD_MAX_LEN 4095
60
62#define LSD_BUF_FRAMES 2
63
74
76typedef void (*lsd_send_cb)(enum lsd_status stat, void *ctx);
78typedef void (*lsd_recv_cb)(enum lsd_status stat, uint8_t ch,
79 char *data, uint16_t len, void *ctx);
80
81/************************************************************************/
84void lsd_init(void);
85
86/************************************************************************/
93int lsd_ch_enable(uint8_t ch);
94
95/************************************************************************/
102int lsd_ch_disable(uint8_t ch);
103
104
105/************************************************************************/
119enum lsd_status lsd_send(uint8_t ch, const char *data, int16_t len,
120 void *ctx, lsd_send_cb send_cb);
121
122/************************************************************************/
132enum lsd_status lsd_send_sync(uint8_t ch, const char *data, int16_t len);
133
134/************************************************************************/
144enum lsd_status lsd_recv(char *buf, int16_t len, void *ctx,
145 lsd_recv_cb recv_cb);
146
147/************************************************************************/
159enum lsd_status lsd_recv_sync(char *buf, uint16_t *len, uint8_t *ch);
160
161/************************************************************************/
167void lsd_process(void);
168
170
171#endif //_LSD_H_
172
Basic SGDK library configuration file.
void lsd_init(void)
Module initialization.
lsd_status
Return status codes for LSD functions.
Definition lsd.h:65
void(* lsd_send_cb)(enum lsd_status stat, void *ctx)
Callback for the asynchronous lsd_send() function.
Definition lsd.h:76
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:78
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:66
@ LSD_STAT_COMPLETE
No error.
Definition lsd.h:71
@ LSD_STAT_BUSY
Doing requested operation.
Definition lsd.h:72
@ LSD_STAT_ERR_IN_PROGRESS
Operation in progress.
Definition lsd.h:69
@ LSD_STAT_ERR_FRAME_TOO_LONG
Frame is too long.
Definition lsd.h:68
@ LSD_STAT_ERROR
General error.
Definition lsd.h:70
@ LSD_STAT_ERR_INVALID_CH
Invalid channel.
Definition lsd.h:67
MegaWiFi command message definitions.
Types definition.