NetBurner 3.5.6
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
28#ifndef _BASICTYPES_H_
29#include <basictypes.h>
30#endif
31
32class TickTimeout;
33#ifdef __cplusplus
34extern "C"
35{
36#endif
37
51 int close(int fd);
52
80 int read(int fd, char *buf, int nbytes);
81
99 int peek(int fd, char *c);
100
121 int write(int fd, const char *buf, int nbytes);
122
142 int writestring(int fd, const char *str);
143
166 int writeall(int fd, const char *buf, int nbytes = 0);
167
198 int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
199
228 int ReadWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
229
257 int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
258
287 int ReadAllWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
288
308 int readall(int fd, char *buf, int nbytes);
309
332 //int PeekWithTimeout(int fd, char *c, unsigned long timeout);
333 int SockPeekWithTimeout(int fd, char *buf, uint32_t maxtime);
334
344 int getchar();
345
357 int dataavail(int fd);
358
370 int writeavail(int fd);
371
383 int haserror(int fd);
384
396
397#ifdef fd_set
398#undef fd_set
399#endif
400
401#ifdef FD_ZERO
402#undef FD_ZERO
403#endif
404
405#ifdef FD_CLR
406#undef FD_CLR
407#endif
408
409#ifdef FD_SET
410#undef FD_SET
411#endif
412
413#ifdef FD_ISSET
414#undef FD_ISSET
415#endif
416
417#ifdef FD_SETSIZE
418#undef FD_SETSIZE
419#endif
420
421#define FD_SETSIZE (FDSET_ELEMENTS * 32)
422
423 class OS_SEM;
424
425 typedef struct
426 {
427 uint32_t fd_set_elements[FDSET_ELEMENTS];
428 } __attribute__((packed)) fd_set;
429
457 typedef void FDCallBack(int fd, FDChangeType change, void *pData);
458
470 void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData);
471
480 void FD_ZERO(fd_set *pfds);
481
492 void FD_CLR(int fd, fd_set *pfds);
493
504 void FD_SET(int fd, fd_set *pfds);
505
527 int FD_ISSET(int fd, fd_set *pfds);
528
540 int FD_OVERLAP(const fd_set *f1, const fd_set *f2);
541
552 void FD_COPY(const fd_set *from, fd_set *to);
553
564 void FD_SETFROMSET(const fd_set *from, fd_set *to);
565
576 void FD_CLRFROMSET(const fd_set *from, fd_set *to);
577
578 // A Select that uses an external SEM so other things can wake it up.
579 int extern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, unsigned long timeout);
580
581 int textern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, TickTimeout &timeout);
582
621 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout);
622
623 int tselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, TickTimeout &timeout);
624
643 int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds);
644
645 int twaitchar(TickTimeout &timeout);
646 int waitchar(uint32_t wait);
647
648/**********************************************************************/
649/* Define sets of flags to pass to the ioctl function */
650/**********************************************************************/
651
657#define IOCTL_TX_CHANGE_CRLF (1)
658#define IOCTL_RX_CHANGE_CRLF (2)
659#define IOCTL_RX_PROCESS_EDITS (4)
660#define IOCTL_RX_ECHO (8)
661#define IOCTL_TX_NO_BLOCK (32)
662#define IOCTL_ALL_OPTIONS (15)
670#define IOCTL_SET (0x4000)
671#define IOCTL_CLR (0x2000)
696 int ioctl(int fd, int cmd);
697
715 int ReplaceStdio(int stdio_fd, int new_fd);
716
724 int CurrentStdioFD(int stdio_fd);
725
731 void IrqStdio();
732
733#ifdef __cplusplus
734}
735#endif
736
737#endif
738
739 // 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...
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:439
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:457
int peek(int fd, char *c)
Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte i...
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).
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.
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)...
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,...
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:441
@ eReadSet
When read data changes from not available to available.
Definition iosys.h:440
@ eErrorSet
When an FD goes from no error to having an error.
Definition iosys.h:442
@ eClosingNow
when the underlying protocol closes the fd
Definition iosys.h:443