[go: up one dir, main page]

0% found this document useful (0 votes)
18 views2 pages

XMC PRNG C

prng

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

XMC PRNG C

prng

Uploaded by

Roberto Dias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1

2 /**
3 * @file xmc_prng.c
4 * @date 2015-06-20
5 *
6 * @cond
7 *****************************************************************************
8 * XMClib v2.2.0 - XMC Peripheral Driver Library
9 *
10 * Copyright (c) 2015-2020, Infineon Technologies AG
11 * All rights reserved.
12 *
13 * Boost Software License - Version 1.0 - August 17th, 2003
14 *
15 * Permission is hereby granted, free of charge, to any person or organization
16 * obtaining a copy of the software and accompanying documentation covered by
17 * this license (the "Software") to use, reproduce, display, distribute,
18 * execute, and transmit the Software, and to prepare derivative works of the
19 * Software, and to permit third-parties to whom the Software is furnished to
20 * do so, all subject to the following:
21 *
22 * The copyright notices in the Software and this entire statement, including
23 * the above license grant, this restriction and the following disclaimer,
24 * must be included in all copies of the Software, in whole or in part, and
25 * all derivative works of the Software, unless such copies or derivative
26 * works are solely in the form of machine-executable object code generated by
27 * a source language processor.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 * DEALINGS IN THE SOFTWARE.
36 *
37 * To improve the quality of the software, users are encouraged to share
38 * modifications, enhancements or bug fixes with Infineon Technologies AG
39 * at XMCSupport@infineon.com.
40 *****************************************************************************
41 *
42 * Change History
43 * --------------
44 *
45 * 2015-02-20:
46 * - Initial <br>
47 * - Removed GetDriverVersion API <br>
48 *
49 * 2015-06-20
50 * - Removed definition of GetDriverVersion API <br>
51 *
52 * @endcond
53 */
54
55 #include "xmc_prng.h"
56
57 #if defined (PRNG)
58
59 /*************************************************************************************
********************************
60 * API IMPLEMENTATION
61
*************************************************************************************
********************************/
62
63 /*
64 * Initializes the PRNG peripheral with the settings in the
65 * initialization structure XMC_PRNG_INIT_t
66 */
67 XMC_PRNG_INIT_STATUS_t XMC_PRNG_Init(const XMC_PRNG_INIT_t *prng)
68 {
69 volatile uint16_t read_warm_up;
70 uint16_t reg_val, iter;
71 XMC_PRNG_INIT_STATUS_t status = XMC_PRNG_INITIALIZED;
72
73 XMC_ASSERT("XMC_PRNG_Init:Null Pointer", (prng != (XMC_PRNG_INIT_t *)NULL));
74
75 /* Configure block size for key loading mode */
76 XMC_PRNG_SetRandomDataBlockSize(XMC_PRNG_RDBS_WORD);
77
78 /* Enable key loading mode */
79 XMC_PRNG_EnableKeyLoadingMode();
80
81 /* Load key words (80 bits) and wait till RDV is set */
82 for (iter = (uint16_t)0UL; iter < (uint16_t)5UL; iter++)
83 {
84 XMC_PRNG_LoadKeyWords(prng->key_words[iter]);
85 while (PRNG_CHK_RDV_Msk != XMC_PRNG_CheckValidStatus());
86 }
87
88 XMC_PRNG_EnableStreamingMode();
89
90 /* Warm up phase: Read and discard 64 bits */
91 read_warm_up = PRNG->WORD;
92 read_warm_up = PRNG->WORD;
93 read_warm_up = PRNG->WORD;
94 reg_val = PRNG->WORD;
95 read_warm_up &= reg_val;
96
97 /* Configure block size either byte (8 bit) or word (16 bit) */
98 XMC_PRNG_SetRandomDataBlockSize(prng->block_size);
99
100 /*
101 * Checks for reset value for "random data block size". If reset,
102 * PRNG is not initialized
103 */
104 if ((uint16_t)XMC_PRNG_RDBS_RESET == (PRNG->CTRL & (uint16_t)PRNG_CTRL_RDBS_Msk))
105 {
106 status = XMC_PRNG_NOT_INITIALIZED;
107 }
108
109 return status;
110 }
111
112 #endif /* #if defined (PRNG) */
113

You might also like