alt_dev.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef __ALT_DEV_H__
  2. #define __ALT_DEV_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. * Altera does not recommend, suggest or require that this reference design *
  32. * file be used in conjunction or combination with any other product. *
  33. ******************************************************************************/
  34. /******************************************************************************
  35. * *
  36. * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
  37. * *
  38. ******************************************************************************/
  39. #include "system.h"
  40. #include "sys/alt_llist.h"
  41. #include "priv/alt_dev_llist.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif /* __cplusplus */
  46. /*
  47. * The value ALT_IRQ_NOT_CONNECTED is used to represent an unconnected
  48. * interrupt line. It cannot evaluate to a valid interrupt number.
  49. */
  50. #define ALT_IRQ_NOT_CONNECTED (-1)
  51. typedef struct alt_dev_s alt_dev;
  52. struct stat;
  53. /*
  54. * The file descriptor structure definition.
  55. */
  56. typedef struct alt_fd_s
  57. {
  58. alt_dev* dev;
  59. alt_u8* priv;
  60. int fd_flags;
  61. } alt_fd;
  62. /*
  63. * The device structure definition.
  64. */
  65. struct alt_dev_s {
  66. alt_llist llist; /* for internal use */
  67. const char* name;
  68. int (*open) (alt_fd* fd, const char* name, int flags, int mode);
  69. int (*close) (alt_fd* fd);
  70. int (*read) (alt_fd* fd, char* ptr, int len);
  71. int (*write) (alt_fd* fd, const char* ptr, int len);
  72. int (*lseek) (alt_fd* fd, int ptr, int dir);
  73. int (*fstat) (alt_fd* fd, struct stat* buf);
  74. int (*ioctl) (alt_fd* fd, int req, void* arg);
  75. };
  76. /*
  77. * Functions used to register device for access through the C standard
  78. * library.
  79. *
  80. * The only difference between alt_dev_reg() and alt_fs_reg() is the
  81. * interpretation that open() places on the device name. In the case of
  82. * alt_dev_reg the device is assumed to be a particular character device,
  83. * and so there must be an exact match in the name for open to succeed.
  84. * In the case of alt_fs_reg() the name of the device is treated as the
  85. * mount point for a directory, and so any call to open() where the name
  86. * is the root of the device filename will succeed.
  87. */
  88. extern int alt_fs_reg (alt_dev* dev);
  89. static ALT_INLINE int alt_dev_reg (alt_dev* dev)
  90. {
  91. extern alt_llist alt_dev_list;
  92. return alt_dev_llist_insert ((alt_dev_llist*) dev, &alt_dev_list);
  93. }
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* __ALT_DEV_H__ */