F2837xD_Ipc_Driver_Util.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. //###########################################################################
  2. //
  3. // FILE: F2837xD_Ipc_Driver_Util.c
  4. //
  5. // TITLE: F2837xD Inter-Processor Communication (IPC) API Driver Utility
  6. // Functions
  7. //
  8. // DESCRIPTION:
  9. // API functions for inter-processor communications between the
  10. // Local and Remote CPU system.
  11. // The driver functions in this file are available only as
  12. // sample functions for application development. Due to the generic
  13. // nature of these functions and the cycle overhead inherent to a
  14. // function call, the code is not intended to be used in cases where
  15. // maximum efficiency is required in a system.
  16. //
  17. // NOTE: This source code is used by both CPUs. That is both CPU1 and CPU2
  18. // cores use this code.
  19. // The active debug CPU will be referred to as Local CPU and the other
  20. // CPU will be referred to as Remote CPU.
  21. // When using this source code in CPU1, the term "local"
  22. // will mean CPU1 and the term "remote" CPU will be mean CPU2.
  23. // When using this source code in CPU2, the term "local"
  24. // will mean CPU2 and the term "remote" CPU will be mean CPU1.
  25. //
  26. // The abbreviations LtoR and RtoL within the function names mean
  27. // Local to Remote and Remote to Local respectively.
  28. //
  29. //###########################################################################
  30. // $TI Release: F2837xD Support Library v3.05.00.00 $
  31. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  32. // $Copyright:
  33. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  34. //
  35. // Redistribution and use in source and binary forms, with or without
  36. // modification, are permitted provided that the following conditions
  37. // are met:
  38. //
  39. // Redistributions of source code must retain the above copyright
  40. // notice, this list of conditions and the following disclaimer.
  41. //
  42. // Redistributions in binary form must reproduce the above copyright
  43. // notice, this list of conditions and the following disclaimer in the
  44. // documentation and/or other materials provided with the
  45. // distribution.
  46. //
  47. // Neither the name of Texas Instruments Incorporated nor the names of
  48. // its contributors may be used to endorse or promote products derived
  49. // from this software without specific prior written permission.
  50. //
  51. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  52. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  53. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  54. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  55. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  56. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  57. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  58. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  59. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  60. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  61. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  62. // $
  63. //###########################################################################
  64. //*****************************************************************************
  65. //
  66. //! \addtogroup ipc_util_api
  67. //! @{
  68. //
  69. //*****************************************************************************
  70. #include "F2837xD_device.h"
  71. #include "F2837xD_GlobalPrototypes.h"
  72. #include "F2837xD_Gpio_defines.h"
  73. #include "F2837xD_Ipc_drivers.h"
  74. //*****************************************************************************
  75. //
  76. //! Local CPU Acknowledges Remote to Local IPC Flag.
  77. //!
  78. //! \param ulFlags specifies the IPC flag mask for flags being acknowledged.
  79. //!
  80. //! This function will allow the Local CPU system to acknowledge/clear the IPC
  81. //! flag set by the Remote CPU system. The \e ulFlags parameter can be any of
  82. //! the IPC flag values: \b IPC_FLAG0 - \b IPC_FLAG31.
  83. //!
  84. //! \return None.
  85. //
  86. //*****************************************************************************
  87. void
  88. IPCRtoLFlagAcknowledge (uint32_t ulFlags)
  89. {
  90. IpcRegs.IPCACK.all |= ulFlags;
  91. }
  92. //*****************************************************************************
  93. //
  94. //! Determines whether the given Remote to Local IPC flags are busy or not.
  95. //!
  96. //! \param ulFlags specifies Remote to Local IPC Flag number masks to check the
  97. //! status of.
  98. //!
  99. //! Allows the caller to determine whether the designated IPC flags are
  100. //! pending. The \e ulFlags parameter can be any of the IPC flag
  101. //! values: \b IPC_FLAG0 - \b IPC_FLAG31.
  102. //!
  103. //! \return Returns \b 1 if the IPC flags are busy or \b 0 if designated
  104. //! IPC flags are free.
  105. //
  106. //*****************************************************************************
  107. Uint16
  108. IPCRtoLFlagBusy (uint32_t ulFlags)
  109. {
  110. Uint16 returnStatus;
  111. if ((IpcRegs.IPCSTS.all & ulFlags) == 0)
  112. {
  113. returnStatus = 0;
  114. }
  115. else
  116. {
  117. returnStatus = 1;
  118. }
  119. return returnStatus;
  120. }
  121. //*****************************************************************************
  122. //
  123. //! Determines whether the given IPC flags are busy or not.
  124. //!
  125. //! \param ulFlags specifies Local to Remote IPC Flag number masks to check the
  126. //! status of.
  127. //!
  128. //! Allows the caller to determine whether the designated IPC flags are
  129. //! available for further control to master system communication. If \b 0 is
  130. //! returned, then all designated tasks have completed and are available.
  131. //! The \e ulFlags parameter can be any of the IPC flag
  132. //! values: \b IPC_FLAG0 - \b IPC_FLAG31.
  133. //!
  134. //! \return Returns \b 1 if the IPC flags are busy or \b 0 if designated
  135. //! IPC flags are free.
  136. //
  137. //*****************************************************************************
  138. Uint16
  139. IPCLtoRFlagBusy (uint32_t ulFlags)
  140. {
  141. Uint16 returnStatus;
  142. if ((IpcRegs.IPCFLG.all & ulFlags) == 0)
  143. {
  144. returnStatus = 0;
  145. }
  146. else
  147. {
  148. returnStatus = 1;
  149. }
  150. return returnStatus;
  151. }
  152. //*****************************************************************************
  153. //
  154. //! Local CPU Sets Local to Remote IPC Flag
  155. //!
  156. //! \param ulFlags specifies the IPC flag mask for flags being set.
  157. //!
  158. //! This function will allow the Local CPU system to set the designated IPC
  159. //! flags to send to the Remote CPU system. The \e ulFlags parameter can be any
  160. //! of the IPC flag values: \b IPC_FLAG0 - \b IPC_FLAG31.
  161. //!
  162. //! \return None.
  163. //
  164. //*****************************************************************************
  165. void
  166. IPCLtoRFlagSet (uint32_t ulFlags)
  167. {
  168. IpcRegs.IPCSET.all |= ulFlags;
  169. }
  170. //*****************************************************************************
  171. //
  172. //! Local CPU Clears Local to Remote IPC Flag
  173. //!
  174. //! \param ulFlags specifies the IPC flag mask for flags being set.
  175. //!
  176. //! This function will allow the Local CPU system to set the designated IPC
  177. //! flags to send to the Remote CPU system. The \e ulFlags parameter can be any
  178. //! of the IPC flag values: \b IPC_FLAG0 - \b IPC_FLAG31.
  179. //!
  180. //! \return None.
  181. //
  182. //*****************************************************************************
  183. void
  184. IPCLtoRFlagClear (uint32_t ulFlags)
  185. {
  186. IpcRegs.IPCCLR.all |= ulFlags;
  187. }
  188. //*****************************************************************************
  189. //
  190. //! Local Return CPU02 BOOT status
  191. //!
  192. //! This function returns the value at IPCBOOTSTS register.
  193. //!
  194. //! \return Boot status.
  195. //
  196. //*****************************************************************************
  197. uint32_t
  198. IPCGetBootStatus (void)
  199. {
  200. return(IpcRegs.IPCBOOTSTS);
  201. }
  202. #if defined (CPU1)
  203. //*****************************************************************************
  204. //! Executes a CPU02 control system bootloader.
  205. //!
  206. //! \param ulBootMode specifies which CPU02 control system boot mode to execute.
  207. //!
  208. //! This function will allow the CPU01 master system to boot the CPU02 control
  209. //! system via the following modes: Boot to RAM, Boot to Flash, Boot via SPI,
  210. //! SCI, I2C, or parallel I/O. Unlike other IPCLite driver functions, this
  211. //! function blocks and waits until the control system boot ROM is configured
  212. //! and ready to receive CPU01 to CPU02 IPC INT0 interrupts. It then blocks and
  213. //! waits until IPC INT0 and IPC FLAG31 are available in the CPU02 boot ROM
  214. //! prior to sending the command to execute the selected bootloader. The \e
  215. //! ulBootMode parameter accepts one of the following values: \b
  216. //! C1C2_BROM_BOOTMODE_BOOT_FROM_PARALLEL, \b
  217. //! C1C2_BROM_BOOTMODE_BOOT_FROM_SCI, \b
  218. //! C1C2_BROM_BOOTMODE_BOOT_FROM_SPI, \b
  219. //! C1C2_BROM_BOOTMODE_BOOT_FROM_I2C, \b C1C2_BROM_BOOTMODE_BOOT_FROM_CAN,
  220. //! \b C1C2_BROM_BOOTMODE_BOOT_FROM_RAM, \b
  221. //! C1C2_BROM_BOOTMODE_BOOT_FROM_FLASH.
  222. //!
  223. //! \return 0 (success) if command is sent, or 1 (failure) if boot mode is
  224. //! invalid and command was not sent.
  225. //
  226. //*****************************************************************************
  227. uint16_t
  228. IPCBootCPU2(uint32_t ulBootMode)
  229. {
  230. uint32_t bootStatus;
  231. uint16_t pin;
  232. uint16_t returnStatus = STATUS_PASS;
  233. //
  234. // If CPU2 has already booted, return a fail to let the application
  235. // know that something is out of the ordinary.
  236. //
  237. bootStatus = IPCGetBootStatus() & 0x0000000F;
  238. if(bootStatus == C2_BOOTROM_BOOTSTS_C2TOC1_BOOT_CMD_ACK)
  239. {
  240. //
  241. // Check if MSB is set as well
  242. //
  243. bootStatus = ((uint32_t)(IPCGetBootStatus() & 0x80000000)) >> 31U;
  244. if(bootStatus != 0)
  245. {
  246. returnStatus = STATUS_FAIL;
  247. return returnStatus;
  248. }
  249. }
  250. //
  251. // Wait until CPU02 control system boot ROM is ready to receive
  252. // CPU01 to CPU02 INT1 interrupts.
  253. //
  254. do
  255. {
  256. bootStatus = IPCGetBootStatus() & C2_BOOTROM_BOOTSTS_SYSTEM_READY;
  257. } while ((bootStatus != C2_BOOTROM_BOOTSTS_SYSTEM_READY));
  258. //
  259. // Loop until CPU02 control system IPC flags 1 and 32 are available
  260. //
  261. while ((IPCLtoRFlagBusy(IPC_FLAG0) == 1) ||
  262. (IPCLtoRFlagBusy(IPC_FLAG31) == 1))
  263. {
  264. }
  265. if (ulBootMode >= C1C2_BROM_BOOTMODE_BOOT_COMMAND_MAX_SUPPORT_VALUE)
  266. {
  267. returnStatus = STATUS_FAIL;
  268. }
  269. else
  270. {
  271. //
  272. // Based on boot mode, enable pull-ups on peripheral pins and
  273. // give GPIO pin control to CPU02 control system.
  274. //
  275. switch (ulBootMode)
  276. {
  277. case C1C2_BROM_BOOTMODE_BOOT_FROM_SCI:
  278. EALLOW;
  279. //
  280. //SCIA connected to CPU02
  281. //
  282. DevCfgRegs.CPUSEL5.bit.SCI_A = 1;
  283. //
  284. //Allows CPU02 bootrom to take control of clock
  285. //configuration registers
  286. //
  287. ClkCfgRegs.CLKSEM.all = 0xA5A50000;
  288. ClkCfgRegs.LOSPCP.all = 0x0002;
  289. EDIS;
  290. GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);
  291. GPIO_SetupPinMux(29,GPIO_MUX_CPU2,1);
  292. GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_ASYNC);
  293. GPIO_SetupPinMux(28,GPIO_MUX_CPU2,1);
  294. break;
  295. case C1C2_BROM_BOOTMODE_BOOT_FROM_SPI:
  296. EALLOW;
  297. //
  298. //SPI-A connected to CPU02
  299. //
  300. DevCfgRegs.CPUSEL6.bit.SPI_A = 1;
  301. //
  302. //Allows CPU02 bootrom to take control of clock configuration
  303. // registers
  304. //
  305. ClkCfgRegs.CLKSEM.all = 0xA5A50000;
  306. EDIS;
  307. GPIO_SetupPinOptions(16, GPIO_INPUT, GPIO_ASYNC);
  308. GPIO_SetupPinMux(16,GPIO_MUX_CPU2,1);
  309. GPIO_SetupPinOptions(17, GPIO_INPUT, GPIO_ASYNC);
  310. GPIO_SetupPinMux(17,GPIO_MUX_CPU2,1);
  311. GPIO_SetupPinOptions(18, GPIO_INPUT, GPIO_ASYNC);
  312. GPIO_SetupPinMux(18,GPIO_MUX_CPU2,1);
  313. GPIO_SetupPinOptions(19, GPIO_OUTPUT, GPIO_ASYNC);
  314. GPIO_SetupPinMux(19,GPIO_MUX_CPU2,0);
  315. break;
  316. case C1C2_BROM_BOOTMODE_BOOT_FROM_I2C:
  317. EALLOW;
  318. //
  319. //I2CA connected to CPU02
  320. //
  321. DevCfgRegs.CPUSEL7.bit.I2C_A = 1;
  322. //
  323. //Allows CPU2 bootrom to take control of clock
  324. //configuration registers
  325. //
  326. ClkCfgRegs.CLKSEM.all = 0xA5A50000;
  327. ClkCfgRegs.LOSPCP.all = 0x0002;
  328. EDIS;
  329. GPIO_SetupPinOptions(32, GPIO_INPUT, GPIO_ASYNC);
  330. GPIO_SetupPinMux(32,GPIO_MUX_CPU2,1);
  331. GPIO_SetupPinOptions(33, GPIO_INPUT, GPIO_ASYNC);
  332. GPIO_SetupPinMux(33,GPIO_MUX_CPU2,1);
  333. break;
  334. case C1C2_BROM_BOOTMODE_BOOT_FROM_PARALLEL:
  335. for(pin=58;pin<=65;pin++)
  336. {
  337. GPIO_SetupPinOptions(pin, GPIO_INPUT, GPIO_ASYNC);
  338. GPIO_SetupPinMux(pin,GPIO_MUX_CPU2,0);
  339. }
  340. GPIO_SetupPinOptions(69, GPIO_OUTPUT, GPIO_ASYNC);
  341. GPIO_SetupPinMux(69,GPIO_MUX_CPU2,0);
  342. GPIO_SetupPinOptions(70, GPIO_INPUT, GPIO_ASYNC);
  343. GPIO_SetupPinMux(70,GPIO_MUX_CPU2,0);
  344. break;
  345. case C1C2_BROM_BOOTMODE_BOOT_FROM_CAN:
  346. //
  347. //Set up the GPIO mux to bring out CANATX on GPIO71
  348. //and CANARX on GPIO70
  349. //
  350. EALLOW;
  351. GpioCtrlRegs.GPCLOCK.all = 0x00000000; //Unlock GPIOs 64-95
  352. //
  353. //Give CPU2 control just in case
  354. //
  355. GpioCtrlRegs.GPCCSEL1.bit.GPIO71 = GPIO_MUX_CPU2;
  356. //
  357. //Set the extended mux to 0x5
  358. //
  359. GpioCtrlRegs.GPCGMUX1.bit.GPIO71 = 0x1;
  360. GpioCtrlRegs.GPCMUX1.bit.GPIO71 = 0x1;
  361. //
  362. //Set qualification to async just in case
  363. //
  364. GpioCtrlRegs.GPCQSEL1.bit.GPIO71 = 0x3;
  365. GpioCtrlRegs.GPCLOCK.all = 0x00000000; //Unlock GPIOs 64-95
  366. //
  367. //Give CPU2 control just in case
  368. //
  369. GpioCtrlRegs.GPCCSEL1.bit.GPIO70 = GPIO_MUX_CPU2;
  370. //
  371. //Set the extended mux to bring out CANATX
  372. //
  373. GpioCtrlRegs.GPCGMUX1.bit.GPIO70 = 0x1;
  374. GpioCtrlRegs.GPCMUX1.bit.GPIO70 = 0x1;
  375. //
  376. //Set qualification to async just in case
  377. //
  378. GpioCtrlRegs.GPCQSEL1.bit.GPIO70 = 0x3;
  379. GpioCtrlRegs.GPCLOCK.all = 0xFFFFFFFF; //Lock GPIOs 64-95
  380. ClkCfgRegs.CLKSRCCTL2.bit.CANABCLKSEL = 0x0;
  381. CpuSysRegs.PCLKCR10.bit.CAN_A = 1;
  382. EDIS;
  383. break;
  384. }
  385. //
  386. //CPU01 to CPU02 IPC Boot Mode Register
  387. //
  388. IpcRegs.IPCBOOTMODE = ulBootMode;
  389. //
  390. // CPU01 To CPU02 IPC Command Register
  391. //
  392. IpcRegs.IPCSENDCOM = BROM_IPC_EXECUTE_BOOTMODE_CMD;
  393. //
  394. // CPU01 to CPU02 IPC flag register
  395. //
  396. IpcRegs.IPCSET.all = 0x80000001;
  397. }
  398. return returnStatus;
  399. }
  400. #endif
  401. //*****************************************************************************
  402. // Close the Doxygen group.
  403. //! @}
  404. //*****************************************************************************