des.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. //*****************************************************************************
  2. //
  3. // des.c - Driver for the DES data transformation.
  4. //
  5. // Copyright (c) 2012-2017 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //*****************************************************************************
  37. //*****************************************************************************
  38. //
  39. //! \addtogroup des_api
  40. //! @{
  41. //
  42. //*****************************************************************************
  43. #include <ti/devices/msp432e4/inc/msp432e411y.h>
  44. #include "types.h"
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_des.h"
  48. #include "debug.h"
  49. #include "des.h"
  50. #include "interrupt.h"
  51. //*****************************************************************************
  52. //
  53. //! Resets the DES Module.
  54. //!
  55. //! \param ui32Base is the base address of the DES module.
  56. //!
  57. //! This function performs a soft-reset sequence of the DES module.
  58. //!
  59. //! \return None.
  60. //
  61. //*****************************************************************************
  62. void
  63. DESReset(uint32_t ui32Base)
  64. {
  65. //
  66. // Check the arguments.
  67. //
  68. ASSERT(ui32Base == DES_BASE);
  69. //
  70. // Trigger the soft reset.
  71. //
  72. HWREG(ui32Base + DES_O_SYSCONFIG) |= DES_SYSCONFIG_SOFTRESET;
  73. //
  74. // Wait for the reset to finish.
  75. //
  76. while ((HWREG(ui32Base + DES_O_SYSSTATUS) &
  77. DES_SYSSTATUS_RESETDONE) == 0)
  78. {
  79. }
  80. }
  81. //*****************************************************************************
  82. //
  83. //! Configures the DES module for operation.
  84. //!
  85. //! \param ui32Base is the base address of the DES module.
  86. //! \param ui32Config is the configuration of the DES module.
  87. //!
  88. //! This function configures the DES module for operation.
  89. //!
  90. //! The \e ui32Config parameter is a bit-wise OR of a number of configuration
  91. //! flags. The valid flags are grouped below based on their function.
  92. //!
  93. //! The direction of the operation is specified with one of the following two
  94. //! flags. Only one is permitted.
  95. //!
  96. //! - \b DES_CFG_DIR_ENCRYPT - Encryption
  97. //! - \b DES_CFG_DIR_DECRYPT - Decryption
  98. //!
  99. //! The operational mode of the DES engine is specified with one of the
  100. //! following flags. Only one is permitted.
  101. //!
  102. //! - \b DES_CFG_MODE_ECB - Electronic Codebook Mode
  103. //! - \b DES_CFG_MODE_CBC - Cipher-Block Chaining Mode
  104. //! - \b DES_CFG_MODE_CFB - Cipher Feedback Mode
  105. //!
  106. //! The selection of single DES or triple DES is specified with one of the
  107. //! following two flags. Only one is permitted.
  108. //!
  109. //! - \b DES_CFG_SINGLE - Single DES
  110. //! - \b DES_CFG_TRIPLE - Triple DES
  111. //!
  112. //! \return None.
  113. //
  114. //*****************************************************************************
  115. void
  116. DESConfigSet(uint32_t ui32Base, uint32_t ui32Config)
  117. {
  118. //
  119. // Check the arguments.
  120. //
  121. ASSERT(ui32Base == DES_BASE);
  122. //
  123. // Backup the save context field.
  124. //
  125. ui32Config |= (HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT);
  126. //
  127. // Write the control register.
  128. //
  129. HWREG(ui32Base + DES_O_CTRL) = ui32Config;
  130. }
  131. //*****************************************************************************
  132. //
  133. //! Sets the key used for DES operations.
  134. //!
  135. //! \param ui32Base is the base address of the DES module.
  136. //! \param pui32Key is a pointer to an array that holds the key
  137. //!
  138. //! This function sets the key used for DES operations.
  139. //!
  140. //! \e pui32Key should be 64 bits long (2 words) if single DES is being used or
  141. //! 192 bits (6 words) if triple DES is being used.
  142. //!
  143. //! \return None.
  144. //
  145. //*****************************************************************************
  146. void
  147. DESKeySet(uint32_t ui32Base, uint32_t *pui32Key)
  148. {
  149. //
  150. // Check the arguments.
  151. //
  152. ASSERT(ui32Base == DES_BASE);
  153. //
  154. // Write the first part of the key.
  155. //
  156. HWREG(ui32Base + DES_O_KEY1_L) = pui32Key[0];
  157. HWREG(ui32Base + DES_O_KEY1_H) = pui32Key[1];
  158. //
  159. // If we are performing tripe DES, then write the key registers for
  160. // the second and third rounds.
  161. //
  162. if (HWREG(ui32Base + DES_O_CTRL) & DES_CFG_TRIPLE)
  163. {
  164. HWREG(ui32Base + DES_O_KEY2_L) = pui32Key[2];
  165. HWREG(ui32Base + DES_O_KEY2_H) = pui32Key[3];
  166. HWREG(ui32Base + DES_O_KEY3_L) = pui32Key[4];
  167. HWREG(ui32Base + DES_O_KEY3_H) = pui32Key[5];
  168. }
  169. }
  170. //*****************************************************************************
  171. //
  172. //! Sets the initialization vector in the DES module.
  173. //!
  174. //! \param ui32Base is the base address of the DES module.
  175. //! \param pui32IVdata is a pointer to an array of 64 bits (2 words) of data to
  176. //! be written into the initialization vectors registers.
  177. //!
  178. //! This function sets the initialization vector in the DES module. It returns
  179. //! true if the registers were successfully written. If the context registers
  180. //! cannot be written at the time the function was called, then false is
  181. //! returned.
  182. //!
  183. //! \return True or false.
  184. //
  185. //*****************************************************************************
  186. bool
  187. DESIVSet(uint32_t ui32Base, uint32_t *pui32IVdata)
  188. {
  189. //
  190. // Check the arguments.
  191. //
  192. ASSERT(ui32Base == DES_BASE);
  193. //
  194. // Check to see if context registers can be overwritten. If not, return
  195. // false.
  196. //
  197. if ((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_CONTEXT) == 0)
  198. {
  199. return (false);
  200. }
  201. //
  202. // Write the initialization vector registers.
  203. //
  204. HWREG(ui32Base + DES_O_IV_L) = pui32IVdata[0];
  205. HWREG(ui32Base + DES_O_IV_H) = pui32IVdata[1];
  206. //
  207. // Return true to indicate the write was successful.
  208. //
  209. return (true);
  210. }
  211. //*****************************************************************************
  212. //
  213. //! Sets the crytographic data length in the DES module.
  214. //!
  215. //! \param ui32Base is the base address of the DES module.
  216. //! \param ui32Length is the length of the data in bytes.
  217. //!
  218. //! This function writes the cryptographic data length into the DES module.
  219. //! When this register is written, the engine is triggered to start using this
  220. //! context.
  221. //!
  222. //! \note Data lengths up to (2^32 - 1) bytes are allowed.
  223. //!
  224. //! \return None.
  225. //
  226. //*****************************************************************************
  227. void
  228. DESLengthSet(uint32_t ui32Base, uint32_t ui32Length)
  229. {
  230. //
  231. // Check the arguments.
  232. //
  233. ASSERT(ui32Base == DES_BASE);
  234. //
  235. // Write the length register.
  236. //
  237. HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
  238. }
  239. //*****************************************************************************
  240. //
  241. //! Reads plaintext/ciphertext from data registers without blocking
  242. //!
  243. //! \param ui32Base is the base address of the DES module.
  244. //! \param pui32Dest is a pointer to an array of 2 words.
  245. //!
  246. //! This function returns true if the data was ready when the function was
  247. //! called. If the data was not ready, false is returned.
  248. //!
  249. //! \return True or false.
  250. //
  251. //*****************************************************************************
  252. bool
  253. DESDataReadNonBlocking(uint32_t ui32Base, uint32_t *pui32Dest)
  254. {
  255. //
  256. // Check the arguments.
  257. //
  258. ASSERT(ui32Base == DES_BASE);
  259. //
  260. // Check to see if the data is ready to be read.
  261. //
  262. if ((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
  263. {
  264. return (false);
  265. }
  266. //
  267. // Read two words of data from the data registers.
  268. //
  269. pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
  270. pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
  271. //
  272. // Return true to indicate a successful write.
  273. //
  274. return (true);
  275. }
  276. //*****************************************************************************
  277. //
  278. //! Reads plaintext/ciphertext from data registers with blocking.
  279. //!
  280. //! \param ui32Base is the base address of the DES module.
  281. //! \param pui32Dest is a pointer to an array of bytes.
  282. //!
  283. //! This function waits until the DES module is finished and encrypted or
  284. //! decrypted data is ready. The output data is then stored in the pui32Dest
  285. //! array.
  286. //!
  287. //! \return None
  288. //
  289. //*****************************************************************************
  290. void
  291. DESDataRead(uint32_t ui32Base, uint32_t *pui32Dest)
  292. {
  293. //
  294. // Check the arguments.
  295. //
  296. ASSERT(ui32Base == DES_BASE);
  297. //
  298. // Wait for data output to be ready.
  299. //
  300. while ((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_OUTPUT_READY) == 0)
  301. {
  302. }
  303. //
  304. // Read two words of data from the data registers.
  305. //
  306. pui32Dest[0] = HWREG(DES_BASE + DES_O_DATA_L);
  307. pui32Dest[1] = HWREG(DES_BASE + DES_O_DATA_H);
  308. }
  309. //*****************************************************************************
  310. //
  311. //! Writes plaintext/ciphertext to data registers without blocking
  312. //!
  313. //! \param ui32Base is the base address of the DES module.
  314. //! \param pui32Src is a pointer to an array of 2 words.
  315. //!
  316. //! This function returns false if the DES module is not ready to accept
  317. //! data. It returns true if the data was written successfully.
  318. //!
  319. //! \return true or false.
  320. //
  321. //*****************************************************************************
  322. bool
  323. DESDataWriteNonBlocking(uint32_t ui32Base, uint32_t *pui32Src)
  324. {
  325. //
  326. // Check the arguments.
  327. //
  328. ASSERT(ui32Base == DES_BASE);
  329. //
  330. // Check if the DES module is ready to encrypt or decrypt data. If it
  331. // is not, return false.
  332. //
  333. if (!(DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))))
  334. {
  335. return (false);
  336. }
  337. //
  338. // Write the data.
  339. //
  340. HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
  341. HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
  342. //
  343. // Return true to indicate a successful write.
  344. //
  345. return (true);
  346. }
  347. //*****************************************************************************
  348. //
  349. //! Writes plaintext/ciphertext to data registers without blocking
  350. //!
  351. //! \param ui32Base is the base address of the DES module.
  352. //! \param pui32Src is a pointer to an array of bytes.
  353. //!
  354. //! This function waits until the DES module is ready before writing the
  355. //! data contained in the pui32Src array.
  356. //!
  357. //! \return None.
  358. //
  359. //*****************************************************************************
  360. void
  361. DESDataWrite(uint32_t ui32Base, uint32_t *pui32Src)
  362. {
  363. //
  364. // Check the arguments.
  365. //
  366. ASSERT(ui32Base == DES_BASE);
  367. //
  368. // Wait for the input ready bit to go high.
  369. //
  370. while (((HWREG(ui32Base + DES_O_CTRL) & DES_CTRL_INPUT_READY)) == 0)
  371. {
  372. }
  373. //
  374. // Write the data.
  375. //
  376. HWREG(DES_BASE + DES_O_DATA_L) = pui32Src[0];
  377. HWREG(DES_BASE + DES_O_DATA_H) = pui32Src[1];
  378. }
  379. //*****************************************************************************
  380. //
  381. //! Processes blocks of data through the DES module.
  382. //!
  383. //! \param ui32Base is the base address of the DES module.
  384. //! \param pui32Src is a pointer to an array of words that contains the
  385. //! source data for processing.
  386. //! \param pui32Dest is a pointer to an array of words consisting of the
  387. //! processed data.
  388. //! \param ui32Length is the length of the cryptographic data in bytes.
  389. //! It must be a multiple of eight.
  390. //!
  391. //! This function takes the data contained in the pui32Src array and processes
  392. //! it using the DES engine. The resulting data is stored in the
  393. //! pui32Dest array. The function blocks until all of the data has been
  394. //! processed. If processing is successful, the function returns true.
  395. //!
  396. //! \note This functions assumes that the DES module has been configured,
  397. //! and initialization values and keys have been written.
  398. //!
  399. //! \return true or false.
  400. //
  401. //*****************************************************************************
  402. bool
  403. DESDataProcess(uint32_t ui32Base, uint32_t *pui32Src, uint32_t *pui32Dest,
  404. uint32_t ui32Length)
  405. {
  406. uint32_t ui32Count;
  407. //
  408. // Check the arguments.
  409. //
  410. ASSERT(ui32Base == DES_BASE);
  411. ASSERT((ui32Length % 8) == 0);
  412. //
  413. // Write the length register first. This triggers the engine to start
  414. // using this context.
  415. //
  416. HWREG(ui32Base + DES_O_LENGTH) = ui32Length;
  417. //
  418. // Now loop until the blocks are written.
  419. //
  420. for (ui32Count = 0; ui32Count < (ui32Length / 4); ui32Count += 2)
  421. {
  422. //
  423. // Check if the input ready is fine
  424. //
  425. while ((DES_CTRL_INPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
  426. {
  427. }
  428. //
  429. // Write the block data.
  430. //
  431. DESDataWriteNonBlocking(ui32Base, pui32Src + ui32Count);
  432. //
  433. // Wait for the output ready
  434. //
  435. while ((DES_CTRL_OUTPUT_READY & (HWREG(ui32Base + DES_O_CTRL))) == 0)
  436. {
  437. }
  438. //
  439. // Read the processed data block.
  440. //
  441. DESDataReadNonBlocking(ui32Base, pui32Dest + ui32Count);
  442. }
  443. //
  444. // Return true to indicate the process was successful.
  445. //
  446. return (true);
  447. }
  448. //*****************************************************************************
  449. //
  450. //! Returns the current interrupt status of the DES module.
  451. //!
  452. //! \param ui32Base is the base address of the DES module.
  453. //! \param bMasked is \b false if the raw interrupt status is required and
  454. //! \b true if the masked interrupt status is required.
  455. //!
  456. //! This function gets the current interrupt status of the DES module.
  457. //! The value returned is a logical OR of the following values:
  458. //!
  459. //! - \b DES_INT_CONTEXT_IN - Context interrupt
  460. //! - \b DES_INT_DATA_IN - Data input interrupt
  461. //! - \b DES_INT_DATA_OUT_INT - Data output interrupt
  462. //! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
  463. //! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
  464. //! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
  465. //!
  466. //! \return A bit mask of the current interrupt status.
  467. //
  468. //*****************************************************************************
  469. uint32_t
  470. DESIntStatus(uint32_t ui32Base, bool bMasked)
  471. {
  472. uint32_t ui32Status, ui32Enable;
  473. //
  474. // Check the arguments.
  475. //
  476. ASSERT(ui32Base == DES_BASE);
  477. //
  478. // Read the status register and return the value.
  479. //
  480. ui32Status = HWREG(ui32Base + DES_O_IRQSTATUS);
  481. if (bMasked)
  482. {
  483. ui32Enable = HWREG(ui32Base + DES_O_IRQENABLE);
  484. return ((ui32Status & ui32Enable) |
  485. (HWREG(ui32Base + DES_O_DMAMIS) << 16));
  486. }
  487. else
  488. {
  489. return (ui32Status | (HWREG(ui32Base + DES_O_DMARIS) << 16));
  490. }
  491. }
  492. //*****************************************************************************
  493. //
  494. //! Enables interrupts in the DES module.
  495. //!
  496. //! \param ui32Base is the base address of the DES module.
  497. //! \param ui32IntFlags is a bit mask of the interrupts to be enabled.
  498. //!
  499. //! \e ui32IntFlags should be a logical OR of one or more of the following
  500. //! values:
  501. //!
  502. //! - \b DES_INT_CONTEXT_IN - Context interrupt
  503. //! - \b DES_INT_DATA_IN - Data input interrupt
  504. //! - \b DES_INT_DATA_OUT - Data output interrupt
  505. //! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
  506. //! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
  507. //! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
  508. //!
  509. //! \return None.
  510. //
  511. //*****************************************************************************
  512. void
  513. DESIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  514. {
  515. //
  516. // Check the arguments.
  517. //
  518. ASSERT(ui32Base == DES_BASE);
  519. ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
  520. (ui32IntFlags & DES_INT_DATA_IN) ||
  521. (ui32IntFlags & DES_INT_DATA_OUT) ||
  522. (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
  523. (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
  524. (ui32IntFlags & DES_INT_DMA_DATA_OUT));
  525. //
  526. // Enable the interrupts from the flags.
  527. //
  528. HWREG(ui32Base + DES_O_DMAIM) |= (ui32IntFlags & 0x00070000) >> 16;
  529. HWREG(ui32Base + DES_O_IRQENABLE) |= ui32IntFlags & 0x0000ffff;
  530. }
  531. //*****************************************************************************
  532. //
  533. //! Disables interrupts in the DES module.
  534. //!
  535. //! \param ui32Base is the base address of the DES module.
  536. //! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
  537. //!
  538. //! This function disables interrupt sources in the DES module.
  539. //! \e ui32IntFlags should be a logical OR of one or more of the following
  540. //! values:
  541. //!
  542. //! - \b DES_INT_CONTEXT_IN - Context interrupt
  543. //! - \b DES_INT_DATA_IN - Data input interrupt
  544. //! - \b DES_INT_DATA_OUT - Data output interrupt
  545. //! - \b DES_INT_DMA_CONTEXT_IN - Context DMA done interrupt
  546. //! - \b DES_INT_DMA_DATA_IN - Data input DMA done interrupt
  547. //! - \b DES_INT_DMA_DATA_OUT - Data output DMA done interrupt
  548. //!
  549. //! \return None.
  550. //
  551. //*****************************************************************************
  552. void
  553. DESIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  554. {
  555. //
  556. // Check the arguments.
  557. //
  558. ASSERT(ui32Base == DES_BASE);
  559. ASSERT((ui32IntFlags & DES_INT_CONTEXT_IN) ||
  560. (ui32IntFlags & DES_INT_DATA_IN) ||
  561. (ui32IntFlags & DES_INT_DATA_OUT) ||
  562. (ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
  563. (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
  564. (ui32IntFlags & DES_INT_DMA_DATA_OUT));
  565. //
  566. // Clear the interrupts from the flags.
  567. //
  568. HWREG(ui32Base + DES_O_DMAIM) &= ~((ui32IntFlags & 0x00070000) >> 16);
  569. HWREG(ui32Base + DES_O_IRQENABLE) &= ~(ui32IntFlags & 0x0000ffff);
  570. }
  571. //*****************************************************************************
  572. //
  573. //! Clears interrupts in the DES module.
  574. //!
  575. //! \param ui32Base is the base address of the DES module.
  576. //! \param ui32IntFlags is a bit mask of the interrupts to be disabled.
  577. //!
  578. //! This function disables interrupt sources in the DES module.
  579. //! \e ui32IntFlags should be a logical OR of one or more of the following
  580. //! values:
  581. //!
  582. //! - \b DES_INT_DMA_CONTEXT_IN - Context interrupt
  583. //! - \b DES_INT_DMA_DATA_IN - Data input interrupt
  584. //! - \b DES_INT_DMA_DATA_OUT - Data output interrupt
  585. //!
  586. //! \note The DMA done interrupts are the only interrupts that can be cleared.
  587. //! The remaining interrupts can be disabled instead using DESIntDisable().
  588. //!
  589. //! \return None.
  590. //
  591. //*****************************************************************************
  592. void
  593. DESIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  594. {
  595. //
  596. // Check the arguments.
  597. //
  598. ASSERT(ui32Base == DES_BASE);
  599. ASSERT((ui32IntFlags & DES_INT_DMA_CONTEXT_IN) ||
  600. (ui32IntFlags & DES_INT_DMA_DATA_IN) ||
  601. (ui32IntFlags & DES_INT_DMA_DATA_OUT));
  602. HWREG(ui32Base + DES_O_DMAIC) = (ui32IntFlags & 0x00070000) >> 16;
  603. }
  604. //*****************************************************************************
  605. //
  606. //! Registers an interrupt handler for the DES module.
  607. //!
  608. //! \param ui32Base is the base address of the DES module.
  609. //! \param pfnHandler is a pointer to the function to be called when the
  610. //! enabled DES interrupts occur.
  611. //!
  612. //! This function registers the interrupt handler in the interrupt vector
  613. //! table, and enables DES interrupts on the interrupt controller; specific DES
  614. //! interrupt sources must be enabled using DESIntEnable(). The interrupt
  615. //! handler being registered must clear the source of the interrupt using
  616. //! DESIntClear().
  617. //!
  618. //! If the application is using a static interrupt vector table stored in
  619. //! flash, then it is not necessary to register the interrupt handler this way.
  620. //! Instead, IntEnable() should be used to enable DES interrupts on the
  621. //! interrupt controller.
  622. //!
  623. //! \sa IntRegister() for important information about registering interrupt
  624. //! handlers.
  625. //!
  626. //! \return None.
  627. //
  628. //*****************************************************************************
  629. void
  630. DESIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  631. {
  632. //
  633. // Check the arguments.
  634. //
  635. ASSERT(ui32Base == DES_BASE);
  636. //
  637. // Register the interrupt handler.
  638. //
  639. IntRegister(INT_DES0, pfnHandler);
  640. //
  641. // Enable the interrupt.
  642. //
  643. IntEnable(INT_DES0);
  644. }
  645. //*****************************************************************************
  646. //
  647. //! Unregisters an interrupt handler for the DES module.
  648. //!
  649. //! \param ui32Base is the base address of the DES module.
  650. //!
  651. //! This function unregisters the previously registered interrupt handler and
  652. //! disables the interrupt in the interrupt controller.
  653. //!
  654. //! \sa IntRegister() for important information about registering interrupt
  655. //! handlers.
  656. //!
  657. //! \return None.
  658. //
  659. //*****************************************************************************
  660. void
  661. DESIntUnregister(uint32_t ui32Base)
  662. {
  663. //
  664. // Check the arguments.
  665. //
  666. ASSERT(ui32Base == DES_BASE);
  667. //
  668. // Disable the interrupt.
  669. //
  670. IntDisable(INT_DES0);
  671. //
  672. // Unregister the interrupt handler.
  673. //
  674. IntUnregister(INT_DES0);
  675. }
  676. //*****************************************************************************
  677. //
  678. //! Enables DMA request sources in the DES module.
  679. //!
  680. //! \param ui32Base is the base address of the DES module.
  681. //! \param ui32Flags is a bit mask of the DMA requests to be enabled.
  682. //!
  683. //! This function enables DMA request sources in the DES module. The
  684. //! \e ui32Flags parameter should be the logical OR of any of the following:
  685. //!
  686. //! - \b DES_DMA_CONTEXT_IN - Context In
  687. //! - \b DES_DMA_DATA_OUT - Data Out
  688. //! - \b DES_DMA_DATA_IN - Data In
  689. //!
  690. //! \return None.
  691. //
  692. //*****************************************************************************
  693. void
  694. DESDMAEnable(uint32_t ui32Base, uint32_t ui32Flags)
  695. {
  696. //
  697. // Check the arguments.
  698. //
  699. ASSERT(ui32Base == DES_BASE);
  700. ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
  701. (ui32Flags & DES_DMA_DATA_OUT) ||
  702. (ui32Flags & DES_DMA_DATA_IN));
  703. //
  704. // Set the data in and data out DMA request enable bits.
  705. //
  706. HWREG(ui32Base + DES_O_SYSCONFIG) |= ui32Flags;
  707. }
  708. //*****************************************************************************
  709. //
  710. //! Disables DMA request sources in the DES module.
  711. //!
  712. //! \param ui32Base is the base address of the DES module.
  713. //! \param ui32Flags is a bit mask of the DMA requests to be disabled.
  714. //!
  715. //! This function disables DMA request sources in the DES module. The
  716. //! \e ui32Flags parameter should be the logical OR of any of the following:
  717. //!
  718. //! - \b DES_DMA_CONTEXT_IN - Context In
  719. //! - \b DES_DMA_DATA_OUT - Data Out
  720. //! - \b DES_DMA_DATA_IN - Data In
  721. //!
  722. //! \return None.
  723. //
  724. //*****************************************************************************
  725. void
  726. DESDMADisable(uint32_t ui32Base, uint32_t ui32Flags)
  727. {
  728. //
  729. // Check the arguments.
  730. //
  731. ASSERT(ui32Base == DES_BASE);
  732. ASSERT((ui32Flags & DES_DMA_CONTEXT_IN) ||
  733. (ui32Flags & DES_DMA_DATA_OUT) ||
  734. (ui32Flags & DES_DMA_DATA_IN));
  735. //
  736. // Disable the DMA sources.
  737. //
  738. HWREG(ui32Base + DES_O_SYSCONFIG) &= ~ui32Flags;
  739. }
  740. //*****************************************************************************
  741. //
  742. // Close the Doxygen group.
  743. //! @}
  744. //
  745. //*****************************************************************************