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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
/**
* @file
* @brief System level header file.
*/
/*******************************************************************************
* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-04-15 09:35:40 -0500 (Mon, 15 Apr 2019) $
* $Revision: 42499 $
*
******************************************************************************/
#ifndef _MXC_SYS_H_
#define _MXC_SYS_H_
#include "mxc_config.h"
#include "uart_regs.h"
#include "i2c_regs.h"
#include "gcr_regs.h"
#include "tmr_regs.h"
#include "icc_regs.h"
#include "spi17y_regs.h"
#include "spimss_regs.h"
#include "gpio.h"
#include "flc_regs.h"
#include "dma.h"
#include "wdt_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined ( __CC_ARM ) /* Suppressing the warning: "enum value is out of range of int" for Keil */
#pragma push
#pragma diag_suppress 66
#endif /* __CC_ARM */
/** @brief System reset0 enumeration. Used in SYS_PeriphReset0 function */
typedef enum {
SYS_RESET0_DMA = MXC_F_GCR_RSTR0_DMA, /**< Reset DMA */
SYS_RESET0_WDT = MXC_F_GCR_RSTR0_WDT, /**< Reset WDT */
SYS_RESET0_GPIO0 = MXC_F_GCR_RSTR0_GPIO0, /**< Reset GPIO0 */
SYS_RESET0_TIMER0 = MXC_F_GCR_RSTR0_TIMER0, /**< Reset TIMER0 */
SYS_RESET0_TIMER1 = MXC_F_GCR_RSTR0_TIMER1, /**< Reset TIMER1 */
SYS_RESET0_TIMER2 = MXC_F_GCR_RSTR0_TIMER2, /**< Reset TIMER2 */
SYS_RESET0_UART0 = MXC_F_GCR_RSTR0_UART0, /**< Reset UART0 */
SYS_RESET0_UART1 = MXC_F_GCR_RSTR0_UART1, /**< Reset UART1 */
SYS_RESET0_SPI0 = MXC_F_GCR_RSTR0_SPI0, /**< Reset SPI0 */
SYS_RESET0_SPI1 = MXC_F_GCR_RSTR0_SPI1, /**< Reset SPI1 */
SYS_RESET0_I2C0 = MXC_F_GCR_RSTR0_I2C0, /**< Reset I2C0 */
SYS_RESET0_RTC = MXC_F_GCR_RSTR0_RTC, /**< Reset RTC */
SYS_RESET0_SRST = MXC_F_GCR_RSTR0_SRST, /**< Soft reset */
SYS_RESET0_PRST = MXC_F_GCR_RSTR0_PRST, /**< Peripheral reset */
SYS_RESET0_SYSTEM = MXC_F_GCR_RSTR0_SYSTEM, /**< System reset */
} sys_reset0_t;
/** @brief System reset1 enumeration. Used in SYS_PeriphReset1 function */
typedef enum {
SYS_RESET1_I2C1 = MXC_F_GCR_RSTR1_I2C1, /**< Reset I2C1 */
} sys_reset1_t;
/** @brief System clock disable enumeration. Used in SYS_ClockDisable and SYS_ClockEnable functions */
typedef enum {
SYS_PERIPH_CLOCK_GPIO0 = MXC_F_GCR_PERCKCN0_GPIO0D, /**< Disable MXC_F_GCR_PERCKCN0_GPIO0D clock */
SYS_PERIPH_CLOCK_DMA = MXC_F_GCR_PERCKCN0_DMAD, /**< Disable MXC_F_GCR_PERCKCN0_DMAD clock */
SYS_PERIPH_CLOCK_SPI17Y = MXC_F_GCR_PERCKCN0_SPI0D, /**< Disable MXC_F_GCR_PERCKCN0_SPI0D clock */
SYS_PERIPH_CLOCK_SPIMSS = MXC_F_GCR_PERCKCN0_SPI1D, /**< Disable MXC_F_GCR_PERCKCN0_SPI1D clock */
SYS_PERIPH_CLOCK_UART0 = MXC_F_GCR_PERCKCN0_UART0D, /**< Disable MXC_F_GCR_PERCKCN0_UART0D clock */
SYS_PERIPH_CLOCK_UART1 = MXC_F_GCR_PERCKCN0_UART1D, /**< Disable MXC_F_GCR_PERCKCN0_UART1D clock */
SYS_PERIPH_CLOCK_I2C0 = MXC_F_GCR_PERCKCN0_I2C0D, /**< Disable MXC_F_GCR_PERCKCN0_I2C0D clock */
SYS_PERIPH_CLOCK_T0 = MXC_F_GCR_PERCKCN0_T0D, /**< Disable MXC_F_GCR_PERCKCN0_T0D clock */
SYS_PERIPH_CLOCK_T1 = MXC_F_GCR_PERCKCN0_T1D, /**< Disable MXC_F_GCR_PERCKCN0_T1D clock */
SYS_PERIPH_CLOCK_T2 = MXC_F_GCR_PERCKCN0_T2D, /**< Disable MXC_F_GCR_PERCKCN0_T2D clock */
SYS_PERIPH_CLOCK_I2C1 = MXC_F_GCR_PERCKCN0_I2C1D, /**< Disable MXC_F_GCR_PERCKCN0_I2C1D clock */
} sys_periph_clock_t;
/** @brief Clock source */
typedef enum {
SYS_CLOCK_NANORING = MXC_V_GCR_CLKCN_CLKSEL_NANORING, /**< 8KHz nanoring on MAX32660 */
SYS_CLOCK_HFXIN = MXC_V_GCR_CLKCN_CLKSEL_HFXIN, /**< 32KHz on MAX32660 */
SYS_CLOCK_HFXIN_DIGITAL = 0x9, /**< External Clock Input*/
SYS_CLOCK_HIRC = MXC_V_GCR_CLKCN_CLKSEL_HIRC, /**< High Frequency Internal Oscillator */
} sys_system_clock_t;
typedef void* sys_cfg_t;
typedef sys_cfg_t sys_cfg_i2c_t;
typedef sys_cfg_t sys_cfg_flc_t;
typedef sys_cfg_t sys_cfg_wdt_t;
/** @brief Map control */
typedef enum {
MAP_A,
MAP_B,
MAP_C,
} sys_map_t;
/** @brief UART Flow control */
typedef enum {
UART_FLOW_DISABLE,
UART_FLOW_ENABLE,
} sys_uart_flow_t;
/** @brief UART system configuration object */
typedef struct {
sys_map_t map;
sys_uart_flow_t flow_flag;
} sys_cfg_uart_t;
/** @brief SPI17Y system configuration object */
typedef struct {
sys_map_t map;
} sys_cfg_spi17y_t;
/** @brief SPIMSS system configuration object */
typedef struct {
sys_map_t map;
} sys_cfg_spimss_t;
/** @brief I2S system configuration object */
typedef struct {
sys_map_t map;
dma_reqsel_t dma_reqsel_tx;
dma_reqsel_t dma_reqsel_rx;
} sys_cfg_i2s_t;
/** @brief TIMER system configuration object */
typedef struct {
int out_en;
} sys_cfg_tmr_t;
/** @brief Real Time Clock system configuration object */
typedef struct {
mxc_tmr_regs_t* tmr;
} sys_cfg_rtc_t;
/** @brief Pulse Train System Configuration Object */
typedef gpio_cfg_t sys_cfg_pt_t;
#if defined ( __CC_ARM ) /* Restore the warning: "enum is out of int range" for Keil */
#pragma pop
#endif /* __CC_ARM */
/***** Function Prototypes *****/
/**
* @brief Selects the system clock and enables it once ready
* @param clock Enumeration for desired clock.
* @param tmr Optional tmr pointer for timeout. NULL if undesired.
*
* @returns #E_NO_ERROR is clock is succesfully selected
*/
int SYS_Clock_Select(sys_system_clock_t clock, mxc_tmr_regs_t* tmr);
/**
* @brief Enables the selected peripheral clock.
* @param clock Enumeration for desired clock.
*/
void SYS_ClockEnable(sys_periph_clock_t clock);
/**
* @brief Disables the selected peripheral clock.
* @param clock Enumeration for desired clock.
*/
void SYS_ClockDisable(sys_periph_clock_t clock);
/**
* @brief Enables the external 32k oscillator.
* @param sys_cfg system configuration object
*
* @returns #E_NO_ERROR is successful, appropriate error otherwise
*/
int SYS_ClockEnable_X32K(sys_cfg_rtc_t *sys_cfg);
/**
* @brief Disables the external 32k oscillator.
*
* @returns #E_NO_ERROR is successful, appropriate error otherwise
*/
int SYS_ClockDisable_X32K(void);
/**
* @brief System level initialization for UART module.
* @param uart Pointer to UART module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_UART_Init(mxc_uart_regs_t *uart, const sys_cfg_uart_t* sys_cfg);
/**
* @brief System level shutdown for UART module
* @param uart Pointer to UART module registers
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_UART_Shutdown(mxc_uart_regs_t *uart);
/**
* @brief System level initialization for I2C module.
* @param i2c Pointer to I2C module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2C_Init(mxc_i2c_regs_t *i2c, const sys_cfg_i2c_t* sys_cfg);
/**
* @brief System level Shutdown for I2C module.
* @param i2c Pointer to I2C module registers
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2C_Shutdown(mxc_i2c_regs_t *i2c);
/**
* @brief Init DMA system settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_DMA_Init(void);
/**
* @brief Shutdown DMA system specific settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_DMA_Shutdown(void);
/**
* @brief Get the frequency of the I2C module source clock
* @param spim Unused, pointer to I2C module registers
*
* @returns frequency in Hz
*/
unsigned SYS_I2C_GetFreq(mxc_i2c_regs_t *i2c);
/**
* @brief Get the frequency of the Timer module source clock.
* @params tmr Unused, pointer to timer module registers
*
* @returns frequency in Hz
*/
unsigned SYS_TMR_GetFreq(mxc_tmr_regs_t *tmr);
/**
* @brief Reset the peripherals and/or CPU in the rstr0 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void SYS_Reset0(sys_reset0_t reset);
/**
* @brief Reset the peripherals and/or CPU in the rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void SYS_Reset1(sys_reset1_t reset);
/**
* @brief Clear Cache and Line buffer.
*/
void SYS_Flash_Operation(void);
/**
* @brief Init TMR system settings
* @param tmr Pointer to timer module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_TMR_Init(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t* sys_cfg);
/**
* @brief Init flash system settings
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_FLC_Init(const sys_cfg_flc_t* sys_cfg);
/**
* @brief Shutdown flash system specific settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_FLC_Shutdown(void);
/**
* @brief System level initialization for SPI17Y module.
* @param spi pointer to spi module registers
* @param sys_cfg System configuration object
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPI17Y_Init( mxc_spi17y_regs_t *spi, const sys_cfg_spi17y_t* sys_cfg);
/**
* @brief System level shutdown for SPI17Y module
* @param pointer to spi module registers
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPI17Y_Shutdown(mxc_spi17y_regs_t *spi);
/**
* @brief System level initialization for SPIMSS module.
* @param spi pointer to spi module registers
* @param sys_cfg System configuration object
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPIMSS_Init(mxc_spimss_regs_t *spi, const sys_cfg_spimss_t* sys_cfg);
/**
* @brief System level shutdown for SPIMSS module
* @param pointer to spi module registers
*
* @returns E_NO_ERROR if everything is successful
*/
int SYS_SPIMSS_Shutdown(mxc_spimss_regs_t *spi);
/**
* @brief Shutdown Timer system specific settings
* @param tmr pointer to timer module registers
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_TMR_Shutdown(mxc_tmr_regs_t *tmr);
/**
* @brief System level initialization for I2S Module
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2S_Init(const sys_cfg_i2s_t* sys_cfg);
/**
* @brief System level shutdown of I2S module
*
* @returns #E_NO_ERROR if everything is successful
*/
int SYS_I2S_Shutdown(void);
/**
* @brief Get the frequency of the I2S module source clock
* @param spimss Pointer to I2S module registers
*
* @returns frequency in Hz
*/
int SYS_I2S_GetFreq(mxc_spimss_regs_t *spimss);
/**
* @brief Init system settings for RTC square wave output.
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_RTC_SqwavInit(const sys_cfg_rtc_t* sys_cfg);
/**
* @brief System Tick Configuration Helper
*
* The function enables selection of the external clock source for
* the System Tick Timer. It initializes the System Timer and its
* interrupt, and starts the System Tick Timer. Counter is in free
* running mode to generate periodic interrupts.
*
* @param ticks Number of ticks between two interrupts.
* @param clk_src Selects between default SystemClock or External Clock.
* - 0 Use external clock source
* @param tmr Optional tmr pointer for timeout. NULL if undesired.
* - 1 SystemClock
*
* @return #E_NO_ERROR Function succeeded, of #E_INVALID if an invalid value is requested
*/
int SYS_SysTick_Config(uint32_t ticks, int clk_src, mxc_tmr_regs_t* tmr);
/**
* @brief Disable System Tick timer
*/
void SYS_SysTick_Disable(void);
/**
* @brief Delay a requested number of SysTick Timer Ticks.
* @param ticks Number of System Ticks to delay.
* @note This delay function is based on the clock used for the SysTick
* timer if the SysTick timer is enabled. If the SysTick timer is
* not enabled, the current SysTick registers are saved and the
* timer will use the SystemClock as the source for the delay. The
* delay is measured in clock ticks and is not based on the SysTick
* interval.
*
* @return #E_NO_ERROR if everything is successful
*/
int SYS_SysTick_Delay(uint32_t ticks);
/**
* @brief Get the frequency of the SysTick Timer
*
* @return frequency in Hz
*/
uint32_t SYS_SysTick_GetFreq(void);
/**
* @brief Delay a requested number of microseconds.
* @param us Number of microseconds to delay.
* @note Calls SYS_SysTick_Delay().
*/
void SYS_SysTick_DelayUs(uint32_t us);
/**
* @brief Init WDT system settings
* @param wdt watchdog registers
* @param sys_cfg System configuration object
*/
int SYS_WDT_Init(mxc_wdt_regs_t* wdt, const sys_cfg_wdt_t* sys_cfg);
#ifdef __cplusplus
}
#endif
#endif /* _MXC_SYS_H_*/
|