blob: eb410881fb77d8c35ad4f59d66503f90915f704d [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* eip97_global_prng.c
2 *
3 * EIP-97 GLobal Control Driver Library
4 * PRNG Module
5 */
6
7/* -------------------------------------------------------------------------- */
8/* */
9/* Module : ddk197 */
10/* Version : 5.6.1 */
11/* Configuration : DDK-197-GPL */
12/* */
13/* Date : 2022-Dec-16 */
14/* */
15/* Copyright (c) 2008-2022 by Rambus, Inc. and/or its subsidiaries. */
16/* */
17/* This program is free software: you can redistribute it and/or modify */
18/* it under the terms of the GNU General Public License as published by */
19/* the Free Software Foundation, either version 2 of the License, or */
20/* any later version. */
21/* */
22/* This program is distributed in the hope that it will be useful, */
23/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
24/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
25/* GNU General Public License for more details. */
26/* */
27/* You should have received a copy of the GNU General Public License */
28/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
29/* -------------------------------------------------------------------------- */
30
31/*----------------------------------------------------------------------------
32 * This module implements (provides) the following interface(s):
33 */
34
35#include "eip97_global_prng.h"
36
37
38/*----------------------------------------------------------------------------
39 * This module uses (requires) the following interface(s):
40 */
41
42// Driver Framework Device API
43#include "device_types.h" // Device_Handle_t
44
45// EIP-97 Global Control Driver Library Internal interfaces
46#include "eip97_global_internal.h"
47#include "eip96_level0.h" // EIP-96 Level 0 macros
48#include "eip97_global_fsm.h" // State machine
49
50
51/*----------------------------------------------------------------------------
52 * Definitions and macros
53 */
54
55
56/*----------------------------------------------------------------------------
57 * Local variables
58 */
59
60
61/*----------------------------------------------------------------------------
62 * EIP97_Global_PRNG_Reseed
63 */
64EIP97_Global_Error_t
65EIP97_Global_PRNG_Reseed(
66 EIP97_Global_IOArea_t * const IOArea_p,
67 const unsigned int PE_Number,
68 const EIP96_PRNG_Reseed_t * const ReseedData_p)
69{
70 Device_Handle_t Device;
71 volatile EIP97_True_IOArea_t * const TrueIOArea_p = IOAREA(IOArea_p);
72
73 EIP97_GLOBAL_CHECK_POINTER(IOArea_p);
74
75 if(PE_Number >= EIP97_GLOBAL_MAX_NOF_PE_TO_USE)
76 return EIP97_GLOBAL_ARGUMENT_ERROR;
77
78 Device = TrueIOArea_p->Device;
79
80#ifdef EIP97_GLOBAL_DEBUG_FSM
81 {
82 EIP97_Global_Error_t rv;
83
84 // Remain in the current state
85 rv = EIP97_Global_State_Set((volatile EIP97_Global_State_t*)&TrueIOArea_p->State,
86 (EIP97_Global_State_t)TrueIOArea_p->State);
87 if(rv != EIP97_GLOBAL_NO_ERROR)
88 return EIP97_GLOBAL_ILLEGAL_IN_STATE;
89 }
90#endif // EIP97_GLOBAL_DEBUG_FSM
91
92 EIP96_PRNG_CTRL_WR(Device,
93 PE_Number, // EIP-96 PE number
94 false, // Disable PRNG
95 false); // Set PRNG Manual mode
96
97 // Write new seed data
98 EIP96_PRNG_SEED_L_WR(Device, PE_Number, ReseedData_p->SeedLo);
99 EIP96_PRNG_SEED_H_WR(Device, PE_Number, ReseedData_p->SeedHi);
100
101 // Write new key data
102 EIP96_PRNG_KEY_0_L_WR(Device, PE_Number, ReseedData_p->Key0Lo);
103 EIP96_PRNG_KEY_0_H_WR(Device, PE_Number, ReseedData_p->Key0Hi);
104 EIP96_PRNG_KEY_1_L_WR(Device, PE_Number, ReseedData_p->Key1Lo);
105 EIP96_PRNG_KEY_1_H_WR(Device, PE_Number, ReseedData_p->Key1Hi);
106
107 // Write new LFSR data
108 EIP96_PRNG_LFSR_L_WR(Device, PE_Number, ReseedData_p->LFSRLo);
109 EIP96_PRNG_LFSR_H_WR(Device, PE_Number, ReseedData_p->LFSRHi);
110
111 EIP96_PRNG_CTRL_WR(Device,
112 PE_Number, // EIP-96 PE number
113 true, // Enable PRNG
114 true); // Set PRNG Auto mode
115
116 return EIP97_GLOBAL_NO_ERROR;
117}
118
119
120/* end of file eip97_global_prng.c */