blob: 3e28a86b104d5ccc01a2231b64a7c1c3b04045f5 [file] [log] [blame]
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05001
2/* Module Description *************************************************/
3/* */
4/* Description: This module contains the implementation for the */
5/* Processor Runtime Diagnostics Scan Communication */
6/* Register class. */
7/* */
8/* Notes: Unless stated otherwise, assume that each function */
9/* specification has no side-effects, no dependencies, and */
10/* constant time complexity. */
11/* */
12/* End Module Description *********************************************/
13
14/*--------------------------------------------------------------------*/
15/* Includes */
16/*--------------------------------------------------------------------*/
17
18#include <iipbits.h>
19#include <iipscr.h>
20#include <iipconst.h>
21
22#include <prdfAssert.h>
23
Zane Shelley871adec2019-07-30 11:01:39 -050024namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050025{
Zane Shelley871adec2019-07-30 11:01:39 -050026
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050027/*--------------------------------------------------------------------*/
28/* User Types */
29/*--------------------------------------------------------------------*/
30
31/*--------------------------------------------------------------------*/
32/* Constants */
33/*--------------------------------------------------------------------*/
34
35/*--------------------------------------------------------------------*/
36/* Macros */
37/*--------------------------------------------------------------------*/
38
39/*--------------------------------------------------------------------*/
40/* Internal Function Prototypes */
41/*--------------------------------------------------------------------*/
42
43/*--------------------------------------------------------------------*/
44/* Global Variables */
45/*--------------------------------------------------------------------*/
46
47/*--------------------------------------------------------------------*/
48/* Static Variables */
49/*--------------------------------------------------------------------*/
50
51// Function Specification //////////////////////////////////////////
52//
53// Title: ~SCAN_COMM_REGISTER_CLASS (Virtual destructor)
54//
55// Purpose: This destructor deallocates the Bit String.
56//
57// Side-effects: Memory is deallocated.
58//
59// Dependencies: None.
60//
61// End Function Specification //////////////////////////////////////
62
63SCAN_COMM_REGISTER_CLASS::~SCAN_COMM_REGISTER_CLASS
64(
65 void
66 /*!i No parameters */
67 )
68/*!o No value returned */
69{
70}
71
72// Function Specification ///////////////////////////////////////////
73//
74// Title: Read
75//
76// Purpose: This function reads the actual hardware register and
77// sets the Bit String data member values. The specified
78// Bit String is then used to mask the Bit String data
79// member. If an error occur, then the error is reported
80// and the Bit String values are undefined.
81//
82// Side-effects: Hardware register is read.
83// Bit String data member is modified.
84// Memory is reallocated.
85//
86// End Function Specification //////////////////////////////////////
87
88uint32_t SCAN_COMM_REGISTER_CLASS::Read
89(
90 BitString & mask
91 /*!i Reference to Bit String mask */
92 )
93/*!o Error return code */
94{
95 uint32_t rc = Read();
96
97 if(rc == SUCCESS)
98 {
99 BitString & bitString = AccessBitString();
100 bitString.maskString(mask);
101 }
102
103 return(rc);
104}
105// Function Specification //////////////////////////////////////////
106//
107// Title: Set Bit
108//
109// Purpose: This function sets(1) the specified bit position in
110// the Bit String. If the Bit String is NULL, then a
111// new Bit String is allocated and cleared to all zero
112// before setting the bit.
113//
114// Side-effects: Bit String is modified.
115// Memory may be allocated.
116//
117// Dependencies: bit_position must be in the string
118//
119// End Function Specification //////////////////////////////////////
120
121void SCAN_COMM_REGISTER_CLASS::SetBit
122(
123 uint32_t bit_position
124 /*!i Bit position in string */
125 )
126/*!o No value returned */
127{
128
129 BitString & bitString = AccessBitString();
130 bitString.setBit(bit_position);
131}
132
133// Function Specification //////////////////////////////////////////
134//
135// Title: Clear Bit
136//
137// Purpose: This function clears(0) the specified bit position in
138// the Bit String. If the Bit String is NULL, then a
139// new Bit String is allocated and cleared to all zeros.
140//
141// Side-effects: Bit String is modified.
142// Memory may be allocated.
143//
144// Dependencies: bit_position must be in the string
145//
146// End Function Specification //////////////////////////////////////
147
148void SCAN_COMM_REGISTER_CLASS::ClearBit
149(
150 uint32_t bit_position
151 /*!i Bit position in string */
152 )
153/*!o No value returned */
154{
155 BitString & bitString = AccessBitString();
156 bitString.clearBit(bit_position);
157}
158
159
160
161// Function Specification ///////////////////////////////////////////
162//
163// Title: Clear Bit String
164//
165// Purpose: This function clears the Bit String. If the data
166// member is NULL, then a new Bit String is allocated.
167// Upon return, the state of the Bit String is all zero.
168//
169// Side-effects: Bit String data member is modified.
170// Memory is allocated or reallocated.
171//
172// End Function Specification //////////////////////////////////////
173
174void SCAN_COMM_REGISTER_CLASS::clearAllBits()
175{
176 BitString & bitString = AccessBitString();
177 bitString.clearAll();
178}
179
180void SCAN_COMM_REGISTER_CLASS::setAllBits()
181{
182 BitString & bitString = AccessBitString();
183 bitString.setAll();
184}
185
186//------------------------------------------------------------------------------
187
188uint64_t SCAN_COMM_REGISTER_CLASS::GetBitFieldJustified( uint32_t i_pos,
189 uint32_t i_len ) const
190{
191 uint64_t o_value = 0;
192
193 const uint32_t len_cpu_word = sizeof(CPU_WORD) * 8;
194 const uint32_t len_uint64 = sizeof(uint64_t) * 8;
195 const uint32_t pos_end = i_pos + i_len;
196
197 PRDF_ASSERT( pos_end <= len_uint64 );
198
199 const BitString * bs = GetBitString();
200
201 for ( uint32_t pos = i_pos; pos < pos_end; pos += len_cpu_word )
202 {
203 // Calculate chunk length.
204 uint32_t len_chunk = len_cpu_word;
205 if ( len_chunk > pos_end - pos )
206 len_chunk = pos_end - pos;
207
208 o_value <<= len_chunk; // Make room for new chunk.
209
210 // Get chunk.
211 o_value |= static_cast<uint64_t>(bs->getFieldJustify(pos, len_chunk));
212 }
213
214 return o_value;
215}
216
217//------------------------------------------------------------------------------
218
219void SCAN_COMM_REGISTER_CLASS::SetBitFieldJustified( uint32_t i_pos,
220 uint32_t i_len,
221 uint64_t i_value )
222{
223 const uint32_t len_cpu_word = sizeof(CPU_WORD) * 8;
224 const uint32_t len_uint64 = sizeof(uint64_t) * 8;
225
226 PRDF_ASSERT( i_pos + i_len <= len_uint64 );
227
228 BitString & bs = AccessBitString();
229
230 for ( uint32_t offset = 0; offset < i_len; offset += len_cpu_word )
231 {
232 // Calculate chunk length.
233 uint32_t len_chunk = len_cpu_word;
234 if ( len_chunk > i_len - offset )
235 len_chunk = i_len - offset;
236
237 uint64_t value = i_value;
238 value >>= i_len - (offset + len_chunk); // right justify
239
240 // Set chunk.
241 bs.setFieldJustify( i_pos + offset, len_chunk,
242 static_cast<CPU_WORD>(value) );
243 }
244}
245
Zane Shelley871adec2019-07-30 11:01:39 -0500246} // end namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500247