F2837xD_Ipc_Driver_Lite.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. //###########################################################################
  2. //
  3. // FILE: F2837xD_Ipc_Driver_Lite.c
  4. //
  5. // TITLE: F2837xD Inter-Processor Communication (IPC) Lite API Driver
  6. // Functions.
  7. //
  8. // DESCRIPTION:
  9. // API functions for inter-processor communications between
  10. // CPU1 control system and CPU2 control system (Lite version). The IPC
  11. // Lite functions only allow for basic functions such as data writes,
  12. // reads, bit setting, and bit clearing. The Lite functions do not
  13. // require the usage of the MSG RAM's or shared memories and can only
  14. // be used with a single IPC interrupt channel. Commands can only
  15. // be processed one at a time without queuing.
  16. // The driver functions in this file are available only as
  17. // sample functions for application development. Due to the generic
  18. // nature of these functions and the cycle overhead inherent to a
  19. // function call, the code is not intended to be used in cases where
  20. // maximum efficiency is required in a system.
  21. //
  22. // NOTE: This source code is used by both CPUs. That is both CPU1 and CPU2
  23. // cores use this code.
  24. // The active debug CPU will be referred to as Local CPU and the other
  25. // CPU will be referred to as Remote CPU.
  26. // When using this source code in CPU1, the term "local"
  27. // will mean CPU1 and the term "remote" CPU will be mean CPU2.
  28. // When using this source code in CPU2, the term "local"
  29. // will mean CPU2 and the term "remote" CPU will be mean CPU1.
  30. //
  31. // The abbreviations LtoR and RtoL within the function names mean
  32. // Local to Remote and Remote to Local respectively.
  33. //
  34. //###########################################################################
  35. // $TI Release: F2837xD Support Library v3.05.00.00 $
  36. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  37. // $Copyright:
  38. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  39. //
  40. // Redistribution and use in source and binary forms, with or without
  41. // modification, are permitted provided that the following conditions
  42. // are met:
  43. //
  44. // Redistributions of source code must retain the above copyright
  45. // notice, this list of conditions and the following disclaimer.
  46. //
  47. // Redistributions in binary form must reproduce the above copyright
  48. // notice, this list of conditions and the following disclaimer in the
  49. // documentation and/or other materials provided with the
  50. // distribution.
  51. //
  52. // Neither the name of Texas Instruments Incorporated nor the names of
  53. // its contributors may be used to endorse or promote products derived
  54. // from this software without specific prior written permission.
  55. //
  56. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  57. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  58. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  59. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  60. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  61. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  62. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  63. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  64. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  66. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. // $
  68. //###########################################################################
  69. //*****************************************************************************
  70. //! \addtogroup ipc_lite_api IPC-Lite API Drivers
  71. //! @{
  72. //*****************************************************************************
  73. #include "F2837xD_device.h"
  74. #include "F2837xD_Ipc_drivers.h"
  75. //
  76. // Function Prototypes
  77. //
  78. void DelayLoop (void);
  79. //*****************************************************************************
  80. //
  81. //! Reads single word data result of Local to Remote IPC command
  82. //!
  83. //! \param pvData is a pointer to the 16/32-bit variable where the result data
  84. //! will be stored.
  85. //! \param usLength designates 16- or 32-bit read.
  86. //! \param ulStatusFlag indicates the Local to Remote CPU Flag number mask used
  87. //! to report the status of the command sent back from the Remote CPU. If
  88. //! a status flag was not used with the command call, set this parameter to 0.
  89. //!
  90. //! Allows the caller to read the 16/32-bit data result of non-blocking IPC
  91. //! functions from the IPCREMOTEREPLY register if the status flag is cleared
  92. //! indicating the IPC command was successfully interpreted. If the status flag
  93. //! is not cleared, the command was not recognized, and the function will
  94. //! return STATUS_FAIL. To determine what data is read from a call to this
  95. //! function, see the descriptions of the non-blocking IPC functions.
  96. //! The \e usLength parameter accepts the following values: \b
  97. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  98. //! accepts any of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  99. //! The function returns \b STATUS_PASS or \b STATUS_FAIL.
  100. //!
  101. //! \return status of command (0=success, 1=error)
  102. //
  103. //*****************************************************************************
  104. uint16_t
  105. IPCLiteLtoRGetResult (void *pvData, uint16_t usLength, uint32_t ulStatusFlag)
  106. {
  107. uint16_t returnStatus;
  108. //
  109. // If Remote System never acknowledged Status Task, indicates command
  110. // failure.
  111. //
  112. if (IpcRegs.IPCFLG.all & ulStatusFlag)
  113. {
  114. returnStatus = STATUS_FAIL;
  115. }
  116. else
  117. {
  118. //
  119. // Read data.
  120. //
  121. if (usLength == IPC_LENGTH_16_BITS)
  122. {
  123. *(uint16_t *)pvData = IpcRegs.IPCREMOTEREPLY;
  124. }
  125. else if (usLength == IPC_LENGTH_32_BITS)
  126. {
  127. *(uint32_t *)pvData = IpcRegs.IPCREMOTEREPLY;
  128. }
  129. returnStatus = STATUS_PASS;
  130. }
  131. return returnStatus;
  132. }
  133. //*****************************************************************************
  134. //
  135. //! Reads either a 16- or 32-bit data word from the remote CPU System address
  136. //!
  137. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  138. //! indicate a command is being sent.
  139. //! \param ulAddress specifies the remote address to read from
  140. //! \param usLength designates 16- or 32-bit read (1 = 16-bit, 2 = 32-bit)
  141. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  142. //! report the status of the command sent back from the remote system.
  143. //!
  144. //! This function will allow the Local CPU System to read 16/32-bit data from
  145. //! the Remote CPU System into the IPCREMOTEREPLY register. After calling this
  146. //! function, a call to \e IPCLiteLtoRGetResult() will read the data value in
  147. //! the IPCREMOTEREPLY register into a 16- or 32-bit variable in the local CPU
  148. //! application.
  149. //! The \e usLength parameter accepts the following values: \b
  150. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  151. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  152. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  153. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  154. //!
  155. //! \return status of command (0=success, 1=error)
  156. //
  157. //*****************************************************************************
  158. uint16_t
  159. IPCLiteLtoRDataRead(uint32_t ulFlag, uint32_t ulAddress, uint16_t usLength,
  160. uint32_t ulStatusFlag)
  161. {
  162. uint16_t returnStatus;
  163. //
  164. // Return false if IPC Local to Remote request or status flags are not
  165. // available.
  166. //
  167. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  168. {
  169. returnStatus = STATUS_FAIL;
  170. }
  171. else
  172. {
  173. //
  174. // Set up read command, address, and word length.
  175. //
  176. if (usLength == IPC_LENGTH_16_BITS)
  177. {
  178. IpcRegs.IPCSENDCOM = IPC_DATA_READ_16;
  179. }
  180. else if (usLength == IPC_LENGTH_32_BITS)
  181. {
  182. IpcRegs.IPCSENDCOM = IPC_DATA_READ_32;
  183. }
  184. IpcRegs.IPCSENDADDR = ulAddress;
  185. //
  186. // Force IPC event on selected request task and enable status-checking.
  187. //
  188. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  189. returnStatus = STATUS_PASS;
  190. }
  191. return returnStatus;
  192. }
  193. //*****************************************************************************
  194. //
  195. //! Sets the designated bits in a 16/32-bit data word at the remote CPU system
  196. //! address
  197. //!
  198. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  199. //! indicate a command is being sent.
  200. //! \param ulAddress specifies the Remote address to write to.
  201. //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
  202. //! remote ulAddress. For 16-bit mask, only the lower 16-bits of ulMask are
  203. //! considered.
  204. //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
  205. //! 32-bit).
  206. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  207. //! report the status of the command sent back from the Remote system.
  208. //!
  209. //! This function will allow the Local CPU system to set bits specified by the
  210. //! \e usMask variable in a 16/32-bit word on the Remote CPU system. The data
  211. //! word at /e ulAddress after the set bits command is then read into the
  212. //! IPCREMOTEREPLY register. After calling this function, a call to \e
  213. //! IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
  214. //! register into a 16/32-bit variable in the Local CPU application.
  215. //! The \e usLength parameter accepts the following values: \b
  216. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  217. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  218. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  219. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  220. //!
  221. //! \return status of command (0=success, 1=error)
  222. //
  223. //*****************************************************************************
  224. uint16_t
  225. IPCLiteLtoRSetBits(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulMask,
  226. uint16_t usLength, uint32_t ulStatusFlag)
  227. {
  228. uint16_t returnStatus;
  229. //
  230. // Return false if IPC Local to Remote request or status flags are not
  231. // available.
  232. //
  233. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  234. {
  235. returnStatus = STATUS_FAIL;
  236. }
  237. else
  238. {
  239. if (usLength == IPC_LENGTH_16_BITS)
  240. {
  241. //
  242. // Set up 16-bit set bits command, address, and mask.
  243. //
  244. IpcRegs.IPCSENDCOM = IPC_SET_BITS_16;
  245. IpcRegs.IPCSENDADDR = ulAddress;
  246. IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
  247. }
  248. else if (usLength == IPC_LENGTH_32_BITS)
  249. {
  250. //
  251. // Set up 32-bit set bits command, address, and mask.
  252. //
  253. IpcRegs.IPCSENDCOM = IPC_SET_BITS_32;
  254. IpcRegs.IPCSENDADDR = ulAddress;
  255. IpcRegs.IPCSENDDATA = ulMask;
  256. }
  257. //
  258. // Force IPC event on selected request task and enable status-checking.
  259. //
  260. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  261. returnStatus = STATUS_PASS;
  262. }
  263. return returnStatus;
  264. }
  265. //*****************************************************************************
  266. //
  267. //! Sets the designated bits in a 16/32-bit write-protected data word at
  268. //! the Remote CPU system address
  269. //!
  270. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  271. //! indicate a command is being sent.
  272. //! \param ulAddress specifies the Remote CPU write-protected address to write
  273. //! to.
  274. //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
  275. //! Remote CPU ulAddress.For 16-bit mask, only the lower 16-bits of ulMask are
  276. //! considered.
  277. //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
  278. //! 32-bit).
  279. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  280. //! report the status of the command sent back from the Master system.
  281. //!
  282. //! This function will allow the Local CPU system to set bits specified by the
  283. //! \e usMask variable in a write-protected 16/32-bit word on the REmote CPU
  284. //! system.
  285. //! The data word at /e ulAddress after the set bits command is then read into
  286. //! the IPCREMOTEREPLY register. After calling this function, a call to
  287. //! \e IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
  288. //! register into a 16/32-bit variable in the Local application.
  289. //! The \e usLength parameter accepts the following values: \b
  290. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  291. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  292. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  293. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  294. //!
  295. //! \return status of command (0=success, 1=error)
  296. //
  297. //*****************************************************************************
  298. uint16_t
  299. IPCLiteLtoRSetBits_Protected (uint32_t ulFlag, uint32_t ulAddress,
  300. uint32_t ulMask, uint16_t usLength,
  301. uint32_t ulStatusFlag)
  302. {
  303. uint16_t returnStatus;
  304. //
  305. // Return false if IPC Local to Remote request or status flags are not
  306. // available.
  307. //
  308. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  309. {
  310. returnStatus = STATUS_FAIL;
  311. }
  312. else
  313. {
  314. if (usLength == IPC_LENGTH_16_BITS)
  315. {
  316. //
  317. // Set up 16-bit set bits command, address, and mask.
  318. //
  319. IpcRegs.IPCSENDCOM = IPC_SET_BITS_16_PROTECTED;
  320. IpcRegs.IPCSENDADDR = ulAddress;
  321. IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
  322. }
  323. else if (usLength == IPC_LENGTH_32_BITS)
  324. {
  325. //
  326. // Set up 32-bit set bits command, address, and mask.
  327. //
  328. IpcRegs.IPCSENDCOM = IPC_SET_BITS_32_PROTECTED;
  329. IpcRegs.IPCSENDADDR = ulAddress;
  330. IpcRegs.IPCSENDDATA = ulMask;
  331. }
  332. //
  333. // Force IPC event on selected request task and enable status-checking.
  334. //
  335. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  336. returnStatus = STATUS_PASS;
  337. }
  338. return returnStatus;
  339. }
  340. //*****************************************************************************
  341. //
  342. //! Sets the designated bits in a 16/32-bit data word at the remote CPU system
  343. //! address
  344. //!
  345. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  346. //! indicate a command is being sent.
  347. //! \param ulAddress specifies the Remote CPU address to write to.
  348. //! \param ulMask specifies the 16/32-bit mask for bits which should be set at
  349. //! the remote CPU ulAddress. (For 16-bit mask, only the lower 16-bits of
  350. //! ulMask are considered.
  351. //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
  352. //! 32-bit).
  353. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  354. //! report the status of the command sent back from the Master system.
  355. //!
  356. //! This function will allow the Local CPU system to set bits specified by the
  357. //! \e usMask variable in a 16/32-bit word on the Remote CPU system. The data
  358. //! word at /e ulAddress after the set bits command is then read into the
  359. //! IPCREMOTEREPLY register. After calling this function, a call to \e
  360. //! IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
  361. //! register into a 16/32-bit variable in the Local CPU application.
  362. //! The \e usLength parameter accepts the following values: \b
  363. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  364. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  365. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  366. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  367. //!
  368. //! \return status of command (0=success, 1=error)
  369. //
  370. //*****************************************************************************
  371. uint16_t
  372. IPCLiteLtoRClearBits(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulMask,
  373. uint16_t usLength, uint32_t ulStatusFlag)
  374. {
  375. uint16_t returnStatus;
  376. //
  377. // Return false if IPC Local to Remote request or status flags are not
  378. // available.
  379. //
  380. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  381. {
  382. returnStatus = STATUS_FAIL;
  383. }
  384. else
  385. {
  386. if (usLength == IPC_LENGTH_16_BITS)
  387. {
  388. //
  389. // Set up 16-bit set bits command, address, and mask.
  390. //
  391. IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_16;
  392. IpcRegs.IPCSENDADDR = ulAddress;
  393. IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
  394. }
  395. else if (usLength == IPC_LENGTH_32_BITS)
  396. {
  397. //
  398. // Set up 32-bit set bits command, address, and mask.
  399. //
  400. IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_32;
  401. IpcRegs.IPCSENDADDR = ulAddress;
  402. IpcRegs.IPCSENDDATA = ulMask;
  403. }
  404. //
  405. // Force IPC event on selected request task and enable status-checking.
  406. //
  407. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  408. returnStatus = STATUS_PASS;
  409. }
  410. return returnStatus;
  411. }
  412. //*****************************************************************************
  413. //
  414. //! Clears the designated bits in a 16/32-bit write-protected data word at
  415. //! Remote CPU system address
  416. //!
  417. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  418. //! indicate a command is being sent.
  419. //! \param ulAddress specifies the Remote CPU write-protected address to write
  420. //! to.
  421. //! \param ulMask specifies the 16/32-bit mask for bits which should be cleared
  422. //! at Remote CPU ulAddress.For 16-bit mask, only the lower 16-bits of ulMask
  423. //! are considered.
  424. //! \param usLength specifies the length of the \e ulMask (1 = 16-bit, 2 =
  425. //! 32-bit).
  426. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  427. //! report the status of the command sent back from the Master system.
  428. //!
  429. //! This function will allow the Local CPU system to clear bits specified by
  430. //! the \e usMask variable in a write-protected 16/32-bit word on the Remote
  431. //! CPU system.
  432. //! The data word at /e ulAddress after the clear bits command is then read
  433. //! into the IPCREMOTEREPLY register. After calling this function, a call to
  434. //! \e IPCLiteLtoRGetResult() will read the data value in the IPCREMOTEREPLY
  435. //! register into a 16/32-bit variable in the Local CPU application.
  436. //! The \e usLength parameter accepts the following values: \b
  437. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  438. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  439. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  440. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  441. //!
  442. //! \return status of command (0=success, 1=error)
  443. //
  444. //*****************************************************************************
  445. uint16_t
  446. IPCLiteLtoRClearBits_Protected (uint32_t ulFlag, uint32_t ulAddress,
  447. uint32_t ulMask, uint16_t usLength,
  448. uint32_t ulStatusFlag)
  449. {
  450. uint16_t returnStatus;
  451. //
  452. // Return false if IPC Local to Remote request or status flags are not
  453. // available.
  454. //
  455. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  456. {
  457. returnStatus = STATUS_FAIL;
  458. }
  459. else
  460. {
  461. if (usLength == IPC_LENGTH_16_BITS)
  462. {
  463. //
  464. // Set up 16-bit set bits command, address, and mask.
  465. //
  466. IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_16_PROTECTED;
  467. IpcRegs.IPCSENDADDR = ulAddress;
  468. IpcRegs.IPCSENDDATA = ulMask & (0x0000FFFF);
  469. }
  470. else if (usLength == IPC_LENGTH_32_BITS)
  471. {
  472. //
  473. // Set up 32-bit set bits command, address, and mask.
  474. //
  475. IpcRegs.IPCSENDCOM = IPC_CLEAR_BITS_32_PROTECTED;
  476. IpcRegs.IPCSENDADDR = ulAddress;
  477. IpcRegs.IPCSENDDATA = ulMask;
  478. }
  479. //
  480. // Force IPC event on selected request task and enable status-checking.
  481. //
  482. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  483. returnStatus = STATUS_PASS;
  484. }
  485. return returnStatus;
  486. }
  487. //*****************************************************************************
  488. //
  489. //! Writes a 16/32-bit data word to Remote CPU System address
  490. //!
  491. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  492. //! indicate a command is being sent.
  493. //! \param ulAddress specifies the Remote CPU address to write to
  494. //! \param ulData specifies the 16/32-bit word which will be written.
  495. //! For 16-bit words, only the lower 16-bits of ulData will be considered by
  496. //! the master system.
  497. //! \param usLength is the length of the word to write (0 = 16-bits, 1 =
  498. //! 32-bits)
  499. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  500. //! report the status of the command sent back from the Remote CPU system.
  501. //!
  502. //! This function will allow the Local CPU System to write a 16/32-bit word
  503. //! via the \e ulData variable to an address on the Remote CPU System.
  504. //! The \e usLength parameter accepts the following values: \b
  505. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  506. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  507. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  508. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  509. //!
  510. //! \return status of command (0=success, 1=error)
  511. //
  512. //*****************************************************************************
  513. uint16_t
  514. IPCLiteLtoRDataWrite(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulData,
  515. uint16_t usLength, uint32_t ulStatusFlag)
  516. {
  517. uint16_t returnStatus;
  518. //
  519. // Return false if IPC Local to Remote request or status flags are not
  520. // available.
  521. //
  522. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  523. {
  524. returnStatus = STATUS_FAIL;
  525. }
  526. else
  527. {
  528. //
  529. // Set up data write command, address, and data. For 16-bit write,
  530. // Master system will look at lower 16-bits only.
  531. //
  532. if (usLength == IPC_LENGTH_16_BITS)
  533. {
  534. IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_16;
  535. }
  536. else if (usLength == IPC_LENGTH_32_BITS)
  537. {
  538. IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_32;
  539. }
  540. IpcRegs.IPCSENDADDR = ulAddress;
  541. IpcRegs.IPCSENDDATA = ulData;
  542. //
  543. // Force IPC event on selected request task and enable status-checking
  544. //
  545. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  546. returnStatus = STATUS_PASS;
  547. }
  548. return returnStatus;
  549. }
  550. //*****************************************************************************
  551. //
  552. //! Writes a 16/32-bit data word to a protected Remote CPU System address
  553. //!
  554. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  555. //! indicate a command is being sent.
  556. //! \param ulAddress specifies the Remote CPU address to write to
  557. //! \param ulData specifies the 16/32-bit word which will be written.
  558. //! For 16-bit words, only the lower 16-bits of ulData will be considered by
  559. //! the master system.
  560. //! \param usLength is the length of the word to write (0 = 16-bits, 1 =
  561. //! 32-bits)
  562. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  563. //! report the status of the command sent back from the Master system.
  564. //!
  565. //! This function will allow the Local CPU System to write a 16/32-bit word
  566. //! via the \e ulData variable to a write-protected address on the Remote CPU
  567. //! System. The \e usLength parameter accepts the following values: \b
  568. //! IPC_LENGTH_16_BITS or \b IPC_LENGTH_32_BITS. The \e ulStatusFlag parameter
  569. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and \b
  570. //! NO_FLAG. The function returns \b STATUS_PASS if the command is successful
  571. //! or \b STATUS_FAIL if the request or status flags are unavailable.
  572. //!
  573. //! \return status of command (0=success, 1=error)
  574. //
  575. //*****************************************************************************
  576. uint16_t
  577. IPCLiteLtoRDataWrite_Protected(uint32_t ulFlag, uint32_t ulAddress,
  578. uint32_t ulData, uint16_t usLength,
  579. uint32_t ulStatusFlag)
  580. {
  581. uint16_t returnStatus;
  582. //
  583. // Return false if IPC Local to Remote request or status flags are not
  584. // available.
  585. //
  586. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  587. {
  588. returnStatus = STATUS_FAIL;
  589. }
  590. else
  591. {
  592. //
  593. // Set up data write command, address, and data. For 16-bit write, Master
  594. // system will look at lower 16-bits only.
  595. //
  596. if (usLength == IPC_LENGTH_16_BITS)
  597. {
  598. IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_16_PROTECTED;
  599. }
  600. else if (usLength == IPC_LENGTH_32_BITS)
  601. {
  602. IpcRegs.IPCSENDCOM = IPC_DATA_WRITE_32_PROTECTED;
  603. }
  604. IpcRegs.IPCSENDADDR = ulAddress;
  605. IpcRegs.IPCSENDDATA = ulData;
  606. //
  607. // Force IPC event on selected request task and enable status-checking
  608. //
  609. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  610. returnStatus = STATUS_PASS;
  611. }
  612. return returnStatus;
  613. }
  614. //*****************************************************************************
  615. //
  616. //! Calls a Remote CPU function with 1 optional parameter and an optional
  617. //! return value.
  618. //!
  619. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  620. //! indicate a command is being sent.
  621. //! \param ulAddress specifies the Remote CPU function address
  622. //! \param ulParam specifies the 32-bit optional parameter value
  623. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  624. //! report the status of the command sent back from the control system.
  625. //!
  626. //! This function will allow the Local CPU system to call a function on the
  627. //! Remote CPU. The \e ulParam variable is a single optional 32-bit parameter
  628. //! to pass to the function. The \e ulFlag parameter accepts any one of the
  629. //! flag values \b IPC_FLAG1 - \b IPC_FLAG32. The \e ulStatusFlag parameter
  630. //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32
  631. //! and \b NO_FLAG. The function returns \b STATUS_PASS if the command is
  632. //! successful or \b STATUS_FAIL if the request or status flags are unavailable.
  633. //!
  634. //! \return status of command (0=success, 1=error)
  635. //
  636. //*****************************************************************************
  637. uint16_t
  638. IPCLiteLtoRFunctionCall(uint32_t ulFlag, uint32_t ulAddress, uint32_t ulParam,
  639. uint32_t ulStatusFlag)
  640. {
  641. uint16_t returnStatus;
  642. //
  643. // Return false if IPC Remote to Local request or status flags are not
  644. // available.
  645. //
  646. if (IpcRegs.IPCFLG.all & (ulFlag | ulStatusFlag))
  647. {
  648. returnStatus = STATUS_FAIL;
  649. }
  650. else
  651. {
  652. //
  653. // Set up function call command, address, and parameter.
  654. //
  655. IpcRegs.IPCSENDCOM = IPC_FUNC_CALL;
  656. IpcRegs.IPCSENDADDR = ulAddress;
  657. IpcRegs.IPCSENDDATA = ulParam;
  658. //
  659. // Force IPC event on selected request task and enable status-checking
  660. //
  661. IpcRegs.IPCSET.all |= (ulFlag | ulStatusFlag);
  662. returnStatus = STATUS_PASS;
  663. }
  664. return returnStatus;
  665. }
  666. //*****************************************************************************
  667. //
  668. //! Slave Requests Master R/W/Exe Access to Shared SARAM.
  669. //!
  670. //! \param ulFlag specifies Local to Remote IPC Flag number mask used to
  671. //! indicate a command is being sent.
  672. //! \param ulMask specifies the 32-bit mask for the GSxMEMSEL RAM control
  673. //! register to indicate which GSx SARAM blocks the Slave is requesting master
  674. //! access to.
  675. //! \param ulMaster specifies whether CPU1 or CPU2 should be the master of the
  676. //! GSx RAM.
  677. //! \param ulStatusFlag indicates the Local to Remote Flag number mask used to
  678. //! report the status of the command sent back from the Master system.
  679. //!
  680. //! This function will allow the slave CPU System to request slave or master
  681. //! mastership of any of the GSx Shared SARAM blocks.
  682. //! The \e ulMaster parameter accepts the following values:
  683. //! \b IPC_GSX_CPU2_MASTER or \b IPC_GSX_CPU1_MASTER. The \e ulStatusFlag
  684. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32
  685. //! and \b NO_FLAG. The function returns \b STATUS_PASS if the command is
  686. //! successful or \b STATUS_FAIL if the request or status flags are unavailable.
  687. //! \note This function calls the \e IPCLiteLtoRSetBits_Protected() or the
  688. //! \e IPCLiteLtoRClearBits_Protected function, and therefore in order to
  689. //! process this function, the above 2 functions should be ready to be called
  690. //! on the master system to process this command.
  691. //!
  692. //! \return status of command (0=success, 1=error)
  693. //
  694. //*****************************************************************************
  695. uint16_t
  696. IPCLiteReqMemAccess (uint32_t ulFlag, uint32_t ulMask, uint16_t ulMaster,
  697. uint32_t ulStatusFlag)
  698. {
  699. uint16_t status;
  700. uint32_t GSxMSEL_REGaddress = (uint32_t)(&MemCfgRegs.GSxMSEL.all);
  701. if (ulMaster == IPC_GSX_CPU2_MASTER)
  702. {
  703. status =
  704. IPCLiteLtoRSetBits_Protected (ulFlag, GSxMSEL_REGaddress, ulMask,
  705. IPC_LENGTH_32_BITS,
  706. ulStatusFlag);
  707. }
  708. else if (ulMaster == IPC_GSX_CPU1_MASTER)
  709. {
  710. status =
  711. IPCLiteLtoRClearBits_Protected (ulFlag, GSxMSEL_REGaddress, ulMask,
  712. IPC_LENGTH_32_BITS,
  713. ulStatusFlag);
  714. }
  715. return status;
  716. }
  717. //*****************************************************************************
  718. //
  719. //! Reads either a 16- or 32-bit data word from the Local CPU system address
  720. //!
  721. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  722. //! indicate a command is being sent.
  723. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  724. //! report the status of the command sent back from the control system.
  725. //!
  726. //! This function will allow the Remote CPU system to read 16/32-bit data from
  727. //! the Local CPU system. The \e ulFlag parameter accepts any one of the
  728. //! flag values \b IPC_FLAG1 - \b IPC_FLAG32, and the \e ulStatusFlag parameter
  729. //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and
  730. //! \b NO_FLAG.
  731. //
  732. //*****************************************************************************
  733. void
  734. IPCLiteRtoLDataRead(uint32_t ulFlag, uint32_t ulStatusFlag)
  735. {
  736. uint32_t* pulRAddress;
  737. uint16_t* pusRAddress;
  738. //
  739. // Wait until IPC Remote to Local request task is flagged
  740. //
  741. while (!(IpcRegs.IPCSTS.all & ulFlag))
  742. {
  743. }
  744. //
  745. // If the command and data length are correct for this function:
  746. // Then read from requested address and write 16/32-bit data
  747. // to IPCLOCALREPLY. Acknowledge the status flag
  748. // and the task flag.
  749. //
  750. if (IpcRegs.IPCRECVCOM == IPC_DATA_READ_16)
  751. {
  752. //
  753. // Perform 16-bit read.
  754. //
  755. pusRAddress = (uint16_t *)IpcRegs.IPCRECVADDR;
  756. IpcRegs.IPCLOCALREPLY = (uint32_t)(*pusRAddress);
  757. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  758. }
  759. else if (IpcRegs.IPCRECVCOM == IPC_DATA_READ_32)
  760. {
  761. pulRAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
  762. IpcRegs.IPCLOCALREPLY = *pulRAddress;
  763. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  764. }
  765. //
  766. // Otherwise, only acknowledge the task flag.
  767. //(Indicates to Remote CPU there was an error)
  768. //
  769. else
  770. {
  771. IpcRegs.IPCACK.all |= (ulFlag);
  772. }
  773. }
  774. //*****************************************************************************
  775. //
  776. //! Sets the designated bits in a 16/32-bit data word at the Local CPU system
  777. //! address
  778. //!
  779. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  780. //! indicate a command is being sent.
  781. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  782. //! report the status of the command sent back from the control system.
  783. //!
  784. //! This function will allow the Remote CPU system to set bits specified by a
  785. //! mask variable in a 16/32-bit word on the Local CPU system, and then read
  786. //! back the word into the IPCLOCALREPLY register. The \e ulFlag parameter
  787. //! accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32, and the
  788. //! \e ulStatusFlag parameter accepts any other one of the flag values \b
  789. //! IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  790. //
  791. //*****************************************************************************
  792. void
  793. IPCLiteRtoLSetBits(uint32_t ulFlag, uint32_t ulStatusFlag)
  794. {
  795. uint16_t* pusAddress;
  796. uint32_t* pulAddress;
  797. //
  798. // Wait until IPC Remote to Local request task is flagged
  799. //
  800. while (!(IpcRegs.IPCSTS.all & ulFlag))
  801. {
  802. }
  803. //
  804. // If the command is correct for this function:
  805. // Then set the mask bits at the requested address
  806. // and write back the 16/32-bit data to IPCLOCALREPLY.
  807. // Acknowledge the status flag and the task flag.
  808. //
  809. if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_16)
  810. {
  811. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
  812. *pusAddress |= (uint16_t)IpcRegs.IPCRECVDATA;
  813. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  814. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  815. }
  816. else if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_32)
  817. {
  818. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
  819. *pulAddress |= (uint32_t)IpcRegs.IPCRECVDATA;
  820. IpcRegs.IPCLOCALREPLY = *pulAddress;
  821. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  822. }
  823. //
  824. // Otherwise, only acknowledge the task flag.
  825. // (Indicates to Remote CPU there was an error)
  826. //
  827. else
  828. {
  829. IpcRegs.IPCACK.all |= (ulFlag);
  830. }
  831. }
  832. //*****************************************************************************
  833. //
  834. //! Sets the designated bits in a 16-bit data word at the Local CPU system
  835. //! write-protected address
  836. //!
  837. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  838. //! indicate a command is being sent.
  839. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  840. //! report the status of the command sent back from the control system.
  841. //!
  842. //! This function will allow the Remote CPU system to set bits specified by a
  843. //! mask variable in a write-protected 16/32-bit word on the Local CPU system,
  844. //! and then read back the word into the IPCLOCALREPLY register. The \e ulFlag
  845. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
  846. //! and the \e ulStatusFlag parameter accepts any other one of the flag values
  847. //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  848. //
  849. //*****************************************************************************
  850. void
  851. IPCLiteRtoLSetBits_Protected (uint32_t ulFlag, uint32_t ulStatusFlag)
  852. {
  853. uint16_t* pusAddress;
  854. uint32_t* pulAddress;
  855. //
  856. // Wait until IPC Remote to Local request task is flagged
  857. //
  858. while (!(IpcRegs.IPCSTS.all & ulFlag))
  859. {
  860. }
  861. //
  862. // If the command is correct for this function:
  863. // Then enable write access with EALLOW and
  864. // set the mask bits at the requested address.
  865. // Write back the 16-bit data to IPCLOCALREPLY.
  866. // Restore write-protection with EDIS.
  867. // Acknowledge the status flag and the task flag.
  868. //
  869. EALLOW;
  870. if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_16_PROTECTED)
  871. {
  872. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;
  873. *pusAddress |= (uint16_t)IpcRegs.IPCRECVDATA;
  874. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  875. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  876. }
  877. else if (IpcRegs.IPCRECVCOM == IPC_SET_BITS_32_PROTECTED)
  878. {
  879. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
  880. *pulAddress |= (uint32_t)IpcRegs.IPCRECVDATA;
  881. IpcRegs.IPCLOCALREPLY = *pulAddress;
  882. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  883. }
  884. //
  885. // Otherwise, only acknowledge the task flag.
  886. //(Indicates to the Remote CPU there was an error)
  887. //
  888. else
  889. {
  890. IpcRegs.IPCACK.all |= (ulFlag);
  891. }
  892. EDIS;
  893. }
  894. //*****************************************************************************
  895. //
  896. //! Clears the designated bits in a 16/32-bit data word at Local CPU system
  897. //! address
  898. //!
  899. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  900. //! indicate a command is being sent.
  901. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  902. //! report the status of the command sent back from the control system.
  903. //!
  904. //! This function will allow the Remote CPU system to clear bits specified by a
  905. //! mask variable in a 16/32-bit word on the Local CPU system, and then read
  906. //! back the word into the IPCLOCALREPLY register. The \e ulFlag
  907. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
  908. //! and the \e ulStatusFlag parameter accepts any other one of the flag values
  909. //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  910. //
  911. //*****************************************************************************
  912. void
  913. IPCLiteRtoLClearBits(uint32_t ulFlag, uint32_t ulStatusFlag)
  914. {
  915. uint16_t* pusAddress;
  916. uint32_t* pulAddress;
  917. //
  918. // Wait until IPC Remote to Local request task is flagged
  919. //
  920. while (!(IpcRegs.IPCSTS.all & ulFlag))
  921. {
  922. }
  923. //
  924. // If the command is correct for this function:
  925. // Then clear the mask bits at the requested address
  926. // and write back the 16/32-bit data to IPCLOCALREPLY.
  927. // Acknowledge the status flag and the task flag.
  928. //
  929. if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_16)
  930. {
  931. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
  932. *pusAddress &= ~((uint16_t)IpcRegs.IPCRECVDATA);
  933. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  934. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  935. }
  936. else if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_32)
  937. {
  938. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
  939. *pulAddress &= ~((uint32_t)IpcRegs.IPCRECVDATA);
  940. IpcRegs.IPCLOCALREPLY = *pulAddress;
  941. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  942. }
  943. //
  944. // Otherwise, only acknowledge the task flag.
  945. // (Indicates to Remote CPU there was an error)
  946. //
  947. else
  948. {
  949. IpcRegs.IPCACK.all |= (ulFlag);
  950. }
  951. }
  952. //*****************************************************************************
  953. //
  954. //! Clears the designated bits in a 16/32-bit data word at the Local CPU system
  955. //! write-protected address
  956. //!
  957. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  958. //! indicate a command is being sent.
  959. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  960. //! report the status of the command sent back from the control system.
  961. //!
  962. //! This function will allow the Remote CPU system to clear bits specified by a
  963. //! mask variable in a 16/32-bit word on the Local CPU system, and then read
  964. //! back the word into the IPCLOCALREPLY register. The \e ulFlag
  965. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
  966. //! and the \e ulStatusFlag parameter accepts any other one of the flag values
  967. //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  968. //
  969. //*****************************************************************************
  970. void
  971. IPCLiteRtoLClearBits_Protected (uint32_t ulFlag, uint32_t ulStatusFlag)
  972. {
  973. uint16_t* pusAddress;
  974. uint32_t* pulAddress;
  975. //
  976. // Wait until IPC Remote to Local request task is flagged
  977. //
  978. while (!(IpcRegs.IPCSTS.all & ulFlag))
  979. {
  980. }
  981. //
  982. // If the command is correct for this function:
  983. // Then enable write access with EALLOW and
  984. // clear the mask bits at the requested address.
  985. // Write back the 16/32-bit data to IPCLOCALREPLY.
  986. // Restore the status of the EALLOW register.
  987. // Acknowledge the status flag and the task flag.
  988. //
  989. EALLOW;
  990. if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_16_PROTECTED)
  991. {
  992. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
  993. *pusAddress &= ~((uint16_t)IpcRegs.IPCRECVDATA);
  994. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  995. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  996. }
  997. else if (IpcRegs.IPCRECVCOM == IPC_CLEAR_BITS_32_PROTECTED)
  998. {
  999. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
  1000. *pulAddress &= ~((uint32_t)IpcRegs.IPCRECVDATA);
  1001. IpcRegs.IPCLOCALREPLY = (uint32_t)*pulAddress;
  1002. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1003. }
  1004. //
  1005. // Otherwise, only acknowledge the task flag.
  1006. // (Indicates to Remote CPU there was an error)
  1007. //
  1008. else
  1009. {
  1010. IpcRegs.IPCACK.all |= (ulFlag);
  1011. }
  1012. EDIS;
  1013. }
  1014. //*****************************************************************************
  1015. //
  1016. //! Writes a 16/32-bit data word to Local CPU system address
  1017. //!
  1018. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  1019. //! indicate a command is being sent.
  1020. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  1021. //! report the status of the command sent back from the control system.
  1022. //!
  1023. //! This function will allow the Remote CPU system to write a 16/32-bit word
  1024. //! to an address on the Local CPU system. The \e ulFlag
  1025. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
  1026. //! and the \e ulStatusFlag parameter accepts any other one of the flag values
  1027. //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  1028. //
  1029. //*****************************************************************************
  1030. void
  1031. IPCLiteRtoLDataWrite(uint32_t ulFlag, uint32_t ulStatusFlag)
  1032. {
  1033. uint32_t* pulAddress;
  1034. uint16_t* pusAddress;
  1035. //
  1036. // Wait until IPC Remote to Local request task is flagged
  1037. //
  1038. while (!(IpcRegs.IPCSTS.all & ulFlag))
  1039. {
  1040. }
  1041. //
  1042. // If the command is correct for this function:
  1043. // Then write the 16/32-bit data to the requested address
  1044. // and write back the 16/32-bit data to IPCLOCALREPLY.
  1045. // Acknowledge the status flag and the task flag.
  1046. //
  1047. if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_16)
  1048. {
  1049. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
  1050. *pusAddress = (uint16_t)IpcRegs.IPCRECVDATA;
  1051. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  1052. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1053. }
  1054. else if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_32)
  1055. {
  1056. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;;
  1057. *pulAddress = IpcRegs.IPCRECVDATA;
  1058. IpcRegs.IPCLOCALREPLY = *pulAddress;
  1059. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1060. }
  1061. //
  1062. // Otherwise, only acknowledge the task flag.
  1063. // (Indicates to Remote CPU there was an error)
  1064. //
  1065. else
  1066. {
  1067. IpcRegs.IPCACK.all |= (ulFlag);
  1068. }
  1069. }
  1070. //*****************************************************************************
  1071. //
  1072. //! Writes a 16/32-bit data word to a write-protected Local CPU system address
  1073. //!
  1074. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  1075. //! indicate a command is being sent.
  1076. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  1077. //! report the status of the command sent back from the control system.
  1078. //!
  1079. //! This function will allow the Remote CPU system to write a 16/32-bit word
  1080. //! to an address on the Local CPU system. The \e ulFlag
  1081. //! parameter accepts any one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32,
  1082. //! and the \e ulStatusFlag parameter accepts any other one of the flag values
  1083. //! \b IPC_FLAG1 - \b IPC_FLAG32 and \b NO_FLAG.
  1084. //
  1085. //*****************************************************************************
  1086. void
  1087. IPCLiteRtoLDataWrite_Protected(uint32_t ulFlag, uint32_t ulStatusFlag)
  1088. {
  1089. uint32_t* pulAddress;
  1090. uint16_t* pusAddress;
  1091. //
  1092. // Wait until IPC Remote to Local request task is flagged
  1093. //
  1094. while (!(IpcRegs.IPCSTS.all & ulFlag))
  1095. {
  1096. }
  1097. //
  1098. // If the command is correct for this function:
  1099. // Then enable write access with EALLOW and
  1100. // write the 16/32-bit data to the requested address
  1101. // and write back the 16/32-bit data to IPCLOCALREPLY.
  1102. // Acknowledge the status flag and the task flag.
  1103. //
  1104. EALLOW;
  1105. if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_16_PROTECTED)
  1106. {
  1107. pusAddress = (uint16_t *)IpcRegs.IPCRECVADDR;;
  1108. *pusAddress = (uint16_t)IpcRegs.IPCRECVDATA;
  1109. IpcRegs.IPCLOCALREPLY = (uint32_t)*pusAddress;
  1110. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1111. }
  1112. else if (IpcRegs.IPCRECVCOM == IPC_DATA_WRITE_32_PROTECTED)
  1113. {
  1114. pulAddress = (uint32_t *)IpcRegs.IPCRECVADDR;
  1115. *pulAddress = IpcRegs.IPCRECVDATA;
  1116. IpcRegs.IPCLOCALREPLY = *pulAddress;
  1117. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1118. }
  1119. //
  1120. // Otherwise, only acknowledge the task flag.
  1121. // (Indicates to Remote CPU there was an error)
  1122. //
  1123. else
  1124. {
  1125. IpcRegs.IPCACK.all |= (ulFlag);
  1126. }
  1127. //
  1128. // Restore write-protection status.
  1129. //
  1130. EDIS;
  1131. }
  1132. //*****************************************************************************
  1133. //
  1134. //! Calls a Local CPU function with a single optional parameter and return
  1135. //! value.
  1136. //!
  1137. //! \param ulFlag specifies Remote to Local IPC Flag number mask used to
  1138. //! indicate a command is being sent.
  1139. //! \param ulStatusFlag indicates the Remote to Local Flag number mask used to
  1140. //! report the status of the command sent back from the control system.
  1141. //!
  1142. //! This function will allow the Remote CPU system to call a Local CPU function
  1143. //! with a single optional parameter and places an optional return value in the
  1144. //! IPCLOCALREPLY register. The \e ulFlag parameter accepts any one of the flag
  1145. //! values \b IPC_FLAG1 - \b IPC_FLAG32, and the \e ulStatusFlag parameter
  1146. //! accepts any other one of the flag values \b IPC_FLAG1 - \b IPC_FLAG32 and
  1147. //! \b NO_FLAG.
  1148. //
  1149. //*****************************************************************************
  1150. void
  1151. IPCLiteRtoLFunctionCall(uint32_t ulFlag, uint32_t ulStatusFlag)
  1152. {
  1153. //
  1154. // Wait until IPC Remote to Local request task is flagged
  1155. //
  1156. while (!(IpcRegs.IPCSTS.all & ulFlag))
  1157. {
  1158. }
  1159. //
  1160. // If the command is correct for this function:
  1161. // Then call function at requested address
  1162. // and if there is a return value, insert into
  1163. // IPCLOCALREPLY register.
  1164. // Acknowledge the status flag and the task flag.
  1165. //
  1166. if (IpcRegs.IPCRECVCOM == IPC_FUNC_CALL)
  1167. {
  1168. tfIpcFuncCall func_call = (tfIpcFuncCall)IpcRegs.IPCRECVADDR;
  1169. IpcRegs.IPCLOCALREPLY = func_call(IpcRegs.IPCRECVDATA);
  1170. IpcRegs.IPCACK.all |= (ulStatusFlag | ulFlag);
  1171. }
  1172. //
  1173. // Otherwise, only acknowledge the task flag.
  1174. //(Indicates to Remote CPU there was an error)
  1175. //
  1176. else
  1177. {
  1178. IpcRegs.IPCACK.all |= (ulFlag);
  1179. }
  1180. }
  1181. void DelayLoop (void)
  1182. {
  1183. __asm(" nop");
  1184. __asm(" nop");
  1185. __asm(" nop");
  1186. __asm(" nop");
  1187. __asm(" nop");
  1188. }
  1189. //*****************************************************************************
  1190. // Close the Doxygen group.
  1191. //! @}
  1192. //*****************************************************************************