sbbif0.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #ifndef _DEV_SBBIF0_H_
  2. #define _DEV_SBBIF0_H_
  3. /*
  4. * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/sbbif0.h
  36. * \brief Serial bit banged interface 0.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.5 2009/01/18 16:44:56 haraldkipp
  42. * Introduced target independent port numbers.
  43. * Distinguish between PIO IDs and port numbers.
  44. *
  45. * Revision 1.4 2009/01/18 10:45:54 haraldkipp
  46. * Fixed bit banging SPI for ARM targets.
  47. *
  48. * Revision 1.3 2008/08/28 16:11:31 haraldkipp
  49. * Fixed bitbanging SPI for ARM targets.
  50. *
  51. * Revision 1.2 2008/08/11 06:59:59 haraldkipp
  52. * BSD types replaced by stdint types (feature request #1282721).
  53. *
  54. * Revision 1.1 2007/04/12 09:07:54 haraldkipp
  55. * Configurable SPI added.
  56. *
  57. *
  58. * \endverbatim
  59. */
  60. #include <cfg/arch/gpio.h>
  61. #include <stdint.h>
  62. /*!
  63. * \brief Maximum number of devices (chip selects).
  64. */
  65. #ifndef SBBI0_MAX_DEVICES
  66. #define SBBI0_MAX_DEVICES 4
  67. #endif
  68. #ifdef SBBI0_CS0_BIT
  69. #undef GPIO_ID
  70. #if defined(SBBI0_CS0_PORT)
  71. #define GPIO_ID SBBI0_CS0_PORT
  72. #endif
  73. #include <cfg/arch/porttran.h>
  74. #define SBBI0_CS0_ENA() GPIO_ENABLE(SBBI0_CS0_BIT)
  75. #define SBBI0_CS0_OUTPUT() GPIO_OUTPUT(SBBI0_CS0_BIT)
  76. #define SBBI0_CS0_SET() GPIO_SET_HI(SBBI0_CS0_BIT)
  77. #define SBBI0_CS0_CLR() GPIO_SET_LO(SBBI0_CS0_BIT)
  78. #else
  79. #define SBBI0_CS0_ENA()
  80. #define SBBI0_CS0_OUTPUT()
  81. #define SBBI0_CS0_CLR()
  82. #define SBBI0_CS0_SET()
  83. #endif
  84. #ifdef SBBI0_CS1_BIT
  85. #undef GPIO_ID
  86. #if defined(SBBI0_CS1_PORT)
  87. #define GPIO_ID SBBI0_CS1_PORT
  88. #endif
  89. #include <cfg/arch/porttran.h>
  90. #define SBBI0_CS1_ENA() GPIO_ENABLE(SBBI0_CS1_BIT)
  91. #define SBBI0_CS1_OUTPUT() GPIO_SET_HI(SBBI0_CS1_BIT)
  92. #define SBBI0_CS1_SET() GPIO_SET_HI(SBBI0_CS1_BIT)
  93. #define SBBI0_CS1_CLR() GPIO_SET_LO(SBBI0_CS1_BIT)
  94. #else
  95. #define SBBI0_CS1_ENA()
  96. #define SBBI0_CS1_OUTPUT()
  97. #define SBBI0_CS1_CLR()
  98. #define SBBI0_CS1_SET()
  99. #endif
  100. #ifdef SBBI0_CS2_BIT
  101. #undef GPIO_ID
  102. #if defined(SBBI0_CS2_PORT)
  103. #define GPIO_ID SBBI0_CS2_PORT
  104. #endif
  105. #include <cfg/arch/porttran.h>
  106. #define SBBI0_CS2_ENA() GPIO_ENABLE(SBBI0_CS2_BIT)
  107. #define SBBI0_CS2_OUTPUT() GPIO_OUTPUT(SBBI0_CS2_BIT)
  108. #define SBBI0_CS2_SET() GPIO_SET_HI(SBBI0_CS2_BIT)
  109. #define SBBI0_CS2_CLR() GPIO_SET_LO(SBBI0_CS2_BIT)
  110. #else
  111. #define SBBI0_CS2_ENA()
  112. #define SBBI0_CS2_OUTPUT()
  113. #define SBBI0_CS2_CLR()
  114. #define SBBI0_CS2_SET()
  115. #endif
  116. #ifdef SBBI0_CS3_BIT
  117. #undef GPIO_ID
  118. #if defined(SBBI0_CS3_PORT)
  119. #define GPIO_ID SBBI0_CS3_PORT
  120. #endif
  121. #include <cfg/arch/porttran.h>
  122. #define SBBI0_CS3_ENA() GPIO_ENABLE(SBBI0_CS3_BIT)
  123. #define SBBI0_CS3_OUTPUT() GPIO_OUTPUT(SBBI0_CS3_BIT)
  124. #define SBBI0_CS3_SET() GPIO_SET_HI(SBBI0_CS3_BIT)
  125. #define SBBI0_CS3_CLR() GPIO_SET_LO(SBBI0_CS3_BIT)
  126. #else
  127. #define SBBI0_CS3_ENA()
  128. #define SBBI0_CS3_OUTPUT()
  129. #define SBBI0_CS3_CLR()
  130. #define SBBI0_CS3_SET()
  131. #endif
  132. #ifdef SBBI0_RST0_BIT
  133. #undef GPIO_ID
  134. #if defined(SBBI0_RST0_PORT)
  135. #define GPIO_ID SBBI0_RST0_PORT
  136. #endif
  137. #include <cfg/arch/porttran.h>
  138. #define SBBI0_RST0_ENA() GPIO_ENABLE(SBBI0_RST0_BIT)
  139. #define SBBI0_RST0_OUTPUT() GPIO_OUTPUT(SBBI0_RST0_BIT)
  140. #define SBBI0_RST0_SET() GPIO_SET_HI(SBBI0_RST0_BIT)
  141. #define SBBI0_RST0_CLR() GPIO_SET_LO(SBBI0_RST0_BIT)
  142. #else
  143. #define SBBI0_RST0_ENA()
  144. #define SBBI0_RST0_OUTPUT()
  145. #define SBBI0_RST0_CLR()
  146. #define SBBI0_RST0_SET()
  147. #endif
  148. #ifdef SBBI0_RST1_BIT
  149. #undef GPIO_ID
  150. #if defined(SBBI0_RST1_PORT)
  151. #define GPIO_ID SBBI0_RST1_PORT
  152. #endif
  153. #include <cfg/arch/porttran.h>
  154. #define SBBI0_RST1_ENA() GPIO_ENABLE(SBBI0_RST1_BIT)
  155. #define SBBI0_RST1_OUTPUT() GPIO_OUTPUT(SBBI0_RST1_BIT)
  156. #define SBBI0_RST1_SET() GPIO_SET_HI(SBBI0_RST1_BIT)
  157. #define SBBI0_RST1_CLR() GPIO_SET_LO(SBBI0_RST1_BIT)
  158. #else
  159. #define SBBI0_RST1_ENA()
  160. #define SBBI0_RST1_OUTPUT()
  161. #define SBBI0_RST1_CLR()
  162. #define SBBI0_RST1_SET()
  163. #endif
  164. #ifdef SBBI0_RST2_BIT
  165. #undef GPIO_ID
  166. #if defined(SBBI0_RST2_PORT)
  167. #define GPIO_ID SBBI0_RST2_PORT
  168. #endif
  169. #include <cfg/arch/porttran.h>
  170. #define SBBI0_RST2_ENA() GPIO_ENABLE(SBBI0_RST2_BIT)
  171. #define SBBI0_RST2_OUTPUT() GPIO_OUTPUT(SBBI0_RST2_BIT)
  172. #define SBBI0_RST2_SET() GPIO_SET_HI(SBBI0_RST2_BIT)
  173. #define SBBI0_RST2_CLR() GPIO_SET_LO(SBBI0_RST2_BIT)
  174. #else
  175. #define SBBI0_RST2_ENA()
  176. #define SBBI0_RST2_OUTPUT()
  177. #define SBBI0_RST2_CLR()
  178. #define SBBI0_RST2_SET()
  179. #endif
  180. #ifdef SBBI0_RST3_BIT
  181. #undef GPIO_ID
  182. #if defined(SBBI0_RST3_PORT)
  183. #define GPIO_ID SBBI0_RST3_PORT
  184. #endif
  185. #include <cfg/arch/porttran.h>
  186. #define SBBI0_RST3_ENA() GPIO_ENABLE(SBBI0_RST3_BIT)
  187. #define SBBI0_RST3_OUTPUT() GPIO_OUTPUT(SBBI0_RST3_BIT)
  188. #define SBBI0_RST3_SET() GPIO_SET_HI(SBBI0_RST3_BIT)
  189. #define SBBI0_RST3_CLR() GPIO_SET_LO(SBBI0_RST3_BIT)
  190. #else
  191. #define SBBI0_RST3_ENA()
  192. #define SBBI0_RST3_OUTPUT()
  193. #define SBBI0_RST3_CLR()
  194. #define SBBI0_RST3_SET()
  195. #endif
  196. #ifdef SBBI0_SCK_BIT
  197. #undef GPIO_ID
  198. #if defined(SBBI0_SCK_PORT)
  199. #define GPIO_ID SBBI0_SCK_PORT
  200. #endif
  201. #include <cfg/arch/porttran.h>
  202. #define SBBI0_SCK_ENA() GPIO_ENABLE(SBBI0_SCK_BIT)
  203. #define SBBI0_SCK_OUTPUT() GPIO_OUTPUT(SBBI0_SCK_BIT)
  204. #define SBBI0_SCK_SET() GPIO_SET_HI(SBBI0_SCK_BIT)
  205. #define SBBI0_SCK_CLR() GPIO_SET_LO(SBBI0_SCK_BIT)
  206. #else
  207. #define SBBI0_SCK_ENA()
  208. #define SBBI0_SCK_OUTPUT()
  209. #define SBBI0_SCK_CLR()
  210. #define SBBI0_SCK_SET()
  211. #endif
  212. #ifdef SBBI0_MOSI_BIT
  213. #undef GPIO_ID
  214. #if defined(SBBI0_MOSI_PORT)
  215. #define GPIO_ID SBBI0_MOSI_PORT
  216. #endif
  217. #include <cfg/arch/porttran.h>
  218. #define SBBI0_MOSI_ENA() GPIO_ENABLE(SBBI0_MOSI_BIT)
  219. #define SBBI0_MOSI_OUTPUT() GPIO_OUTPUT(SBBI0_MOSI_BIT)
  220. #define SBBI0_MOSI_SET() GPIO_SET_HI(SBBI0_MOSI_BIT)
  221. #define SBBI0_MOSI_CLR() GPIO_SET_LO(SBBI0_MOSI_BIT)
  222. #else
  223. #define SBBI0_MOSI_ENA()
  224. #define SBBI0_MOSI_OUTPUT()
  225. #define SBBI0_MOSI_CLR()
  226. #define SBBI0_MOSI_SET()
  227. #endif
  228. #ifdef SBBI0_MISO_BIT
  229. #undef GPIO_ID
  230. #if defined(SBBI0_MISO_PORT)
  231. #define GPIO_ID SBBI0_MISO_PORT
  232. #endif
  233. #include <cfg/arch/porttran.h>
  234. #define SBBI0_MISO_ENA() GPIO_ENABLE(SBBI0_MISO_BIT)
  235. #define SBBI0_MISO_TST() GPIO_GET(SBBI0_MISO_BIT)
  236. #else
  237. #define SBBI0_MISO_ENA()
  238. #define SBBI0_MISO_TST() 0
  239. #endif
  240. #define SBBI0_INIT() \
  241. { \
  242. SBBI0_SCK_CLR(); \
  243. SBBI0_SCK_ENA(); \
  244. SBBI0_MOSI_CLR(); \
  245. SBBI0_MOSI_ENA(); \
  246. SBBI0_MISO_ENA(); \
  247. }
  248. extern int Sbbi0SetMode(ureg_t ix, ureg_t mode);
  249. extern void Sbbi0SetSpeed(ureg_t ix, uint32_t rate);
  250. extern void Sbbi0Enable(ureg_t ix);
  251. extern void Sbbi0ChipReset(ureg_t ix, ureg_t hi);
  252. extern void Sbbi0ChipSelect(ureg_t ix, ureg_t hi);
  253. extern void Sbbi0SelectDevice(ureg_t ix);
  254. extern void Sbbi0DeselectDevice(ureg_t ix);
  255. extern void Sbbi0NegSelectDevice(ureg_t ix);
  256. extern void Sbbi0NegDeselectDevice(ureg_t ix);
  257. extern uint8_t Sbbi0Byte(uint8_t data);
  258. extern void Sbbi0Transact(const void *wdata, void *rdata, size_t len);
  259. #endif