NetBurner 3.5.0
PDF Version
 
iosys.h
Go to the documentation of this file.
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
343 int getchar();
344
356 int dataavail(int fd);
357
369 int writeavail(int fd);
370
382 int haserror(int fd);
383
395
396#ifdef fd_set
397#undef fd_set
398#endif
399
400#ifdef FD_ZERO
401#undef FD_ZERO
402#endif
403
404#ifdef FD_CLR
405#undef FD_CLR
406#endif
407
408#ifdef FD_SET
409#undef FD_SET
410#endif
411
412#ifdef FD_ISSET
413#undef FD_ISSET
414#endif
415
416#ifdef FD_SETSIZE
417#undef FD_SETSIZE
418#endif
419
420#define FD_SETSIZE (FDSET_ELEMENTS * 32)
421
422 class OS_SEM;
423
424 typedef struct
425 {
426 uint32_t fd_set_elements[FDSET_ELEMENTS];
427 } __attribute__((packed)) fd_set;
428
456 typedef void FDCallBack(int fd, FDChangeType change, void *pData);
457
469 void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData);
470
479 void FD_ZERO(fd_set *pfds);
480
491 void FD_CLR(int fd, fd_set *pfds);
492
503 void FD_SET(int fd, fd_set *pfds);
504
526 int FD_ISSET(int fd, fd_set *pfds);
527
539 int FD_OVERLAP(const fd_set *f1, const fd_set *f2);
540
551 void FD_COPY(const fd_set *from, fd_set *to);
552
563 void FD_SETFROMSET(const fd_set *from, fd_set *to);
564
575 void FD_CLRFROMSET(const fd_set *from, fd_set *to);
576
577 // A Select that uses an external SEM so other things can wake it up.
578 int extern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, unsigned long timeout);
579
580 int textern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, TickTimeout &timeout);
581
620 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout);
621
622 int tselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, TickTimeout &timeout);
623
642 int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds);
643
644/**********************************************************************/
645/* Define sets of flags to pass to the ioctl function */
646/**********************************************************************/
647
653#define IOCTL_TX_CHANGE_CRLF (1)
654#define IOCTL_RX_CHANGE_CRLF (2)
655#define IOCTL_RX_PROCESS_EDITS (4)
656#define IOCTL_RX_ECHO (8)
657#define IOCTL_TX_NO_BLOCK (32)
658#define IOCTL_ALL_OPTIONS (15)
666#define IOCTL_SET (0x4000)
667#define IOCTL_CLR (0x2000)
692 int ioctl(int fd, int cmd);
693
711 int ReplaceStdio(int stdio_fd, int new_fd);
712
720 int CurrentStdioFD(int stdio_fd);
721
727 void IrqStdio();
728
729#ifdef __cplusplus
730}
731#endif
732
733#endif
734
735 // groupIOSYS
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:157
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:438
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:456
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 PeekWithTimeout(int fd, char *c, unsigned long timeout)
This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed t...
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:440
@ eReadSet
When read data changes from not available to available.
Definition iosys.h:439
@ eErrorSet
When an FD goes from no error to having an error.
Definition iosys.h:441
@ eClosingNow
when the underlying protocol closes the fd
Definition iosys.h:442
NetBurner System Constants.
#define FDSET_ELEMENTS
Definition nbrtos/include/constants.h:202
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:386