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