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