summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV64_PolarFire_SoftConsole/polarfire_hal/platform/mpfs_hal/common/nwc/mss_cfm.h
blob: 1429da6cc722d4a144df7dbab50a6cc07f8e7b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*******************************************************************************
 * Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
 *
 */
/*=========================================================================*//**
  @mainpage PolarFire MSS Frequency Meter Bare Metal Driver.
   The MSS Clock Frequency Meter (CFM) block is used to support test of the
   DLL's within the MSS. All functional clocks are connected to the CFM block.

   The frequency meter can be configured to measure time or frequency, time
   allowing items such as PLL lock times to be tested and frequency to test
   oscillator frequencies.

   Upto 8 circuit counters are implemented.

  @section intro_sec Introduction

 *//*=========================================================================*/
#ifndef __COREPLEX_PLATFORM_CFM_H_
#define __COREPLEX_PLATFORM_CFM_H_

#ifdef __cplusplus
extern "C" {
#endif



/* CFM Register base address. */
#define CFM_REG_BASE 0x20006000

/***************************************************************************//**
  The __cfm_count_id_t enumeration is used to identify the channel used.
 */
typedef enum __cfm_count_id
{
    CFM_COUNT_0 = 0,
    CFM_COUNT_1,
    CFM_COUNT_2,
    CFM_COUNT_3,
    CFM_COUNT_4,
    CFM_COUNT_5,
    CFM_COUNT_6,
    CFM_COUNT_7,
    cfm_lastCH,
} cfm_count_id_t;



/***************************************************************************//**
  The cfm_channel_mode enumeration is used to specify the channel mode.
 */
typedef enum __cfm_channel_mode
{
    CFM_CH_DISABLED = 0,
    CFM_CH_FREQUENCY_MODE,
    CFM_CH_RESERVER,
    CFM_CH_TIMER_MODE,
    CFM_CH_lastmd
} cfm_channel_mode;



typedef enum __cfm_error_id_t
{
    CFM_OK = 0,
    ERROR_INVALID_CLK_SELECTION_GROUP,
    ERROR_INVALID_REF_SEL0,
    ERROR_INVALID_REF_SEL1,
    ERROR_INVALID_CHANNEL_DRIVE_CLK_MONITOR,
    ERROR_INVALID_CFM_BUSY,

    ERROR_NULL_VALUE,

    ERROR_CFMLAST_ID
} cfm_error_id_t;


typedef struct _cfmRegs
{
    __IO uint32_t controlReg;           /* CFM Control Register */
    __IO uint32_t clkselReg;            /* Clock Selection Register */
    __IO uint32_t runtimeReg;           /* Reference Count Value */
    __IO uint32_t modelReg;             /* Sets the measurement mode */

    __I  uint32_t count0;               /* Count x value */
    __I  uint32_t count1;
    __I  uint32_t count2;
    __I  uint32_t count3;
    __I  uint32_t count4;
    __I  uint32_t count5;
    __I  uint32_t count6;
    __I  uint32_t count7;

    __I  uint32_t reserved[4];          /*Reserved registers, padding structure */


}CFM;


#define CFM_REG                       ((CFM *)CFM_REG_BASE)

typedef struct _cfmChannelMode
{
    uint8_t channel0;        /* Channel x mode */
    uint8_t channel1;        /* Channel x mode */
    uint8_t channel2;        /* Channel x mode */
    uint8_t channel3;        /* Channel x mode */
    uint8_t channel4;        /* Channel x mode */
    uint8_t channel5;        /* Channel x mode */
    uint8_t channel6;        /* Channel x mode */
    uint8_t channel7;        /* Channel x mode */

}cfmChannelMode;

#define CFM_CONTROL_REG_BUSY_MASK        0x01U
#define CFM_CONTROL_REG_START_MASK       0x01U
#define CFM_CONTROL_REG_STOP_BITS_SHIFT  0x01U

#define CFM_CLK_SEL_MASK                 0x07U


#define CFM_CLK_REFSEL0_MASK             0x01U
#define CFM_CLK_REFSEL0SHIFT             0x04U


#define CFM_CLK_REFSEL1_MASK             0x01U
#define CFM_CLK_REFSEL1SHIFT             0x05U


#define CFM_CLK_MONSEL_MASK              0x07U
#define CFM_CLK_MONSEL_SHIFT             0x08U



#define CFM_CLK_MONEN_MASK               0x01
#define CFM_CLK_MONEN_SHIFT              11U

#define CFM_RUNTIME_REG_MASK             0xFFFFFFU

#define CFM_CHANNEL_MODE_MASK            0x3U

#define CFM_CH0_SHIFT_MASK           0x00U
#define CFM_CH1_SHIFT_MASK           0x02U
#define CFM_CH2_SHIFT_MASK           0x04U
#define CFM_CH3_SHIFT_MASK           0x06U
#define CFM_CH4_SHIFT_MASK           0x08U
#define CFM_CH5_SHIFT_MASK           0x0AU
#define CFM_CH6_SHIFT_MASK           0x0CU
#define CFM_CH7_SHIFT_MASK           0x0EU



/*****************************************************************************
 * CFM Function Prototypes
 *******************************************************************************
 */
/*-------------------------------------------------------------------------*//**
  The MSS_CFM_control_start() function causes the measurement circuitry
  to start. This state of 'busy' will clear which measurement is complete.


  @param None

   @return
    Busy state

  Example:
  The following call will start the CFM
  @code
  MSS_CFM_control_start(  );
  @endcode
 */
uint8_t MSS_CFM_control_start(void);



/*-------------------------------------------------------------------------*//**
  The MSS_CFM_control_stop() function causes the measurement circuitry
  to stop.


  @param None


  @return uint8_t
   Returns the busy flag.


  Example:
  The following call will stop the CFM
  @code
  MSS_CFM_control_stop(  );
  @endcode
 */
uint8_t MSS_CFM_control_stop(void);





/*-------------------------------------------------------------------------*//**
  The MSS_CLF_clk_configuration() function is used to configure the clock
  selection register.

  @param clkSel
    Selects which group of clock inputs are selected by the channels, control
    the input multiplexer.

  @param refsel0
    Selects the reference input, 0=clkref1 / 1=clkref2

  @param refsel1
    When in timer mode allows ATPG (corners) / clkref3 clock input to clock
    the channel counters. This clock input is expected to be sourced from an
    on-chip PLL to support at-speed testing. This allows the timer to clocked
    off a much higher clock frequency that the reference counter that is limited
    to 100Mhz.

  @param monSEL
    Selects which channel drives the clock monitor output 0-7.


  @param monEN
   Enables the clock monitor output.


   @return
    cfm_error_id_t

  Example:
  The following call will configure clk 0, using clkref1, channel zero drives
  the clock monitor and enable the clock monitor output.
  @code
  MSS_GPIO_config( 0, 0, 0, 0, 1 );
  @endcode
 */
cfm_error_id_t MSS_CLF_clk_configuration(
        uint8_t clkSel,
        uint8_t refsel0,
        uint8_t refsel1,
        uint8_t monSEL,
        uint8_t monEN
    );




/*-------------------------------------------------------------------------*//**
  The MSS_CFM_runtime_register() function is used to set how many reference
  clock cycles the frequency and time measurement should be made.
  The register does NOT change during oepration

  @param refcount
    The reference count value.

 */
void MSS_CFM_runtime_register(
        uint32_t  referenceCount
    );



/*-------------------------------------------------------------------------*//**
  The MSS_CFM_channel_mode() function is used to set the measurement mode for
  the specified channel.
   2'b00: Disabled
   2'b01: Frequency Mode
   2'b11: Timer Mode
   2'b10: Reserved

  @param cfmChannelMode
   Configuration structure for each channel

   @return
    None

 */
void MSS_CFM_channel_mode(cfmChannelMode  chMode);


/*-------------------------------------------------------------------------*//**
  The MSS_CFM_get_count() function is used to get the count value.
  Block must not be busy.

  @param ch
     The channel ID to return the count for.

  @param count
      The count for the channel register.

   @return
    cfm_error_id_t

  Example:
  The following call will return the value in count register. channel 0

  @code
  MSS_CFM_get_count();
  @endcode
 */
cfm_error_id_t MSS_CFM_get_count(cfm_count_id_t ch, uint32_t *count);


#ifdef __cplusplus
}
#endif


#endif  /* __COREPLEX_PLATFORM_CFM_H_ */