csl_semAux.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /**
  2. * @file csl_semAux.h
  3. *
  4. * @brief
  5. * This is the SEM Auxilary Header File which exposes the various
  6. * CSL Functional Layer API's to configure the SEM Module.
  7. *
  8. * \par
  9. * ============================================================================
  10. * @n (C) Copyright 2008-2012, Texas Instruments, Inc.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef CSL_SEMAUX_H_
  42. #define CSL_SEMAUX_H_
  43. #if !(defined(SOC_OMAPL137) || defined(SOC_OMAPL138))
  44. #include <ti/csl/csl_sem.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /** @addtogroup CSL_SEM_FUNCTION
  49. @{ */
  50. /** ============================================================================
  51. * @n@b CSL_semSetEoi
  52. *
  53. * @b Description
  54. * @n This function sets the SEM Module EOI Register to rearm the interrupt line
  55. * after processing an existing interrupt.
  56. *
  57. * @b Arguments
  58. @verbatim
  59. eoiVal Value to be written to the EOI register.
  60. @endverbatim
  61. *
  62. * <b> Return Value </b>
  63. * @n None
  64. *
  65. * <b> Pre Condition </b>
  66. * @n None
  67. *
  68. * @b Writes
  69. * @n SEM_SEM_EOI_SELECT_INTERRUPT_REARM
  70. *
  71. * <b> Post Condition </b>
  72. * @n Semaphore interrupts to the specific Master are reenabled.
  73. *
  74. * @b Example
  75. * @verbatim
  76. // Reenable Semaphore interrupts for CPU Core 0.
  77. CSL_semSetEoi (semHandle, CSL_SEM_REARM_SEMINT0);
  78. @endverbatim
  79. * =============================================================================
  80. */
  81. static inline void CSL_semSetEoi (Uint8 eoiVal)
  82. {
  83. hSEM->SEM_EOI = CSL_FMK(SEM_SEM_EOI_EOI, eoiVal);
  84. }
  85. /** ============================================================================
  86. * @n@b CSL_semAcquireDirect
  87. *
  88. * @b Description
  89. * @n This function acquires a semaphore for direct access.
  90. *
  91. * @b Arguments
  92. @verbatim
  93. semNum Semaphore which is to be acquired.
  94. @endverbatim
  95. *
  96. * <b> Return Value </b>
  97. * @n 1 - Resource was available and has been allocated to the Master
  98. * @n 0 - Resource was NOT available and has NOT been allocated to the Master
  99. *
  100. * <b> Pre Condition </b>
  101. * @n None
  102. *
  103. * <b> Post Condition </b>
  104. * @n Semaphore is allocated to the Master on Success.
  105. *
  106. * @b Reads
  107. * @n SEM_SEM_FREE
  108. *
  109. * @b Example
  110. * @verbatim
  111. Uint8 status;
  112. // Acquire the semaphore number 2.
  113. status = CSL_semAcquireDirect (2);
  114. @endverbatim
  115. * =============================================================================
  116. */
  117. static inline Uint8 CSL_semAcquireDirect (Uint8 semNum)
  118. {
  119. /* Direct Access Request: Read from the SEMn register */
  120. return CSL_FEXT (hSEM->SEM[semNum], SEM_SEM_FREE0);
  121. }
  122. /** ============================================================================
  123. * @n@b CSL_semAcquireIndirect
  124. *
  125. * @b Description
  126. * @n This function acquires a semaphore for indirect access.
  127. *
  128. * @b Arguments
  129. @verbatim
  130. semNum Semaphore which is to be acquired.
  131. @endverbatim
  132. *
  133. * <b> Return Value </b>
  134. * @n None
  135. *
  136. * <b> Pre Condition </b>
  137. * @n None
  138. *
  139. * <b> Post Condition </b>
  140. * @n Semaphore is placed into the request queue to be acquired.
  141. *
  142. * @b Writes
  143. * @n SEM_SEM_FREE=0
  144. *
  145. * @b Example
  146. * @verbatim
  147. // Acquire the semaphore number 2.
  148. CSL_semAcquireIndirect (2);
  149. @endverbatim
  150. * =============================================================================
  151. */
  152. static inline void CSL_semAcquireIndirect (Uint8 semNum)
  153. {
  154. /* Indirect Access Request: Write a 0 to the SEMn register; to request for the resource. */
  155. hSEM->SEM[semNum] = CSL_FMK (SEM_SEM_FREE0, 0);
  156. }
  157. /** ============================================================================
  158. * @n@b CSL_semAcquireCombined
  159. *
  160. * @b Description
  161. * @n This function acquires a semaphore for combined access.
  162. *
  163. * @b Arguments
  164. @verbatim
  165. semNum Semaphore which is to be acquired.
  166. @endverbatim
  167. *
  168. * <b> Return Value </b>
  169. * @n None
  170. *
  171. * <b> Pre Condition </b>
  172. * @n None
  173. *
  174. * <b> Post Condition </b>
  175. * @n Semaphore is acquired immediately if free else it is placed into the request
  176. * queue to be acquired.
  177. *
  178. * @b Reads
  179. * @n SEM_ISEM_FREE
  180. *
  181. * @b Example
  182. * @verbatim
  183. Uint8 status;
  184. // Acquire the semaphore number 2.
  185. status = CSL_semAcquireCombined (2);
  186. @endverbatim
  187. * =============================================================================
  188. */
  189. static inline Uint8 CSL_semAcquireCombined(Uint8 semNum)
  190. {
  191. /* Combined Access Request: Read from the Indirect register */
  192. return CSL_FEXT (hSEM->ISEM[semNum], SEM_ISEM_FREE0);
  193. }
  194. /** ============================================================================
  195. * @n@b CSL_semReleaseSemaphore
  196. *
  197. * @b Description
  198. * @n This function is used to release a sempahore which had been acquired
  199. * previously.
  200. *
  201. * @b Arguments
  202. @verbatim
  203. semNum Semaphore which is to be released.
  204. @endverbatim
  205. *
  206. * <b> Return Value </b>
  207. * @n None
  208. *
  209. * <b> Pre Condition </b>
  210. * @n @a CSL_semAcquireDirect() or @a CSL_semAcquireCombined() @a CSL_semAcquireIndirect()
  211. * must be called.
  212. *
  213. * <b> Post Condition </b>
  214. * @n Semaphore resource is freed up
  215. *
  216. * @b Writes
  217. * @n SEM_SEM_FREE=1
  218. *
  219. * @b Example
  220. * @verbatim
  221. // Acquire the semaphore using the direct method.
  222. CSL_semAcquireDirect (2);
  223. ...
  224. // Release the semaphore.
  225. CSL_semReleaseSemaphore (2);
  226. @endverbatim
  227. * =============================================================================
  228. */
  229. static inline void CSL_semReleaseSemaphore (Uint8 semNum)
  230. {
  231. /* Semaphore is released up by writing a 1 to the SEMn register */
  232. hSEM->SEM[semNum] = CSL_FMK (SEM_SEM_FREE0, 1);
  233. }
  234. /** ============================================================================
  235. * @n@b CSL_semIsFree
  236. *
  237. * @b Description
  238. * @n This function checks if the specified semaphore is acquired or not?
  239. *
  240. * @b Arguments
  241. @verbatim
  242. semNum Semaphore which is to be queried.
  243. @endverbatim
  244. *
  245. * <b> Return Value </b>
  246. * @n TRUE - Semaphore is Free
  247. * @n FALSE - Semaphore is Available
  248. *
  249. * <b> Pre Condition </b>
  250. * @n None
  251. *
  252. * <b> Post Condition </b>
  253. * @n None
  254. *
  255. * @b Reads
  256. * @n SEM_QSEM_FREE
  257. *
  258. * @b Example
  259. * @verbatim
  260. Bool isFree;
  261. // Check if Semaphore is available.
  262. isFree = CSL_semIsFree (2);
  263. @endverbatim
  264. * =============================================================================
  265. */
  266. static inline Bool CSL_semIsFree(Uint8 semNum)
  267. {
  268. /* Read the Query Status register to determine the semaphore status. */
  269. return (Bool)CSL_FEXT (hSEM->QSEM[semNum], SEM_QSEM_FREE0);
  270. }
  271. /** ============================================================================
  272. * @n@b CSL_semGetFlags
  273. *
  274. * @b Description
  275. * @n This function returns the contents of the SEMFLAG register for a specific
  276. * master. This is used in the indirect or combined access method to determine
  277. * if a resource has been acquired. The corresponding bit indicates that the
  278. * specific resource number which had been requested is now available.
  279. *
  280. * @b Arguments
  281. @verbatim
  282. masterId Master ID for which the SEMFLAG register is read.
  283. @endverbatim
  284. *
  285. * <b> Return Value </b>
  286. * @n Uint32
  287. *
  288. * <b> Pre Condition </b>
  289. * @n None
  290. *
  291. * <b> Post Condition </b>
  292. * @n None
  293. *
  294. * @b Reads
  295. * @n SEM_SEMFLAGL_CLEAR
  296. *
  297. * @b Example
  298. * @verbatim
  299. Uint32 semFlags;
  300. // Read the bits of the semaphore flag register for master 0.
  301. semFlags = CSL_semGetFlags(0);
  302. @endverbatim
  303. * =============================================================================
  304. */
  305. static inline Uint32 CSL_semGetFlags(Uint8 masterId)
  306. {
  307. return (Uint32)hSEM->SEMFLAGL_CLEAR[masterId];
  308. }
  309. /** ============================================================================
  310. * @n@b CSL_semClearFlags
  311. *
  312. * @b Description
  313. * @n This function is used by the host by the host to inform the SEM Module
  314. * that the resource which had been marked as FREE has been processed by
  315. * the host.
  316. *
  317. * @b Arguments
  318. @verbatim
  319. masterId Master ID for which the SEMFLAG register is read.
  320. semFlags Semaphore Flags retreived through the CSL_semGetFlags API.
  321. @endverbatim
  322. *
  323. * <b> Return Value </b>
  324. * @n None
  325. *
  326. * <b> Pre Condition </b>
  327. * @n None
  328. *
  329. * <b> Post Condition </b>
  330. * @n None
  331. *
  332. * @b Writes
  333. * @n SEM_SEMFLAGL_CLEAR
  334. *
  335. * @b Affects
  336. * @n SEM_SEMFLAGL_CLEAR
  337. *
  338. * @b Example
  339. * @verbatim
  340. Uint32 semFlags;
  341. // Read the bits of the semaphore flag register for master 0.
  342. semFlags = CSL_semGetFlags(0);
  343. ...
  344. // Clear the bits of the semaphore flag register for master 0.
  345. CSL_semClearFlags (0, semFlags);
  346. @endverbatim
  347. * =============================================================================
  348. */
  349. static inline void CSL_semClearFlags(Uint8 masterId, Uint32 semFlags)
  350. {
  351. /* Write the value to the CLEAR Register. */
  352. hSEM->SEMFLAGL_CLEAR[masterId] = semFlags;
  353. }
  354. /** ============================================================================
  355. * @n@b CSL_semGetErrorCode
  356. *
  357. * @b Description
  358. * @n This function is used to get the Error code.
  359. *
  360. * @b Arguments
  361. * @n None
  362. *
  363. * <b> Return Value </b>
  364. * @n Error Code
  365. *
  366. * <b> Pre Condition </b>
  367. * @n None
  368. *
  369. * <b> Post Condition </b>
  370. * @n None
  371. *
  372. * @b Reads
  373. * @n SEM_SEMERR_ERR
  374. *
  375. * @b Example
  376. * @verbatim
  377. Uint8 errCode;
  378. // Check if there is an error which has been reported.
  379. errCode = CSL_semGetErrorCode();
  380. if (errCode != 0)
  381. {
  382. // Semaphore Module has reported an Error.
  383. }
  384. @endverbatim
  385. * =============================================================================
  386. */
  387. static inline Uint8 CSL_semGetErrorCode (void)
  388. {
  389. return (Uint8)CSL_FEXT(hSEM->SEMERR, SEM_SEMERR_ERR);
  390. }
  391. /** ============================================================================
  392. * @n@b CSL_semGetErrorSemaphoreNumber
  393. *
  394. * @b Description
  395. * @n This function is used to get the semaphore number which is in error.
  396. *
  397. * @b Arguments
  398. * @n None
  399. *
  400. * <b> Return Value </b>
  401. * @n Semaphore Number which caused the error.
  402. *
  403. * <b> Pre Condition </b>
  404. * @n None
  405. *
  406. * <b> Post Condition </b>
  407. * @n None
  408. *
  409. * @b Reads
  410. * @n SEM_SEMERR_SEMNUM
  411. *
  412. * @b Example
  413. * @verbatim
  414. Uint8 errCode;
  415. Uint8 semNumber;
  416. // Check if there is an error which has been reported.
  417. errCode = CSL_semGetErrorCode();
  418. if (errCode != 0)
  419. {
  420. // Semaphore Module has reported an error; get the semaphore number.
  421. semNumber = CSL_semGetErrorSemaphoreNumber();
  422. ...
  423. }
  424. @endverbatim
  425. * =============================================================================
  426. */
  427. static inline Uint8 CSL_semGetErrorSemaphoreNumber (void)
  428. {
  429. return (Uint8)CSL_FEXT(hSEM->SEMERR, SEM_SEMERR_SEMNUM);
  430. }
  431. /** ============================================================================
  432. * @n@b CSL_semGetErrorFaultID
  433. *
  434. * @b Description
  435. * @n This function is used to get the resource owner which caused the error.
  436. *
  437. * @b Arguments
  438. * @n None
  439. *
  440. * <b> Return Value </b>
  441. * @n Resource Number which caused the error.
  442. *
  443. * <b> Pre Condition </b>
  444. * @n None
  445. *
  446. * <b> Post Condition </b>
  447. * @n None
  448. *
  449. * @b Reads
  450. * @n SEM_SEMERR_FAULTID
  451. *
  452. * @b Example
  453. * @verbatim
  454. Uint8 errCode;
  455. Uint8 semNumber;
  456. Uint8 faultId;
  457. // Check if there is an error which has been reported.
  458. errCode = CSL_semGetErrorCode();
  459. if (errCode != 0)
  460. {
  461. // Semaphore Module has reported an error; get the semaphore number.
  462. semNumber = CSL_semGetErrorSemaphoreNumber();
  463. // Get the fault id.
  464. faultId = CSL_semGetErrorFaultID();
  465. ...
  466. }
  467. @endverbatim
  468. * =============================================================================
  469. */
  470. static inline Uint8 CSL_semGetErrorFaultID (void)
  471. {
  472. return (Uint8)CSL_FEXT(hSEM->SEMERR, SEM_SEMERR_FAULTID);
  473. }
  474. /** ============================================================================
  475. * @n@b CSL_semClearError
  476. *
  477. * @b Description
  478. * @n This function is used to clear the semaphore module error.
  479. *
  480. * @b Arguments
  481. * @n None
  482. *
  483. * <b> Return Value </b>
  484. * @n None
  485. *
  486. * <b> Pre Condition </b>
  487. * @n None
  488. *
  489. * <b> Post Condition </b>
  490. * @n None
  491. *
  492. * @b Writes
  493. * @n SEM_SEMERR_CLEAR_CLRERR=1
  494. *
  495. * @b Example
  496. * @verbatim
  497. Uint8 errCode;
  498. Uint8 semNumber;
  499. Uint8 faultId;
  500. // Check if there is an error which has been reported.
  501. errCode = CSL_semGetErrorCode();
  502. if (errCode != 0)
  503. {
  504. // Semaphore Module has reported an error; get the semaphore number.
  505. semNumber = CSL_semGetErrorSemaphoreNumber();
  506. // Get the fault id.
  507. faultId = CSL_semGetErrorFaultID();
  508. ...
  509. // Clear the error.
  510. CSL_semClearError ();
  511. }
  512. @endverbatim
  513. * =============================================================================
  514. */
  515. static inline void CSL_semClearError (void)
  516. {
  517. hSEM->SEMERR_CLEAR = CSL_FMK(SEM_SEMERR_CLEAR_CLRERR, 1);
  518. }
  519. /**
  520. @}
  521. */
  522. #ifdef __cplusplus
  523. }
  524. #endif
  525. #endif
  526. #endif /* CSL_SEMAUX_H_ */