]> rtime.felk.cvut.cz Git - sysless.git/blob - arch/mcs51/generic/libs/ulan/ulan.h
68af65818d39642eee5e0e7827c88b4ae9a79445
[sysless.git] / arch / mcs51 / generic / libs / ulan / ulan.h
1 #ifndef _ULAN_H
2 #define _ULAN_H
3
4 #ifdef __cplusplus
5 /*extern "C" {*/
6 #endif
7
8 #include <ul_lib/ul_utsubst.h>
9
10 #ifndef uchar
11  #define uchar unsigned char
12 #endif
13
14 typedef int ul_ssize_t;
15 typedef unsigned int ul_size_t;
16 typedef int ul_fd_t;
17
18 typedef struct ul_idstr_t {
19   char *name;
20   char len; 
21 } ul_idstr_t;
22
23 #define UL_FD_INVALID 0
24
25 #ifndef UL_WITH_HANDLE
26   #define UL_WITHOUT_HANDLE
27 #endif /*UL_WITH_HANDLE*/
28
29 #define UL_ARGPTRTYPE __xdata
30 //#define UL_ARGPTRTYPE
31
32 #undef UL_WITH_NAKED
33
34 #ifdef UL_WITH_NAKED
35   #define UL_FNC_NAKED _naked
36 #else /*UL_WITH_NAKED*/
37   #define UL_FNC_NAKED
38 #endif /*UL_WITH_NAKED*/
39
40 #if !defined(SDCC_MODEL_LARGE) || !defined(SDCC)
41   #define UL_FNC_REENTRANT
42 #else
43   #define UL_FNC_REENTRANT __reentrant
44 #endif
45
46 /*******************************************************************/
47
48 /* ul_mess_head flags definition defines proccessing 
49    of message or its frames stored in bll */
50 /*#define UL_BFL_LOCK 0x00*/    /* locked message is pointed only once */
51 /*#define UL_BFL_MSST 0x00*/      /* Message must be received by some proccess */
52 /*#define UL_BFL_M2IN 0x00*/      /* After succesfull proccessing move to proc_bll */
53 /*#define UL_BFL_LNMM 0x00*/      /* Length of received frame must match expected len */
54 /*#define UL_BFL_VERL 0x00*/      /* Verify free space in buffer of destination station */
55 /*#define UL_BFL_REWA 0x00*/      /* If error occurs do wait with retry */
56
57 #define UL_BFL_NORE 0x40      /* Do not try to repeat if error occurs */
58 #define UL_BFL_TAIL 0x20      /* Multiframe message continues by next bll block */
59 #define UL_BFL_SND  0x00      /* Send this frame */
60 #define UL_BFL_REC  0x10      /* Receive answer frame into this bll block */
61 #define UL_BFL_FAIL 0x08      /* Message cannot be proccessed - error */
62 #define UL_BFL_PROC 0x04      /* Processed outgoing message */
63 #define UL_BFL_PRQ  0x02      /* Request imediate proccessing of frame by receiver station */
64 #define UL_BFL_ARQ  0x01      /* Request imediate acknowledge by receiving station */
65
66 typedef struct ul_msginfo {
67         uchar   dadr;           /* destignation address */
68         uchar   sadr;           /* source address */
69         uchar   cmd;            /* command/socket number */
70         uchar   flg;            /* message flags */
71         uchar   stamp;          /* unigue message number */
72         unsigned len;           /* length of frame */
73 } ul_msginfo;
74
75 /*******************************************************************/
76 /* command definitions */
77
78 /* standard command codes 
79    00H .. 3FH    store to buffer 
80    40H .. 7FH    store to buffer without ACK
81    80H .. 9FH    proccess at onece
82    A0H .. BFH    process with additional receive
83    C0H .. FFH    process with additional send
84 */
85
86 #define UL_CMD_RES      0x80    /* Reinitialize RS485 */
87 #define UL_CMD_SFT      0x81    /* Test free space in input buffer */
88 #define UL_CMD_SYN      0x85    /* Sychronization */
89 #define UL_CMD_SID      0xF0    /* Send identification */
90 #define UL_CMD_SFI      0xF1    /* Send amount of free space in IB */
91 #define UL_CMD_TF0      0x98    /* End of stepping */
92 #define UL_CMD_TF1      0x99    /* Begin of stepping */
93 #define UL_CMD_STP      0x9A    /* Do step */
94 #define UL_CMD_DEB      0x9B    /* Additional debug commands */
95 #define UL_CMD_SPC      0xDA    /* Send state - for 8051 PCL PCH PSW ACC */
96
97 #define UL_CMD_RDM      0xF8    /* Read memory   T T B B L L */
98 #define UL_CMD_WRM      0xB8    /* Write mamory  T T B B L L */
99 #define UL_CMD_ERM      0x88    /* Erase memory T T B B L L */
100
101 /* uLan parameter setup and initialization functions */
102 char    ul_drv_init(void);
103 char    ul_drv_set_adr(uchar addr);
104 char    ul_drv_set_bdiv(uchar bdiv);
105 void    ul_str(void);
106 void    ul_int(void);
107
108 /* uLan standard IO functions */
109 ul_fd_t ul_open(const char *dev_name, const char *options);
110 int     ul_close(ul_fd_t ul_fd);
111 ul_ssize_t ul_read(ul_fd_t ul_fd,void *buffer, ul_size_t size);
112 ul_ssize_t ul_write(ul_fd_t ul_fd,const void *buffer, ul_size_t size);
113 int     ul_newmsg(ul_fd_t ul_fd,const ul_msginfo UL_ARGPTRTYPE  *msginfo);
114 int     ul_tailmsg(ul_fd_t ul_fd,const ul_msginfo UL_ARGPTRTYPE  *msginfo);
115 int     ul_freemsg(ul_fd_t ul_fd);
116 int     ul_acceptmsg(ul_fd_t ul_fd,ul_msginfo UL_ARGPTRTYPE  *msginfo);
117 int     ul_actailmsg(ul_fd_t ul_fd,ul_msginfo UL_ARGPTRTYPE  *msginfo);
118 int     ul_addfilt(ul_fd_t ul_fd,const ul_msginfo UL_ARGPTRTYPE  *msginfo);
119 int     ul_abortmsg(ul_fd_t ul_fd);
120 uchar   ul_inepoll(ul_fd_t ul_fd);
121 int     ul_drv_debflg(ul_fd_t ul_fd,int debug_msk);
122 int     ul_fd_wait(ul_fd_t ul_fd, int wait_sec);
123 int     ul_stroke(ul_fd_t ul_fd);
124 int     ul_setmyadr(ul_fd_t ul_fd, int newadr);
125 int     ul_setidstr(ul_fd_t ul_fd, const char *idstr);
126
127 #ifdef UL_WITHOUT_HANDLE
128 ul_ssize_t __ul_read_avail(void) UL_FNC_NAKED;
129 ul_ssize_t __ul_read(void *buffer, ul_size_t size) UL_FNC_NAKED UL_FNC_REENTRANT;
130 ul_ssize_t __ul_write(const void *buffer, ul_size_t size) UL_FNC_NAKED UL_FNC_REENTRANT;
131 int     __ul_newmsg(const ul_msginfo UL_ARGPTRTYPE  *msginfo) UL_FNC_NAKED;
132 int     __ul_tailmsg(const ul_msginfo UL_ARGPTRTYPE  *msginfo) UL_FNC_NAKED;
133 int     __ul_freemsg() UL_FNC_NAKED;
134 int     __ul_acceptmsg(ul_msginfo UL_ARGPTRTYPE  *msginfo) UL_FNC_NAKED;
135 int     __ul_actailmsg(ul_msginfo UL_ARGPTRTYPE  *msginfo) UL_FNC_NAKED;
136 int     __ul_addfilt(const ul_msginfo UL_ARGPTRTYPE  *msginfo);
137 int     __ul_abortmsg(void);
138 uchar   __ul_inepoll(void) UL_FNC_NAKED;
139 int     __ul_o_close(void) UL_FNC_NAKED;
140 int     __ul_i_close(void) UL_FNC_NAKED;
141
142 #define ul_read(ul_fd, buffer, size) __ul_read(buffer, size)
143 #define ul_write(ul_fd, buffer, size) __ul_write(buffer, size)
144 #define ul_newmsg(ul_fd, msginfo) __ul_newmsg(msginfo)
145 #define ul_tailmsg(ul_fd, msginfo) __ul_tailmsg(msginfo)
146 #define ul_freemsg(ul_fd) __ul_freemsg()
147 #define ul_acceptmsg(ul_fd, msginfo) __ul_acceptmsg(msginfo)
148 #define ul_actailmsg(ul_fd, msginfo) __ul_actailmsg(msginfo)
149 #define ul_addfilt(ul_fd, msginfo) __ul_addfilt(msginfo)
150 #define ul_abortmsg(ul_fd) __ul_abortmsg()
151 #define ul_inepoll(ul_fd) __ul_inepoll()
152 #define ul_i_close(ul_fd) __ul_i_close()
153 #define ul_o_close(ul_fd) __ul_o_close()
154 #define ul_stroke(ul_fd) ul_str() 
155 #define ul_setmyadr(ul_fd,newadr) ul_drv_set_adr(newadr)
156 #define ul_setidstr(ul_fd,idstr)
157
158 #endif /*UL_WITHOUT_HANDLE*/
159
160 /* simple message operations */
161
162 int ul_send_command(ul_fd_t ul_fd,int dadr,int cmd,int flg,
163                     const void *buf,int len);
164 int ul_send_command_wait(ul_fd_t ul_fd,int dadr,int cmd,int flg,
165                          const void *buf,int len);
166 int ul_send_query(ul_fd_t ul_fd,int dadr,int cmd,int flg,
167                   const void *buf,int len);
168 int ul_send_query_wait(ul_fd_t ul_fd,int dadr,int cmd,int flg,
169                        const void *bufin,int lenin,void **bufout,int *lenout);
170
171 /* basic uLan commands/services */
172
173 #define UL_CMD_OISV     0x10    /* Object Interface Service */
174 #define UL_CMD_LCDABS   0x4f    /* Absorbance data block */
175 #define UL_CMD_LCDMRK   0x4e    /* Mark */
176 #define UL_CMD_NCS      0x7f    /* Network Control Service */
177 #define UL_CMD_GST      0xc1    /* Fast module get status */
178
179 /* UL_CMD_NCS   Network Control Service */
180
181 #define ULNCS_ADR_RQ      0xC0    /* SN0 SN1 SN2 SN3 */
182 #define ULNCS_SET_ADDR    0xC1    /* SN0 SN1 SN2 SN3 NEW_ADR */
183 #define ULNCS_SID_RQ      0xC2    /* send serial num and ID string request */
184 #define ULNCS_SID_RPLY    0xC3    /* SN0 SN1 SN2 SN3 ID ... */
185 #define ULNCS_ADDR_NVSV   0xC4    /* SN0 SN1 SN2 SN3 - save addres to EEPROM */
186 #define ULNCS_BOOT_ACT    0xC5    /* SN0 SN1 SN2 SN3 */
187 #define ULNCS_BOOT_ACK    0xC6    /* SN0 SN1 SN2 SN3 */
188 #define ULNCS_SET_SN      0xE0    /* SN0 SN1 SN2 SN3 */
189
190 /* debugging support routines */
191 /*int uloi_debug_flg;*/
192
193 #define UL_LOGL_MASK (0xff)
194 #define UL_LOGL_CONT (0x1000)
195
196 /*typedef void (ul_log_fnc_t)(const char *domain, int level,
197         const char *format, va_list ap);*/
198
199 /*void ul_log(const char *domain, int level,
200         const char *format, ...);*/
201 //#define ul_log(domain,level,format, ...)
202
203 /*void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags);*/
204 //#define ul_log_redir(log_fnc, add_flags)
205
206 #ifdef UL_WITHOUT_HANDLE
207   /* 
208    * this is used to preserve space and speed consumed by creation
209    * of many local instances of these variables on small MCU systems
210    */
211   extern ul_fd_t        ul_fd;
212   extern UL_ARGPTRTYPE ul_msginfo msginfo;
213 #endif /*UL_WITH_HANDLE*/
214         
215 #ifdef __cplusplus
216 /*}*/ /* extern "C"*/
217 #endif
218
219 #endif /* _ULAN_H */
220