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 __sys_lnp_h__
27 #define __sys_lnp_h__
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include "../lnp.h"
34 
35 #ifdef CONF_LNP
36 
38 //
39 // Definitions
40 //
42 
43 #define LNP_HOSTMASK CONF_LNP_HOSTMASK
44 
45 #define LNP_PORTMASK (0x00ff & ~CONF_LNP_HOSTMASK)
47 
48 #if defined(CONF_RCX_PROTOCOL) || defined(CONF_RCX_MESSAGE)
49 #define LNP_RCX_HEADER_LENGTH (3-1)
51 
53 #define LNP_RCX_REMOTE_OP_LENGTH (5-3)
54 
56 #define LNP_RCX_MSG_OP_LENGTH (5-3)
57 #endif
58 
60 typedef enum {
65 
66 #if defined(CONF_RCX_PROTOCOL) || defined(CONF_RCX_MESSAGE)
67  LNPwaitRMH1, // note that first byte is consumed by LNPwaitHeader
69  LNPwaitRMH2, // inverted header
70  LNPwaitRMH3, // actually, RCX opcode dispatch
71  LNPwaitRMH4, // remote opcode inverted
72 #endif
73 
74 
75 #ifdef CONF_RCX_PROTOCOL
76  LNPwaitRB0, // high-byte
79  LNPwaitRB1, // low-byte
81  LNPwaitRC, // RCX checksum
83 #endif
84 
85 #ifdef CONF_RCX_MESSAGE
86  LNPwaitMH3, // RCX message OP
89  LNPwaitMN, // message number
91  LNPwaitMC, // RCX checksum
93 #endif
95 
96 
98 //
99 // Variables
100 //
102 
104 extern volatile unsigned short lnp_timeout_counter;
105 
107 extern unsigned short lnp_timeout;
108 
110 extern lnp_integrity_state_t lnp_integrity_state;
111 
112 
114 //
115 // Functions
116 //
118 
120 extern unsigned char lnp_checksum_copy( unsigned char *dest,
121  const unsigned char *data,
122  unsigned length );
123 
126 
128 extern void lnp_integrity_byte(unsigned char b);
129 
131 extern void lnp_integrity_reset(void)
132 #ifdef CONF_RCX_COMPILER
133 __attribute__ ((rcx_interrupt))
134 #endif
135 ;
136 
138 
140 extern inline int lnp_integrity_active(void) {
141  return lnp_integrity_state!=LNPwaitHeader;
142 }
143 
145 extern void lnp_timeout_reset(void)
146 #ifdef CONF_RCX_COMPILER
147 __attribute__ ((rcx_interrupt))
148 #endif
149 ;
150 
153 
155 extern inline void lnp_timeout_set(unsigned short timeout) {
156  lnp_timeout_counter=lnp_timeout=timeout;
157 }
158 
160 
163 extern void lnp_init(void);
164 
165 #endif // CONF_LNP
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 
171 #endif // __sys_lnp_h__
172 
lnp_integrity_state_t lnp_integrity_state
the integrity layer state
void lnp_timeout_reset(void)
reset the inter-byte timeout counter.
Definition: lnp.h:64
Definition: lnp.h:82
unsigned char lnp_checksum_copy(unsigned char *dest, const unsigned char *data, unsigned length)
the LNP `copy and compute checksum&#39; function.
states when waiting for rcx message opcode
Definition: lnp.h:87
lnp_integrity_state_t
states for the integrity layer state machine
Definition: lnp.h:60
states when waiting for remote buttons args
Definition: lnp.h:77
Definition: lnp.h:92
Definition: lnp.h:91
volatile unsigned short lnp_timeout_counter
the timeout counter in ms
void lnp_integrity_byte(unsigned char b)
receive a byte from the physical layer, decoding integrity layer packets.
Definition: lnp.h:81
void lnp_timeout_set(unsigned short timeout)
set the inter-byte timeout and reset the timeout counter to that value.
Definition: lnp.h:155
Definition: lnp.h:79
Definition: lnp.h:88
unsigned short lnp_timeout
the timeout length in ms
int lnp_integrity_active(void)
return whether a packet is currently being received
Definition: lnp.h:140
void lnp_init(void)
Initialise protocol handlers.
Definition: lnp.h:90
Definition: lnp.h:89
void lnp_integrity_reset(void)
reset the integrity layer on error or timeout.
states when waiting for rcx protocol message
Definition: lnp.h:68

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.8.11