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