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