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.

317 lines
11 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * pru/hal/uart/src/pru.c
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated
  5. * Author: Jitendra Kumar <jitendra@mistralsolutions.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation version 2.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
  12. * whether express or implied; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. */
  16. /************************************************************
  17. * Include Files *
  18. ************************************************************/
  19. #include "tistdtypes.h"
  20. #include "csl/cslr.h"
  21. #include "csl/soc_OMAPL138.h"
  22. #include "csl/cslr_prucore.h"
  23. #include "csl/cslr_psc_OMAPL138.h"
  24. #include "pru.h"
  25. /************************************************************
  26. * Local Function Declarations *
  27. ************************************************************/
  28. static void pru_psc_disable(arm_pru_iomap * pru_arm_iomap);
  29. static void pru_psc_enable(arm_pru_iomap * pru_arm_iomap);
  30. // Load the specified PRU with code
  31. Uint32 pru_load(Uint8 pruNum, Uint32 * pruCode, Uint32 codeSizeInWords,
  32. arm_pru_iomap * pru_arm_iomap)
  33. {
  34. Uint32 *pruIram;
  35. Uint32 i;
  36. if (pruNum == CSL_PRUCORE_0) {
  37. pruIram = (Uint32 *) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x8000);
  38. } else if (pruNum == CSL_PRUCORE_1) {
  39. pruIram = (Uint32 *) ((Uint32 )pru_arm_iomap->pru_io_addr + 0xc000);
  40. } else {
  41. return E_FAIL;
  42. }
  43. pru_enable(pruNum, pru_arm_iomap);
  44. // Copy dMAX code to its instruction RAM
  45. for (i = 0; i < codeSizeInWords; i++) {
  46. pruIram[i] = pruCode[i];
  47. }
  48. return E_PASS;
  49. }
  50. Uint32 pru_run(Uint8 pruNum, arm_pru_iomap * pru_arm_iomap)
  51. {
  52. CSL_PrucoreRegsOvly hPru;
  53. if (pruNum == CSL_PRUCORE_0) {
  54. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7000); //CSL_PRUCORE_0_REGS;
  55. } else if (pruNum == CSL_PRUCORE_1) {
  56. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7800); //CSL_PRUCORE_1_REGS;
  57. } else {
  58. return E_FAIL;
  59. }
  60. // Enable dMAX, let it execute the code we just copied
  61. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_COUNTENABLE, ENABLE);
  62. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_ENABLE, ENABLE);
  63. return E_PASS;
  64. }
  65. Uint32 pru_waitForHalt(Uint8 pruNum, Int32 timeout,
  66. arm_pru_iomap * pru_arm_iomap)
  67. {
  68. CSL_PrucoreRegsOvly hPru;
  69. Int32 cnt = timeout;
  70. if (pruNum == CSL_PRUCORE_0) {
  71. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7000); //CSL_PRUCORE_0_REGS;
  72. } else if (pruNum == CSL_PRUCORE_1) {
  73. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7800); //CSL_PRUCORE_1_REGS;
  74. } else {
  75. return E_FAIL;
  76. }
  77. while (CSL_FEXT(hPru->CONTROL, PRUCORE_CONTROL_RUNSTATE) ==
  78. CSL_PRUCORE_CONTROL_RUNSTATE_RUN) {
  79. if (cnt > 0) {
  80. cnt--;
  81. }
  82. if (cnt == 0) {
  83. return E_TIMEOUT;
  84. }
  85. }
  86. return E_PASS;
  87. }
  88. Uint32 pru_disable(arm_pru_iomap * pru_arm_iomap)
  89. {
  90. CSL_PrucoreRegsOvly hPru;
  91. // Disable PRU0
  92. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7000); //CSL_PRUCORE_0_REGS;
  93. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_COUNTENABLE, DISABLE);
  94. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_ENABLE, DISABLE);
  95. // Reset PRU0
  96. hPru->CONTROL = CSL_PRUCORE_CONTROL_RESETVAL;
  97. // Disable PRU1
  98. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7800); //CSL_PRUCORE_1_REGS;
  99. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_COUNTENABLE, DISABLE);
  100. CSL_FINST(hPru->CONTROL, PRUCORE_CONTROL_ENABLE, DISABLE);
  101. // Reset PRU1
  102. hPru->CONTROL = CSL_PRUCORE_CONTROL_RESETVAL;
  103. // Disable PRU SS
  104. pru_psc_disable(pru_arm_iomap);
  105. return E_PASS;
  106. }
  107. Uint32 pru_enable(Uint8 pruNum, arm_pru_iomap * pru_arm_iomap)
  108. {
  109. CSL_PrucoreRegsOvly hPru;
  110. // Enable PRU SS
  111. pru_psc_enable(pru_arm_iomap);
  112. if (pruNum == CSL_PRUCORE_0) {
  113. // Reset PRU0
  114. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7000); //CSL_PRUCORE_0_REGS;
  115. hPru->CONTROL = CSL_PRUCORE_CONTROL_RESETVAL;
  116. } else if (pruNum == CSL_PRUCORE_1) {
  117. // Reset PRU1
  118. hPru = (CSL_PrucoreRegsOvly) ((Uint32 )pru_arm_iomap->pru_io_addr + 0x7800); //CSL_PRUCORE_1_REGS;
  119. hPru->CONTROL = CSL_PRUCORE_CONTROL_RESETVAL;
  120. }
  121. return E_PASS;
  122. }
  123. /************************************************************
  124. * Local Function Definitions *
  125. ************************************************************/
  126. static void pru_psc_enable(arm_pru_iomap * pru_arm_iomap)
  127. {
  128. CSL_PscRegsOvly PSC = (CSL_PscRegsOvly) pru_arm_iomap->psc0_io_addr; //CSL_PSC_0_REGS;
  129. // Wait for any outstanding transition to complete
  130. while (CSL_FEXT(PSC->PTSTAT, PSC_PTSTAT_GOSTAT0) ==
  131. CSL_PSC_PTSTAT_GOSTAT0_IN_TRANSITION) ;
  132. // If we are already in that state, just return
  133. if (CSL_FEXT(PSC->MDSTAT[CSL_PSC_PRU], PSC_MDSTAT_STATE) ==
  134. CSL_PSC_MDSTAT_STATE_ENABLE)
  135. return;
  136. // Perform transition
  137. CSL_FINST(PSC->MDCTL[CSL_PSC_PRU], PSC_MDCTL_NEXT, ENABLE);
  138. CSL_FINST(PSC->PTCMD, PSC_PTCMD_GO0, SET);
  139. // Wait for transition to complete
  140. while (CSL_FEXT(PSC->PTSTAT, PSC_PTSTAT_GOSTAT0) ==
  141. CSL_PSC_PTSTAT_GOSTAT0_IN_TRANSITION) ;
  142. // Wait and verify the state
  143. while (CSL_FEXT(PSC->MDSTAT[CSL_PSC_PRU], PSC_MDSTAT_STATE) !=
  144. CSL_PSC_MDSTAT_STATE_ENABLE) ;
  145. }
  146. static void pru_psc_disable(arm_pru_iomap * pru_arm_iomap)
  147. {
  148. CSL_PscRegsOvly PSC = (CSL_PscRegsOvly) pru_arm_iomap->psc0_io_addr; //CSL_PSC_0_REGS;
  149. // Wait for any outstanding transition to complete
  150. while (CSL_FEXT(PSC->PTSTAT, PSC_PTSTAT_GOSTAT0) ==
  151. CSL_PSC_PTSTAT_GOSTAT0_IN_TRANSITION) ;
  152. // If we are already in that state, just return
  153. if (CSL_FEXT(PSC->MDSTAT[CSL_PSC_PRU], PSC_MDSTAT_STATE) ==
  154. CSL_PSC_MDSTAT_STATE_SYNCRST)
  155. return;
  156. // Perform transition
  157. CSL_FINST(PSC->MDCTL[CSL_PSC_PRU], PSC_MDCTL_NEXT, SYNCRST);
  158. CSL_FINST(PSC->PTCMD, PSC_PTCMD_GO0, SET);
  159. // Wait for transition to complete
  160. while (CSL_FEXT(PSC->PTSTAT, PSC_PTSTAT_GOSTAT0) ==
  161. CSL_PSC_PTSTAT_GOSTAT0_IN_TRANSITION) ;
  162. // Wait and verify the state
  163. while (CSL_FEXT(PSC->MDSTAT[CSL_PSC_PRU], PSC_MDSTAT_STATE) !=
  164. CSL_PSC_MDSTAT_STATE_SYNCRST) ;
  165. }
  166. /***********************************************************
  167. * End file *
  168. ***********************************************************/
  169. /** ********************************************************************************************************
  170. * \brief pru_ram_write_data() Download the data into data RAM of PRU0 or PRU1 of OMAP L138.
  171. *
  172. * This API will be called by the Application to download the data into data RAM of PRU0 or PRU1
  173. *
  174. * \param u32offset Offset of the data RAM where the data has to be written
  175. * \param pu32datatowrite Pointer to a buffer that holds the data to be written into RAM
  176. * \param u16wordstowrite Number of bytes to be written into that RAM
  177. *
  178. * \return SUCCESS or FAILURE
  179. *
  180. ***********************************************************************************************************/
  181. short pru_ram_write_data
  182. (Uint32 u32offset,
  183. Uint8 * pu8datatowrite,
  184. Uint16 u16bytestowrite, arm_pru_iomap * pru_arm_iomap) {
  185. Uint8 *pu8addresstowrite;
  186. Uint16 u16loop;
  187. u32offset = (unsigned int)pru_arm_iomap->pru_io_addr + u32offset;
  188. pu8addresstowrite = (Uint8 *) (u32offset);
  189. for (u16loop = 0; u16loop < u16bytestowrite; u16loop++)
  190. *pu8addresstowrite++ = *pu8datatowrite++;
  191. return 0;
  192. }
  193. /** ********************************************************************************************************
  194. * \brief pru_ram_read_data() Download the data into data RAM of PRU0 or PRU1 of OMAP L138.
  195. *
  196. * This API will be called by the Application to read the data from data RAM of PRU0 or PRU1
  197. *
  198. * \param u32offset Offset of the data RAM where the data has to be read
  199. * \param pu8datatoread Pointer to a buffer that would hold the data to be read from the RAM
  200. * \param u16bytestoread Number of bytes to be read from RAM
  201. *
  202. * \return SUCCESS or FAILURE
  203. *
  204. ***********************************************************************************************************/
  205. short pru_ram_read_data
  206. (Uint32 u32offset,
  207. Uint8 * pu8datatoread,
  208. Uint16 u16bytestoread, arm_pru_iomap * pru_arm_iomap) {
  209. Uint8 *pu8addresstoread;
  210. Uint16 u16loop;
  211. u32offset = (unsigned int)pru_arm_iomap->pru_io_addr + u32offset;
  212. pu8addresstoread = (Uint8 *) (u32offset);
  213. for (u16loop = 0; u16loop < u16bytestoread; u16loop++)
  214. *pu8datatoread++ = *pu8addresstoread++;
  215. return 0;
  216. }
  217. /** ********************************************************************************************************
  218. * \brief pru_ram_write_data_4byte() Download the data into data RAM of PRU0 or PRU1 of OMAP L138.
  219. *
  220. * This API will be called by the Application to download the data into data RAM of PRU0 or PRU1
  221. *
  222. * \param u32offset Offset of the data RAM where the data has to be written
  223. * \param pu32datatowrite Pointer to a buffer that holds the data to be written into RAM
  224. * \param u16wordstowrite Number of words to be written into that RAM
  225. *
  226. * \r//eturn SUCCESS or FAILURE
  227. *
  228. ***********************************************************************************************************/
  229. short pru_ram_write_data_4byte(unsigned int u32offset,
  230. unsigned int *pu32datatowrite,
  231. short u16wordstowrite)
  232. {
  233. unsigned int *pu32addresstowrite;
  234. short u16loop;
  235. pu32addresstowrite = (unsigned int *)(u32offset);
  236. for (u16loop = 0; u16loop < u16wordstowrite; u16loop++)
  237. *pu32addresstowrite++ = *pu32datatowrite++;
  238. return 0;
  239. }
  240. /** ********************************************************************************************************
  241. * \brief pru_ram_read_data_4byte() Download the data into data RAM of PRU0 or PRU1 of OMAP L138.
  242. *
  243. * This API will be called by the Application to read the data from data RAM of PRU0 or PRU1
  244. *
  245. * \param u32offset Offset of the data RAM where the data has to be read
  246. * \param pu32datatoread Pointer to a buffer that would hold the data to be read from the RAM
  247. * \param u16wordstoread Number of words to be read from RAM
  248. *
  249. * \return SUCCESS or FAILURE
  250. *
  251. ***********************************************************************************************************/
  252. short pru_ram_read_data_4byte(unsigned int u32offset,
  253. unsigned int *pu32datatoread,
  254. short u16wordstoread)
  255. {
  256. unsigned int *pu32addresstoread;
  257. short u16loop;
  258. pu32addresstoread = (unsigned int *)(u32offset);
  259. for (u16loop = 0; u16loop < u16wordstoread; u16loop++)
  260. *pu32datatoread++ = *pu32addresstoread++;
  261. return 0;
  262. }