sppif0.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #ifndef _DEV_SPPIF0_H_
  2. #define _DEV_SPPIF0_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 EGNITE SOFTWARE GMBH 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 EGNITE
  23. * SOFTWARE GMBH 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/sppif0.h
  36. * \brief Serial bit banged interface 0.
  37. *
  38. * \verbatim
  39. *
  40. * $Log: sppif0.h,v $
  41. * Revision 1.1 2007/04/12 09:07:54 haraldkipp
  42. * Configurable SPI added.
  43. *
  44. *
  45. * \endverbatim
  46. */
  47. #include <cfg/arch/gpio.h>
  48. /*!
  49. * \brief Maximum number of devices (chip selects).
  50. */
  51. #ifndef SPPI0_MAX_DEVICES
  52. #define SPPI0_MAX_DEVICES 4
  53. #endif
  54. #if defined(__AVR__) /* MCU */
  55. /*
  56. * AVR implementation.
  57. * ======================================
  58. */
  59. #ifdef SPPI0_CS0_BIT
  60. #if (SPPI0_CS0_AVRPORT == AVRPORTB)
  61. #define SPPI0_CS0_SOD_REG PORTB
  62. #define SPPI0_CS0_OE_REG DDRB
  63. #elif (SPPI0_CS0_AVRPORT == AVRPORTD)
  64. #define SPPI0_CS0_SOD_REG PORTD
  65. #define SPPI0_CS0_OE_REG DDRD
  66. #elif (SPPI0_CS0_AVRPORT == AVRPORTE)
  67. #define SPPI0_CS0_SOD_REG PORTE
  68. #define SPPI0_CS0_OE_REG DDRE
  69. #elif (SPPI0_CS0_AVRPORT == AVRPORTF)
  70. #define SPPI0_CS0_SOD_REG PORTF
  71. #define SPPI0_CS0_OE_REG DDRF
  72. #elif (SPPI0_CS0_AVRPORT == AVRPORTG)
  73. #define SPPI0_CS0_SOD_REG PORTG
  74. #define SPPI0_CS0_OE_REG DDRG
  75. #elif (SPPI0_CS0_AVRPORT == AVRPORTH)
  76. #define SPPI0_CS0_SOD_REG PORTH
  77. #define SPPI0_CS0_OE_REG DDRH
  78. #endif
  79. /*! \brief Enable SPPI0 chip select 0 output. */
  80. #define SPPI0_CS0_ENA() sbi(SPPI0_CS0_OE_REG, SPPI0_CS0_BIT)
  81. /*! \brief Set SPPI0 chip select 0 output low. */
  82. #define SPPI0_CS0_CLR() cbi(SPPI0_CS0_SOD_REG, SPPI0_CS0_BIT)
  83. /*! \brief Set SPPI0 chip select 0 output high. */
  84. #define SPPI0_CS0_SET() sbi(SPPI0_CS0_SOD_REG, SPPI0_CS0_BIT)
  85. #endif /* SPPI0_CS0_BIT */
  86. #ifdef SPPI0_CS1_BIT
  87. #if (SPPI0_CS1_AVRPORT == AVRPORTB)
  88. #define SPPI0_CS1_SOD_REG PORTB
  89. #define SPPI0_CS1_OE_REG DDRB
  90. #elif (SPPI0_CS1_AVRPORT == AVRPORTD)
  91. #define SPPI0_CS1_SOD_REG PORTD
  92. #define SPPI0_CS1_OE_REG DDRD
  93. #elif (SPPI0_CS1_AVRPORT == AVRPORTE)
  94. #define SPPI0_CS1_SOD_REG PORTE
  95. #define SPPI0_CS1_OE_REG DDRE
  96. #elif (SPPI0_CS1_AVRPORT == AVRPORTF)
  97. #define SPPI0_CS1_SOD_REG PORTF
  98. #define SPPI0_CS1_OE_REG DDRF
  99. #elif (SPPI0_CS1_AVRPORT == AVRPORTG)
  100. #define SPPI0_CS1_SOD_REG PORTG
  101. #define SPPI0_CS1_OE_REG DDRG
  102. #elif (SPPI0_CS1_AVRPORT == AVRPORTH)
  103. #define SPPI0_CS1_SOD_REG PORTH
  104. #define SPPI0_CS1_OE_REG DDRH
  105. #endif
  106. /*! \brief Enable SPPI0 chip select 1 output. */
  107. #define SPPI0_CS1_ENA() sbi(SPPI0_CS1_OE_REG, SPPI0_CS1_BIT)
  108. /*! \brief Set SPPI0 chip select 1 output low. */
  109. #define SPPI0_CS1_CLR() cbi(SPPI0_CS1_SOD_REG, SPPI0_CS1_BIT)
  110. /*! \brief Set SPPI0 chip select 1 output high. */
  111. #define SPPI0_CS1_SET() sbi(SPPI0_CS1_SOD_REG, SPPI0_CS1_BIT)
  112. #endif /* SPPI0_CS1_BIT */
  113. #ifdef SPPI0_CS2_BIT
  114. #if (SPPI0_CS2_AVRPORT == AVRPORTB)
  115. #define SPPI0_CS2_SOD_REG PORTB
  116. #define SPPI0_CS2_OE_REG DDRB
  117. #elif (SPPI0_CS2_AVRPORT == AVRPORTD)
  118. #define SPPI0_CS2_SOD_REG PORTD
  119. #define SPPI0_CS2_OE_REG DDRD
  120. #elif (SPPI0_CS2_AVRPORT == AVRPORTE)
  121. #define SPPI0_CS2_SOD_REG PORTE
  122. #define SPPI0_CS2_OE_REG DDRE
  123. #elif (SPPI0_CS2_AVRPORT == AVRPORTF)
  124. #define SPPI0_CS2_SOD_REG PORTF
  125. #define SPPI0_CS2_OE_REG DDRF
  126. #elif (SPPI0_CS2_AVRPORT == AVRPORTG)
  127. #define SPPI0_CS2_SOD_REG PORTG
  128. #define SPPI0_CS2_OE_REG DDRG
  129. #elif (SPPI0_CS2_AVRPORT == AVRPORTH)
  130. #define SPPI0_CS2_SOD_REG PORTH
  131. #define SPPI0_CS2_OE_REG DDRH
  132. #endif
  133. /*! \brief Enable SPPI0 chip select 2 output. */
  134. #define SPPI0_CS2_ENA() sbi(SPPI0_CS2_OE_REG, SPPI0_CS2_BIT)
  135. /*! \brief Set SPPI0 chip select 2 output low. */
  136. #define SPPI0_CS2_CLR() cbi(SPPI0_CS2_SOD_REG, SPPI0_CS2_BIT)
  137. /*! \brief Set SPPI0 chip select 2 output high. */
  138. #define SPPI0_CS2_SET() sbi(SPPI0_CS2_SOD_REG, SPPI0_CS2_BIT)
  139. #endif /* SPPI0_CS2_BIT */
  140. #ifdef SPPI0_CS3_BIT
  141. #if (SPPI0_CS3_AVRPORT == AVRPORTB)
  142. #define SPPI0_CS3_SOD_REG PORTB
  143. #define SPPI0_CS3_OE_REG DDRB
  144. #elif (SPPI0_CS3_AVRPORT == AVRPORTD)
  145. #define SPPI0_CS3_SOD_REG PORTD
  146. #define SPPI0_CS3_OE_REG DDRD
  147. #elif (SPPI0_CS3_AVRPORT == AVRPORTE)
  148. #define SPPI0_CS3_SOD_REG PORTE
  149. #define SPPI0_CS3_OE_REG DDRE
  150. #elif (SPPI0_CS3_AVRPORT == AVRPORTF)
  151. #define SPPI0_CS3_SOD_REG PORTF
  152. #define SPPI0_CS3_OE_REG DDRF
  153. #elif (SPPI0_CS3_AVRPORT == AVRPORTG)
  154. #define SPPI0_CS3_SOD_REG PORTG
  155. #define SPPI0_CS3_OE_REG DDRG
  156. #elif (SPPI0_CS3_AVRPORT == AVRPORTH)
  157. #define SPPI0_CS3_SOD_REG PORTH
  158. #define SPPI0_CS3_OE_REG DDRH
  159. #endif
  160. /*! \brief Enable SPPI0 chip select 3 output. */
  161. #define SPPI0_CS3_ENA() sbi(SPPI0_CS3_OE_REG, SPPI0_CS3_BIT)
  162. /*! \brief Set SPPI0 chip select 3 output low. */
  163. #define SPPI0_CS3_CLR() cbi(SPPI0_CS3_SOD_REG, SPPI0_CS3_BIT)
  164. /*! \brief Set SPPI0 chip select 3 output high. */
  165. #define SPPI0_CS3_SET() sbi(SPPI0_CS3_SOD_REG, SPPI0_CS3_BIT)
  166. #endif /* SPPI0_CS3_BIT */
  167. #ifdef SPPI0_RST0_BIT
  168. #if (SPPI0_RST0_AVRPORT == AVRPORTB)
  169. #define SPPI0_RST0_SOD_REG PORTB
  170. #define SPPI0_RST0_OE_REG DDRB
  171. #elif (SPPI0_RST0_AVRPORT == AVRPORTD)
  172. #define SPPI0_RST0_SOD_REG PORTD
  173. #define SPPI0_RST0_OE_REG DDRD
  174. #elif (SPPI0_RST0_AVRPORT == AVRPORTE)
  175. #define SPPI0_RST0_SOD_REG PORTE
  176. #define SPPI0_RST0_OE_REG DDRE
  177. #elif (SPPI0_RST0_AVRPORT == AVRPORTF)
  178. #define SPPI0_RST0_SOD_REG PORTF
  179. #define SPPI0_RST0_OE_REG DDRF
  180. #elif (SPPI0_RST0_AVRPORT == AVRPORTG)
  181. #define SPPI0_RST0_SOD_REG PORTG
  182. #define SPPI0_RST0_OE_REG DDRG
  183. #elif (SPPI0_RST0_AVRPORT == AVRPORTH)
  184. #define SPPI0_RST0_SOD_REG PORTH
  185. #define SPPI0_RST0_OE_REG DDRH
  186. #endif
  187. /*! \brief Enable SPPI0 reset 0 output. */
  188. #define SPPI0_RST0_ENA() sbi(SPPI0_RST0_OE_REG, SPPI0_RST0_BIT)
  189. /*! \brief Set SPPI0 reset 0 output low. */
  190. #define SPPI0_RST0_CLR() cbi(SPPI0_RST0_SOD_REG, SPPI0_RST0_BIT)
  191. /*! \brief Set SPPI0 reset 0 output high. */
  192. #define SPPI0_RST0_SET() sbi(SPPI0_RST0_SOD_REG, SPPI0_RST0_BIT)
  193. #endif /* SPPI0_RST0_BIT */
  194. #ifdef SPPI0_RST1_BIT
  195. #if (SPPI0_RST1_AVRPORT == AVRPORTB)
  196. #define SPPI0_RST1_SOD_REG PORTB
  197. #define SPPI0_RST1_OE_REG DDRB
  198. #elif (SPPI0_RST1_AVRPORT == AVRPORTD)
  199. #define SPPI0_RST1_SOD_REG PORTD
  200. #define SPPI0_RST1_OE_REG DDRD
  201. #elif (SPPI0_RST1_AVRPORT == AVRPORTE)
  202. #define SPPI0_RST1_SOD_REG PORTE
  203. #define SPPI0_RST1_OE_REG DDRE
  204. #elif (SPPI0_RST1_AVRPORT == AVRPORTF)
  205. #define SPPI0_RST1_SOD_REG PORTF
  206. #define SPPI0_RST1_OE_REG DDRF
  207. #elif (SPPI0_RST1_AVRPORT == AVRPORTG)
  208. #define SPPI0_RST1_SOD_REG PORTG
  209. #define SPPI0_RST1_OE_REG DDRG
  210. #elif (SPPI0_RST1_AVRPORT == AVRPORTH)
  211. #define SPPI0_RST1_SOD_REG PORTH
  212. #define SPPI0_RST1_OE_REG DDRH
  213. #endif
  214. /*! \brief Enable SPPI0 reset 1 output. */
  215. #define SPPI0_RST1_ENA() sbi(SPPI0_RST1_OE_REG, SPPI0_RST1_BIT)
  216. /*! \brief Set SPPI0 reset 1 output low. */
  217. #define SPPI0_RST1_CLR() cbi(SPPI0_RST1_SOD_REG, SPPI0_RST1_BIT)
  218. /*! \brief Set SPPI0 reset 1 output high. */
  219. #define SPPI0_RST1_SET() sbi(SPPI0_RST1_SOD_REG, SPPI0_RST1_BIT)
  220. #endif /* SPPI0_RST1_BIT */
  221. #ifdef SPPI0_RST2_BIT
  222. #if (SPPI0_RST2_AVRPORT == AVRPORTB)
  223. #define SPPI0_RST2_SOD_REG PORTB
  224. #define SPPI0_RST2_OE_REG DDRB
  225. #elif (SPPI0_RST2_AVRPORT == AVRPORTD)
  226. #define SPPI0_RST2_SOD_REG PORTD
  227. #define SPPI0_RST2_OE_REG DDRD
  228. #elif (SPPI0_RST2_AVRPORT == AVRPORTE)
  229. #define SPPI0_RST2_SOD_REG PORTE
  230. #define SPPI0_RST2_OE_REG DDRE
  231. #elif (SPPI0_RST2_AVRPORT == AVRPORTF)
  232. #define SPPI0_RST2_SOD_REG PORTF
  233. #define SPPI0_RST2_OE_REG DDRF
  234. #elif (SPPI0_RST2_AVRPORT == AVRPORTG)
  235. #define SPPI0_RST2_SOD_REG PORTG
  236. #define SPPI0_RST2_OE_REG DDRG
  237. #elif (SPPI0_RST2_AVRPORT == AVRPORTH)
  238. #define SPPI0_RST2_SOD_REG PORTH
  239. #define SPPI0_RST2_OE_REG DDRH
  240. #endif
  241. /*! \brief Enable SPPI0 reset 2 output. */
  242. #define SPPI0_RST2_ENA() sbi(SPPI0_RST2_OE_REG, SPPI0_RST2_BIT)
  243. /*! \brief Set SPPI0 chip reset 2 output low. */
  244. #define SPPI0_RST2_CLR() cbi(SPPI0_RST2_SOD_REG, SPPI0_RST2_BIT)
  245. /*! \brief Set SPPI0 chip reset 2 output high. */
  246. #define SPPI0_RST2_SET() sbi(SPPI0_RST2_SOD_REG, SPPI0_RST2_BIT)
  247. #endif /* SPPI0_RST2_BIT */
  248. #ifdef SPPI0_RST3_BIT
  249. #if (SPPI0_RST3_AVRPORT == AVRPORTB)
  250. #define SPPI0_RST3_SOD_REG PORTB
  251. #define SPPI0_RST3_OE_REG DDRB
  252. #elif (SPPI0_RST3_AVRPORT == AVRPORTD)
  253. #define SPPI0_RST3_SOD_REG PORTD
  254. #define SPPI0_RST3_OE_REG DDRD
  255. #elif (SPPI0_RST3_AVRPORT == AVRPORTE)
  256. #define SPPI0_RST3_SOD_REG PORTE
  257. #define SPPI0_RST3_OE_REG DDRE
  258. #elif (SPPI0_RST3_AVRPORT == AVRPORTF)
  259. #define SPPI0_RST3_SOD_REG PORTF
  260. #define SPPI0_RST3_OE_REG DDRF
  261. #elif (SPPI0_RST3_AVRPORT == AVRPORTG)
  262. #define SPPI0_RST3_SOD_REG PORTG
  263. #define SPPI0_RST3_OE_REG DDRG
  264. #elif (SPPI0_RST3_AVRPORT == AVRPORTH)
  265. #define SPPI0_RST3_SOD_REG PORTH
  266. #define SPPI0_RST3_OE_REG DDRH
  267. #endif
  268. /*! \brief Enable SPPI0 reset 3 output. */
  269. #define SPPI0_RST3_ENA() sbi(SPPI0_RST3_OE_REG, SPPI0_RST3_BIT)
  270. /*! \brief Set SPPI0 reset 3 output low. */
  271. #define SPPI0_RST3_CLR() cbi(SPPI0_RST3_SOD_REG, SPPI0_RST3_BIT)
  272. /*! \brief Set SPPI0 reset 3 output high. */
  273. #define SPPI0_RST3_SET() sbi(SPPI0_RST3_SOD_REG, SPPI0_RST3_BIT)
  274. #endif /* SPPI0_RST3_BIT */
  275. #else /* MCU */
  276. /*
  277. * AT91 implementation.
  278. * ======================================
  279. */
  280. #ifdef SPPI0_CS0_BIT
  281. #if !defined(SPPI0_CS0_PIO_ID)
  282. #define SPPI0_CS0_PE_REG PIO_PER
  283. #define SPPI0_CS0_OE_REG PIO_OER
  284. #define SPPI0_CS0_COD_REG PIO_CODR
  285. #define SPPI0_CS0_SOD_REG PIO_SODR
  286. #elif SPPI0_CS0_PIO_ID == PIO_ID
  287. #define SPPI0_CS0_PE_REG PIO_PER
  288. #define SPPI0_CS0_OE_REG PIO_OER
  289. #define SPPI0_CS0_COD_REG PIO_CODR
  290. #define SPPI0_CS0_SOD_REG PIO_SODR
  291. #elif SPPI0_CS0_PIO_ID == PIOA_ID
  292. #define SPPI0_CS0_PE_REG PIOA_PER
  293. #define SPPI0_CS0_OE_REG PIOA_OER
  294. #define SPPI0_CS0_COD_REG PIOA_CODR
  295. #define SPPI0_CS0_SOD_REG PIOA_SODR
  296. #elif SPPI0_CS0_PIO_ID == PIOB_ID
  297. #define SPPI0_CS0_PE_REG PIOB_PER
  298. #define SPPI0_CS0_OE_REG PIOB_OER
  299. #define SPPI0_CS0_COD_REG PIOB_CODR
  300. #define SPPI0_CS0_SOD_REG PIOB_SODR
  301. #elif SPPI0_CS0_PIO_ID == PIOC_ID
  302. #define SPPI0_CS0_PE_REG PIOC_PER
  303. #define SPPI0_CS0_OE_REG PIOC_OER
  304. #define SPPI0_CS0_COD_REG PIOC_CODR
  305. #define SPPI0_CS0_SOD_REG PIOC_SODR
  306. #endif
  307. /*! \brief Enable SPPI0 chip select 0 output. */
  308. #define SPPI0_CS0_ENA() \
  309. outr(SPPI0_CS0_PE_REG, _BV(SPPI0_CS0_BIT)); \
  310. outr(SPPI0_CS0_OE_REG, _BV(SPPI0_CS0_BIT))
  311. /*! \brief Set SPPI0 chip select 0 output low. */
  312. #define SPPI0_CS0_CLR() outr(SPPI0_CS0_COD_REG, _BV(SPPI0_CS0_BIT))
  313. /*! \brief Set SPPI0 chip select 0 output high. */
  314. #define SPPI0_CS0_SET() outr(SPPI0_CS0_SOD_REG, _BV(SPPI0_CS0_BIT))
  315. #endif /* SPPI0_CS0_BIT */
  316. #ifdef SPPI0_CS1_BIT
  317. #if !defined(SPPI0_CS1_PIO_ID)
  318. #define SPPI0_CS1_PE_REG PIO_PER
  319. #define SPPI0_CS1_OE_REG PIO_OER
  320. #define SPPI0_CS1_COD_REG PIO_CODR
  321. #define SPPI0_CS1_SOD_REG PIO_SODR
  322. #elif SPPI0_CS1_PIO_ID == PIO_ID
  323. #define SPPI0_CS1_PE_REG PIO_PER
  324. #define SPPI0_CS1_OE_REG PIO_OER
  325. #define SPPI0_CS1_COD_REG PIO_CODR
  326. #define SPPI0_CS1_SOD_REG PIO_SODR
  327. #elif SPPI0_CS1_PIO_ID == PIOA_ID
  328. #define SPPI0_CS1_PE_REG PIOA_PER
  329. #define SPPI0_CS1_OE_REG PIOA_OER
  330. #define SPPI0_CS1_COD_REG PIOA_CODR
  331. #define SPPI0_CS1_SOD_REG PIOA_SODR
  332. #elif SPPI0_CS1_PIO_ID == PIOB_ID
  333. #define SPPI0_CS1_PE_REG PIOB_PER
  334. #define SPPI0_CS1_OE_REG PIOB_OER
  335. #define SPPI0_CS1_COD_REG PIOB_CODR
  336. #define SPPI0_CS1_SOD_REG PIOB_SODR
  337. #elif SPPI0_CS1_PIO_ID == PIOC_ID
  338. #define SPPI0_CS1_PE_REG PIOC_PER
  339. #define SPPI0_CS1_OE_REG PIOC_OER
  340. #define SPPI0_CS1_COD_REG PIOC_CODR
  341. #define SPPI0_CS1_SOD_REG PIOC_SODR
  342. #endif
  343. /*! \brief Enable SPPI0 chip select output. */
  344. #define SPPI0_CS1_ENA() \
  345. outr(SPPI0_CS1_PE_REG, _BV(SPPI0_CS1_BIT)); \
  346. outr(SPPI0_CS1_OE_REG, _BV(SPPI0_CS1_BIT))
  347. /*! \brief Set SPPI0 chip select output low. */
  348. #define SPPI0_CS1_CLR() outr(SPPI0_CS1_COD_REG, _BV(SPPI0_CS1_BIT))
  349. /*! \brief Set SPPI0 chip select output high. */
  350. #define SPPI0_CS1_SET() outr(SPPI0_CS1_SOD_REG, _BV(SPPI0_CS1_BIT))
  351. #endif /* SPPI0_CS1_BIT */
  352. #ifdef SPPI0_CS2_BIT
  353. #if !defined(SPPI0_CS2_PIO_ID)
  354. #define SPPI0_CS2_PE_REG PIO_PER
  355. #define SPPI0_CS2_OE_REG PIO_OER
  356. #define SPPI0_CS2_COD_REG PIO_CODR
  357. #define SPPI0_CS2_SOD_REG PIO_SODR
  358. #elif SPPI0_CS2_PIO_ID == PIO_ID
  359. #define SPPI0_CS2_PE_REG PIO_PER
  360. #define SPPI0_CS2_OE_REG PIO_OER
  361. #define SPPI0_CS2_COD_REG PIO_CODR
  362. #define SPPI0_CS2_SOD_REG PIO_SODR
  363. #elif SPPI0_CS2_PIO_ID == PIOA_ID
  364. #define SPPI0_CS2_PE_REG PIOA_PER
  365. #define SPPI0_CS2_OE_REG PIOA_OER
  366. #define SPPI0_CS2_COD_REG PIOA_CODR
  367. #define SPPI0_CS2_SOD_REG PIOA_SODR
  368. #elif SPPI0_CS2_PIO_ID == PIOB_ID
  369. #define SPPI0_CS2_PE_REG PIOB_PER
  370. #define SPPI0_CS2_OE_REG PIOB_OER
  371. #define SPPI0_CS2_COD_REG PIOB_CODR
  372. #define SPPI0_CS2_SOD_REG PIOB_SODR
  373. #elif SPPI0_CS2_PIO_ID == PIOC_ID
  374. #define SPPI0_CS2_PE_REG PIOC_PER
  375. #define SPPI0_CS2_OE_REG PIOC_OER
  376. #define SPPI0_CS2_COD_REG PIOC_CODR
  377. #define SPPI0_CS2_SOD_REG PIOC_SODR
  378. #endif
  379. /*! \brief Enable SPPI0 chip select output. */
  380. #define SPPI0_CS2_ENA() \
  381. outr(SPPI0_CS2_PE_REG, _BV(SPPI0_CS2_BIT)); \
  382. outr(SPPI0_CS2_OE_REG, _BV(SPPI0_CS2_BIT))
  383. /*! \brief Set SPPI0 chip select output low. */
  384. #define SPPI0_CS2_CLR() outr(SPPI0_CS2_COD_REG, _BV(SPPI0_CS2_BIT))
  385. /*! \brief Set SPPI0 chip select output high. */
  386. #define SPPI0_CS2_SET() outr(SPPI0_CS2_SOD_REG, _BV(SPPI0_CS2_BIT))
  387. #endif /* SPPI0_CS2_BIT */
  388. #ifdef SPPI0_CS3_BIT
  389. #if !defined(SPPI0_CS3_PIO_ID)
  390. #define SPPI0_CS3_PE_REG PIO_PER
  391. #define SPPI0_CS3_OE_REG PIO_OER
  392. #define SPPI0_CS3_COD_REG PIO_CODR
  393. #define SPPI0_CS3_SOD_REG PIO_SODR
  394. #elif SPPI0_CS3_PIO_ID == PIO_ID
  395. #define SPPI0_CS3_PE_REG PIO_PER
  396. #define SPPI0_CS3_OE_REG PIO_OER
  397. #define SPPI0_CS3_COD_REG PIO_CODR
  398. #define SPPI0_CS3_SOD_REG PIO_SODR
  399. #elif SPPI0_CS3_PIO_ID == PIOA_ID
  400. #define SPPI0_CS3_PE_REG PIOA_PER
  401. #define SPPI0_CS3_OE_REG PIOA_OER
  402. #define SPPI0_CS3_COD_REG PIOA_CODR
  403. #define SPPI0_CS3_SOD_REG PIOA_SODR
  404. #elif SPPI0_CS3_PIO_ID == PIOB_ID
  405. #define SPPI0_CS3_PE_REG PIOB_PER
  406. #define SPPI0_CS3_OE_REG PIOB_OER
  407. #define SPPI0_CS3_COD_REG PIOB_CODR
  408. #define SPPI0_CS3_SOD_REG PIOB_SODR
  409. #elif SPPI0_CS3_PIO_ID == PIOC_ID
  410. #define SPPI0_CS3_PE_REG PIOC_PER
  411. #define SPPI0_CS3_OE_REG PIOC_OER
  412. #define SPPI0_CS3_COD_REG PIOC_CODR
  413. #define SPPI0_CS3_SOD_REG PIOC_SODR
  414. #endif
  415. /*! \brief Enable SPPI0 chip select output. */
  416. #define SPPI0_CS3_ENA() \
  417. outr(SPPI0_CS3_PE_REG, _BV(SPPI0_CS3_BIT)); \
  418. outr(SPPI0_CS3_OE_REG, _BV(SPPI0_CS3_BIT))
  419. /*! \brief Set SPPI0 chip select output low. */
  420. #define SPPI0_CS3_CLR() outr(SPPI0_CS3_COD_REG, _BV(SPPI0_CS3_BIT))
  421. /*! \brief Set SPPI0 chip select output high. */
  422. #define SPPI0_CS3_SET() outr(SPPI0_CS3_SOD_REG, _BV(SPPI0_CS3_BIT))
  423. #endif /* SPPI0_CS3_BIT */
  424. #ifdef SPPI0_RST0_BIT
  425. #if !defined(SPPI0_RST0_PIO_ID)
  426. #define SPPI0_RST0_PE_REG PIO_PER
  427. #define SPPI0_RST0_OE_REG PIO_OER
  428. #define SPPI0_RST0_COD_REG PIO_CODR
  429. #define SPPI0_RST0_SOD_REG PIO_SODR
  430. #elif SPPI0_RST0_PIO_ID == PIO_ID
  431. #define SPPI0_RST0_PE_REG PIO_PER
  432. #define SPPI0_RST0_OE_REG PIO_OER
  433. #define SPPI0_RST0_COD_REG PIO_CODR
  434. #define SPPI0_RST0_SOD_REG PIO_SODR
  435. #elif SPPI0_RST0_PIO_ID == PIOA_ID
  436. #define SPPI0_RST0_PE_REG PIOA_PER
  437. #define SPPI0_RST0_OE_REG PIOA_OER
  438. #define SPPI0_RST0_COD_REG PIOA_CODR
  439. #define SPPI0_RST0_SOD_REG PIOA_SODR
  440. #elif SPPI0_RST0_PIO_ID == PIOB_ID
  441. #define SPPI0_RST0_PE_REG PIOB_PER
  442. #define SPPI0_RST0_OE_REG PIOB_OER
  443. #define SPPI0_RST0_COD_REG PIOB_CODR
  444. #define SPPI0_RST0_SOD_REG PIOB_SODR
  445. #elif SPPI0_RST0_PIO_ID == PIOC_ID
  446. #define SPPI0_RST0_PE_REG PIOC_PER
  447. #define SPPI0_RST0_OE_REG PIOC_OER
  448. #define SPPI0_RST0_COD_REG PIOC_CODR
  449. #define SPPI0_RST0_SOD_REG PIOC_SODR
  450. #endif
  451. /*! \brief Enable SPPI0 reset output. */
  452. #define SPPI0_RST0_ENA() \
  453. outr(SPPI0_RST0_PE_REG, _BV(SPPI0_RST0_BIT)); \
  454. outr(SPPI0_RST0_OE_REG, _BV(SPPI0_RST0_BIT))
  455. /*! \brief Set SPPI0 reset output low. */
  456. #define SPPI0_RST0_CLR() outr(SPPI0_RST0_COD_REG, _BV(SPPI0_RST0_BIT))
  457. /*! \brief Set SPPI0 reset output high. */
  458. #define SPPI0_RST0_SET() outr(SPPI0_RST0_SOD_REG, _BV(SPPI0_RST0_BIT))
  459. #endif /* SPPI0_RST0_BIT */
  460. #ifdef SPPI0_RST1_BIT
  461. #if !defined(SPPI0_RST1_PIO_ID)
  462. #define SPPI0_RST1_PE_REG PIO_PER
  463. #define SPPI0_RST1_OE_REG PIO_OER
  464. #define SPPI0_RST1_COD_REG PIO_CODR
  465. #define SPPI0_RST1_SOD_REG PIO_SODR
  466. #elif SPPI0_RST1_PIO_ID == PIO_ID
  467. #define SPPI0_RST1_PE_REG PIO_PER
  468. #define SPPI0_RST1_OE_REG PIO_OER
  469. #define SPPI0_RST1_COD_REG PIO_CODR
  470. #define SPPI0_RST1_SOD_REG PIO_SODR
  471. #elif SPPI0_RST1_PIO_ID == PIOA_ID
  472. #define SPPI0_RST1_PE_REG PIOA_PER
  473. #define SPPI0_RST1_OE_REG PIOA_OER
  474. #define SPPI0_RST1_COD_REG PIOA_CODR
  475. #define SPPI0_RST1_SOD_REG PIOA_SODR
  476. #elif SPPI0_RST1_PIO_ID == PIOB_ID
  477. #define SPPI0_RST1_PE_REG PIOB_PER
  478. #define SPPI0_RST1_OE_REG PIOB_OER
  479. #define SPPI0_RST1_COD_REG PIOB_CODR
  480. #define SPPI0_RST1_SOD_REG PIOB_SODR
  481. #elif SPPI0_RST1_PIO_ID == PIOC_ID
  482. #define SPPI0_RST1_PE_REG PIOC_PER
  483. #define SPPI0_RST1_OE_REG PIOC_OER
  484. #define SPPI0_RST1_COD_REG PIOC_CODR
  485. #define SPPI0_RST1_SOD_REG PIOC_SODR
  486. #endif
  487. /*! \brief Enable SPPI0 reset output. */
  488. #define SPPI0_RST1_ENA() \
  489. outr(SPPI0_RST1_PE_REG, _BV(SPPI0_RST1_BIT)); \
  490. outr(SPPI0_RST1_OE_REG, _BV(SPPI0_RST1_BIT))
  491. /*! \brief Set SPPI0 reset output low. */
  492. #define SPPI0_RST1_CLR() outr(SPPI0_RST1_COD_REG, _BV(SPPI0_RST1_BIT))
  493. /*! \brief Set SPPI0 reset output high. */
  494. #define SPPI0_RST1_SET() outr(SPPI0_RST1_SOD_REG, _BV(SPPI0_RST1_BIT))
  495. #endif /* SPPI0_RST1_BIT */
  496. #ifdef SPPI0_RST2_BIT
  497. #if !defined(SPPI0_RST2_PIO_ID)
  498. #define SPPI0_RST2_PE_REG PIO_PER
  499. #define SPPI0_RST2_OE_REG PIO_OER
  500. #define SPPI0_RST2_COD_REG PIO_CODR
  501. #define SPPI0_RST2_SOD_REG PIO_SODR
  502. #elif SPPI0_RST2_PIO_ID == PIO_ID
  503. #define SPPI0_RST2_PE_REG PIO_PER
  504. #define SPPI0_RST2_OE_REG PIO_OER
  505. #define SPPI0_RST2_COD_REG PIO_CODR
  506. #define SPPI0_RST2_SOD_REG PIO_SODR
  507. #elif SPPI0_RST2_PIO_ID == PIOA_ID
  508. #define SPPI0_RST2_PE_REG PIOA_PER
  509. #define SPPI0_RST2_OE_REG PIOA_OER
  510. #define SPPI0_RST2_COD_REG PIOA_CODR
  511. #define SPPI0_RST2_SOD_REG PIOA_SODR
  512. #elif SPPI0_RST2_PIO_ID == PIOB_ID
  513. #define SPPI0_RST2_PE_REG PIOB_PER
  514. #define SPPI0_RST2_OE_REG PIOB_OER
  515. #define SPPI0_RST2_COD_REG PIOB_CODR
  516. #define SPPI0_RST2_SOD_REG PIOB_SODR
  517. #elif SPPI0_RST2_PIO_ID == PIOC_ID
  518. #define SPPI0_RST2_PE_REG PIOC_PER
  519. #define SPPI0_RST2_OE_REG PIOC_OER
  520. #define SPPI0_RST2_COD_REG PIOC_CODR
  521. #define SPPI0_RST2_SOD_REG PIOC_SODR
  522. #endif
  523. /*! \brief Enable SPPI0 reset output. */
  524. #define SPPI0_RST2_ENA() \
  525. outr(SPPI0_RST2_PE_REG, _BV(SPPI0_RST2_BIT)); \
  526. outr(SPPI0_RST2_OE_REG, _BV(SPPI0_RST2_BIT))
  527. /*! \brief Set SPPI0 reset output low. */
  528. #define SPPI0_RST2_CLR() outr(SPPI0_RST2_COD_REG, _BV(SPPI0_RST2_BIT))
  529. /*! \brief Set SPPI0 reset output high. */
  530. #define SPPI0_RST2_SET() outr(SPPI0_RST2_SOD_REG, _BV(SPPI0_RST2_BIT))
  531. #endif /* SPPI0_RST2_BIT */
  532. #ifdef SPPI0_RST3_BIT
  533. #if !defined(SPPI0_RST3_PIO_ID)
  534. #define SPPI0_RST3_PE_REG PIO_PER
  535. #define SPPI0_RST3_OE_REG PIO_OER
  536. #define SPPI0_RST3_COD_REG PIO_CODR
  537. #define SPPI0_RST3_SOD_REG PIO_SODR
  538. #elif SPPI0_RST3_PIO_ID == PIO_ID
  539. #define SPPI0_RST3_PE_REG PIO_PER
  540. #define SPPI0_RST3_OE_REG PIO_OER
  541. #define SPPI0_RST3_COD_REG PIO_CODR
  542. #define SPPI0_RST3_SOD_REG PIO_SODR
  543. #elif SPPI0_RST3_PIO_ID == PIOA_ID
  544. #define SPPI0_RST3_PE_REG PIOA_PER
  545. #define SPPI0_RST3_OE_REG PIOA_OER
  546. #define SPPI0_RST3_COD_REG PIOA_CODR
  547. #define SPPI0_RST3_SOD_REG PIOA_SODR
  548. #elif SPPI0_RST3_PIO_ID == PIOB_ID
  549. #define SPPI0_RST3_PE_REG PIOB_PER
  550. #define SPPI0_RST3_OE_REG PIOB_OER
  551. #define SPPI0_RST3_COD_REG PIOB_CODR
  552. #define SPPI0_RST3_SOD_REG PIOB_SODR
  553. #elif SPPI0_RST3_PIO_ID == PIOC_ID
  554. #define SPPI0_RST3_PE_REG PIOC_PER
  555. #define SPPI0_RST3_OE_REG PIOC_OER
  556. #define SPPI0_RST3_COD_REG PIOC_CODR
  557. #define SPPI0_RST3_SOD_REG PIOC_SODR
  558. #endif
  559. /*! \brief Enable SPPI0 reset output. */
  560. #define SPPI0_RST3_ENA() \
  561. outr(SPPI0_RST3_PE_REG, _BV(SPPI0_RST3_BIT)); \
  562. outr(SPPI0_RST3_OE_REG, _BV(SPPI0_RST3_BIT))
  563. /*! \brief Set SPPI0 reset output low. */
  564. #define SPPI0_RST3_CLR() outr(SPPI0_RST3_COD_REG, _BV(SPPI0_RST3_BIT))
  565. /*! \brief Set SPPI0 reset output high. */
  566. #define SPPI0_RST3_SET() outr(SPPI0_RST3_SOD_REG, _BV(SPPI0_RST3_BIT))
  567. #endif /* SPPI0_RST3_BIT */
  568. #endif /* MCU */
  569. __BEGIN_DECLS
  570. /* Function prototypes */
  571. extern int Sppi0SetMode(ureg_t ix, ureg_t mode);
  572. extern void Sppi0SetSpeed(ureg_t ix, u_long rate);
  573. extern void Sppi0Enable(ureg_t ix);
  574. extern void Sppi0ChipReset(ureg_t ix, u_char hi);
  575. extern void Sppi0ChipSelect(ureg_t ix, u_char hi);
  576. extern void Sppi0SelectDevice(ureg_t ix);
  577. extern void Sppi0DeselectDevice(ureg_t ix);
  578. extern void Sppi0NegSelectDevice(ureg_t ix);
  579. extern void Sppi0NegDeselectDevice(ureg_t ix);
  580. extern u_char Sppi0Byte(u_char data);
  581. extern void Sppi0Transact(CONST void *wdata, void *rdata, size_t len);
  582. __END_DECLS
  583. /* End of prototypes */
  584. #endif