Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb0_host_dataio.c 99KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835
  1. /*******************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only
  4. * intended for use with Renesas products. No other uses are authorized. This
  5. * software is owned by Renesas Electronics Corporation and is protected under
  6. * all applicable laws, including copyright laws.
  7. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  8. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
  9. * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  10. * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
  11. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
  12. * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
  13. * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
  14. * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
  15. * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  16. * Renesas reserves the right, without notice, to make changes to this software
  17. * and to discontinue the availability of this software. By using this software,
  18. * you agree to the additional terms and conditions found by accessing the
  19. * following link:
  20. * http://www.renesas.com/disclaimer
  21. * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
  22. *******************************************************************************/
  23. /*******************************************************************************
  24. * File Name : usb0_host_dataio.c
  25. * $Rev: 1116 $
  26. * $Date:: 2014-07-09 16:29:19 +0900#$
  27. * Device(s) : RZ/A1H
  28. * Tool-Chain :
  29. * OS : None
  30. * H/W Platform :
  31. * Description : RZ/A1H R7S72100 USB Sample Program
  32. * Operation :
  33. * Limitations :
  34. *******************************************************************************/
  35. /*******************************************************************************
  36. Includes <System Includes> , "Project Includes"
  37. *******************************************************************************/
  38. #include "usb0_host.h"
  39. /*******************************************************************************
  40. Typedef definitions
  41. *******************************************************************************/
  42. /*******************************************************************************
  43. Macro definitions
  44. *******************************************************************************/
  45. /*******************************************************************************
  46. Imported global variables and functions (from other files)
  47. *******************************************************************************/
  48. /*******************************************************************************
  49. Exported global variables and functions (to be accessed by other files)
  50. *******************************************************************************/
  51. /*******************************************************************************
  52. Private global variables and functions
  53. *******************************************************************************/
  54. static uint16_t g_usb0_host_mbw[(USB_HOST_MAX_PIPE_NO + 1)];
  55. static void usb0_host_start_receive_trns_c(uint16_t pipe, uint32_t size, uint8_t *data);
  56. static void usb0_host_start_receive_trns_d0(uint16_t pipe, uint32_t size, uint8_t *data);
  57. static void usb0_host_start_receive_trns_d1(uint16_t pipe, uint32_t size, uint8_t *data);
  58. static void usb0_host_start_receive_dma_d0(uint16_t pipe, uint32_t size, uint8_t *data);
  59. static void usb0_host_start_receive_dma_d1(uint16_t pipe, uint32_t size, uint8_t *data);
  60. static uint16_t usb0_host_read_dma_d0(uint16_t pipe);
  61. static uint16_t usb0_host_read_dma_d1(uint16_t pipe);
  62. static uint16_t usb0_host_write_dma_d0(uint16_t pipe);
  63. static uint16_t usb0_host_write_dma_d1(uint16_t pipe);
  64. static void usb0_host_read_c_fifo(uint16_t pipe, uint16_t count);
  65. static void usb0_host_write_c_fifo(uint16_t Pipe, uint16_t count);
  66. static void usb0_host_read_d0_fifo(uint16_t pipe, uint16_t count);
  67. static void usb0_host_write_d0_fifo(uint16_t pipe, uint16_t count);
  68. static void usb0_host_read_d1_fifo(uint16_t pipe, uint16_t count);
  69. static void usb0_host_write_d1_fifo(uint16_t pipe, uint16_t count);
  70. static void usb0_host_clear_transaction_counter(uint16_t pipe);
  71. static void usb0_host_set_transaction_counter(uint16_t pipe, uint32_t count);
  72. static uint32_t usb0_host_com_get_dmasize(uint32_t trncount, uint32_t dtptr);
  73. static uint16_t usb0_host_set_dfacc_d0(uint16_t mbw, uint32_t count);
  74. static uint16_t usb0_host_set_dfacc_d1(uint16_t mbw, uint32_t count);
  75. /*******************************************************************************
  76. * Function Name: usb0_host_start_send_transfer
  77. * Description : Starts the USB data communication using pipe specified by the argument.
  78. * Arguments : uint16_t pipe ; Pipe Number
  79. * : uint32_t size ; Data Size
  80. * : uint8_t *data ; Data data Address
  81. * Return Value : USB_HOST_WRITEEND ; Write end
  82. * : USB_HOST_WRITESHRT ; short data
  83. * : USB_HOST_WRITING ; Continue of data write
  84. * : USB_HOST_WRITEDMA ; Write DMA
  85. * : USB_HOST_FIFOERROR ; FIFO status
  86. *******************************************************************************/
  87. uint16_t usb0_host_start_send_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
  88. {
  89. uint16_t status;
  90. uint16_t usefifo;
  91. uint16_t mbw;
  92. g_usb0_host_data_count[pipe] = size;
  93. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  94. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  95. usb0_host_clear_bemp_sts(pipe);
  96. usb0_host_clear_brdy_sts(pipe);
  97. usb0_host_clear_nrdy_sts(pipe);
  98. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  99. usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  100. switch (usefifo)
  101. {
  102. case USB_HOST_D0FIFO_USE:
  103. case USB_HOST_D0FIFO_DMA:
  104. usefifo = USB_HOST_D0USE;
  105. break;
  106. case USB_HOST_D1FIFO_USE:
  107. case USB_HOST_D1FIFO_DMA:
  108. usefifo = USB_HOST_D1USE;
  109. break;
  110. default:
  111. usefifo = USB_HOST_CUSE;
  112. break;
  113. };
  114. usb0_host_set_curpipe(USB_HOST_PIPE0, usefifo, USB_HOST_NO, mbw);
  115. usb0_host_clear_transaction_counter(pipe);
  116. #if(1) /* ohci_wrapp */
  117. #else
  118. usb0_host_aclrm(pipe);
  119. #endif
  120. status = usb0_host_write_buffer(pipe);
  121. if (status != USB_HOST_FIFOERROR)
  122. {
  123. usb0_host_set_pid_buf(pipe);
  124. }
  125. return status;
  126. }
  127. /*******************************************************************************
  128. * Function Name: usb0_host_write_buffer
  129. * Description : Writes data in the buffer allocated in the pipe specified by
  130. * : the argument. The FIFO for using is set in the pipe definition table.
  131. * Arguments : uint16_t pipe ; Pipe Number
  132. * Return Value : USB_HOST_WRITEEND ; Write end
  133. * : USB_HOST_WRITESHRT ; short data
  134. * : USB_HOST_WRITING ; Continue of data write
  135. * : USB_HOST_WRITEDMA ; Write DMA
  136. * : USB_HOST_FIFOERROR ; FIFO status
  137. *******************************************************************************/
  138. uint16_t usb0_host_write_buffer (uint16_t pipe)
  139. {
  140. uint16_t status;
  141. uint16_t usefifo;
  142. g_usb0_host_PipeIgnore[pipe] = 0;
  143. usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  144. switch (usefifo)
  145. {
  146. case USB_HOST_D0FIFO_USE:
  147. status = usb0_host_write_buffer_d0(pipe);
  148. break;
  149. case USB_HOST_D1FIFO_USE:
  150. status = usb0_host_write_buffer_d1(pipe);
  151. break;
  152. case USB_HOST_D0FIFO_DMA:
  153. status = usb0_host_write_dma_d0(pipe);
  154. break;
  155. case USB_HOST_D1FIFO_DMA:
  156. status = usb0_host_write_dma_d1(pipe);
  157. break;
  158. default:
  159. status = usb0_host_write_buffer_c(pipe);
  160. break;
  161. };
  162. switch (status)
  163. {
  164. case USB_HOST_WRITING: /* Continue of data write */
  165. usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
  166. usb0_host_enable_brdy_int(pipe); /* Enable Ready Interrupt */
  167. break;
  168. case USB_HOST_WRITEEND: /* End of data write */
  169. case USB_HOST_WRITESHRT: /* End of data write */
  170. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  171. usb0_host_clear_nrdy_sts(pipe);
  172. usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
  173. /* for last transfer */
  174. usb0_host_enable_bemp_int(pipe); /* Enable Empty Interrupt */
  175. break;
  176. case USB_HOST_WRITEDMA: /* DMA write */
  177. usb0_host_clear_nrdy_sts(pipe);
  178. usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
  179. break;
  180. case USB_HOST_FIFOERROR: /* FIFO access status */
  181. default:
  182. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  183. usb0_host_disable_bemp_int(pipe); /* Disable Empty Interrupt */
  184. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
  185. break;
  186. }
  187. return status; /* End or Err or Continue */
  188. }
  189. /*******************************************************************************
  190. * Function Name: usb0_host_write_buffer_c
  191. * Description : Writes data in the buffer allocated in the pipe specified in
  192. * : the argument. Writes data by CPU transfer using CFIFO.
  193. * Arguments : uint16_t pipe ; Pipe Number
  194. * Return Value : USB_HOST_WRITEEND ; Write end
  195. * : USB_HOST_WRITESHRT ; short data
  196. * : USB_HOST_WRITING ; Continue of data write
  197. * : USB_HOST_WRITEDMA ; Write DMA
  198. * : USB_HOST_FIFOERROR ; FIFO status
  199. *******************************************************************************/
  200. uint16_t usb0_host_write_buffer_c (uint16_t pipe)
  201. {
  202. uint32_t count;
  203. uint16_t size;
  204. uint16_t buffer;
  205. uint16_t mxps;
  206. uint16_t status;
  207. uint16_t mbw;
  208. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  209. if (pipe == USB_HOST_PIPE0)
  210. {
  211. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_CFIFO_WRITE, mbw);
  212. }
  213. else
  214. {
  215. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
  216. }
  217. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  218. {
  219. return USB_HOST_FIFOERROR;
  220. }
  221. size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  222. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  223. if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
  224. {
  225. status = USB_HOST_WRITEEND; /* write continues */
  226. count = g_usb0_host_data_count[pipe];
  227. if (count == 0)
  228. {
  229. status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
  230. }
  231. if ((count % mxps) != 0)
  232. {
  233. status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
  234. }
  235. }
  236. else
  237. {
  238. status = USB_HOST_WRITING; /* write continues */
  239. count = (uint32_t)size;
  240. }
  241. usb0_host_write_c_fifo(pipe, (uint16_t)count);
  242. if (g_usb0_host_data_count[pipe] < (uint32_t)size)
  243. {
  244. g_usb0_host_data_count[pipe] = 0;
  245. if (RZA_IO_RegRead_16(&USB200.CFIFOCTR,
  246. USB_CFIFOCTR_BVAL_SHIFT,
  247. USB_CFIFOCTR_BVAL) == 0)
  248. {
  249. USB200.CFIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
  250. }
  251. }
  252. else
  253. {
  254. g_usb0_host_data_count[pipe] -= count;
  255. }
  256. return status; /* End or Err or Continue */
  257. }
  258. /*******************************************************************************
  259. * Function Name: usb0_host_write_buffer_d0
  260. * Description : Writes data in the buffer allocated in the pipe specified in the argument.
  261. * : Writes data by CPU transfer using D0FIFO.
  262. * Arguments : uint16_t pipe ; Pipe Number
  263. * Return Value : USB_HOST_WRITEEND ; Write end
  264. * : USB_HOST_WRITESHRT ; short data
  265. * : USB_HOST_WRITING ; Continue of data write
  266. * : USB_HOST_WRITEDMA ; Write DMA
  267. * : USB_HOST_FIFOERROR ; FIFO status
  268. *******************************************************************************/
  269. uint16_t usb0_host_write_buffer_d0 (uint16_t pipe)
  270. {
  271. uint32_t count;
  272. uint16_t size;
  273. uint16_t buffer;
  274. uint16_t mxps;
  275. uint16_t status;
  276. uint16_t mbw;
  277. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  278. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
  279. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  280. {
  281. return USB_HOST_FIFOERROR;
  282. }
  283. size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  284. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  285. if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
  286. {
  287. status = USB_HOST_WRITEEND; /* write continues */
  288. count = g_usb0_host_data_count[pipe];
  289. if (count == 0)
  290. {
  291. status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
  292. }
  293. if ((count % mxps) != 0)
  294. {
  295. status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
  296. }
  297. }
  298. else
  299. {
  300. status = USB_HOST_WRITING; /* write continues */
  301. count = (uint32_t)size;
  302. }
  303. usb0_host_write_d0_fifo(pipe, (uint16_t)count);
  304. if (g_usb0_host_data_count[pipe] < (uint32_t)size)
  305. {
  306. g_usb0_host_data_count[pipe] = 0;
  307. if (RZA_IO_RegRead_16(&USB200.D0FIFOCTR,
  308. USB_DnFIFOCTR_BVAL_SHIFT,
  309. USB_DnFIFOCTR_BVAL) == 0)
  310. {
  311. USB200.D0FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
  312. }
  313. }
  314. else
  315. {
  316. g_usb0_host_data_count[pipe] -= count;
  317. }
  318. return status; /* End or Err or Continue */
  319. }
  320. /*******************************************************************************
  321. * Function Name: usb0_host_write_buffer_d1
  322. * Description : Writes data in the buffer allocated in the pipe specified in the argument.
  323. * : Writes data by CPU transfer using D1FIFO.
  324. * Arguments : uint16_t pipe ; Pipe Number
  325. * Return Value : USB_HOST_WRITEEND ; Write end
  326. * : USB_HOST_WRITESHRT ; short data
  327. * : USB_HOST_WRITING ; Continue of data write
  328. * : USB_HOST_WRITEDMA ; Write DMA
  329. * : USB_HOST_FIFOERROR ; FIFO status
  330. *******************************************************************************/
  331. uint16_t usb0_host_write_buffer_d1 (uint16_t pipe)
  332. {
  333. uint32_t count;
  334. uint16_t size;
  335. uint16_t buffer;
  336. uint16_t mxps;
  337. uint16_t status;
  338. uint16_t mbw;
  339. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  340. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
  341. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  342. {
  343. return USB_HOST_FIFOERROR;
  344. }
  345. size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  346. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  347. if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
  348. {
  349. status = USB_HOST_WRITEEND; /* write continues */
  350. count = g_usb0_host_data_count[pipe];
  351. if (count == 0)
  352. {
  353. status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
  354. }
  355. if ((count % mxps) != 0)
  356. {
  357. status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
  358. }
  359. }
  360. else
  361. {
  362. status = USB_HOST_WRITING; /* write continues */
  363. count = (uint32_t)size;
  364. }
  365. usb0_host_write_d1_fifo(pipe, (uint16_t)count);
  366. if (g_usb0_host_data_count[pipe] < (uint32_t)size)
  367. {
  368. g_usb0_host_data_count[pipe] = 0;
  369. if (RZA_IO_RegRead_16(&USB200.D1FIFOCTR,
  370. USB_DnFIFOCTR_BVAL_SHIFT,
  371. USB_DnFIFOCTR_BVAL) == 0)
  372. {
  373. USB200.D1FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
  374. }
  375. }
  376. else
  377. {
  378. g_usb0_host_data_count[pipe] -= count;
  379. }
  380. return status; /* End or Err or Continue */
  381. }
  382. /*******************************************************************************
  383. * Function Name: usb0_host_write_dma_d0
  384. * Description : Writes data in the buffer allocated in the pipe specified in the argument.
  385. * : Writes data by DMA transfer using D0FIFO.
  386. * : The DMA-ch for using is specified by Userdef_USB_usb0_host_start_dma().
  387. * Arguments : uint16_t pipe ; Pipe Number
  388. * Return Value : USB_HOST_WRITEEND : Write end
  389. * : USB_HOST_WRITESHRT : short data
  390. * : USB_HOST_WRITING : Continue of data write
  391. * : USB_HOST_WRITEDMA : Write DMA
  392. * : USB_HOST_FIFOERROR : FIFO status
  393. *******************************************************************************/
  394. static uint16_t usb0_host_write_dma_d0 (uint16_t pipe)
  395. {
  396. uint32_t count;
  397. uint16_t size;
  398. uint16_t buffer;
  399. uint16_t status;
  400. uint16_t mbw;
  401. uint16_t dfacc = 0;
  402. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  403. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
  404. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  405. {
  406. return USB_HOST_FIFOERROR;
  407. }
  408. size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  409. count = g_usb0_host_data_count[pipe];
  410. if (count != 0)
  411. {
  412. g_usb0_host_DmaPipe[USB_HOST_D0FIFO] = pipe;
  413. if ((count % size) != 0)
  414. {
  415. g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 1;
  416. }
  417. else
  418. {
  419. g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 0;
  420. }
  421. dfacc = usb0_host_set_dfacc_d0(mbw, count);
  422. if (mbw == USB_HOST_BITMBW_32)
  423. {
  424. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
  425. }
  426. else if (mbw == USB_HOST_BITMBW_16)
  427. {
  428. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
  429. }
  430. else
  431. {
  432. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
  433. }
  434. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
  435. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_BUF2FIFO;
  436. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
  437. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
  438. Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
  439. usb0_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw, dfacc);
  440. RZA_IO_RegWrite_16(&USB200.D0FIFOSEL,
  441. 1,
  442. USB_DnFIFOSEL_DREQE_SHIFT,
  443. USB_DnFIFOSEL_DREQE);
  444. g_usb0_host_data_count[pipe] = 0;
  445. g_usb0_host_data_pointer[pipe] += count;
  446. status = USB_HOST_WRITEDMA; /* DMA write */
  447. }
  448. else
  449. {
  450. if (RZA_IO_RegRead_16(&USB200.D0FIFOCTR,
  451. USB_DnFIFOCTR_BVAL_SHIFT,
  452. USB_DnFIFOCTR_BVAL) == 0)
  453. {
  454. RZA_IO_RegWrite_16(&USB200.D0FIFOCTR,
  455. 1,
  456. USB_DnFIFOCTR_BVAL_SHIFT,
  457. USB_DnFIFOCTR_BVAL); /* Short Packet */
  458. }
  459. status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
  460. }
  461. return status; /* End or Err or Continue */
  462. }
  463. /*******************************************************************************
  464. * Function Name: usb0_host_write_dma_d1
  465. * Description : Writes data in the buffer allocated in the pipe specified in the argument.
  466. * : Writes data by DMA transfer using D1FIFO.
  467. * : The DMA-ch for using is specified by Userdef_USB_usb0_host_start_dma().
  468. * Arguments : uint16_t pipe ; Pipe Number
  469. * Return Value : USB_HOST_WRITEEND : Write end
  470. * : USB_HOST_WRITESHRT : short data
  471. * : USB_HOST_WRITING : Continue of data write
  472. * : USB_HOST_WRITEDMA : Write DMA
  473. * : USB_HOST_FIFOERROR : FIFO status
  474. *******************************************************************************/
  475. static uint16_t usb0_host_write_dma_d1 (uint16_t pipe)
  476. {
  477. uint32_t count;
  478. uint16_t size;
  479. uint16_t buffer;
  480. uint16_t status;
  481. uint16_t mbw;
  482. uint16_t dfacc = 0;
  483. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  484. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
  485. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  486. {
  487. return USB_HOST_FIFOERROR;
  488. }
  489. size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  490. count = g_usb0_host_data_count[pipe];
  491. if (count != 0)
  492. {
  493. g_usb0_host_DmaPipe[USB_HOST_D1FIFO] = pipe;
  494. if ((count % size) != 0)
  495. {
  496. g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 1;
  497. }
  498. else
  499. {
  500. g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 0;
  501. }
  502. dfacc = usb0_host_set_dfacc_d1(mbw, count);
  503. if (mbw == USB_HOST_BITMBW_32)
  504. {
  505. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
  506. }
  507. else if (mbw == USB_HOST_BITMBW_16)
  508. {
  509. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
  510. }
  511. else
  512. {
  513. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
  514. }
  515. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
  516. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_BUF2FIFO;
  517. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
  518. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
  519. Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
  520. usb0_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw, dfacc);
  521. RZA_IO_RegWrite_16(&USB200.D1FIFOSEL,
  522. 1,
  523. USB_DnFIFOSEL_DREQE_SHIFT,
  524. USB_DnFIFOSEL_DREQE);
  525. g_usb0_host_data_count[pipe] = 0;
  526. g_usb0_host_data_pointer[pipe] += count;
  527. status = USB_HOST_WRITEDMA; /* DMA write */
  528. }
  529. else
  530. {
  531. if (RZA_IO_RegRead_16(&USB200.D1FIFOCTR,
  532. USB_DnFIFOCTR_BVAL_SHIFT,
  533. USB_DnFIFOCTR_BVAL) == 0)
  534. {
  535. RZA_IO_RegWrite_16(&USB200.D1FIFOCTR,
  536. 1,
  537. USB_DnFIFOCTR_BVAL_SHIFT,
  538. USB_DnFIFOCTR_BVAL); /* Short Packet */
  539. }
  540. status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
  541. }
  542. return status; /* End or Err or Continue */
  543. }
  544. /*******************************************************************************
  545. * Function Name: usb0_host_start_receive_transfer
  546. * Description : Starts USB data reception using the pipe specified in the argument.
  547. * : The FIFO for using is set in the pipe definition table.
  548. * Arguments : uint16_t pipe ; Pipe Number
  549. * : uint32_t size ; Data Size
  550. * : uint8_t *data ; Data Address
  551. * Return Value : none
  552. *******************************************************************************/
  553. void usb0_host_start_receive_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
  554. {
  555. uint16_t usefifo;
  556. usb0_host_clear_bemp_sts(pipe);
  557. usb0_host_clear_brdy_sts(pipe);
  558. usb0_host_clear_nrdy_sts(pipe);
  559. usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  560. switch (usefifo)
  561. {
  562. case USB_HOST_D0FIFO_USE:
  563. usb0_host_start_receive_trns_d0(pipe, size, data);
  564. break;
  565. case USB_HOST_D1FIFO_USE:
  566. usb0_host_start_receive_trns_d1(pipe, size, data);
  567. break;
  568. case USB_HOST_D0FIFO_DMA:
  569. usb0_host_start_receive_dma_d0(pipe, size, data);
  570. break;
  571. case USB_HOST_D1FIFO_DMA:
  572. usb0_host_start_receive_dma_d1(pipe, size, data);
  573. break;
  574. default:
  575. usb0_host_start_receive_trns_c(pipe, size, data);
  576. break;
  577. }
  578. }
  579. /*******************************************************************************
  580. * Function Name: usb0_host_start_receive_trns_c
  581. * Description : Reads data from the buffer allocated in the pipe specified in the argument.
  582. * : Reads data by CPU transfer using CFIFO.
  583. * : When storing data in the buffer allocated in the pipe specified in the
  584. * : argument, BRDY interrupt is generated to read data
  585. * : in the interrupt.
  586. * Arguments : uint16_t pipe ; Pipe Number
  587. * : uint32_t size ; Data Size
  588. * : uint8_t *data ; Data Address
  589. * Return Value : none
  590. *******************************************************************************/
  591. static void usb0_host_start_receive_trns_c (uint16_t pipe, uint32_t size, uint8_t * data)
  592. {
  593. uint16_t mbw;
  594. usb0_host_set_pid_nak(pipe);
  595. g_usb0_host_data_count[pipe] = size;
  596. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  597. g_usb0_host_PipeIgnore[pipe] = 0;
  598. g_usb0_host_PipeDataSize[pipe] = size;
  599. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  600. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  601. usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_CFIFO_READ, mbw);
  602. USB200.CFIFOCTR = USB_HOST_BITBCLR;
  603. usb0_host_set_transaction_counter(pipe, size);
  604. #if(1) /* ohci_wrapp */
  605. #else
  606. usb0_host_aclrm(pipe);
  607. #endif
  608. usb0_host_enable_nrdy_int(pipe);
  609. usb0_host_enable_brdy_int(pipe);
  610. usb0_host_set_pid_buf(pipe);
  611. }
  612. /*******************************************************************************
  613. * Function Name: usb0_host_start_receive_trns_d0
  614. * Description : Reads data from the buffer allocated in the pipe specified in the argument.
  615. * : Reads data by CPU transfer using D0FIFO.
  616. * : This function does not read data from the buffer.
  617. * : When storing data in the buffer allocated in the pipe specified
  618. * : in the argument, BRDY interrupt is generated to read data in the
  619. * : interrupt.
  620. * Arguments : uint16_t pipe ; Pipe Number
  621. * : uint32_t size ; Data Size
  622. * : uint8_t *data ; Data Address
  623. * Return Value : none
  624. *******************************************************************************/
  625. static void usb0_host_start_receive_trns_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
  626. {
  627. uint16_t mbw;
  628. usb0_host_set_pid_nak(pipe);
  629. g_usb0_host_data_count[pipe] = size;
  630. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  631. g_usb0_host_PipeIgnore[pipe] = 0;
  632. g_usb0_host_PipeDataSize[pipe] = size;
  633. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  634. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  635. usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
  636. usb0_host_set_transaction_counter(pipe, size);
  637. #if(1) /* ohci_wrapp */
  638. #else
  639. usb0_host_aclrm(pipe);
  640. #endif
  641. usb0_host_enable_nrdy_int(pipe);
  642. usb0_host_enable_brdy_int(pipe);
  643. usb0_host_set_pid_buf(pipe);
  644. }
  645. /*******************************************************************************
  646. * Function Name: usb0_host_start_receive_trns_d1
  647. * Description : Reads data from the buffer allocated in the pipe specified in the argument.
  648. * : Reads data by CPU transfer using D1FIFO.
  649. * : This function does not read data from the buffer.
  650. * : When storing data in the buffer allocated in the pipe specified
  651. * : in the argument, BRDY interrupt is generated to read data.
  652. * Arguments : uint16_t pipe ; Pipe Number
  653. * : uint32_t size ; Data Size
  654. * : uint8_t *data ; Data Address
  655. * Return Value : none
  656. *******************************************************************************/
  657. static void usb0_host_start_receive_trns_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
  658. {
  659. uint16_t mbw;
  660. usb0_host_set_pid_nak(pipe);
  661. g_usb0_host_data_count[pipe] = size;
  662. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  663. g_usb0_host_PipeIgnore[pipe] = 0;
  664. g_usb0_host_PipeDataSize[pipe] = size;
  665. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  666. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  667. usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
  668. usb0_host_set_transaction_counter(pipe, size);
  669. #if(1) /* ohci_wrapp */
  670. #else
  671. usb0_host_aclrm(pipe);
  672. #endif
  673. usb0_host_enable_nrdy_int(pipe);
  674. usb0_host_enable_brdy_int(pipe);
  675. usb0_host_set_pid_buf(pipe);
  676. }
  677. /*******************************************************************************
  678. * Function Name: usb0_host_start_receive_dma_d0
  679. * Description : Reads data from the buffer allocated in the pipe specified in the argument.
  680. * : Reads data by DMA transfer using D0FIFO.
  681. * : This function does not read data from the buffer.
  682. * : When storing data in the buffer allocated in the pipe specified
  683. * : in the argument, delivered read request to DMAC to read data from
  684. * : the buffer by DMAC.
  685. * Arguments : uint16_t pipe ; Pipe Number
  686. * : uint32_t size ; Data Size
  687. * : uint8_t *data ; Data Address
  688. * Return Value : none
  689. *******************************************************************************/
  690. static void usb0_host_start_receive_dma_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
  691. {
  692. uint16_t mbw;
  693. usb0_host_set_pid_nak(pipe);
  694. g_usb0_host_data_count[pipe] = size;
  695. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  696. g_usb0_host_PipeIgnore[pipe] = 0;
  697. g_usb0_host_PipeDataSize[pipe] = 0;
  698. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  699. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  700. usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
  701. usb0_host_set_transaction_counter(pipe, size);
  702. #if(1) /* ohci_wrapp */
  703. #else
  704. usb0_host_aclrm(pipe);
  705. #endif
  706. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  707. {
  708. usb0_host_read_dma(pipe);
  709. usb0_host_enable_nrdy_int(pipe);
  710. usb0_host_enable_brdy_int(pipe);
  711. }
  712. else
  713. {
  714. usb0_host_enable_nrdy_int(pipe);
  715. usb0_host_enable_brdy_int(pipe);
  716. }
  717. usb0_host_set_pid_buf(pipe);
  718. }
  719. /*******************************************************************************
  720. * Function Name: usb0_host_start_receive_dma_d1
  721. * Description : Read data from the buffer allocated in the pipe specified in the argument.
  722. * : Reads data by DMA transfer using D0FIFO.
  723. * : This function does not read data from the buffer.
  724. * : When storing data in the buffer allocated in the pipe specified
  725. * : in the argument, delivered read request to DMAC to read data from
  726. * : the buffer by DMAC.
  727. * Arguments : uint16_t pipe ; Pipe Number
  728. * : uint32_t size ; Data Size
  729. * : uint8_t *data ; Data Address
  730. * Return Value : none
  731. *******************************************************************************/
  732. static void usb0_host_start_receive_dma_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
  733. {
  734. uint16_t mbw;
  735. usb0_host_set_pid_nak(pipe);
  736. g_usb0_host_data_count[pipe] = size;
  737. g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
  738. g_usb0_host_PipeIgnore[pipe] = 0;
  739. g_usb0_host_PipeDataSize[pipe] = 0;
  740. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
  741. mbw = usb0_host_get_mbw(size, (uint32_t)data);
  742. usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
  743. usb0_host_set_transaction_counter(pipe, size);
  744. #if(1) /* ohci_wrapp */
  745. #else
  746. usb0_host_aclrm(pipe);
  747. #endif
  748. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  749. {
  750. usb0_host_read_dma(pipe);
  751. usb0_host_enable_nrdy_int(pipe);
  752. usb0_host_enable_brdy_int(pipe);
  753. }
  754. else
  755. {
  756. usb0_host_enable_nrdy_int(pipe);
  757. usb0_host_enable_brdy_int(pipe);
  758. }
  759. usb0_host_set_pid_buf(pipe);
  760. }
  761. /*******************************************************************************
  762. * Function Name: usb0_host_read_buffer
  763. * Description : Reads data from the buffer allocated in the pipe specified
  764. * : in the argument.
  765. * : Uses FIF0 set in the pipe definition table.
  766. * Arguments : uint16_t pipe ; Pipe Number
  767. * Return Value : USB_HOST_READEND ; Read end
  768. * : USB_HOST_READSHRT ; short data
  769. * : USB_HOST_READING ; Continue of data read
  770. * : USB_HOST_READOVER ; buffer over
  771. * : USB_HOST_FIFOERROR ; FIFO status
  772. *******************************************************************************/
  773. uint16_t usb0_host_read_buffer (uint16_t pipe)
  774. {
  775. uint16_t status;
  776. g_usb0_host_PipeIgnore[pipe] = 0;
  777. if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
  778. {
  779. status = usb0_host_read_buffer_d0(pipe);
  780. }
  781. else if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
  782. {
  783. status = usb0_host_read_buffer_d1(pipe);
  784. }
  785. else
  786. {
  787. status = usb0_host_read_buffer_c(pipe);
  788. }
  789. switch (status)
  790. {
  791. case USB_HOST_READING: /* Continue of data read */
  792. break;
  793. case USB_HOST_READEND: /* End of data read */
  794. case USB_HOST_READSHRT: /* End of data read */
  795. usb0_host_disable_brdy_int(pipe);
  796. g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
  797. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  798. break;
  799. case USB_HOST_READOVER: /* buffer over */
  800. if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
  801. {
  802. USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  803. }
  804. else if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
  805. {
  806. USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  807. }
  808. else
  809. {
  810. USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  811. }
  812. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  813. #if(1) /* ohci_wrapp */
  814. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  815. #else
  816. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
  817. #endif
  818. g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
  819. break;
  820. case USB_HOST_FIFOERROR: /* FIFO access status */
  821. default:
  822. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  823. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
  824. break;
  825. }
  826. return status; /* End or Err or Continue */
  827. }
  828. /*******************************************************************************
  829. * Function Name: usb0_host_read_buffer_c
  830. * Description : Reads data from the buffer allocated in the pipe specified in the argument.
  831. * : Reads data by CPU transfer using CFIFO.
  832. * Arguments : uint16_t pipe ; Pipe Number
  833. * Return Value : USB_HOST_READEND ; Read end
  834. * : USB_HOST_READSHRT ; short data
  835. * : USB_HOST_READING ; Continue of data read
  836. * : USB_HOST_READOVER ; buffer over
  837. * : USB_HOST_FIFOERROR ; FIFO status
  838. *******************************************************************************/
  839. uint16_t usb0_host_read_buffer_c (uint16_t pipe)
  840. {
  841. uint32_t count;
  842. uint32_t dtln;
  843. uint16_t buffer;
  844. uint16_t mxps;
  845. uint16_t status;
  846. uint16_t mbw;
  847. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  848. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
  849. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  850. {
  851. return USB_HOST_FIFOERROR;
  852. }
  853. dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
  854. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  855. if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
  856. {
  857. status = USB_HOST_READOVER;
  858. usb0_host_set_pid_nak(pipe); /* Set NAK */
  859. count = g_usb0_host_data_count[pipe];
  860. }
  861. else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
  862. {
  863. status = USB_HOST_READEND;
  864. usb0_host_set_pid_nak(pipe); /* Set NAK */
  865. count = dtln;
  866. if (count == 0)
  867. {
  868. status = USB_HOST_READSHRT; /* Null Packet receive */
  869. }
  870. if ((count % mxps) != 0)
  871. {
  872. status = USB_HOST_READSHRT; /* Short Packet receive */
  873. }
  874. }
  875. else /* continue Receive data */
  876. {
  877. status = USB_HOST_READING;
  878. count = dtln;
  879. if (count == 0)
  880. {
  881. status = USB_HOST_READSHRT; /* Null Packet receive */
  882. usb0_host_set_pid_nak(pipe); /* Set NAK */
  883. }
  884. if ((count % mxps) != 0)
  885. {
  886. status = USB_HOST_READSHRT; /* Short Packet receive */
  887. usb0_host_set_pid_nak(pipe); /* Set NAK */
  888. }
  889. }
  890. if (count == 0) /* 0 length packet */
  891. {
  892. USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  893. }
  894. else
  895. {
  896. usb0_host_read_c_fifo(pipe, (uint16_t)count);
  897. }
  898. g_usb0_host_data_count[pipe] -= count;
  899. return status; /* End or Err or Continue */
  900. }
  901. /*******************************************************************************
  902. * Function Name: usb0_host_read_buffer_d0
  903. * Description : Reads data from the buffer allocated in the pipe specified in
  904. * : the argument.
  905. * : Reads data by CPU transfer using D0FIFO.
  906. * Arguments : uint16_t pipe ; Pipe Number
  907. * Return Value : USB_HOST_READEND ; Read end
  908. * : USB_HOST_READSHRT ; short data
  909. * : USB_HOST_READING ; Continue of data read
  910. * : USB_HOST_READOVER ; buffer over
  911. * : USB_HOST_FIFOERROR ; FIFO status
  912. *******************************************************************************/
  913. uint16_t usb0_host_read_buffer_d0 (uint16_t pipe)
  914. {
  915. uint32_t count;
  916. uint32_t dtln;
  917. uint16_t buffer;
  918. uint16_t mxps;
  919. uint16_t status;
  920. uint16_t mbw;
  921. uint16_t pipebuf_size;
  922. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  923. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
  924. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  925. {
  926. return USB_HOST_FIFOERROR;
  927. }
  928. dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
  929. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  930. if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
  931. {
  932. status = USB_HOST_READOVER;
  933. usb0_host_set_pid_nak(pipe); /* Set NAK */
  934. count = g_usb0_host_data_count[pipe];
  935. }
  936. else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
  937. {
  938. status = USB_HOST_READEND;
  939. usb0_host_set_pid_nak(pipe); /* Set NAK */
  940. count = dtln;
  941. if (count == 0)
  942. {
  943. status = USB_HOST_READSHRT; /* Null Packet receive */
  944. }
  945. if ((count % mxps) != 0)
  946. {
  947. status = USB_HOST_READSHRT; /* Short Packet receive */
  948. }
  949. }
  950. else /* continue Receive data */
  951. {
  952. status = USB_HOST_READING;
  953. count = dtln;
  954. if (count == 0)
  955. {
  956. status = USB_HOST_READSHRT; /* Null Packet receive */
  957. usb0_host_set_pid_nak(pipe); /* Set NAK */
  958. }
  959. if ((count % mxps) != 0)
  960. {
  961. status = USB_HOST_READSHRT; /* Short Packet receive */
  962. usb0_host_set_pid_nak(pipe); /* Set NAK */
  963. }
  964. else
  965. {
  966. pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  967. if (count != pipebuf_size)
  968. {
  969. status = USB_HOST_READSHRT; /* Short Packet receive */
  970. usb0_host_set_pid_nak(pipe); /* Set NAK */
  971. }
  972. }
  973. }
  974. if (count == 0) /* 0 length packet */
  975. {
  976. USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  977. }
  978. else
  979. {
  980. usb0_host_read_d0_fifo(pipe, (uint16_t)count);
  981. }
  982. g_usb0_host_data_count[pipe] -= count;
  983. return status; /* End or Err or Continue */
  984. }
  985. /*******************************************************************************
  986. * Function Name: usb0_host_read_buffer_d1
  987. * Description : Reads data from the buffer allocated in the pipe specified
  988. * : in the argument.
  989. * : Reads data by CPU transfer using D1FIFO.
  990. * Arguments : uint16_t pipe ; Pipe Number
  991. * Return Value : USB_HOST_READEND ; Read end
  992. * : USB_HOST_READSHRT ; short data
  993. * : USB_HOST_READING ; Continue of data read
  994. * : USB_HOST_READOVER ; buffer over
  995. * : USB_HOST_FIFOERROR ; FIFO status
  996. *******************************************************************************/
  997. uint16_t usb0_host_read_buffer_d1 (uint16_t pipe)
  998. {
  999. uint32_t count;
  1000. uint32_t dtln;
  1001. uint16_t buffer;
  1002. uint16_t mxps;
  1003. uint16_t status;
  1004. uint16_t mbw;
  1005. uint16_t pipebuf_size;
  1006. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  1007. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
  1008. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  1009. {
  1010. return USB_HOST_FIFOERROR;
  1011. }
  1012. dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
  1013. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  1014. if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
  1015. {
  1016. status = USB_HOST_READOVER;
  1017. usb0_host_set_pid_nak(pipe); /* Set NAK */
  1018. count = g_usb0_host_data_count[pipe];
  1019. }
  1020. else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
  1021. {
  1022. status = USB_HOST_READEND;
  1023. usb0_host_set_pid_nak(pipe); /* Set NAK */
  1024. count = dtln;
  1025. if (count == 0)
  1026. {
  1027. status = USB_HOST_READSHRT; /* Null Packet receive */
  1028. }
  1029. if ((count % mxps) !=0)
  1030. {
  1031. status = USB_HOST_READSHRT; /* Short Packet receive */
  1032. }
  1033. }
  1034. else /* continue Receive data */
  1035. {
  1036. status = USB_HOST_READING;
  1037. count = dtln;
  1038. if (count == 0)
  1039. {
  1040. status = USB_HOST_READSHRT; /* Null Packet receive */
  1041. usb0_host_set_pid_nak(pipe); /* Set NAK */
  1042. }
  1043. if ((count % mxps) != 0)
  1044. {
  1045. status = USB_HOST_READSHRT; /* Short Packet receive */
  1046. usb0_host_set_pid_nak(pipe); /* Set NAK */
  1047. }
  1048. else
  1049. {
  1050. pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  1051. if (count != pipebuf_size)
  1052. {
  1053. status = USB_HOST_READSHRT; /* Short Packet receive */
  1054. usb0_host_set_pid_nak(pipe); /* Set NAK */
  1055. }
  1056. }
  1057. }
  1058. if (count == 0) /* 0 length packet */
  1059. {
  1060. USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  1061. }
  1062. else
  1063. {
  1064. usb0_host_read_d1_fifo(pipe, (uint16_t)count);
  1065. }
  1066. g_usb0_host_data_count[pipe] -= count;
  1067. return status; /* End or Err or Continue */
  1068. }
  1069. /*******************************************************************************
  1070. * Function Name: usb0_host_read_dma
  1071. * Description : Reads data from the buffer allocated in the pipe specified
  1072. * : in the argument.
  1073. * : Reads data by DMA transfer using D0FIFO or D1FIFO.
  1074. * Arguments : uint16_t pipe ; Pipe Number
  1075. * Return Value : USB_HOST_READEND ; Read end
  1076. * : USB_HOST_READSHRT ; short data
  1077. * : USB_HOST_READZERO ; zero data
  1078. * : USB_HOST_READING ; Continue of data read
  1079. * : USB_HOST_READOVER ; buffer over
  1080. * : USB_HOST_FIFOERROR ; FIFO status
  1081. *******************************************************************************/
  1082. uint16_t usb0_host_read_dma (uint16_t pipe)
  1083. {
  1084. uint16_t status;
  1085. g_usb0_host_PipeIgnore[pipe] = 0;
  1086. if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_DMA)
  1087. {
  1088. status = usb0_host_read_dma_d0(pipe);
  1089. }
  1090. else
  1091. {
  1092. status = usb0_host_read_dma_d1(pipe);
  1093. }
  1094. switch (status)
  1095. {
  1096. case USB_HOST_READING: /* Continue of data read */
  1097. break;
  1098. case USB_HOST_READZERO: /* End of data read */
  1099. usb0_host_disable_brdy_int(pipe);
  1100. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  1101. break;
  1102. case USB_HOST_READEND: /* End of data read */
  1103. case USB_HOST_READSHRT: /* End of data read */
  1104. usb0_host_disable_brdy_int(pipe);
  1105. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  1106. {
  1107. g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
  1108. }
  1109. break;
  1110. case USB_HOST_READOVER: /* buffer over */
  1111. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  1112. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  1113. {
  1114. g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
  1115. }
  1116. #if(1) /* ohci_wrapp */
  1117. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  1118. #else
  1119. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
  1120. #endif
  1121. break;
  1122. case USB_HOST_FIFOERROR: /* FIFO access status */
  1123. default:
  1124. usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
  1125. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
  1126. break;
  1127. }
  1128. return status; /* End or Err or Continue */
  1129. }
  1130. /*******************************************************************************
  1131. * Function Name: usb0_host_read_dma_d0
  1132. * Description : Writes data in the buffer allocated in the pipe specified
  1133. * : in the argument.
  1134. * : Reads data by DMA transfer using D0FIFO.
  1135. * Arguments : uint16_t pipe ; Pipe Number
  1136. * Return Value : USB_HOST_READEND ; Read end
  1137. * : USB_HOST_READSHRT ; short data
  1138. * : USB_HOST_READZERO ; zero data
  1139. * : USB_HOST_READING ; Continue of data read
  1140. * : USB_HOST_READOVER ; buffer over
  1141. * : USB_HOST_FIFOERROR ; FIFO status
  1142. *******************************************************************************/
  1143. static uint16_t usb0_host_read_dma_d0 (uint16_t pipe)
  1144. {
  1145. uint32_t count;
  1146. uint32_t dtln;
  1147. uint16_t buffer;
  1148. uint16_t mxps;
  1149. uint16_t status;
  1150. uint16_t mbw;
  1151. uint16_t dfacc = 0;
  1152. uint16_t pipebuf_size;
  1153. g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_READY;
  1154. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  1155. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  1156. {
  1157. count = g_usb0_host_data_count[pipe];
  1158. status = USB_HOST_READING;
  1159. }
  1160. else
  1161. {
  1162. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
  1163. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  1164. {
  1165. return USB_HOST_FIFOERROR;
  1166. }
  1167. dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
  1168. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  1169. if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
  1170. {
  1171. status = USB_HOST_READOVER;
  1172. count = g_usb0_host_data_count[pipe];
  1173. }
  1174. else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
  1175. {
  1176. status = USB_HOST_READEND;
  1177. count = dtln;
  1178. if (count == 0)
  1179. {
  1180. status = USB_HOST_READSHRT; /* Null Packet receive */
  1181. }
  1182. if ((count % mxps) != 0)
  1183. {
  1184. status = USB_HOST_READSHRT; /* Short Packet receive */
  1185. }
  1186. }
  1187. else /* continue Receive data */
  1188. {
  1189. status = USB_HOST_READING;
  1190. count = dtln;
  1191. if (count == 0)
  1192. {
  1193. status = USB_HOST_READSHRT; /* Null Packet receive */
  1194. }
  1195. if ((count % mxps) != 0)
  1196. {
  1197. status = USB_HOST_READSHRT; /* Short Packet receive */
  1198. }
  1199. else
  1200. {
  1201. pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  1202. if (count != pipebuf_size)
  1203. {
  1204. status = USB_HOST_READSHRT; /* Short Packet receive */
  1205. }
  1206. }
  1207. }
  1208. }
  1209. if (count == 0) /* 0 length packet */
  1210. {
  1211. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  1212. {
  1213. USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear B_CLR */
  1214. status = USB_HOST_READZERO; /* Null Packet receive */
  1215. }
  1216. else
  1217. {
  1218. usb0_host_set_curpipe(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
  1219. /* transaction counter No set */
  1220. /* FRDY = 1, DTLN = 0 -> BRDY */
  1221. }
  1222. }
  1223. else
  1224. {
  1225. dfacc = usb0_host_set_dfacc_d0(mbw, count);
  1226. if (mbw == USB_HOST_BITMBW_32)
  1227. {
  1228. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
  1229. }
  1230. else if (mbw == USB_HOST_BITMBW_16)
  1231. {
  1232. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
  1233. }
  1234. else
  1235. {
  1236. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
  1237. }
  1238. g_usb0_host_DmaPipe[USB_HOST_D0FIFO] = pipe; /* not use in read operation */
  1239. g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 0; /* not use in read operation */
  1240. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
  1241. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_FIFO2BUF;
  1242. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
  1243. g_usb0_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
  1244. if (status == USB_HOST_READING)
  1245. {
  1246. g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSY;
  1247. }
  1248. else
  1249. {
  1250. g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSYEND;
  1251. }
  1252. Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
  1253. usb0_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw, dfacc);
  1254. RZA_IO_RegWrite_16(&USB200.D0FIFOSEL,
  1255. 1,
  1256. USB_DnFIFOSEL_DREQE_SHIFT,
  1257. USB_DnFIFOSEL_DREQE);
  1258. }
  1259. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  1260. {
  1261. g_usb0_host_data_count[pipe] -= count;
  1262. g_usb0_host_data_pointer[pipe] += count;
  1263. g_usb0_host_PipeDataSize[pipe] += count;
  1264. }
  1265. return status; /* End or Err or Continue */
  1266. }
  1267. /*******************************************************************************
  1268. * Function Name: usb0_host_read_dma_d1
  1269. * Description : Reads data from the buffer allocated in the pipe specified in
  1270. * : the argument.
  1271. * : Reads data by DMA transfer using D1FIFO.
  1272. * Arguments : uint16_t pipe ; Pipe Number
  1273. * Return Value : USB_HOST_READEND ; Read end
  1274. * : USB_HOST_READSHRT ; short data
  1275. * : USB_HOST_READZERO ; zero data
  1276. * : USB_HOST_READING ; Continue of data read
  1277. * : USB_HOST_READOVER ; buffer over
  1278. * : USB_HOST_FIFOERROR ; FIFO status
  1279. *******************************************************************************/
  1280. static uint16_t usb0_host_read_dma_d1 (uint16_t pipe)
  1281. {
  1282. uint32_t count;
  1283. uint32_t dtln;
  1284. uint16_t buffer;
  1285. uint16_t mxps;
  1286. uint16_t status;
  1287. uint16_t mbw;
  1288. uint16_t dfacc = 0;
  1289. uint16_t pipebuf_size;
  1290. g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_READY;
  1291. mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
  1292. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  1293. {
  1294. count = g_usb0_host_data_count[pipe];
  1295. status = USB_HOST_READING;
  1296. }
  1297. else
  1298. {
  1299. buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
  1300. if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
  1301. {
  1302. return USB_HOST_FIFOERROR;
  1303. }
  1304. dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
  1305. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  1306. if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
  1307. {
  1308. status = USB_HOST_READOVER;
  1309. count = g_usb0_host_data_count[pipe];
  1310. }
  1311. else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
  1312. {
  1313. status = USB_HOST_READEND;
  1314. count = dtln;
  1315. if (count == 0)
  1316. {
  1317. status = USB_HOST_READSHRT; /* Null Packet receive */
  1318. }
  1319. if ((count % mxps) != 0)
  1320. {
  1321. status = USB_HOST_READSHRT; /* Short Packet receive */
  1322. }
  1323. }
  1324. else /* continue Receive data */
  1325. {
  1326. status = USB_HOST_READING;
  1327. count = dtln;
  1328. if (count == 0)
  1329. {
  1330. status = USB_HOST_READSHRT; /* Null Packet receive */
  1331. }
  1332. if ((count % mxps) != 0)
  1333. {
  1334. status = USB_HOST_READSHRT; /* Short Packet receive */
  1335. }
  1336. else
  1337. {
  1338. pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
  1339. if (count != pipebuf_size)
  1340. {
  1341. status = USB_HOST_READSHRT; /* Short Packet receive */
  1342. }
  1343. }
  1344. }
  1345. }
  1346. if (count == 0) /* 0 length packet */
  1347. {
  1348. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  1349. {
  1350. USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
  1351. status = USB_HOST_READZERO; /* Null Packet receive */
  1352. }
  1353. else
  1354. {
  1355. usb0_host_set_curpipe(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
  1356. /* transaction counter No set */
  1357. /* FRDY = 1, DTLN = 0 -> BRDY */
  1358. }
  1359. }
  1360. else
  1361. {
  1362. dfacc = usb0_host_set_dfacc_d1(mbw, count);
  1363. if (mbw == USB_HOST_BITMBW_32)
  1364. {
  1365. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
  1366. }
  1367. else if (mbw == USB_HOST_BITMBW_16)
  1368. {
  1369. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
  1370. }
  1371. else
  1372. {
  1373. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
  1374. }
  1375. g_usb0_host_DmaPipe[USB_HOST_D1FIFO] = pipe; /* not use in read operation */
  1376. g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 0; /* not use in read operation */
  1377. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
  1378. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_FIFO2BUF;
  1379. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
  1380. g_usb0_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
  1381. if (status == USB_HOST_READING)
  1382. {
  1383. g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSY;
  1384. }
  1385. else
  1386. {
  1387. g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSYEND;
  1388. }
  1389. Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
  1390. usb0_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw, dfacc);
  1391. RZA_IO_RegWrite_16(&USB200.D1FIFOSEL,
  1392. 1,
  1393. USB_DnFIFOSEL_DREQE_SHIFT,
  1394. USB_DnFIFOSEL_DREQE);
  1395. }
  1396. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  1397. {
  1398. g_usb0_host_data_count[pipe] -= count;
  1399. g_usb0_host_data_pointer[pipe] += count;
  1400. g_usb0_host_PipeDataSize[pipe] += count;
  1401. }
  1402. return status; /* End or Err or Continue */
  1403. }
  1404. /*******************************************************************************
  1405. * Function Name: usb0_host_change_fifo_port
  1406. * Description : Allocates FIF0 specified by the argument in the pipe assigned
  1407. * : by the argument. After allocating FIF0, waits in the software
  1408. * : till the corresponding pipe becomes ready.
  1409. * Arguments : uint16_t pipe ; Pipe Number
  1410. * : uint16_t fifosel ; Select FIFO
  1411. * : uint16_t isel ; FIFO Access Direction
  1412. * : uint16_t mbw ; FIFO Port Access Bit Width
  1413. * Return Value : USB_HOST_FIFOERROR ; Error
  1414. * : Others ; CFIFOCTR/D0FIFOCTR/D1FIFOCTR Register Value
  1415. *******************************************************************************/
  1416. uint16_t usb0_host_change_fifo_port (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
  1417. {
  1418. uint16_t buffer;
  1419. uint32_t loop;
  1420. volatile uint32_t loop2;
  1421. usb0_host_set_curpipe(pipe, fifosel, isel, mbw);
  1422. for (loop = 0; loop < 4; loop++)
  1423. {
  1424. switch (fifosel)
  1425. {
  1426. case USB_HOST_CUSE:
  1427. buffer = USB200.CFIFOCTR;
  1428. break;
  1429. case USB_HOST_D0USE:
  1430. case USB_HOST_D0DMA:
  1431. buffer = USB200.D0FIFOCTR;
  1432. break;
  1433. case USB_HOST_D1USE:
  1434. case USB_HOST_D1DMA:
  1435. buffer = USB200.D1FIFOCTR;
  1436. break;
  1437. default:
  1438. buffer = 0;
  1439. break;
  1440. }
  1441. if ((buffer & USB_HOST_BITFRDY) == USB_HOST_BITFRDY)
  1442. {
  1443. return buffer;
  1444. }
  1445. loop2 = 25;
  1446. while (loop2-- > 0)
  1447. {
  1448. /* wait */
  1449. }
  1450. }
  1451. return USB_HOST_FIFOERROR;
  1452. }
  1453. /*******************************************************************************
  1454. * Function Name: usb0_host_set_curpipe
  1455. * Description : Allocates FIF0 specified by the argument in the pipe assigned
  1456. * : by the argument.
  1457. * Arguments : uint16_t pipe ; Pipe Number
  1458. * : uint16_t fifosel ; Select FIFO
  1459. * : uint16_t isel ; FIFO Access Direction
  1460. * : uint16_t mbw ; FIFO Port Access Bit Width
  1461. * Return Value : none
  1462. *******************************************************************************/
  1463. void usb0_host_set_curpipe (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
  1464. {
  1465. uint16_t buffer;
  1466. uint32_t loop;
  1467. volatile uint32_t loop2;
  1468. g_usb0_host_mbw[pipe] = mbw;
  1469. switch (fifosel)
  1470. {
  1471. case USB_HOST_CUSE:
  1472. buffer = USB200.CFIFOSEL;
  1473. buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
  1474. buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
  1475. USB200.CFIFOSEL = buffer;
  1476. for (loop = 0; loop < 4; loop++)
  1477. {
  1478. if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
  1479. == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
  1480. {
  1481. break;
  1482. }
  1483. loop2 = 100;
  1484. while (loop2-- > 0)
  1485. {
  1486. /* wait */
  1487. }
  1488. }
  1489. buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1490. buffer |= (uint16_t)(isel | pipe | mbw);
  1491. USB200.CFIFOSEL = buffer;
  1492. for (loop = 0; loop < 4; loop++)
  1493. {
  1494. if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
  1495. == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
  1496. {
  1497. break;
  1498. }
  1499. loop2 = 100;
  1500. while (loop2-- > 0)
  1501. {
  1502. /* wait */
  1503. }
  1504. }
  1505. break;
  1506. case USB_HOST_D0DMA:
  1507. case USB_HOST_D0USE:
  1508. buffer = USB200.D0FIFOSEL;
  1509. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
  1510. USB200.D0FIFOSEL = buffer;
  1511. for (loop = 0; loop < 4; loop++)
  1512. {
  1513. if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1514. {
  1515. break;
  1516. }
  1517. loop2 = 100;
  1518. while (loop2-- > 0)
  1519. {
  1520. /* wait */
  1521. }
  1522. }
  1523. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1524. buffer |= (uint16_t)(pipe | mbw);
  1525. USB200.D0FIFOSEL = buffer;
  1526. for (loop = 0; loop < 4; loop++)
  1527. {
  1528. if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1529. {
  1530. break;
  1531. }
  1532. loop2 = 100;
  1533. while (loop2-- > 0)
  1534. {
  1535. /* wait */
  1536. }
  1537. }
  1538. break;
  1539. case USB_HOST_D1DMA:
  1540. case USB_HOST_D1USE:
  1541. buffer = USB200.D1FIFOSEL;
  1542. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
  1543. USB200.D1FIFOSEL = buffer;
  1544. for (loop = 0; loop < 4; loop++)
  1545. {
  1546. if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1547. {
  1548. break;
  1549. }
  1550. loop2 = 100;
  1551. while (loop2-- > 0)
  1552. {
  1553. /* wait */
  1554. }
  1555. }
  1556. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1557. buffer |= (uint16_t)(pipe | mbw);
  1558. USB200.D1FIFOSEL = buffer;
  1559. for (loop = 0; loop < 4; loop++)
  1560. {
  1561. if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1562. {
  1563. break;
  1564. }
  1565. loop2 = 100;
  1566. while (loop2-- > 0)
  1567. {
  1568. /* wait */
  1569. }
  1570. }
  1571. break;
  1572. default:
  1573. break;
  1574. }
  1575. /* Cautions !!!
  1576. * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
  1577. * For details, please look at the data sheet. */
  1578. loop2 = 100;
  1579. while (loop2-- > 0)
  1580. {
  1581. /* wait */
  1582. }
  1583. }
  1584. /*******************************************************************************
  1585. * Function Name: usb0_host_set_curpipe2
  1586. * Description : Allocates FIF0 specified by the argument in the pipe assigned
  1587. * : by the argument.(DFACC)
  1588. * Arguments : uint16_t pipe ; Pipe Number
  1589. * : uint16_t fifosel ; Select FIFO
  1590. * : uint16_t isel ; FIFO Access Direction
  1591. * : uint16_t mbw ; FIFO Port Access Bit Width
  1592. * : uint16_t dfacc ; DFACC Access mode
  1593. * Return Value : none
  1594. *******************************************************************************/
  1595. void usb0_host_set_curpipe2 (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw, uint16_t dfacc)
  1596. {
  1597. uint16_t buffer;
  1598. uint32_t loop;
  1599. #ifdef __USB_HOST_DF_ACC_ENABLE__
  1600. uint32_t dummy;
  1601. #endif
  1602. volatile uint32_t loop2;
  1603. g_usb0_host_mbw[pipe] = mbw;
  1604. switch (fifosel)
  1605. {
  1606. case USB_HOST_CUSE:
  1607. buffer = USB200.CFIFOSEL;
  1608. buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
  1609. buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
  1610. USB200.CFIFOSEL = buffer;
  1611. for (loop = 0; loop < 4; loop++)
  1612. {
  1613. if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
  1614. == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
  1615. {
  1616. break;
  1617. }
  1618. loop2 = 100;
  1619. while (loop2-- > 0)
  1620. {
  1621. /* wait */
  1622. }
  1623. }
  1624. buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1625. buffer |= (uint16_t)(isel | pipe | mbw);
  1626. USB200.CFIFOSEL = buffer;
  1627. for (loop = 0; loop < 4; loop++)
  1628. {
  1629. if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
  1630. == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
  1631. {
  1632. break;
  1633. }
  1634. loop2 = 100;
  1635. while (loop2-- > 0)
  1636. {
  1637. /* wait */
  1638. }
  1639. }
  1640. break;
  1641. case USB_HOST_D0DMA:
  1642. case USB_HOST_D0USE:
  1643. buffer = USB200.D0FIFOSEL;
  1644. #ifdef __USB_HOST_DF_ACC_ENABLE__
  1645. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1646. if (dfacc != 0)
  1647. {
  1648. buffer |= (uint16_t)(USB_HOST_BITMBW_32);
  1649. }
  1650. #else
  1651. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
  1652. #endif
  1653. USB200.D0FIFOSEL = buffer;
  1654. for (loop = 0; loop < 4; loop++)
  1655. {
  1656. if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1657. {
  1658. break;
  1659. }
  1660. loop2 = 100;
  1661. while (loop2-- > 0)
  1662. {
  1663. /* wait */
  1664. }
  1665. }
  1666. #ifdef __USB_HOST_DF_ACC_ENABLE__
  1667. if (dfacc != 0)
  1668. {
  1669. dummy = USB200.D0FIFO.UINT32;
  1670. }
  1671. #endif
  1672. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1673. buffer |= (uint16_t)(pipe | mbw);
  1674. USB200.D0FIFOSEL = buffer;
  1675. for (loop = 0; loop < 4; loop++)
  1676. {
  1677. if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1678. {
  1679. break;
  1680. }
  1681. loop2 = 100;
  1682. while (loop2-- > 0)
  1683. {
  1684. /* wait */
  1685. }
  1686. }
  1687. break;
  1688. case USB_HOST_D1DMA:
  1689. case USB_HOST_D1USE:
  1690. buffer = USB200.D1FIFOSEL;
  1691. #ifdef __USB_HOST_DF_ACC_ENABLE__
  1692. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1693. if (dfacc != 0)
  1694. {
  1695. buffer |= (uint16_t)(USB_HOST_BITMBW_32);
  1696. }
  1697. #else
  1698. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
  1699. #endif
  1700. USB200.D1FIFOSEL = buffer;
  1701. for (loop = 0; loop < 4; loop++)
  1702. {
  1703. if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1704. {
  1705. break;
  1706. }
  1707. loop2 = 100;
  1708. while (loop2-- > 0)
  1709. {
  1710. /* wait */
  1711. }
  1712. }
  1713. #ifdef __USB_HOST_DF_ACC_ENABLE__
  1714. if (dfacc != 0)
  1715. {
  1716. dummy = USB200.D1FIFO.UINT32;
  1717. loop = dummy; // avoid warning.
  1718. }
  1719. #endif
  1720. buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
  1721. buffer |= (uint16_t)(pipe | mbw);
  1722. USB200.D1FIFOSEL = buffer;
  1723. for (loop = 0; loop < 4; loop++)
  1724. {
  1725. if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
  1726. {
  1727. break;
  1728. }
  1729. loop2 = 100;
  1730. while (loop2-- > 0)
  1731. {
  1732. /* wait */
  1733. }
  1734. }
  1735. break;
  1736. default:
  1737. break;
  1738. }
  1739. /* Cautions !!!
  1740. * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
  1741. * For details, please look at the data sheet. */
  1742. loop2 = 100;
  1743. while (loop2-- > 0)
  1744. {
  1745. /* wait */
  1746. }
  1747. }
  1748. /*******************************************************************************
  1749. * Function Name: usb0_host_write_c_fifo
  1750. * Description : Writes data in CFIFO.
  1751. * : Writes data by BYTE/WORD/LONG according to access size
  1752. * : to the pipe specified by the arguments.
  1753. * : Before executing this function, allocating CFIF0 in the specified pipe
  1754. * : should be completed.
  1755. * : Before executing this function, access size to the specified pipe
  1756. * : should be fixed and set in g_usb1_host_mbw[].
  1757. * Arguments : uint16_t pipe ; Pipe Number
  1758. * : uint16_t count ; Data Size(Byte)
  1759. * Return Value : none
  1760. *******************************************************************************/
  1761. static void usb0_host_write_c_fifo (uint16_t pipe, uint16_t count)
  1762. {
  1763. uint16_t even;
  1764. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1765. {
  1766. for (even = count; even; --even)
  1767. {
  1768. USB200.CFIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
  1769. g_usb0_host_data_pointer[pipe] += 1;
  1770. }
  1771. }
  1772. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1773. {
  1774. for (even = (uint16_t)(count / 2); even; --even)
  1775. {
  1776. USB200.CFIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
  1777. g_usb0_host_data_pointer[pipe] += 2;
  1778. }
  1779. }
  1780. else
  1781. {
  1782. for (even = (uint16_t)(count / 4); even; --even)
  1783. {
  1784. USB200.CFIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
  1785. g_usb0_host_data_pointer[pipe] += 4;
  1786. }
  1787. }
  1788. }
  1789. /*******************************************************************************
  1790. * Function Name: usb0_host_read_c_fifo
  1791. * Description : Reads data from CFIFO.
  1792. * : Reads data by BYTE/WORD/LONG according to access size
  1793. * : to the pipe specified by the arguments.
  1794. * : Before executing this function, allocating CFIF0 in the specified pipe
  1795. * : should be completed.
  1796. * : Before executing this function, access size to the specified pipe
  1797. * : should be fixed and set in g_usb0_host_mbw[].
  1798. * Arguments : uint16_t pipe ; Pipe Number
  1799. * : uint16_t count ; Data Size(Byte)
  1800. * Return Value : none
  1801. *******************************************************************************/
  1802. static void usb0_host_read_c_fifo (uint16_t pipe, uint16_t count)
  1803. {
  1804. uint16_t even;
  1805. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1806. {
  1807. for (even = count; even; --even)
  1808. {
  1809. *g_usb0_host_data_pointer[pipe] = USB200.CFIFO.UINT8[HH];
  1810. g_usb0_host_data_pointer[pipe] += 1;
  1811. }
  1812. }
  1813. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1814. {
  1815. for (even = (uint16_t)((count + 1) / 2); even; --even)
  1816. {
  1817. *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.CFIFO.UINT16[H];
  1818. g_usb0_host_data_pointer[pipe] += 2;
  1819. }
  1820. }
  1821. else
  1822. {
  1823. for (even = (uint16_t)((count + 3) / 4); even; --even)
  1824. {
  1825. *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.CFIFO.UINT32;
  1826. g_usb0_host_data_pointer[pipe] += 4;
  1827. }
  1828. }
  1829. }
  1830. /*******************************************************************************
  1831. * Function Name: usb0_host_write_d0_fifo
  1832. * Description : Writes data in D0FIFO.
  1833. * : Writes data by BYTE/WORD/LONG according to access size
  1834. * : to the pipe specified by the arguments.
  1835. * : Before executing this function, allocating CFIF0 in the specified pipe
  1836. * : should be completed.
  1837. * : Before executing this function, access size to the specified pipe
  1838. * : should be fixed and set in g_usb0_host_mbw[].
  1839. * Arguments : uint16_t pipe ; Pipe Number
  1840. * : uint16_t count ; Data Size(Byte)
  1841. * Return Value : none
  1842. *******************************************************************************/
  1843. static void usb0_host_write_d0_fifo (uint16_t pipe, uint16_t count)
  1844. {
  1845. uint16_t even;
  1846. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1847. {
  1848. for (even = count; even; --even)
  1849. {
  1850. USB200.D0FIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
  1851. g_usb0_host_data_pointer[pipe] += 1;
  1852. }
  1853. }
  1854. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1855. {
  1856. for (even = (uint16_t)(count / 2); even; --even)
  1857. {
  1858. USB200.D0FIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
  1859. g_usb0_host_data_pointer[pipe] += 2;
  1860. }
  1861. }
  1862. else
  1863. {
  1864. for (even = (uint16_t)(count / 4); even; --even)
  1865. {
  1866. USB200.D0FIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
  1867. g_usb0_host_data_pointer[pipe] += 4;
  1868. }
  1869. }
  1870. }
  1871. /*******************************************************************************
  1872. * Function Name: usb0_host_read_d0_fifo
  1873. * Description : Reads data from D0FIFO.
  1874. * : Reads data by BYTE/WORD/LONG according to access size
  1875. * : to the pipe specified by the arguments.
  1876. * : Before executing this function, allocating DOFIF0 in the specified pipe
  1877. * : should be completed.
  1878. * : Before executing this function, access size to the specified pipe
  1879. * : should be fixed and set in g_usb0_host_mbw[].
  1880. * Arguments : uint16_t Pipe ; Pipe Number
  1881. * : uint16_t count ; Data Size(Byte)
  1882. * Return Value : none
  1883. *******************************************************************************/
  1884. static void usb0_host_read_d0_fifo (uint16_t pipe, uint16_t count)
  1885. {
  1886. uint16_t even;
  1887. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1888. {
  1889. for (even = count; even; --even)
  1890. {
  1891. *g_usb0_host_data_pointer[pipe] = USB200.D0FIFO.UINT8[HH];
  1892. g_usb0_host_data_pointer[pipe] += 1;
  1893. }
  1894. }
  1895. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1896. {
  1897. for (even = (uint16_t)((count + 1) / 2); even; --even)
  1898. {
  1899. *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.D0FIFO.UINT16[H];
  1900. g_usb0_host_data_pointer[pipe] += 2;
  1901. }
  1902. }
  1903. else
  1904. {
  1905. for (even = (uint16_t)((count + 3) / 4); even; --even)
  1906. {
  1907. *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.D0FIFO.UINT32;
  1908. g_usb0_host_data_pointer[pipe] += 4;
  1909. }
  1910. }
  1911. }
  1912. /*******************************************************************************
  1913. * Function Name: usb0_host_write_d1_fifo
  1914. * Description : Writes data in D1FIFO.
  1915. * : Writes data by BYTE/WORD/LONG according to access size
  1916. * : to the pipe specified by the arguments.
  1917. * : Before executing this function, allocating D1FIF0 in the specified pipe
  1918. * : should be completed.
  1919. * : Before executing this function, access size to the specified pipe
  1920. * : should be fixed and set in g_usb1_host_mbw[].
  1921. * Arguments : uint16_t pipe ; Pipe Number
  1922. * : uint16_t count ; Data Size(Byte)
  1923. * Return Value : none
  1924. *******************************************************************************/
  1925. static void usb0_host_write_d1_fifo (uint16_t pipe, uint16_t count)
  1926. {
  1927. uint16_t even;
  1928. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1929. {
  1930. for (even = count; even; --even)
  1931. {
  1932. USB200.D1FIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
  1933. g_usb0_host_data_pointer[pipe] += 1;
  1934. }
  1935. }
  1936. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1937. {
  1938. for (even = (uint16_t)(count / 2); even; --even)
  1939. {
  1940. USB200.D1FIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
  1941. g_usb0_host_data_pointer[pipe] += 2;
  1942. }
  1943. }
  1944. else
  1945. {
  1946. for (even = (uint16_t)(count / 4); even; --even)
  1947. {
  1948. USB200.D1FIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
  1949. g_usb0_host_data_pointer[pipe] += 4;
  1950. }
  1951. }
  1952. }
  1953. /*******************************************************************************
  1954. * Function Name: usb0_host_read_d1_fifo
  1955. * Description : Reads data from D1FIFO.
  1956. * : Reads data by BYTE/WORD/LONG according to access size
  1957. * : to the pipe specified by the arguments.
  1958. * : Before executing this function, allocating D1FIF0 in the specified pipe
  1959. * : should be completed.
  1960. * : Before executing this function, access size to the specified pipe
  1961. * : should be fixed and set in g_usb1_host_mbw[].
  1962. * Arguments : uint16_t pipe ; Pipe Number
  1963. * : uint16_t count ; Data Size(Byte)
  1964. * Return Value : none
  1965. *******************************************************************************/
  1966. static void usb0_host_read_d1_fifo (uint16_t pipe, uint16_t count)
  1967. {
  1968. uint16_t even;
  1969. if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
  1970. {
  1971. for (even = count; even; --even)
  1972. {
  1973. *g_usb0_host_data_pointer[pipe] = USB200.D1FIFO.UINT8[HH];
  1974. g_usb0_host_data_pointer[pipe] += 1;
  1975. }
  1976. }
  1977. else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
  1978. {
  1979. for (even = (uint16_t)((count + 1) / 2); even; --even)
  1980. {
  1981. *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.D1FIFO.UINT16[H];
  1982. g_usb0_host_data_pointer[pipe] += 2;
  1983. }
  1984. }
  1985. else
  1986. {
  1987. for (even = (uint16_t)((count + 3) / 4); even; --even)
  1988. {
  1989. *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.D1FIFO.UINT32;
  1990. g_usb0_host_data_pointer[pipe] += 4;
  1991. }
  1992. }
  1993. }
  1994. /*******************************************************************************
  1995. * Function Name: usb0_host_com_get_dmasize
  1996. * Description : Calculates access width of DMA transfer by the argument to
  1997. return as the Return Value.
  1998. * Arguments : uint32_t trncount : transfer byte
  1999. * : uint32_t dtptr : transfer data pointer
  2000. * Return Value : DMA transfer size : 0 8bit
  2001. * : : 1 16bit
  2002. * : : 2 32bit
  2003. *******************************************************************************/
  2004. static uint32_t usb0_host_com_get_dmasize (uint32_t trncount, uint32_t dtptr)
  2005. {
  2006. uint32_t size;
  2007. if (((trncount & 0x0001) != 0) || ((dtptr & 0x00000001) != 0))
  2008. {
  2009. /* When transfer byte count is odd */
  2010. /* or transfer data area is 8-bit alignment */
  2011. size = 0; /* 8bit */
  2012. }
  2013. else if (((trncount & 0x0003) != 0) || ((dtptr & 0x00000003) != 0))
  2014. {
  2015. /* When the transfer byte count is multiples of 2 */
  2016. /* or the transfer data area is 16-bit alignment */
  2017. size = 1; /* 16bit */
  2018. }
  2019. else
  2020. {
  2021. /* When the transfer byte count is multiples of 4 */
  2022. /* or the transfer data area is 32-bit alignment */
  2023. size = 2; /* 32bit */
  2024. }
  2025. return size;
  2026. }
  2027. /*******************************************************************************
  2028. * Function Name: usb0_host_get_mbw
  2029. * Description : Calculates access width of DMA to return the value set in MBW.
  2030. * Arguments : uint32_t trncount : transfer byte
  2031. * : uint32_t dtptr : transfer data pointer
  2032. * Return Value : FIFO transfer size : USB_HOST_BITMBW_8 8bit
  2033. * : : USB_HOST_BITMBW_16 16bit
  2034. * : : USB_HOST_BITMBW_32 32bit
  2035. *******************************************************************************/
  2036. uint16_t usb0_host_get_mbw (uint32_t trncount, uint32_t dtptr)
  2037. {
  2038. uint32_t size;
  2039. uint16_t mbw;
  2040. size = usb0_host_com_get_dmasize(trncount, dtptr);
  2041. if (size == 0)
  2042. {
  2043. /* 8bit */
  2044. mbw = USB_HOST_BITMBW_8;
  2045. }
  2046. else if (size == 1)
  2047. {
  2048. /* 16bit */
  2049. mbw = USB_HOST_BITMBW_16;
  2050. }
  2051. else
  2052. {
  2053. /* 32bit */
  2054. mbw = USB_HOST_BITMBW_32;
  2055. }
  2056. return mbw;
  2057. }
  2058. /*******************************************************************************
  2059. * Function Name: usb0_host_set_transaction_counter
  2060. * Description : Sets transaction counter by the argument(PIPEnTRN).
  2061. * : Clears transaction before setting to enable transaction counter setting.
  2062. * Arguments : uint16_t pipe ; Pipe number
  2063. * : uint32_t bsize : Data transfer size
  2064. * Return Value : none
  2065. *******************************************************************************/
  2066. static void usb0_host_set_transaction_counter (uint16_t pipe, uint32_t bsize)
  2067. {
  2068. uint16_t mxps;
  2069. uint16_t cnt;
  2070. if (bsize == 0)
  2071. {
  2072. return;
  2073. }
  2074. mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
  2075. if ((bsize % mxps) == 0)
  2076. {
  2077. cnt = (uint16_t)(bsize / mxps);
  2078. }
  2079. else
  2080. {
  2081. cnt = (uint16_t)((bsize / mxps) + 1);
  2082. }
  2083. switch (pipe)
  2084. {
  2085. case USB_HOST_PIPE1:
  2086. RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
  2087. 1,
  2088. USB_PIPEnTRE_TRCLR_SHIFT,
  2089. USB_PIPEnTRE_TRCLR);
  2090. USB200.PIPE1TRN = cnt;
  2091. RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
  2092. 1,
  2093. USB_PIPEnTRE_TRENB_SHIFT,
  2094. USB_PIPEnTRE_TRENB);
  2095. break;
  2096. case USB_HOST_PIPE2:
  2097. RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
  2098. 1,
  2099. USB_PIPEnTRE_TRCLR_SHIFT,
  2100. USB_PIPEnTRE_TRCLR);
  2101. USB200.PIPE2TRN = cnt;
  2102. RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
  2103. 1,
  2104. USB_PIPEnTRE_TRENB_SHIFT,
  2105. USB_PIPEnTRE_TRENB);
  2106. break;
  2107. case USB_HOST_PIPE3:
  2108. RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
  2109. 1,
  2110. USB_PIPEnTRE_TRCLR_SHIFT,
  2111. USB_PIPEnTRE_TRCLR);
  2112. USB200.PIPE3TRN = cnt;
  2113. RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
  2114. 1,
  2115. USB_PIPEnTRE_TRENB_SHIFT,
  2116. USB_PIPEnTRE_TRENB);
  2117. break;
  2118. case USB_HOST_PIPE4:
  2119. RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
  2120. 1,
  2121. USB_PIPEnTRE_TRCLR_SHIFT,
  2122. USB_PIPEnTRE_TRCLR);
  2123. USB200.PIPE4TRN = cnt;
  2124. RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
  2125. 1,
  2126. USB_PIPEnTRE_TRENB_SHIFT,
  2127. USB_PIPEnTRE_TRENB);
  2128. break;
  2129. case USB_HOST_PIPE5:
  2130. RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
  2131. 1,
  2132. USB_PIPEnTRE_TRCLR_SHIFT,
  2133. USB_PIPEnTRE_TRCLR);
  2134. USB200.PIPE5TRN = cnt;
  2135. RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
  2136. 1,
  2137. USB_PIPEnTRE_TRENB_SHIFT,
  2138. USB_PIPEnTRE_TRENB);
  2139. break;
  2140. case USB_HOST_PIPE9:
  2141. RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
  2142. 1,
  2143. USB_PIPEnTRE_TRCLR_SHIFT,
  2144. USB_PIPEnTRE_TRCLR);
  2145. USB200.PIPE9TRN = cnt;
  2146. RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
  2147. 1,
  2148. USB_PIPEnTRE_TRENB_SHIFT,
  2149. USB_PIPEnTRE_TRENB);
  2150. break;
  2151. default:
  2152. break;
  2153. }
  2154. }
  2155. /*******************************************************************************
  2156. * Function Name: usb0_host_clear_transaction_counter
  2157. * Description : Clears the transaction counter by the argument.
  2158. * : After executing this function, the transaction counter is invalid.
  2159. * Arguments : uint16_t pipe ; Pipe number
  2160. * Return Value : none
  2161. *******************************************************************************/
  2162. void usb0_host_clear_transaction_counter (uint16_t pipe)
  2163. {
  2164. switch (pipe)
  2165. {
  2166. case USB_HOST_PIPE1:
  2167. RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
  2168. 0,
  2169. USB_PIPEnTRE_TRENB_SHIFT,
  2170. USB_PIPEnTRE_TRENB);
  2171. RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
  2172. 1,
  2173. USB_PIPEnTRE_TRCLR_SHIFT,
  2174. USB_PIPEnTRE_TRCLR);
  2175. break;
  2176. case USB_HOST_PIPE2:
  2177. RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
  2178. 0,
  2179. USB_PIPEnTRE_TRENB_SHIFT,
  2180. USB_PIPEnTRE_TRENB);
  2181. RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
  2182. 1,
  2183. USB_PIPEnTRE_TRCLR_SHIFT,
  2184. USB_PIPEnTRE_TRCLR);
  2185. break;
  2186. case USB_HOST_PIPE3:
  2187. RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
  2188. 0,
  2189. USB_PIPEnTRE_TRENB_SHIFT,
  2190. USB_PIPEnTRE_TRENB);
  2191. RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
  2192. 1,
  2193. USB_PIPEnTRE_TRCLR_SHIFT,
  2194. USB_PIPEnTRE_TRCLR);
  2195. break;
  2196. case USB_HOST_PIPE4:
  2197. RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
  2198. 0,
  2199. USB_PIPEnTRE_TRENB_SHIFT,
  2200. USB_PIPEnTRE_TRENB);
  2201. RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
  2202. 1,
  2203. USB_PIPEnTRE_TRCLR_SHIFT,
  2204. USB_PIPEnTRE_TRCLR);
  2205. break;
  2206. case USB_HOST_PIPE5:
  2207. RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
  2208. 0,
  2209. USB_PIPEnTRE_TRENB_SHIFT,
  2210. USB_PIPEnTRE_TRENB);
  2211. RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
  2212. 1,
  2213. USB_PIPEnTRE_TRCLR_SHIFT,
  2214. USB_PIPEnTRE_TRCLR);
  2215. break;
  2216. case USB_HOST_PIPE9:
  2217. RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
  2218. 0,
  2219. USB_PIPEnTRE_TRENB_SHIFT,
  2220. USB_PIPEnTRE_TRENB);
  2221. RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
  2222. 1,
  2223. USB_PIPEnTRE_TRCLR_SHIFT,
  2224. USB_PIPEnTRE_TRCLR);
  2225. break;
  2226. default:
  2227. break;
  2228. }
  2229. }
  2230. /*******************************************************************************
  2231. * Function Name: usb0_host_stop_transfer
  2232. * Description : Stops the USB transfer in the pipe specified by the argument.
  2233. * : After stopping the USB transfer, clears the buffer allocated in
  2234. * : the pipe.
  2235. * : After executing this function, allocation in FIF0 becomes USB_HOST_PIPE0;
  2236. * : invalid. After executing this function, BRDY/NRDY/BEMP interrupt
  2237. * : in the corresponding pipe becomes invalid. Sequence bit is also
  2238. * : cleared.
  2239. * Arguments : uint16_t pipe ; Pipe Number
  2240. * Return Value : none
  2241. *******************************************************************************/
  2242. void usb0_host_stop_transfer (uint16_t pipe)
  2243. {
  2244. uint16_t usefifo;
  2245. uint32_t remain;
  2246. usb0_host_set_pid_nak(pipe);
  2247. usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  2248. switch (usefifo)
  2249. {
  2250. case USB_HOST_D0FIFO_USE:
  2251. usb0_host_clear_transaction_counter(pipe);
  2252. USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
  2253. break;
  2254. case USB_HOST_D1FIFO_USE:
  2255. usb0_host_clear_transaction_counter(pipe);
  2256. USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
  2257. break;
  2258. case USB_HOST_D0FIFO_DMA:
  2259. remain = Userdef_USB_usb0_host_stop_dma0();
  2260. usb0_host_dma_stop_d0(pipe, remain);
  2261. usb0_host_clear_transaction_counter(pipe);
  2262. USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
  2263. break;
  2264. case USB_HOST_D1FIFO_DMA:
  2265. remain = Userdef_USB_usb0_host_stop_dma1();
  2266. usb0_host_dma_stop_d1(pipe, remain);
  2267. usb0_host_clear_transaction_counter(pipe);
  2268. USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
  2269. break;
  2270. default:
  2271. usb0_host_clear_transaction_counter(pipe);
  2272. USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
  2273. break;
  2274. }
  2275. /* Interrupt of pipe set is disabled */
  2276. usb0_host_disable_brdy_int(pipe);
  2277. usb0_host_disable_nrdy_int(pipe);
  2278. usb0_host_disable_bemp_int(pipe);
  2279. #if(1) /* ohci_wrapp */
  2280. #else
  2281. usb0_host_aclrm(pipe);
  2282. #endif
  2283. usb0_host_set_csclr(pipe);
  2284. }
  2285. /*******************************************************************************
  2286. * Function Name: usb0_host_set_dfacc_d0
  2287. * Description : Sets the DFACC setting value in D0FIFO using the transfer size.
  2288. * Arguments : uint16_t mbw ; MBW
  2289. * : uint16_t count ; data count
  2290. * Return Value : DFACC Access mode
  2291. *******************************************************************************/
  2292. static uint16_t usb0_host_set_dfacc_d0 (uint16_t mbw, uint32_t count)
  2293. {
  2294. uint16_t dfacc = 0;
  2295. #ifndef __USB_HOST_DF_ACC_ENABLE__
  2296. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2297. 0,
  2298. USB_DnFBCFG_DFACC_SHIFT,
  2299. USB_DnFBCFG_DFACC);
  2300. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2301. 0,
  2302. USB_DnFBCFG_TENDE_SHIFT,
  2303. USB_DnFBCFG_TENDE);
  2304. dfacc = 0;
  2305. #else
  2306. if (mbw == USB_HOST_BITMBW_32)
  2307. {
  2308. if ((count % 32) == 0)
  2309. {
  2310. /* 32byte transfer */
  2311. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2312. 2,
  2313. USB_DnFBCFG_DFACC_SHIFT,
  2314. USB_DnFBCFG_DFACC);
  2315. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2316. 0,
  2317. USB_DnFBCFG_TENDE_SHIFT,
  2318. USB_DnFBCFG_TENDE);
  2319. dfacc = 2;
  2320. }
  2321. else if ((count % 16) == 0)
  2322. {
  2323. /* 16byte transfer */
  2324. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2325. 1,
  2326. USB_DnFBCFG_DFACC_SHIFT,
  2327. USB_DnFBCFG_DFACC);
  2328. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2329. 0,
  2330. USB_DnFBCFG_TENDE_SHIFT,
  2331. USB_DnFBCFG_TENDE);
  2332. dfacc = 1;
  2333. }
  2334. else
  2335. {
  2336. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2337. 0,
  2338. USB_DnFBCFG_DFACC_SHIFT,
  2339. USB_DnFBCFG_DFACC);
  2340. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2341. 0,
  2342. USB_DnFBCFG_TENDE_SHIFT,
  2343. USB_DnFBCFG_TENDE);
  2344. dfacc = 0;
  2345. }
  2346. }
  2347. else if (mbw == USB_HOST_BITMBW_16)
  2348. {
  2349. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2350. 0,
  2351. USB_DnFBCFG_DFACC_SHIFT,
  2352. USB_DnFBCFG_DFACC);
  2353. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2354. 0,
  2355. USB_DnFBCFG_TENDE_SHIFT,
  2356. USB_DnFBCFG_TENDE);
  2357. dfacc = 0;
  2358. }
  2359. else
  2360. {
  2361. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2362. 0,
  2363. USB_DnFBCFG_DFACC_SHIFT,
  2364. USB_DnFBCFG_DFACC);
  2365. RZA_IO_RegWrite_16(&USB200.D0FBCFG,
  2366. 0,
  2367. USB_DnFBCFG_TENDE_SHIFT,
  2368. USB_DnFBCFG_TENDE);
  2369. dfacc = 0;
  2370. }
  2371. #endif
  2372. return dfacc;
  2373. }
  2374. /*******************************************************************************
  2375. * Function Name: usb0_host_set_dfacc_d1
  2376. * Description : Sets the DFACC setting value in D1FIFO using the transfer size.
  2377. * Arguments : uint16_t mbw ; MBW
  2378. * : uint16_t count ; data count
  2379. * Return Value : DFACC Access mode
  2380. *******************************************************************************/
  2381. static uint16_t usb0_host_set_dfacc_d1 (uint16_t mbw, uint32_t count)
  2382. {
  2383. uint16_t dfacc = 0;
  2384. #ifndef __USB_HOST_DF_ACC_ENABLE__
  2385. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2386. 0,
  2387. USB_DnFBCFG_DFACC_SHIFT,
  2388. USB_DnFBCFG_DFACC);
  2389. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2390. 0,
  2391. USB_DnFBCFG_TENDE_SHIFT,
  2392. USB_DnFBCFG_TENDE);
  2393. dfacc = 0;
  2394. #else
  2395. if (mbw == USB_HOST_BITMBW_32)
  2396. {
  2397. if ((count % 32) == 0)
  2398. {
  2399. /* 32byte transfer */
  2400. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2401. 2,
  2402. USB_DnFBCFG_DFACC_SHIFT,
  2403. USB_DnFBCFG_DFACC);
  2404. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2405. 0,
  2406. USB_DnFBCFG_TENDE_SHIFT,
  2407. USB_DnFBCFG_TENDE);
  2408. dfacc = 2;
  2409. }
  2410. else if ((count % 16) == 0)
  2411. {
  2412. /* 16byte transfer */
  2413. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2414. 1,
  2415. USB_DnFBCFG_DFACC_SHIFT,
  2416. USB_DnFBCFG_DFACC);
  2417. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2418. 0,
  2419. USB_DnFBCFG_TENDE_SHIFT,
  2420. USB_DnFBCFG_TENDE);
  2421. dfacc = 1;
  2422. }
  2423. else
  2424. {
  2425. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2426. 0,
  2427. USB_DnFBCFG_DFACC_SHIFT,
  2428. USB_DnFBCFG_DFACC);
  2429. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2430. 0,
  2431. USB_DnFBCFG_TENDE_SHIFT,
  2432. USB_DnFBCFG_TENDE);
  2433. dfacc = 0;
  2434. }
  2435. }
  2436. else if (mbw == USB_HOST_BITMBW_16)
  2437. {
  2438. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2439. 0,
  2440. USB_DnFBCFG_DFACC_SHIFT,
  2441. USB_DnFBCFG_DFACC);
  2442. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2443. 0,
  2444. USB_DnFBCFG_TENDE_SHIFT,
  2445. USB_DnFBCFG_TENDE);
  2446. dfacc = 0;
  2447. }
  2448. else
  2449. {
  2450. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2451. 0,
  2452. USB_DnFBCFG_DFACC_SHIFT,
  2453. USB_DnFBCFG_DFACC);
  2454. RZA_IO_RegWrite_16(&USB200.D1FBCFG,
  2455. 0,
  2456. USB_DnFBCFG_TENDE_SHIFT,
  2457. USB_DnFBCFG_TENDE);
  2458. dfacc = 0;
  2459. }
  2460. #endif
  2461. return dfacc;
  2462. }
  2463. /* End of File */