NetBurner 3.5.8
PDF Version
iosys.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
9
18
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
64 int close(int fd);
65
93 int read(int fd, char *buf, int nbytes);
94
112 int peek(int fd, char *c);
113
134 int write(int fd, const char *buf, int nbytes);
135
155 int writestring(int fd, const char *str);
156
179 int writeall(int fd, const char *buf, int nbytes = 0);
180
209 int ReadWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
210
241 inline int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
242 {
243 TickTimeout t(timeout);
244 return ReadWithTickTimeout(fd,buf,nbytes,t);
245 }
246
274 int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
275
304 int ReadAllWithTickTimeout(int fd, char *buf, int nbytes, TickTimeout &timeout);
305
325 int readall(int fd, char *buf, int nbytes);
326
349 //int PeekWithTimeout(int fd, char *c, unsigned long timeout);
350 int SockPeekWithTimeout(int fd, char *buf, uint32_t maxtime);
351
361 int getchar();
362
374 int dataavail(int fd);
375
387 int writeavail(int fd);
388
400 int haserror(int fd);
401
413
414#ifdef fd_set
415#undef fd_set
416#endif
417
418#ifdef FD_ZERO
419#undef FD_ZERO
420#endif
421
422#ifdef FD_CLR
423#undef FD_CLR
424#endif
425
426#ifdef FD_SET
427#undef FD_SET
428#endif
429
430#ifdef FD_ISSET
431#undef FD_ISSET
432#endif
433
434#ifdef FD_SETSIZE
435#undef FD_SETSIZE
436#endif
437
438#define FD_SETSIZE (FDSET_ELEMENTS * 32)
439
440 class OS_SEM;
441
442 typedef struct
443 {
444 uint32_t fd_set_elements[FDSET_ELEMENTS];
445 } __attribute__((packed)) fd_set;
446
462
463
474 typedef void FDCallBack(int fd, FDChangeType change, void *pData);
475
487 void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData);
488
497 void FD_ZERO(fd_set *pfds);
498
509 void FD_CLR(int fd, fd_set *pfds);
510
521 void FD_SET(int fd, fd_set *pfds);
522
544 int FD_ISSET(int fd, fd_set *pfds);
545
557 int FD_OVERLAP(const fd_set *f1, const fd_set *f2);
558
569 void FD_COPY(const fd_set *from, fd_set *to);
570
581 void FD_SETFROMSET(const fd_set *from, fd_set *to);
582
593 void FD_CLRFROMSET(const fd_set *from, fd_set *to);
594
595 int textern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, TickTimeout &timeout);
596
597 // A Select that uses an external SEM so other things can wake it up.
598 inline int extern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, unsigned long timeout)
599 {
600 TickTimeout t(timeout);
601 return textern_sem_select(nfds, readfds, writefds, errorfds, sem, t);
602 }
603
604 inline int tselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, TickTimeout &timeout)
605 {
606 OS_SEM SelectSem;
607 return textern_sem_select(nfds, readfds, writefds, errorfds, SelectSem, timeout);
608 }
609
648 inline int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
649 {
650 TickTimeout t(timeout);
651
652 return tselect(nfds, readfds, writefds, errorfds, t);
653
654 }
655
674 int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds);
675
676 int twaitchar(TickTimeout &timeout);
677 int waitchar(uint32_t wait);
678
679/**********************************************************************/
680/* Define sets of flags to pass to the ioctl function */
681/**********************************************************************/
682
688#define IOCTL_TX_CHANGE_CRLF (1)
689#define IOCTL_RX_CHANGE_CRLF (2)
690#define IOCTL_RX_PROCESS_EDITS (4)
691#define IOCTL_RX_ECHO (8)
692#define IOCTL_TX_NO_BLOCK (32)
693#define IOCTL_ALL_OPTIONS (15)
695
701#define IOCTL_SET (0x4000)
702#define IOCTL_CLR (0x2000)
704
727 int ioctl(int fd, int cmd);
728
746 int ReplaceStdio(int stdio_fd, int new_fd);
747
755 int CurrentStdioFD(int stdio_fd);
756
762 void IrqStdio();
763
764#ifdef __cplusplus
765}
766#endif
767
768#endif
769 // groupIOSYS
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:162
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:241
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:456
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:474
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)...
Definition iosys.h:648
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:458
@ eReadSet
When read data changes from not available to available.
Definition iosys.h:457
@ eErrorSet
When an FD goes from no error to having an error.
Definition iosys.h:459
@ eClosingNow
when the underlying protocol closes the fd
Definition iosys.h:460
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:407