Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

threewire.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _GPXE_NVS_THREEWIRE_H
  2. #define _GPXE_NVS_THREEWIRE_H
  3. /** @file
  4. *
  5. * Three-wire serial interface
  6. *
  7. */
  8. struct threewire;
  9. /** Three-wire interface methods */
  10. struct threewire_operations {
  11. /**
  12. * Set status of Chip Select line
  13. *
  14. * @v three Three-wire interface
  15. * @v cs New status for chip select line
  16. */
  17. void ( * setcs ) ( struct threewire *three, int cs );
  18. /**
  19. * Set status of Serial Clock line
  20. *
  21. * @v three Three-wire interface
  22. * @v sk New status for serial clock line
  23. */
  24. void ( * setsk ) ( struct threewire *three, int sk );
  25. /**
  26. * Set status of Data Input line
  27. *
  28. * @v three Three-wire interface
  29. * @v di New status for data input line
  30. */
  31. void ( * setdi ) ( struct threewire *three, int di );
  32. /**
  33. * Get status of Data Output line
  34. *
  35. * @v three Three-wire interface
  36. * @ret do Status of data output line
  37. */
  38. int ( * getdo ) ( struct threewire *three );
  39. };
  40. /**
  41. * A three-wire serial interface
  42. *
  43. * This interface consists of a clock line (SK), data input (DI) and
  44. * data output (DO). There is also a chip select line (CS) which is
  45. * integral to the operation of the device, but Atmel still calls it a
  46. * three-wire interface.
  47. *
  48. */
  49. struct threewire {
  50. /** Interface methods */
  51. struct threewire_operations *ops;
  52. /** Address size (in bits) */
  53. unsigned int adrsize;
  54. /** Data size (in bits) */
  55. unsigned int datasize;
  56. /** Delay between SK transitions (in us) */
  57. unsigned int udelay;
  58. };
  59. /**
  60. * Calculate read command for a specified address
  61. *
  62. * @v three Three-wire interface
  63. * @v address Address
  64. * @ret cmd Command
  65. */
  66. static inline __attribute__ (( always_inline )) unsigned long
  67. threewire_cmd_read ( struct threewire *three, unsigned long address ) {
  68. return ( ( 0x6 << three->adrsize ) | address );
  69. }
  70. /**
  71. * Calculate command length
  72. *
  73. * @v three Three-wire interface
  74. * @ret len Command length, in bits
  75. */
  76. static inline __attribute__ (( always_inline )) int
  77. threewire_cmd_len ( struct threewire *three ) {
  78. return ( three->adrsize + 3 );
  79. }
  80. /* Constants for some standard parts */
  81. #define AT93C46_ORG8_ADRSIZE 7
  82. #define AT93C46_ORG8_DATASIZE 8
  83. #define AT93C46_ORG16_ADRSIZE 6
  84. #define AT93C46_ORG16_DATASIZE 16
  85. #define AT93C46_UDELAY 1
  86. #define AT93C56_ORG8_ADRSIZE 9
  87. #define AT93C56_ORG8_DATASIZE 8
  88. #define AT93C56_ORG16_ADRSIZE 8
  89. #define AT93C56_ORG16_DATASIZE 16
  90. #define AT93C56_UDELAY 1
  91. extern unsigned long threewire_read ( struct threewire *three,
  92. unsigned long address );
  93. #endif /* _GPXE_NVS_THREEWIRE_H */