NetBurner 3.5.7
PDF Version
iosys.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
19#ifndef _NB_IOSYS_H
20#define _NB_IOSYS_H
21
22#ifndef _CONSTANTS_H
23#include <constants.h>
24#endif
25
26#include <stdio.h>
27#include <nbrtos.h>
28
29#ifndef _BASICTYPES_H_
30#include <basictypes.h>
31#endif
32
33class TickTimeout;
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
52 int close(int fd);
53
81 int read(int fd, char *buf, int nbytes);
82
100 int peek(int fd, char *c);
101
122 int write(int fd, const char *buf, int nbytes);
123
143 int writestring(int fd, const char *str);
144
167 int writeall(int fd, const char *buf, int nbytes = 0);
168
197 int ReadWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
198
229 inline int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
230 {
231 TickTimeout t(timeout);
232 return ReadWithTickTimeout(fd,buf,nbytes,t);
233 }
234
262 int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
263
292 int ReadAllWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
293
313 int readall(int fd, char *buf, int nbytes);
314
337 //int PeekWithTimeout(int fd, char *c, unsigned long timeout);
338 int SockPeekWithTimeout(int fd, char *buf, uint32_t maxtime);
339
349 int getchar();
350
362 int dataavail(int fd);
363
375 int writeavail(int fd);
376
388 int haserror(int fd);
389
401
402#ifdef fd_set
403#undef fd_set
404#endif
405
406#ifdef FD_ZERO
407#undef FD_ZERO
408#endif
409
410#ifdef FD_CLR
411#undef FD_CLR
412#endif
413
414#ifdef FD_SET
415#undef FD_SET
416#endif
417
418#ifdef FD_ISSET
419#undef FD_ISSET
420#endif
421
422#ifdef FD_SETSIZE
423#undef FD_SETSIZE
424#endif
425
426#define FD_SETSIZE (FDSET_ELEMENTS * 32)
427
428 class OS_SEM;
429
430 typedef struct
431 {
432 uint32_t fd_set_elements[FDSET_ELEMENTS];
433 } __attribute__((packed)) fd_set;
434
462 typedef void FDCallBack(int fd, FDChangeType change, void *pData);
463
475 void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData);
476
485 void FD_ZERO(fd_set *pfds);
486
497 void FD_CLR(int fd, fd_set *pfds);
498
509 void FD_SET(int fd, fd_set *pfds);
510
532 int FD_ISSET(int fd, fd_set *pfds);
533
545 int FD_OVERLAP(const fd_set *f1, const fd_set *f2);
546
557 void FD_COPY(const fd_set *from, fd_set *to);
558
569 void FD_SETFROMSET(const fd_set *from, fd_set *to);
570
581 void FD_CLRFROMSET(const fd_set *from, fd_set *to);
582
583 int textern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, TickTimeout &timeout);
584
585 // A Select that uses an external SEM so other things can wake it up.
586 inline int extern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, unsigned long timeout)
587 {
588 TickTimeout t(timeout);
589 return textern_sem_select(nfds, readfds, writefds, errorfds, sem, t);
590 }
591
592 inline int tselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, TickTimeout &timeout)
593 {
594 OS_SEM SelectSem;
595 return textern_sem_select(nfds, readfds, writefds, errorfds, SelectSem, timeout);
596 }
597
636 inline int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
637 {
638 TickTimeout t(timeout);
639
640 return tselect(nfds, readfds, writefds, errorfds, t);
641
642 }
643
662 int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds);
663
664 int twaitchar(TickTimeout &timeout);
665 int waitchar(uint32_t wait);
666
667/**********************************************************************/
668/* Define sets of flags to pass to the ioctl function */
669/**********************************************************************/
670
676#define IOCTL_TX_CHANGE_CRLF (1)
677#define IOCTL_RX_CHANGE_CRLF (2)
678#define IOCTL_RX_PROCESS_EDITS (4)
679#define IOCTL_RX_ECHO (8)
680#define IOCTL_TX_NO_BLOCK (32)
681#define IOCTL_ALL_OPTIONS (15)
689#define IOCTL_SET (0x4000)
690#define IOCTL_CLR (0x2000)
715 int ioctl(int fd, int cmd);
716
734 int ReplaceStdio(int stdio_fd, int new_fd);
735
743 int CurrentStdioFD(int stdio_fd);
744
750 void IrqStdio();
751
752#ifdef __cplusplus
753}
754#endif
755
756#endif
757
758 // groupIOSYS
int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
Read data from a file descriptor(fd), or return if at least one byte is not read within the specified...
Definition iosys.h:229
int ReplaceStdio(int stdio_fd, int new_fd)
Maps stdio to any file descriptor (fd).
int charavail()
Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port...
void FD_SETFROMSET(const fd_set *from, fd_set *to)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function adds the file des...
int FD_OVERLAP(const fd_set *f1, const fd_set *f2)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function determines whethe...
int ReadAllWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout)
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an un...
void FD_CLRFROMSET(const fd_set *from, fd_set *to)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function remove the file d...
FDChangeType
The notifications that a registered FD monitor can receive.
Definition iosys.h:444
int SockPeekWithTimeout(int fd, char *buf, uint32_t maxtime)
This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed t...
int readall(int fd, char *buf, int nbytes)
Read the specified number of bytes from a file descriptor (fd). This function will block until either...
int FD_ISSET(int fd, fd_set *pfds)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or...
void FD_COPY(const fd_set *from, fd_set *to)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function copies one file d...
int dataavail(int fd)
Check the specified file descriptor to detmeine if data is available to be read.
int writeavail(int fd)
Check the specified file descriptor to determine data can be written.
void FDCallBack(int fd, FDChangeType change, void *pData)
Define the function signature for file descriptor notification callbacks.
Definition iosys.h:462
int(* peek)(int fd, char *buf)
Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte i...
Definition iointernal.h:3
int CurrentStdioFD(int stdio_fd)
Returns the current file descriptor mapped to the stdio file descriptor.
int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
Attempt to read the specified number of bytes from a file descriptor, or return with the number of by...
int(* read)(int fd, char *buf, int nbytes)
Read data from a file descriptor (fd).
Definition iointernal.h:0
void IrqStdio()
Open the system default serial port in interrupt mode using the system default baud rate,...
void FD_SET(int fd, fd_set *pfds)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a sp...
int(* close)(int fd)
Close the specified file descriptor and free the associated resources.
Definition iointernal.h:2
void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData)
Register a callback function to receive notification when an FD state changes. Register a NULL fp to ...
int writeall(int fd, const char *buf, int nbytes=0)
Write the specified number of bytes to a file descriptor. Will block until all bytes are sent,...
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
Wait for events to occur on one or more I/O resources associated with a set of file descriptors (fds)...
Definition iosys.h:636
int writestring(int fd, const char *str)
Write a null terminated ascii string to the stream associated with a file descriptor (fd)....
int getchar()
Get a character from stdin. Will block if no character is available, from stdio library....
void FD_ZERO(fd_set *pfds)
Clear (set to 0) a fd_set (file descriptor set) so no file descriptors (fds) are selected.
int ioctl(int fd, int cmd)
This function controls the selection of input/output control options for stdio: stdin = 0,...
int haserror(int fd)
Check if a file descriptor has an error.
int(* write)(int fd, const char *buf, int nbytes)
Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio,...
Definition iointernal.h:1
int ReadWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout)
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an un...
void FD_CLR(int fd, fd_set *pfds)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or removes...
int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds)
Returns whether events have occurred on one or more I/O resources associated with a set of file descr...
@ eWriteSet
When an FD changes from not writable to writeable.
Definition iosys.h:446
@ eReadSet
When read data changes from not available to available.
Definition iosys.h:445
@ eErrorSet
When an FD goes from no error to having an error.
Definition iosys.h:447
@ eClosingNow
when the underlying protocol closes the fd
Definition iosys.h:448
Internal IPv4 Header Representation.
Definition arp.h:1035