NetBurner 3.1
iosys.h
Go to the documentation of this file.
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
16 #ifndef _NB_IOSYS_H
17 #define _NB_IOSYS_H
18 
19 #ifndef _CONSTANTS_H
20 #include <constants.h>
21 #endif
22 
23 #include <stdio.h>
24 
25 #ifndef _BASICTYPES_H_
26 #include <basictypes.h>
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34  /**********************************************************************/
35  /*This file defines the operations on the I/O system */
36  /*All serial I/O and TCP socket I/O is done through these IO calls. */
37  /**********************************************************************/
38 
54  int close(int fd);
55 
78  int read(int fd, char *buf, int nbytes);
79 
103  int peek(int fd, char *c);
104 
130  int write(int fd, const char *buf, int nbytes);
131 
152  int writestring(int fd, const char *str);
153 
175  int writeall(int fd, const char *buf, int nbytes);
176 
209  int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
210 
237  int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout);
238 
264  int readall(int fd, char *buf, int nbytes);
265 
290  int PeekWithTimeout(int fd, char *c, unsigned long timeout);
291 
305  int dataavail(int fd);
306 
319  int writeavail(int fd);
320 
333  int haserror(int fd);
334 
345  int charavail();
346 
347 #ifdef fd_set
348 #undef fd_set
349 #endif
350 
351 #ifdef FD_ZERO
352 #undef FD_ZERO
353 #endif
354 
355 #ifdef FD_CLR
356 #undef FD_CLR
357 #endif
358 
359 #ifdef FD_SET
360 #undef FD_SET
361 #endif
362 
363 #ifdef FD_ISSET
364 #undef FD_ISSET
365 #endif
366 
367 #ifdef FD_SETSIZE
368 #undef FD_SETSIZE
369 #endif
370 
371 #define FD_SETSIZE (FDSET_ELEMENTS * 32)
372  class OS_SEM;
373 
374  typedef struct
375  {
376  uint32_t fd_set_elements[FDSET_ELEMENTS];
377  } __attribute__((packed)) fd_set;
378 
383  {
384  eReadSet, /* When read data goes from not availible to availible */
385  eWriteSet, /* When an FD goes from not writable to writeable */
386  eErrorSet /*When an FD goes from no error to having an error */
387  };
388 
398  typedef void FDCallBack(int fd, FDChangeType change, void *pData);
399 
410  void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData);
411 
422  void FD_ZERO(fd_set *pfds);
423 
436  void FD_CLR(int fd, fd_set *pfds);
437 
450  void FD_SET(int fd, fd_set *pfds);
451 
464  int FD_ISSET(int fd, fd_set *pfds);
465 
466  // A Select that uses an external SEM so other things can wke it up.
467  int extern_sem_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, OS_SEM &sem, unsigned long timeout);
468 
494  int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout);
495 
518  int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds);
519 
520  /**********************************************************************/
521  /* This defines a set of flags to pass to the ioctl function */
522  /**********************************************************************/
523 
528 #define IOCTL_TX_CHANGE_CRLF (1)
529 #define IOCTL_RX_CHANGE_CRLF (2)
530 #define IOCTL_RX_PROCESS_EDITS (4)
531 #define IOCTL_RX_ECHO (8)
532 #define IOCTL_TX_NO_BLOCK (32)
533 #define IOCTL_ALL_OPTIONS (15)
534 
536 
540 #define IOCTL_SET (0x4000)
541 #define IOCTL_CLR (0x2000)
542 
544 
565  int ioctl(int fd, int cmd);
566 
583  int ReplaceStdio(int stdio_fd, int new_fd);
584 
585  // Returns current FD mapped to stdio file
593  int CurrentStdioFD(int stdio_fd);
594 
599  void IrqStdio();
600 
601 #ifdef __cplusplus
602 }
603 #endif
604 
605 #endif
606 
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
This function waits for events to occur on one or more I/O resources associated with a set of file de...
Definition: iosys.cpp:362
int writeavail(int fd)
Check to see if a file descriptor is available for write.
Definition: iosys.cpp:407
int writestring(int fd, const char *str)
This function writes null terminated string data to the stream associated with a file descriptor (fd)...
Definition: iosys.cpp:387
void FDCallBack(int fd, FDChangeType change, void *pData)
This defines the funciton signature for FD notifcation callbacks.
Definition: iosys.h:398
void IrqStdio()
Automatically open the system default serial port in interrupt mode using the system default baud rat...
Definition: IrqStdio.cpp:12
int haserror(int fd)
Check to see if a file descriptor has an error.
Definition: iosys.cpp:412
Semaphores are used to control access to shared resource critical section, or to communicate between ...
Definition: nbrtos.h:318
int CurrentStdioFD(int stdio_fd)
Determine the current file descriptor mapped to stdio file.
Definition: fileio.cpp:453
int readall(int fd, char *buf, int nbytes)
This function reads data from a file descriptor (fd), with a specified time-out value (as opposed to ...
Definition: iosys.cpp:209
int PeekWithTimeout(int fd, char *c, unsigned long timeout)
This function peeks at data from a file descriptor (fd), with a specified time-out value (as opposed ...
int write(int fd, const char *buf, int nbytes)
This function writes data to the stream associated with a file descriptor (fd).
Definition: fileio.cpp:152
void FD_ZERO(fd_set *pfds)
This function zero&#39;s an fd_set (file descriptor set) so that it has no file descriptors (fds) selecte...
Definition: iosys.cpp:214
void RegisterFDCallBack(int fd, FDCallBack *fp, void *pData)
Register a call back function to recieve notifcation when an FD state changes. Register a NULL pf to ...
Definition: iosys.cpp:41
void FD_CLR(int fd, fd_set *pfds)
An fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or remove...
Definition: iosys.cpp:225
int ioctl(int fd, int cmd)
This function controls the selection of input/output control options for stdio: stdin = 0...
Definition: fileio.cpp:81
int read(int fd, char *buf, int nbytes)
This function reads data from a file descriptor (fd), and will block forever until at least one byte ...
Definition: fileio.cpp:288
int peek(int fd, char *c)
This function peeks at data from a file descriptor (fd), and will block forever until at least one by...
Definition: fileio.cpp:232
int ReadWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
This function reads data from a file descriptor (fd), with a specified time-out value (as opposed to ...
Definition: iosys.cpp:164
FDChangeType
This enum lists the notificatiosn that a registered FD monitor can recieve.
Definition: iosys.h:382
int writeall(int fd, const char *buf, int nbytes)
This function writes data to the stream associated with a file descriptor (fd).
Definition: iosys.cpp:368
int ReplaceStdio(int stdio_fd, int new_fd)
This function allows you to map stdio to any file descriptor (fd).
Definition: fileio.cpp:431
int ReadAllWithTimeout(int fd, char *buf, int nbytes, unsigned long timeout)
This function reads data from a file descriptor (fd), with a specified time-out value (as opposed to ...
Definition: iosys.cpp:185
int FD_ISSET(int fd, fd_set *pfds)
An fd_set (file descriptor set) holds a set of file descriptors (fds). This function indicates whethe...
Definition: iosys.cpp:245
int charavail()
This function checks to see if data is available for read on stdin.
Definition: fileio.cpp:415
int dataavail(int fd)
This function checks to see if data is available for read.
Definition: iosys.cpp:401
int close(int fd)
This function closes the resources associated with a file descriptor (fd). This can be a TCP socket o...
Definition: fileio.cpp:99
void FD_SET(int fd, fd_set *pfds)
An fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a s...
Definition: iosys.cpp:235
int ZeroWaitSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds)
This function returns whether events have occurred on one or more I/O resources associated with a set...
Definition: iosys.cpp:280