des.c 24 KB

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