sbbif0.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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 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/sbbif0.h
  36. * \brief Serial bit banged interface 0.
  37. *
  38. * \verbatim
  39. *
  40. * $Log: sbbif0.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 SBBI0_MAX_DEVICES
  52. #define SBBI0_MAX_DEVICES 4
  53. #endif
  54. #if defined(__AVR__) /* MCU */
  55. /*
  56. * AVR implementation.
  57. * ======================================
  58. */
  59. #ifdef SBBI0_CS0_BIT
  60. #if (SBBI0_CS0_AVRPORT == AVRPORTB)
  61. #define SBBI0_CS0_SOD_REG PORTB
  62. #define SBBI0_CS0_OE_REG DDRB
  63. #elif (SBBI0_CS0_AVRPORT == AVRPORTD)
  64. #define SBBI0_CS0_SOD_REG PORTD
  65. #define SBBI0_CS0_OE_REG DDRD
  66. #elif (SBBI0_CS0_AVRPORT == AVRPORTE)
  67. #define SBBI0_CS0_SOD_REG PORTE
  68. #define SBBI0_CS0_OE_REG DDRE
  69. #elif (SBBI0_CS0_AVRPORT == AVRPORTF)
  70. #define SBBI0_CS0_SOD_REG PORTF
  71. #define SBBI0_CS0_OE_REG DDRF
  72. #elif (SBBI0_CS0_AVRPORT == AVRPORTG)
  73. #define SBBI0_CS0_SOD_REG PORTG
  74. #define SBBI0_CS0_OE_REG DDRG
  75. #elif (SBBI0_CS0_AVRPORT == AVRPORTH)
  76. #define SBBI0_CS0_SOD_REG PORTH
  77. #define SBBI0_CS0_OE_REG DDRH
  78. #endif
  79. /*! \brief Enable SBBI0 chip select 0 output. */
  80. #define SBBI0_CS0_ENA() sbi(SBBI0_CS0_OE_REG, SBBI0_CS0_BIT)
  81. /*! \brief Set SBBI0 chip select 0 output low. */
  82. #define SBBI0_CS0_CLR() cbi(SBBI0_CS0_SOD_REG, SBBI0_CS0_BIT)
  83. /*! \brief Set SBBI0 chip select 0 output high. */
  84. #define SBBI0_CS0_SET() sbi(SBBI0_CS0_SOD_REG, SBBI0_CS0_BIT)
  85. #else /* SBBI0_CS0_BIT */
  86. #define SBBI0_CS0_ENA()
  87. #define SBBI0_CS0_CLR()
  88. #define SBBI0_CS0_SET()
  89. #endif /* SBBI0_CS0_BIT */
  90. #ifdef SBBI0_CS1_BIT
  91. #if (SBBI0_CS1_AVRPORT == AVRPORTB)
  92. #define SBBI0_CS1_SOD_REG PORTB
  93. #define SBBI0_CS1_OE_REG DDRB
  94. #elif (SBBI0_CS1_AVRPORT == AVRPORTD)
  95. #define SBBI0_CS1_SOD_REG PORTD
  96. #define SBBI0_CS1_OE_REG DDRD
  97. #elif (SBBI0_CS1_AVRPORT == AVRPORTE)
  98. #define SBBI0_CS1_SOD_REG PORTE
  99. #define SBBI0_CS1_OE_REG DDRE
  100. #elif (SBBI0_CS1_AVRPORT == AVRPORTF)
  101. #define SBBI0_CS1_SOD_REG PORTF
  102. #define SBBI0_CS1_OE_REG DDRF
  103. #elif (SBBI0_CS1_AVRPORT == AVRPORTG)
  104. #define SBBI0_CS1_SOD_REG PORTG
  105. #define SBBI0_CS1_OE_REG DDRG
  106. #elif (SBBI0_CS1_AVRPORT == AVRPORTH)
  107. #define SBBI0_CS1_SOD_REG PORTH
  108. #define SBBI0_CS1_OE_REG DDRH
  109. #endif
  110. /*! \brief Enable SBBI0 chip select 1 output. */
  111. #define SBBI0_CS1_ENA() sbi(SBBI0_CS1_OE_REG, SBBI0_CS1_BIT)
  112. /*! \brief Set SBBI0 chip select 1 output low. */
  113. #define SBBI0_CS1_CLR() cbi(SBBI0_CS1_SOD_REG, SBBI0_CS1_BIT)
  114. /*! \brief Set SBBI0 chip select 1 output high. */
  115. #define SBBI0_CS1_SET() sbi(SBBI0_CS1_SOD_REG, SBBI0_CS1_BIT)
  116. #else /* SBBI0_CS1_BIT */
  117. #define SBBI0_CS1_ENA()
  118. #define SBBI0_CS1_CLR()
  119. #define SBBI0_CS1_SET()
  120. #endif /* SBBI0_CS1_BIT */
  121. #ifdef SBBI0_CS2_BIT
  122. #if (SBBI0_CS2_AVRPORT == AVRPORTB)
  123. #define SBBI0_CS2_SOD_REG PORTB
  124. #define SBBI0_CS2_OE_REG DDRB
  125. #elif (SBBI0_CS2_AVRPORT == AVRPORTD)
  126. #define SBBI0_CS2_SOD_REG PORTD
  127. #define SBBI0_CS2_OE_REG DDRD
  128. #elif (SBBI0_CS2_AVRPORT == AVRPORTE)
  129. #define SBBI0_CS2_SOD_REG PORTE
  130. #define SBBI0_CS2_OE_REG DDRE
  131. #elif (SBBI0_CS2_AVRPORT == AVRPORTF)
  132. #define SBBI0_CS2_SOD_REG PORTF
  133. #define SBBI0_CS2_OE_REG DDRF
  134. #elif (SBBI0_CS2_AVRPORT == AVRPORTG)
  135. #define SBBI0_CS2_SOD_REG PORTG
  136. #define SBBI0_CS2_OE_REG DDRG
  137. #elif (SBBI0_CS2_AVRPORT == AVRPORTH)
  138. #define SBBI0_CS2_SOD_REG PORTH
  139. #define SBBI0_CS2_OE_REG DDRH
  140. #endif
  141. /*! \brief Enable SBBI0 chip select 2 output. */
  142. #define SBBI0_CS2_ENA() sbi(SBBI0_CS2_OE_REG, SBBI0_CS2_BIT)
  143. /*! \brief Set SBBI0 chip select 2 output low. */
  144. #define SBBI0_CS2_CLR() cbi(SBBI0_CS2_SOD_REG, SBBI0_CS2_BIT)
  145. /*! \brief Set SBBI0 chip select 2 output high. */
  146. #define SBBI0_CS2_SET() sbi(SBBI0_CS2_SOD_REG, SBBI0_CS2_BIT)
  147. #else /* SBBI0_CS2_BIT */
  148. #define SBBI0_CS2_ENA()
  149. #define SBBI0_CS2_CLR()
  150. #define SBBI0_CS2_SET()
  151. #endif /* SBBI0_CS2_BIT */
  152. #ifdef SBBI0_CS3_BIT
  153. #if (SBBI0_CS3_AVRPORT == AVRPORTB)
  154. #define SBBI0_CS3_SOD_REG PORTB
  155. #define SBBI0_CS3_OE_REG DDRB
  156. #elif (SBBI0_CS3_AVRPORT == AVRPORTD)
  157. #define SBBI0_CS3_SOD_REG PORTD
  158. #define SBBI0_CS3_OE_REG DDRD
  159. #elif (SBBI0_CS3_AVRPORT == AVRPORTE)
  160. #define SBBI0_CS3_SOD_REG PORTE
  161. #define SBBI0_CS3_OE_REG DDRE
  162. #elif (SBBI0_CS3_AVRPORT == AVRPORTF)
  163. #define SBBI0_CS3_SOD_REG PORTF
  164. #define SBBI0_CS3_OE_REG DDRF
  165. #elif (SBBI0_CS3_AVRPORT == AVRPORTG)
  166. #define SBBI0_CS3_SOD_REG PORTG
  167. #define SBBI0_CS3_OE_REG DDRG
  168. #elif (SBBI0_CS3_AVRPORT == AVRPORTH)
  169. #define SBBI0_CS3_SOD_REG PORTH
  170. #define SBBI0_CS3_OE_REG DDRH
  171. #endif
  172. /*! \brief Enable SBBI0 chip select 3 output. */
  173. #define SBBI0_CS3_ENA() sbi(SBBI0_CS3_OE_REG, SBBI0_CS3_BIT)
  174. /*! \brief Set SBBI0 chip select 3 output low. */
  175. #define SBBI0_CS3_CLR() cbi(SBBI0_CS3_SOD_REG, SBBI0_CS3_BIT)
  176. /*! \brief Set SBBI0 chip select 3 output high. */
  177. #define SBBI0_CS3_SET() sbi(SBBI0_CS3_SOD_REG, SBBI0_CS3_BIT)
  178. #else /* SBBI0_CS3_BIT */
  179. #define SBBI0_CS3_ENA()
  180. #define SBBI0_CS3_CLR()
  181. #define SBBI0_CS3_SET()
  182. #endif /* SBBI0_CS3_BIT */
  183. #ifdef SBBI0_RST0_BIT
  184. #if (SBBI0_RST0_AVRPORT == AVRPORTB)
  185. #define SBBI0_RST0_SOD_REG PORTB
  186. #define SBBI0_RST0_OE_REG DDRB
  187. #elif (SBBI0_RST0_AVRPORT == AVRPORTD)
  188. #define SBBI0_RST0_SOD_REG PORTD
  189. #define SBBI0_RST0_OE_REG DDRD
  190. #elif (SBBI0_RST0_AVRPORT == AVRPORTE)
  191. #define SBBI0_RST0_SOD_REG PORTE
  192. #define SBBI0_RST0_OE_REG DDRE
  193. #elif (SBBI0_RST0_AVRPORT == AVRPORTF)
  194. #define SBBI0_RST0_SOD_REG PORTF
  195. #define SBBI0_RST0_OE_REG DDRF
  196. #elif (SBBI0_RST0_AVRPORT == AVRPORTG)
  197. #define SBBI0_RST0_SOD_REG PORTG
  198. #define SBBI0_RST0_OE_REG DDRG
  199. #elif (SBBI0_RST0_AVRPORT == AVRPORTH)
  200. #define SBBI0_RST0_SOD_REG PORTH
  201. #define SBBI0_RST0_OE_REG DDRH
  202. #endif
  203. /*! \brief Enable SBBI0 reset 0 output. */
  204. #define SBBI0_RST0_ENA() sbi(SBBI0_RST0_OE_REG, SBBI0_RST0_BIT)
  205. /*! \brief Set SBBI0 reset 0 output low. */
  206. #define SBBI0_RST0_CLR() cbi(SBBI0_RST0_SOD_REG, SBBI0_RST0_BIT)
  207. /*! \brief Set SBBI0 reset 0 output high. */
  208. #define SBBI0_RST0_SET() sbi(SBBI0_RST0_SOD_REG, SBBI0_RST0_BIT)
  209. #else /* SBBI0_RST0_BIT */
  210. #define SBBI0_RST0_ENA()
  211. #define SBBI0_RST0_CLR()
  212. #define SBBI0_RST0_SET()
  213. #endif /* SBBI0_RST0_BIT */
  214. #ifdef SBBI0_RST1_BIT
  215. #if (SBBI0_RST1_AVRPORT == AVRPORTB)
  216. #define SBBI0_RST1_SOD_REG PORTB
  217. #define SBBI0_RST1_OE_REG DDRB
  218. #elif (SBBI0_RST1_AVRPORT == AVRPORTD)
  219. #define SBBI0_RST1_SOD_REG PORTD
  220. #define SBBI0_RST1_OE_REG DDRD
  221. #elif (SBBI0_RST1_AVRPORT == AVRPORTE)
  222. #define SBBI0_RST1_SOD_REG PORTE
  223. #define SBBI0_RST1_OE_REG DDRE
  224. #elif (SBBI0_RST1_AVRPORT == AVRPORTF)
  225. #define SBBI0_RST1_SOD_REG PORTF
  226. #define SBBI0_RST1_OE_REG DDRF
  227. #elif (SBBI0_RST1_AVRPORT == AVRPORTG)
  228. #define SBBI0_RST1_SOD_REG PORTG
  229. #define SBBI0_RST1_OE_REG DDRG
  230. #elif (SBBI0_RST1_AVRPORT == AVRPORTH)
  231. #define SBBI0_RST1_SOD_REG PORTH
  232. #define SBBI0_RST1_OE_REG DDRH
  233. #endif
  234. /*! \brief Enable SBBI0 reset 1 output. */
  235. #define SBBI0_RST1_ENA() sbi(SBBI0_RST1_OE_REG, SBBI0_RST1_BIT)
  236. /*! \brief Set SBBI0 reset 1 output low. */
  237. #define SBBI0_RST1_CLR() cbi(SBBI0_RST1_SOD_REG, SBBI0_RST1_BIT)
  238. /*! \brief Set SBBI0 reset 1 output high. */
  239. #define SBBI0_RST1_SET() sbi(SBBI0_RST1_SOD_REG, SBBI0_RST1_BIT)
  240. #else /* SBBI0_RST1_BIT */
  241. #define SBBI0_RST1_ENA()
  242. #define SBBI0_RST1_CLR()
  243. #define SBBI0_RST1_SET()
  244. #endif /* SBBI0_RST1_BIT */
  245. #ifdef SBBI0_RST2_BIT
  246. #if (SBBI0_RST2_AVRPORT == AVRPORTB)
  247. #define SBBI0_RST2_SOD_REG PORTB
  248. #define SBBI0_RST2_OE_REG DDRB
  249. #elif (SBBI0_RST2_AVRPORT == AVRPORTD)
  250. #define SBBI0_RST2_SOD_REG PORTD
  251. #define SBBI0_RST2_OE_REG DDRD
  252. #elif (SBBI0_RST2_AVRPORT == AVRPORTE)
  253. #define SBBI0_RST2_SOD_REG PORTE
  254. #define SBBI0_RST2_OE_REG DDRE
  255. #elif (SBBI0_RST2_AVRPORT == AVRPORTF)
  256. #define SBBI0_RST2_SOD_REG PORTF
  257. #define SBBI0_RST2_OE_REG DDRF
  258. #elif (SBBI0_RST2_AVRPORT == AVRPORTG)
  259. #define SBBI0_RST2_SOD_REG PORTG
  260. #define SBBI0_RST2_OE_REG DDRG
  261. #elif (SBBI0_RST2_AVRPORT == AVRPORTH)
  262. #define SBBI0_RST2_SOD_REG PORTH
  263. #define SBBI0_RST2_OE_REG DDRH
  264. #endif
  265. /*! \brief Enable SBBI0 reset 2 output. */
  266. #define SBBI0_RST2_ENA() sbi(SBBI0_RST2_OE_REG, SBBI0_RST2_BIT)
  267. /*! \brief Set SBBI0 chip reset 2 output low. */
  268. #define SBBI0_RST2_CLR() cbi(SBBI0_RST2_SOD_REG, SBBI0_RST2_BIT)
  269. /*! \brief Set SBBI0 chip reset 2 output high. */
  270. #define SBBI0_RST2_SET() sbi(SBBI0_RST2_SOD_REG, SBBI0_RST2_BIT)
  271. #else /* SBBI0_RST2_BIT */
  272. #define SBBI0_RST2_ENA()
  273. #define SBBI0_RST2_CLR()
  274. #define SBBI0_RST2_SET()
  275. #endif /* SBBI0_RST2_BIT */
  276. #ifdef SBBI0_RST3_BIT
  277. #if (SBBI0_RST3_AVRPORT == AVRPORTB)
  278. #define SBBI0_RST3_SOD_REG PORTB
  279. #define SBBI0_RST3_OE_REG DDRB
  280. #elif (SBBI0_RST3_AVRPORT == AVRPORTD)
  281. #define SBBI0_RST3_SOD_REG PORTD
  282. #define SBBI0_RST3_OE_REG DDRD
  283. #elif (SBBI0_RST3_AVRPORT == AVRPORTE)
  284. #define SBBI0_RST3_SOD_REG PORTE
  285. #define SBBI0_RST3_OE_REG DDRE
  286. #elif (SBBI0_RST3_AVRPORT == AVRPORTF)
  287. #define SBBI0_RST3_SOD_REG PORTF
  288. #define SBBI0_RST3_OE_REG DDRF
  289. #elif (SBBI0_RST3_AVRPORT == AVRPORTG)
  290. #define SBBI0_RST3_SOD_REG PORTG
  291. #define SBBI0_RST3_OE_REG DDRG
  292. #elif (SBBI0_RST3_AVRPORT == AVRPORTH)
  293. #define SBBI0_RST3_SOD_REG PORTH
  294. #define SBBI0_RST3_OE_REG DDRH
  295. #endif
  296. /*! \brief Enable SBBI0 reset 3 output. */
  297. #define SBBI0_RST3_ENA() sbi(SBBI0_RST3_OE_REG, SBBI0_RST3_BIT)
  298. /*! \brief Set SBBI0 reset 3 output low. */
  299. #define SBBI0_RST3_CLR() cbi(SBBI0_RST3_SOD_REG, SBBI0_RST3_BIT)
  300. /*! \brief Set SBBI0 reset 3 output high. */
  301. #define SBBI0_RST3_SET() sbi(SBBI0_RST3_SOD_REG, SBBI0_RST3_BIT)
  302. #else /* SBBI0_RST3_BIT */
  303. #define SBBI0_RST3_ENA()
  304. #define SBBI0_RST3_CLR()
  305. #define SBBI0_RST3_SET()
  306. #endif /* SBBI0_RST3_BIT */
  307. #ifdef SBBI0_SCK_BIT
  308. #if (SBBI0_SCK_AVRPORT == AVRPORTB)
  309. #define SBBI0_SCK_SOD_REG PORTB
  310. #define SBBI0_SCK_OE_REG DDRB
  311. #elif (SBBI0_SCK_AVRPORT == AVRPORTD)
  312. #define SBBI0_SCK_SOD_REG PORTD
  313. #define SBBI0_SCK_OE_REG DDRD
  314. #elif (SBBI0_SCK_AVRPORT == AVRPORTE)
  315. #define SBBI0_SCK_SOD_REG PORTE
  316. #define SBBI0_SCK_OE_REG DDRE
  317. #elif (SBBI0_SCK_AVRPORT == AVRPORTF)
  318. #define SBBI0_SCK_SOD_REG PORTF
  319. #define SBBI0_SCK_OE_REG DDRF
  320. #elif (SBBI0_SCK_AVRPORT == AVRPORTG)
  321. #define SBBI0_SCK_SOD_REG PORTG
  322. #define SBBI0_SCK_OE_REG DDRG
  323. #elif (SBBI0_SCK_AVRPORT == AVRPORTH)
  324. #define SBBI0_SCK_SOD_REG PORTH
  325. #define SBBI0_SCK_OE_REG DDRH
  326. #endif
  327. /*! \brief Enable SBBI0 clock output. */
  328. #define SBBI0_SCK_ENA() sbi(SBBI0_SCK_OE_REG, SBBI0_SCK_BIT)
  329. /*! \brief Set SBBI0 clock output low. */
  330. #define SBBI0_SCK_CLR() cbi(SBBI0_SCK_SOD_REG, SBBI0_SCK_BIT)
  331. /*! \brief Set SBBI0 clock output high. */
  332. #define SBBI0_SCK_SET() sbi(SBBI0_SCK_SOD_REG, SBBI0_SCK_BIT)
  333. #if defined(SBBI0_MOSI_BIT)
  334. #if (SBBI0_MOSI_AVRPORT == AVRPORTB)
  335. #define SBBI0_MOSI_SOD_REG PORTB
  336. #define SBBI0_MOSI_OE_REG DDRB
  337. #elif (SBBI0_MOSI_AVRPORT == AVRPORTD)
  338. #define SBBI0_MOSI_SOD_REG PORTD
  339. #define SBBI0_MOSI_OE_REG DDRD
  340. #elif (SBBI0_MOSI_AVRPORT == AVRPORTE)
  341. #define SBBI0_MOSI_SOD_REG PORTE
  342. #define SBBI0_MOSI_OE_REG DDRE
  343. #elif (SBBI0_MOSI_AVRPORT == AVRPORTF)
  344. #define SBBI0_MOSI_SOD_REG PORTF
  345. #define SBBI0_MOSI_OE_REG DDRF
  346. #elif (SBBI0_MOSI_AVRPORT == AVRPORTG)
  347. #define SBBI0_MOSI_SOD_REG PORTG
  348. #define SBBI0_MOSI_OE_REG DDRG
  349. #elif (SBBI0_MOSI_AVRPORT == AVRPORTH)
  350. #define SBBI0_MOSI_SOD_REG PORTH
  351. #define SBBI0_MOSI_OE_REG DDRH
  352. #endif
  353. /*! \brief Enable SBBI0 data output. */
  354. #define SBBI0_MOSI_ENA() sbi(SBBI0_MOSI_OE_REG, SBBI0_MOSI_BIT)
  355. /*! \brief Set SBBI0 data output low. */
  356. #define SBBI0_MOSI_CLR() cbi(SBBI0_MOSI_SOD_REG, SBBI0_MOSI_BIT)
  357. /*! \brief Set SBBI0 data output high. */
  358. #define SBBI0_MOSI_SET() sbi(SBBI0_MOSI_SOD_REG, SBBI0_MOSI_BIT)
  359. #else /* SBBI0_MOSI_BIT */
  360. #define SBBI0_MOSI_ENA()
  361. #define SBBI0_MOSI_CLR()
  362. #define SBBI0_MOSI_SET()
  363. #endif /* SBBI0_MOSI_BIT */
  364. #if defined(SBBI0_MISO_BIT)
  365. #if (SBBI0_MISO_AVRPORT == AVRPORTB)
  366. #define SBBI0_MISO_PDS_REG PINB
  367. #define SBBI0_MISO_PUE_REG PORTB
  368. #define SBBI0_MISO_OE_REG DDRB
  369. #elif (SBBI0_MISO_AVRPORT == AVRPORTD)
  370. #define SBBI0_MISO_PDS_REG PIND
  371. #define SBBI0_MISO_PUE_REG PORTD
  372. #define SBBI0_MISO_OE_REG DDRD
  373. #elif (SBBI0_MISO_AVRPORT == AVRPORTE)
  374. #define SBBI0_MISO_PDS_REG PINE
  375. #define SBBI0_MISO_PUE_REG PORTE
  376. #define SBBI0_MISO_OE_REG DDRE
  377. #elif (SBBI0_MISO_AVRPORT == AVRPORTF)
  378. #define SBBI0_MISO_PDS_REG PINF
  379. #define SBBI0_MISO_PUE_REG PORTF
  380. #define SBBI0_MISO_OE_REG DDRF
  381. #elif (SBBI0_MISO_AVRPORT == AVRPORTG)
  382. #define SBBI0_MISO_PDS_REG PING
  383. #define SBBI0_MISO_PUE_REG PORTG
  384. #define SBBI0_MISO_OE_REG DDRG
  385. #elif (SBBI0_MISO_AVRPORT == AVRPORTH)
  386. #define SBBI0_MISO_PDS_REG PINH
  387. #define SBBI0_MISO_PUE_REG PORTH
  388. #define SBBI0_MISO_OE_REG DDRH
  389. #endif
  390. /*! \brief Enable SBBI0 data input. */
  391. #define SBBI0_MISO_ENA() \
  392. cbi(SBBI0_MISO_OE_REG, SBBI0_MISO_BIT); \
  393. sbi(SBBI0_MISO_PUE_REG, SBBI0_MISO_BIT)
  394. /*! \brief Query SBBI0 data input. */
  395. #define SBBI0_MISO_TST() ((inb(SBBI0_MISO_PDS_REG) & _BV(SBBI0_MISO_BIT)) == _BV(SBBI0_MISO_BIT))
  396. #else /* SBBI0_MISO_BIT */
  397. #define SBBI0_MISO_ENA()
  398. #define SBBI0_MISO_TST() 0
  399. #endif /* SBBI0_MISO_BIT */
  400. #else /* SBBI0_SCK_BIT */
  401. #define SBBI0_SCK_ENA()
  402. #define SBBI0_SCK_CLR()
  403. #define SBBI0_SCK_SET()
  404. #define SBBI0_MOSI_ENA()
  405. #define SBBI0_MOSI_CLR()
  406. #define SBBI0_MOSI_SET()
  407. #define SBBI0_MISO_ENA()
  408. #define SBBI0_MISO_TST() 0
  409. #endif /* SBBI0_SCK_BIT */
  410. #else /* MCU */
  411. /*
  412. * AT91 implementation.
  413. * ======================================
  414. */
  415. #ifdef SBBI0_CS0_BIT
  416. #if !defined(SBBI0_CS0_PIO_ID)
  417. #define SBBI0_CS0_PE_REG PIO_PER
  418. #define SBBI0_CS0_OE_REG PIO_OER
  419. #define SBBI0_CS0_COD_REG PIO_CODR
  420. #define SBBI0_CS0_SOD_REG PIO_SODR
  421. #elif SBBI0_CS0_PIO_ID == PIO_ID
  422. #define SBBI0_CS0_PE_REG PIO_PER
  423. #define SBBI0_CS0_OE_REG PIO_OER
  424. #define SBBI0_CS0_COD_REG PIO_CODR
  425. #define SBBI0_CS0_SOD_REG PIO_SODR
  426. #elif SBBI0_CS0_PIO_ID == PIOA_ID
  427. #define SBBI0_CS0_PE_REG PIOA_PER
  428. #define SBBI0_CS0_OE_REG PIOA_OER
  429. #define SBBI0_CS0_COD_REG PIOA_CODR
  430. #define SBBI0_CS0_SOD_REG PIOA_SODR
  431. #elif SBBI0_CS0_PIO_ID == PIOB_ID
  432. #define SBBI0_CS0_PE_REG PIOB_PER
  433. #define SBBI0_CS0_OE_REG PIOB_OER
  434. #define SBBI0_CS0_COD_REG PIOB_CODR
  435. #define SBBI0_CS0_SOD_REG PIOB_SODR
  436. #elif SBBI0_CS0_PIO_ID == PIOC_ID
  437. #define SBBI0_CS0_PE_REG PIOC_PER
  438. #define SBBI0_CS0_OE_REG PIOC_OER
  439. #define SBBI0_CS0_COD_REG PIOC_CODR
  440. #define SBBI0_CS0_SOD_REG PIOC_SODR
  441. #endif
  442. /*! \brief Enable SBBI0 chip select 0 output. */
  443. #define SBBI0_CS0_ENA() \
  444. outr(SBBI0_CS0_PE_REG, _BV(SBBI0_CS0_BIT)); \
  445. outr(SBBI0_CS0_OE_REG, _BV(SBBI0_CS0_BIT))
  446. /*! \brief Set SBBI0 chip select 0 output low. */
  447. #define SBBI0_CS0_CLR() outr(SBBI0_CS0_COD_REG, _BV(SBBI0_CS0_BIT))
  448. /*! \brief Set SBBI0 chip select 0 output high. */
  449. #define SBBI0_CS0_SET() outr(SBBI0_CS0_SOD_REG, _BV(SBBI0_CS0_BIT))
  450. #else /* SBBI0_CS0_BIT */
  451. #define SBBI0_CS0_ENA()
  452. #define SBBI0_CS0_CLR()
  453. #define SBBI0_CS0_SET()
  454. #endif /* SBBI0_CS0_BIT */
  455. #ifdef SBBI0_CS1_BIT
  456. #if !defined(SBBI0_CS1_PIO_ID)
  457. #define SBBI0_CS1_PE_REG PIO_PER
  458. #define SBBI0_CS1_OE_REG PIO_OER
  459. #define SBBI0_CS1_COD_REG PIO_CODR
  460. #define SBBI0_CS1_SOD_REG PIO_SODR
  461. #elif SBBI0_CS1_PIO_ID == PIO_ID
  462. #define SBBI0_CS1_PE_REG PIO_PER
  463. #define SBBI0_CS1_OE_REG PIO_OER
  464. #define SBBI0_CS1_COD_REG PIO_CODR
  465. #define SBBI0_CS1_SOD_REG PIO_SODR
  466. #elif SBBI0_CS1_PIO_ID == PIOA_ID
  467. #define SBBI0_CS1_PE_REG PIOA_PER
  468. #define SBBI0_CS1_OE_REG PIOA_OER
  469. #define SBBI0_CS1_COD_REG PIOA_CODR
  470. #define SBBI0_CS1_SOD_REG PIOA_SODR
  471. #elif SBBI0_CS1_PIO_ID == PIOB_ID
  472. #define SBBI0_CS1_PE_REG PIOB_PER
  473. #define SBBI0_CS1_OE_REG PIOB_OER
  474. #define SBBI0_CS1_COD_REG PIOB_CODR
  475. #define SBBI0_CS1_SOD_REG PIOB_SODR
  476. #elif SBBI0_CS1_PIO_ID == PIOC_ID
  477. #define SBBI0_CS1_PE_REG PIOC_PER
  478. #define SBBI0_CS1_OE_REG PIOC_OER
  479. #define SBBI0_CS1_COD_REG PIOC_CODR
  480. #define SBBI0_CS1_SOD_REG PIOC_SODR
  481. #endif
  482. /*! \brief Enable SBBI0 chip select output. */
  483. #define SBBI0_CS1_ENA() \
  484. outr(SBBI0_CS1_PE_REG, _BV(SBBI0_CS1_BIT)); \
  485. outr(SBBI0_CS1_OE_REG, _BV(SBBI0_CS1_BIT))
  486. /*! \brief Set SBBI0 chip select output low. */
  487. #define SBBI0_CS1_CLR() outr(SBBI0_CS1_COD_REG, _BV(SBBI0_CS1_BIT))
  488. /*! \brief Set SBBI0 chip select output high. */
  489. #define SBBI0_CS1_SET() outr(SBBI0_CS1_SOD_REG, _BV(SBBI0_CS1_BIT))
  490. #else /* SBBI0_CS1_BIT */
  491. #define SBBI0_CS1_ENA()
  492. #define SBBI0_CS1_CLR()
  493. #define SBBI0_CS1_SET()
  494. #endif /* SBBI0_CS1_BIT */
  495. #ifdef SBBI0_CS2_BIT
  496. #if !defined(SBBI0_CS2_PIO_ID)
  497. #define SBBI0_CS2_PE_REG PIO_PER
  498. #define SBBI0_CS2_OE_REG PIO_OER
  499. #define SBBI0_CS2_COD_REG PIO_CODR
  500. #define SBBI0_CS2_SOD_REG PIO_SODR
  501. #elif SBBI0_CS2_PIO_ID == PIO_ID
  502. #define SBBI0_CS2_PE_REG PIO_PER
  503. #define SBBI0_CS2_OE_REG PIO_OER
  504. #define SBBI0_CS2_COD_REG PIO_CODR
  505. #define SBBI0_CS2_SOD_REG PIO_SODR
  506. #elif SBBI0_CS2_PIO_ID == PIOA_ID
  507. #define SBBI0_CS2_PE_REG PIOA_PER
  508. #define SBBI0_CS2_OE_REG PIOA_OER
  509. #define SBBI0_CS2_COD_REG PIOA_CODR
  510. #define SBBI0_CS2_SOD_REG PIOA_SODR
  511. #elif SBBI0_CS2_PIO_ID == PIOB_ID
  512. #define SBBI0_CS2_PE_REG PIOB_PER
  513. #define SBBI0_CS2_OE_REG PIOB_OER
  514. #define SBBI0_CS2_COD_REG PIOB_CODR
  515. #define SBBI0_CS2_SOD_REG PIOB_SODR
  516. #elif SBBI0_CS2_PIO_ID == PIOC_ID
  517. #define SBBI0_CS2_PE_REG PIOC_PER
  518. #define SBBI0_CS2_OE_REG PIOC_OER
  519. #define SBBI0_CS2_COD_REG PIOC_CODR
  520. #define SBBI0_CS2_SOD_REG PIOC_SODR
  521. #endif
  522. /*! \brief Enable SBBI0 chip select output. */
  523. #define SBBI0_CS2_ENA() \
  524. outr(SBBI0_CS2_PE_REG, _BV(SBBI0_CS2_BIT)); \
  525. outr(SBBI0_CS2_OE_REG, _BV(SBBI0_CS2_BIT))
  526. /*! \brief Set SBBI0 chip select output low. */
  527. #define SBBI0_CS2_CLR() outr(SBBI0_CS2_COD_REG, _BV(SBBI0_CS2_BIT))
  528. /*! \brief Set SBBI0 chip select output high. */
  529. #define SBBI0_CS2_SET() outr(SBBI0_CS2_SOD_REG, _BV(SBBI0_CS2_BIT))
  530. #else /* SBBI0_CS2_BIT */
  531. #define SBBI0_CS2_ENA()
  532. #define SBBI0_CS2_CLR()
  533. #define SBBI0_CS2_SET()
  534. #endif /* SBBI0_CS2_BIT */
  535. #ifdef SBBI0_CS3_BIT
  536. #if !defined(SBBI0_CS3_PIO_ID)
  537. #define SBBI0_CS3_PE_REG PIO_PER
  538. #define SBBI0_CS3_OE_REG PIO_OER
  539. #define SBBI0_CS3_COD_REG PIO_CODR
  540. #define SBBI0_CS3_SOD_REG PIO_SODR
  541. #elif SBBI0_CS3_PIO_ID == PIO_ID
  542. #define SBBI0_CS3_PE_REG PIO_PER
  543. #define SBBI0_CS3_OE_REG PIO_OER
  544. #define SBBI0_CS3_COD_REG PIO_CODR
  545. #define SBBI0_CS3_SOD_REG PIO_SODR
  546. #elif SBBI0_CS3_PIO_ID == PIOA_ID
  547. #define SBBI0_CS3_PE_REG PIOA_PER
  548. #define SBBI0_CS3_OE_REG PIOA_OER
  549. #define SBBI0_CS3_COD_REG PIOA_CODR
  550. #define SBBI0_CS3_SOD_REG PIOA_SODR
  551. #elif SBBI0_CS3_PIO_ID == PIOB_ID
  552. #define SBBI0_CS3_PE_REG PIOB_PER
  553. #define SBBI0_CS3_OE_REG PIOB_OER
  554. #define SBBI0_CS3_COD_REG PIOB_CODR
  555. #define SBBI0_CS3_SOD_REG PIOB_SODR
  556. #elif SBBI0_CS3_PIO_ID == PIOC_ID
  557. #define SBBI0_CS3_PE_REG PIOC_PER
  558. #define SBBI0_CS3_OE_REG PIOC_OER
  559. #define SBBI0_CS3_COD_REG PIOC_CODR
  560. #define SBBI0_CS3_SOD_REG PIOC_SODR
  561. #endif
  562. /*! \brief Enable SBBI0 chip select output. */
  563. #define SBBI0_CS3_ENA() \
  564. outr(SBBI0_CS3_PE_REG, _BV(SBBI0_CS3_BIT)); \
  565. outr(SBBI0_CS3_OE_REG, _BV(SBBI0_CS3_BIT))
  566. /*! \brief Set SBBI0 chip select output low. */
  567. #define SBBI0_CS3_CLR() outr(SBBI0_CS3_COD_REG, _BV(SBBI0_CS3_BIT))
  568. /*! \brief Set SBBI0 chip select output high. */
  569. #define SBBI0_CS3_SET() outr(SBBI0_CS3_SOD_REG, _BV(SBBI0_CS3_BIT))
  570. #else /* SBBI0_CS3_BIT */
  571. #define SBBI0_CS3_ENA()
  572. #define SBBI0_CS3_CLR()
  573. #define SBBI0_CS3_SET()
  574. #endif /* SBBI0_CS3_BIT */
  575. #ifdef SBBI0_RST0_BIT
  576. #if !defined(SBBI0_RST0_PIO_ID)
  577. #define SBBI0_RST0_PE_REG PIO_PER
  578. #define SBBI0_RST0_OE_REG PIO_OER
  579. #define SBBI0_RST0_COD_REG PIO_CODR
  580. #define SBBI0_RST0_SOD_REG PIO_SODR
  581. #elif SBBI0_RST0_PIO_ID == PIO_ID
  582. #define SBBI0_RST0_PE_REG PIO_PER
  583. #define SBBI0_RST0_OE_REG PIO_OER
  584. #define SBBI0_RST0_COD_REG PIO_CODR
  585. #define SBBI0_RST0_SOD_REG PIO_SODR
  586. #elif SBBI0_RST0_PIO_ID == PIOA_ID
  587. #define SBBI0_RST0_PE_REG PIOA_PER
  588. #define SBBI0_RST0_OE_REG PIOA_OER
  589. #define SBBI0_RST0_COD_REG PIOA_CODR
  590. #define SBBI0_RST0_SOD_REG PIOA_SODR
  591. #elif SBBI0_RST0_PIO_ID == PIOB_ID
  592. #define SBBI0_RST0_PE_REG PIOB_PER
  593. #define SBBI0_RST0_OE_REG PIOB_OER
  594. #define SBBI0_RST0_COD_REG PIOB_CODR
  595. #define SBBI0_RST0_SOD_REG PIOB_SODR
  596. #elif SBBI0_RST0_PIO_ID == PIOC_ID
  597. #define SBBI0_RST0_PE_REG PIOC_PER
  598. #define SBBI0_RST0_OE_REG PIOC_OER
  599. #define SBBI0_RST0_COD_REG PIOC_CODR
  600. #define SBBI0_RST0_SOD_REG PIOC_SODR
  601. #endif
  602. /*! \brief Enable SBBI0 reset output. */
  603. #define SBBI0_RST0_ENA() \
  604. outr(SBBI0_RST0_PE_REG, _BV(SBBI0_RST0_BIT)); \
  605. outr(SBBI0_RST0_OE_REG, _BV(SBBI0_RST0_BIT))
  606. /*! \brief Set SBBI0 reset output low. */
  607. #define SBBI0_RST0_CLR() outr(SBBI0_RST0_COD_REG, _BV(SBBI0_RST0_BIT))
  608. /*! \brief Set SBBI0 reset output high. */
  609. #define SBBI0_RST0_SET() outr(SBBI0_RST0_SOD_REG, _BV(SBBI0_RST0_BIT))
  610. #else /* SBBI0_RST0_BIT */
  611. #define SBBI0_RST0_ENA()
  612. #define SBBI0_RST0_CLR()
  613. #define SBBI0_RST0_SET()
  614. #endif /* SBBI0_RST0_BIT */
  615. #ifdef SBBI0_RST1_BIT
  616. #if !defined(SBBI0_RST1_PIO_ID)
  617. #define SBBI0_RST1_PE_REG PIO_PER
  618. #define SBBI0_RST1_OE_REG PIO_OER
  619. #define SBBI0_RST1_COD_REG PIO_CODR
  620. #define SBBI0_RST1_SOD_REG PIO_SODR
  621. #elif SBBI0_RST1_PIO_ID == PIO_ID
  622. #define SBBI0_RST1_PE_REG PIO_PER
  623. #define SBBI0_RST1_OE_REG PIO_OER
  624. #define SBBI0_RST1_COD_REG PIO_CODR
  625. #define SBBI0_RST1_SOD_REG PIO_SODR
  626. #elif SBBI0_RST1_PIO_ID == PIOA_ID
  627. #define SBBI0_RST1_PE_REG PIOA_PER
  628. #define SBBI0_RST1_OE_REG PIOA_OER
  629. #define SBBI0_RST1_COD_REG PIOA_CODR
  630. #define SBBI0_RST1_SOD_REG PIOA_SODR
  631. #elif SBBI0_RST1_PIO_ID == PIOB_ID
  632. #define SBBI0_RST1_PE_REG PIOB_PER
  633. #define SBBI0_RST1_OE_REG PIOB_OER
  634. #define SBBI0_RST1_COD_REG PIOB_CODR
  635. #define SBBI0_RST1_SOD_REG PIOB_SODR
  636. #elif SBBI0_RST1_PIO_ID == PIOC_ID
  637. #define SBBI0_RST1_PE_REG PIOC_PER
  638. #define SBBI0_RST1_OE_REG PIOC_OER
  639. #define SBBI0_RST1_COD_REG PIOC_CODR
  640. #define SBBI0_RST1_SOD_REG PIOC_SODR
  641. #endif
  642. /*! \brief Enable SBBI0 reset output. */
  643. #define SBBI0_RST1_ENA() \
  644. outr(SBBI0_RST1_PE_REG, _BV(SBBI0_RST1_BIT)); \
  645. outr(SBBI0_RST1_OE_REG, _BV(SBBI0_RST1_BIT))
  646. /*! \brief Set SBBI0 reset output low. */
  647. #define SBBI0_RST1_CLR() outr(SBBI0_RST1_COD_REG, _BV(SBBI0_RST1_BIT))
  648. /*! \brief Set SBBI0 reset output high. */
  649. #define SBBI0_RST1_SET() outr(SBBI0_RST1_SOD_REG, _BV(SBBI0_RST1_BIT))
  650. #else /* SBBI0_RST1_BIT */
  651. #define SBBI0_RST1_ENA()
  652. #define SBBI0_RST1_CLR()
  653. #define SBBI0_RST1_SET()
  654. #endif /* SBBI0_RST1_BIT */
  655. #ifdef SBBI0_RST2_BIT
  656. #if !defined(SBBI0_RST2_PIO_ID)
  657. #define SBBI0_RST2_PE_REG PIO_PER
  658. #define SBBI0_RST2_OE_REG PIO_OER
  659. #define SBBI0_RST2_COD_REG PIO_CODR
  660. #define SBBI0_RST2_SOD_REG PIO_SODR
  661. #elif SBBI0_RST2_PIO_ID == PIO_ID
  662. #define SBBI0_RST2_PE_REG PIO_PER
  663. #define SBBI0_RST2_OE_REG PIO_OER
  664. #define SBBI0_RST2_COD_REG PIO_CODR
  665. #define SBBI0_RST2_SOD_REG PIO_SODR
  666. #elif SBBI0_RST2_PIO_ID == PIOA_ID
  667. #define SBBI0_RST2_PE_REG PIOA_PER
  668. #define SBBI0_RST2_OE_REG PIOA_OER
  669. #define SBBI0_RST2_COD_REG PIOA_CODR
  670. #define SBBI0_RST2_SOD_REG PIOA_SODR
  671. #elif SBBI0_RST2_PIO_ID == PIOB_ID
  672. #define SBBI0_RST2_PE_REG PIOB_PER
  673. #define SBBI0_RST2_OE_REG PIOB_OER
  674. #define SBBI0_RST2_COD_REG PIOB_CODR
  675. #define SBBI0_RST2_SOD_REG PIOB_SODR
  676. #elif SBBI0_RST2_PIO_ID == PIOC_ID
  677. #define SBBI0_RST2_PE_REG PIOC_PER
  678. #define SBBI0_RST2_OE_REG PIOC_OER
  679. #define SBBI0_RST2_COD_REG PIOC_CODR
  680. #define SBBI0_RST2_SOD_REG PIOC_SODR
  681. #endif
  682. /*! \brief Enable SBBI0 reset output. */
  683. #define SBBI0_RST2_ENA() \
  684. outr(SBBI0_RST2_PE_REG, _BV(SBBI0_RST2_BIT)); \
  685. outr(SBBI0_RST2_OE_REG, _BV(SBBI0_RST2_BIT))
  686. /*! \brief Set SBBI0 reset output low. */
  687. #define SBBI0_RST2_CLR() outr(SBBI0_RST2_COD_REG, _BV(SBBI0_RST2_BIT))
  688. /*! \brief Set SBBI0 reset output high. */
  689. #define SBBI0_RST2_SET() outr(SBBI0_RST2_SOD_REG, _BV(SBBI0_RST2_BIT))
  690. #else /* SBBI0_RST2_BIT */
  691. #define SBBI0_RST2_ENA()
  692. #define SBBI0_RST2_CLR()
  693. #define SBBI0_RST2_SET()
  694. #endif /* SBBI0_RST2_BIT */
  695. #ifdef SBBI0_RST3_BIT
  696. #if !defined(SBBI0_RST3_PIO_ID)
  697. #define SBBI0_RST3_PE_REG PIO_PER
  698. #define SBBI0_RST3_OE_REG PIO_OER
  699. #define SBBI0_RST3_COD_REG PIO_CODR
  700. #define SBBI0_RST3_SOD_REG PIO_SODR
  701. #elif SBBI0_RST3_PIO_ID == PIO_ID
  702. #define SBBI0_RST3_PE_REG PIO_PER
  703. #define SBBI0_RST3_OE_REG PIO_OER
  704. #define SBBI0_RST3_COD_REG PIO_CODR
  705. #define SBBI0_RST3_SOD_REG PIO_SODR
  706. #elif SBBI0_RST3_PIO_ID == PIOA_ID
  707. #define SBBI0_RST3_PE_REG PIOA_PER
  708. #define SBBI0_RST3_OE_REG PIOA_OER
  709. #define SBBI0_RST3_COD_REG PIOA_CODR
  710. #define SBBI0_RST3_SOD_REG PIOA_SODR
  711. #elif SBBI0_RST3_PIO_ID == PIOB_ID
  712. #define SBBI0_RST3_PE_REG PIOB_PER
  713. #define SBBI0_RST3_OE_REG PIOB_OER
  714. #define SBBI0_RST3_COD_REG PIOB_CODR
  715. #define SBBI0_RST3_SOD_REG PIOB_SODR
  716. #elif SBBI0_RST3_PIO_ID == PIOC_ID
  717. #define SBBI0_RST3_PE_REG PIOC_PER
  718. #define SBBI0_RST3_OE_REG PIOC_OER
  719. #define SBBI0_RST3_COD_REG PIOC_CODR
  720. #define SBBI0_RST3_SOD_REG PIOC_SODR
  721. #endif
  722. /*! \brief Enable SBBI0 reset output. */
  723. #define SBBI0_RST3_ENA() \
  724. outr(SBBI0_RST3_PE_REG, _BV(SBBI0_RST3_BIT)); \
  725. outr(SBBI0_RST3_OE_REG, _BV(SBBI0_RST3_BIT))
  726. /*! \brief Set SBBI0 reset output low. */
  727. #define SBBI0_RST3_CLR() outr(SBBI0_RST3_COD_REG, _BV(SBBI0_RST3_BIT))
  728. /*! \brief Set SBBI0 reset output high. */
  729. #define SBBI0_RST3_SET() outr(SBBI0_RST3_SOD_REG, _BV(SBBI0_RST3_BIT))
  730. #else /* SBBI0_RST3_BIT */
  731. #define SBBI0_RST3_ENA()
  732. #define SBBI0_RST3_CLR()
  733. #define SBBI0_RST3_SET()
  734. #endif /* SBBI0_RST3_BIT */
  735. #ifdef SBBI0_SCK_BIT
  736. #if !defined(SBBI0_SCK_PIO_ID)
  737. #define SBBI0_SCK_PE_REG PIO_PER
  738. #define SBBI0_SCK_OE_REG PIO_OER
  739. #define SBBI0_SCK_COD_REG PIO_CODR
  740. #define SBBI0_SCK_SOD_REG PIO_SODR
  741. #elif SBBI0_SCK_PIO_ID == PIO_ID
  742. #define SBBI0_SCK_PE_REG PIO_PER
  743. #define SBBI0_SCK_OE_REG PIO_OER
  744. #define SBBI0_SCK_COD_REG PIO_CODR
  745. #define SBBI0_SCK_SOD_REG PIO_SODR
  746. #elif SBBI0_SCK_PIO_ID == PIOA_ID
  747. #define SBBI0_SCK_PE_REG PIOA_PER
  748. #define SBBI0_SCK_OE_REG PIOA_OER
  749. #define SBBI0_SCK_COD_REG PIOA_CODR
  750. #define SBBI0_SCK_SOD_REG PIOA_SODR
  751. #elif SBBI0_SCK_PIO_ID == PIOB_ID
  752. #define SBBI0_SCK_PE_REG PIOB_PER
  753. #define SBBI0_SCK_OE_REG PIOB_OER
  754. #define SBBI0_SCK_COD_REG PIOB_CODR
  755. #define SBBI0_SCK_SOD_REG PIOB_SODR
  756. #elif SBBI0_SCK_PIO_ID == PIOC_ID
  757. #define SBBI0_SCK_PE_REG PIOC_PER
  758. #define SBBI0_SCK_OE_REG PIOC_OER
  759. #define SBBI0_SCK_COD_REG PIOC_CODR
  760. #define SBBI0_SCK_SOD_REG PIOC_SODR
  761. #endif
  762. /*! \brief Enable SBBI0 clock output. */
  763. #define SBBI0_SCK_ENA() \
  764. outr(SBBI0_SCK_PE_REG, _BV(SBBI0_SCK_BIT)); \
  765. outr(SBBI0_SCK_OE_REG, _BV(SBBI0_SCK_BIT))
  766. /*! \brief Set SBBI0 clock output low. */
  767. #define SBBI0_SCK_CLR() outr(SBBI0_SCK_COD_REG, _BV(SBBI0_SCK_BIT))
  768. /*! \brief Set SBBI0 clock output high. */
  769. #define SBBI0_SCK_SET() outr(SBBI0_SCK_SOD_REG, _BV(SBBI0_SCK_BIT))
  770. #ifdef SBBI0_MOSI_BIT
  771. #if !defined(SBBI0_MOSI_PIO_ID)
  772. #define SBBI0_MOSI_PE_REG PIO_PER
  773. #define SBBI0_MOSI_OE_REG PIO_OER
  774. #define SBBI0_MOSI_COD_REG PIO_CODR
  775. #define SBBI0_MOSI_SOD_REG PIO_SODR
  776. #elif SBBI0_MOSI_PIO_ID == PIO_ID
  777. #define SBBI0_MOSI_PE_REG PIO_PER
  778. #define SBBI0_MOSI_OE_REG PIO_OER
  779. #define SBBI0_MOSI_COD_REG PIO_CODR
  780. #define SBBI0_MOSI_SOD_REG PIO_SODR
  781. #elif SBBI0_MOSI_PIO_ID == PIOA_ID
  782. #define SBBI0_MOSI_PE_REG PIOA_PER
  783. #define SBBI0_MOSI_OE_REG PIOA_OER
  784. #define SBBI0_MOSI_COD_REG PIOA_CODR
  785. #define SBBI0_MOSI_SOD_REG PIOA_SODR
  786. #elif SBBI0_MOSI_PIO_ID == PIOB_ID
  787. #define SBBI0_MOSI_PE_REG PIOB_PER
  788. #define SBBI0_MOSI_OE_REG PIOB_OER
  789. #define SBBI0_MOSI_COD_REG PIOB_CODR
  790. #define SBBI0_MOSI_SOD_REG PIOB_SODR
  791. #elif SBBI0_MOSI_PIO_ID == PIOC_ID
  792. #define SBBI0_MOSI_PE_REG PIOC_PER
  793. #define SBBI0_MOSI_OE_REG PIOC_OER
  794. #define SBBI0_MOSI_COD_REG PIOC_CODR
  795. #define SBBI0_MOSI_SOD_REG PIOC_SODR
  796. #endif
  797. /*! \brief Enable SBBI0 data output. */
  798. #define SBBI0_MOSI_ENA() \
  799. outr(SBBI0_MOSI_PE_REG, _BV(SBBI0_MOSI_BIT)); \
  800. outr(SBBI0_MOSI_OE_REG, _BV(SBBI0_MOSI_BIT))
  801. /*! \brief Set SBBI0 data output low. */
  802. #define SBBI0_MOSI_CLR() outr(SBBI0_MOSI_COD_REG, _BV(SBBI0_MOSI_BIT))
  803. /*! \brief Set SBBI0 data output high. */
  804. #define SBBI0_MOSI_SET() outr(SBBI0_MOSI_SOD_REG, _BV(SBBI0_MOSI_BIT))
  805. #else /* SBBI0_MOSI_BIT */
  806. #define SBBI0_MOSI_ENA()
  807. #define SBBI0_MOSI_CLR()
  808. #define SBBI0_MOSI_SET()
  809. #endif /* SBBI0_MOSI_BIT */
  810. #ifdef SBBI0_MISO_BIT
  811. #if !defined(SBBI0_MISO_PIO_ID)
  812. #define SBBI0_MISO_PE_REG PIO_PER
  813. #define SBBI0_MISO_OD_REG PIO_ODR
  814. #define SBBI0_MISO_PDS_REG PIO_PDSR
  815. #elif SBBI0_MISO_PIO_ID == PIO_ID
  816. #define SBBI0_MISO_PE_REG PIO_PER
  817. #define SBBI0_MISO_OD_REG PIO_ODR
  818. #define SBBI0_MISO_PDS_REG PIO_PDSR
  819. #elif SBBI0_MISO_PIO_ID == PIOA_ID
  820. #define SBBI0_MISO_PE_REG PIOA_PER
  821. #define SBBI0_MISO_OD_REG PIOA_ODR
  822. #define SBBI0_MISO_PDS_REG PIOA_PDSR
  823. #elif SBBI0_MISO_PIO_ID == PIOB_ID
  824. #define SBBI0_MISO_PE_REG PIOB_PER
  825. #define SBBI0_MISO_OD_REG PIOB_ODR
  826. #define SBBI0_MISO_PDS_REG PIOB_PDSR
  827. #elif SBBI0_MISO_PIO_ID == PIOC_ID
  828. #define SBBI0_MISO_PE_REG PIOC_PER
  829. #define SBBI0_MISO_OD_REG PIOC_ODR
  830. #define SBBI0_MISO_PDS_REG PIOC_PDSR
  831. #endif
  832. /*! \brief Enable SBBI0 data input. */
  833. #define SBBI0_MISO_ENA() \
  834. outr(SBBI0_MISO_PE_REG, _BV(SBBI0_MISO_BIT)); \
  835. outr(SBBI0_MISO_OD_REG, _BV(SBBI0_MISO_BIT))
  836. /*! \brief Query SBBI0 data input. */
  837. #define SBBI0_MISO_TST() ((inr(SBBI0_MISO_PDS_REG) & _BV(SBBI0_MISO_BIT)) == _BV(SBBI0_MISO_BIT))
  838. #else /* SBBI0_MISO_BIT */
  839. #define SBBI0_MISO_ENA()
  840. #define SBBI0_MISO_TST() 0
  841. #endif /* SBBI0_MISO_BIT */
  842. #else /* SBBI0_SCK_BIT */
  843. #define SBBI0_SCK_ENA()
  844. #define SBBI0_SCK_CLR()
  845. #define SBBI0_SCK_SET()
  846. #define SBBI0_MOSI_ENA()
  847. #define SBBI0_MOSI_CLR()
  848. #define SBBI0_MOSI_SET()
  849. #define SBBI0_MISO_ENA()
  850. #define SBBI0_MISO_TST() 0
  851. #endif /* SBBI0_SCK_BIT */
  852. #endif /* MCU */
  853. #define SBBI0_INIT() \
  854. { \
  855. SBBI0_SCK_CLR(); \
  856. SBBI0_SCK_ENA(); \
  857. SBBI0_MOSI_CLR(); \
  858. SBBI0_MOSI_ENA(); \
  859. SBBI0_MISO_ENA(); \
  860. }
  861. __BEGIN_DECLS
  862. /* Function prototypes */
  863. extern int Sbbi0SetMode(ureg_t ix, ureg_t mode);
  864. extern void Sbbi0SetSpeed(ureg_t ix, u_long rate);
  865. extern void Sbbi0Enable(ureg_t ix);
  866. extern void Sbbi0ChipReset(ureg_t ix, ureg_t hi);
  867. extern void Sbbi0ChipSelect(ureg_t ix, ureg_t hi);
  868. extern void Sbbi0SelectDevice(ureg_t ix);
  869. extern void Sbbi0DeselectDevice(ureg_t ix);
  870. extern void Sbbi0NegSelectDevice(ureg_t ix);
  871. extern void Sbbi0NegDeselectDevice(ureg_t ix);
  872. extern u_char Sbbi0Byte(u_char data);
  873. extern void Sbbi0Transact(CONST void *wdata, void *rdata, size_t len);
  874. __END_DECLS
  875. /* End of prototypes */
  876. #endif