des.c 27 KB

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