brickOS Kernel Developer v0.9.0
lnp.h
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License
10 * at http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 * the License for the specific language governing rights and
15 * limitations under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 */
25
26#ifndef __lnp_h__
27#define __lnp_h__
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <config.h>
34
35#ifdef CONF_LNP
36
37#ifdef CONF_RCX_MESSAGE
38#include <unistd.h>
39#endif
40
42//
43// Definitions
44//
46
48
50typedef void (*lnp_integrity_handler_t) (const unsigned char *, unsigned char);
51
53
55typedef void (*lnp_addressing_handler_t) (const unsigned char *, unsigned char, unsigned char);
56
58#define LNP_DUMMY_INTEGRITY ((lnp_integrity_handler_t)0)
59
61#define LNP_DUMMY_ADDRESSING ((lnp_addressing_handler_t)0)
62
63#ifdef CONF_RCX_PROTOCOL
65
67typedef void (*lnp_remote_handler_t) (unsigned int);
68
70#define LNP_DUMMY_REMOTE ((lnp_remote_handler_t)0)
71#endif
72
74//
75// Variables
76//
78
80// one handler.
82
85
87extern unsigned char lnp_hostaddr;
88
89#ifdef CONF_RCX_PROTOCOL
92#endif
93
95//
96// Functions
97//
99
102{
103 lnp_integrity_handler = handler;
104}
105
107extern inline void lnp_addressing_set_handler(unsigned char port, lnp_addressing_handler_t handler)
108{
109 if (!(port & CONF_LNP_HOSTMASK)) // sanity check.
110
111 lnp_addressing_handler[port] = handler;
112}
113
115extern inline void lnp_set_hostaddr(unsigned char host)
116{
117 lnp_hostaddr = ((host << 4) & CONF_LNP_HOSTMASK);
118}
119
120#ifdef CONF_RCX_PROTOCOL
123{
124 lnp_remote_handler = handler;
125}
126#endif
127
128#ifdef CONF_RCX_MESSAGE
130extern unsigned char lnp_rcx_message;
131
133extern int send_msg(unsigned char msg);
134
136extern inline void clear_msg(void)
137{
138 lnp_rcx_message = 0;
139}
140
143
145extern inline unsigned char get_msg(void)
146{
147 clear_msg();
148 if (wait_event(msg_received, 0) == 0)
149 return 0;
150 return lnp_rcx_message;
151}
152
153#endif
154
156
158extern int lnp_integrity_write(const unsigned char *data,unsigned char length);
159
161
163extern int lnp_addressing_write(const unsigned char *data,unsigned char length,
164 unsigned char dest,unsigned char srcport);
165
166#endif // CONF_LNP
167
168#ifdef __cplusplus
169}
170#endif
171
172#endif // _lnp_h__
kernel configuration file
#define CONF_LNP_HOSTMASK
LNP host mask.
Definition config.h:58
volatile lnp_addressing_handler_t lnp_addressing_handler[]
addressing layer packets may be directed to a variety of ports.
int lnp_integrity_write(const unsigned char *data, unsigned char length)
send a LNP integrity layer packet of given length
lnp_remote_handler_t lnp_remote_handler
packets from remote have no ports
wakeup_t msg_received(wakeup_t m)
wait until receive a message
void clear_msg(void)
clear last message from standard firmware
Definition lnp.h:136
unsigned char lnp_hostaddr
LNP host address.
void lnp_integrity_set_handler(lnp_integrity_handler_t handler)
set the integrity layer packet handler
Definition lnp.h:101
unsigned char lnp_rcx_message
message variable
void lnp_set_hostaddr(unsigned char host)
set new LNP host address
Definition lnp.h:115
volatile lnp_integrity_handler_t lnp_integrity_handler
there are no ports for integrity layer packets, so there's just
void lnp_remote_set_handler(lnp_remote_handler_t handler)
set the remote packet handler
Definition lnp.h:122
void lnp_addressing_set_handler(unsigned char port, lnp_addressing_handler_t handler)
set an addressing layer packet handler for a port.
Definition lnp.h:107
void(* lnp_addressing_handler_t)(const unsigned char *, unsigned char, unsigned char)
the addressing layer packet handler type
Definition lnp.h:55
unsigned char get_msg(void)
read received message from standard firmware
Definition lnp.h:145
void(* lnp_remote_handler_t)(unsigned int)
handler for remote
Definition lnp.h:67
void(* lnp_integrity_handler_t)(const unsigned char *, unsigned char)
the integrity layer packet handler type
Definition lnp.h:50
int lnp_addressing_write(const unsigned char *data, unsigned char length, unsigned char dest, unsigned char srcport)
send a LNP addressing layer packet of given length
int send_msg(unsigned char msg)
send a standard firmware message
unsigned long wakeup_t
wakeup data area type
Definition tm.h:57
Interface: reduced UNIX standard library.
wakeup_t wait_event(wakeup_t(*wakeup)(wakeup_t), wakeup_t data)
Definition unistd.h:112