ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_sys.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ___FW_SYS_H___
16#define ___FW_SYS_H___
17
18#include "fw_conf.h"
19#include "fw_types.h"
20
21typedef enum
22{
26
27typedef enum
28{
32
45#define __SYSCLOCK (__CONF_FOSC / ((__CONF_CLKDIV == 0) ? 1 : __CONF_CLKDIV))
46
47#define SYS_SetFOSC(__IRCBAND__, __VRTRIM__, __IRTRIM__, __LIRTRIM__) do { \
48 IRCBAND = ((__IRCBAND__) & 0x03); \
49 VRTRIM = (__VRTRIM__); \
50 IRTRIM = (__IRTRIM__); \
51 LIRTRIM = ((__LIRTRIM__) & 0x03); \
52 } while(0)
53
57#define SYS_EnableOscillatorHSI() do { \
58 SFRX_ON(); \
59 (HIRCCR) = (HIRCCR) | (0x01 << 7); \
60 while (!(HIRCCR & 0x01)); \
61 SFRX_OFF(); \
62 } while(0)
66#define SYS_DisableOscillatorHSI() do { \
67 SFRX_ON(); \
68 (HIRCCR) = (HIRCCR) & ~(0x01 << 7); \
69 SFRX_OFF(); \
70 } while(0)
71
75#define SYS_EnableOscillatorLSI() do { \
76 SFRX_ON(); \
77 (IRC32KCR) = (IRC32KCR) | (0x01 << 7); \
78 while (!(IRC32KCR & 0x01)); \
79 SFRX_OFF(); \
80 } while(0)
84#define SYS_DisableOscillatorLSI() do { \
85 SFRX_ON(); \
86 (IRC32KCR) = (IRC32KCR) & ~(0x01 << 7); \
87 SFRX_OFF(); \
88 } while(0)
89
93#define SYS_EnableOscillatorHSE() do { \
94 SFRX_ON(); \
95 (XOSCCR) = (XOSCCR) | (0x01 << 7); \
96 while (!(HIRCCR & 0x01)); \
97 SFRX_OFF(); \
98 } while(0)
102#define SYS_DisableOscillatorHSE() do { \
103 SFRX_ON(); \
104 (XOSCCR) = (XOSCCR) & ~(0x01 << 7); \
105 SFRX_OFF(); \
106 } while(0)
110#define SYS_SetExternalOscType(__TYPE__) SFRX_ASSIGN(XOSCCR, 6, (__TYPE__))
111
115#define SYS_EnableOscillatorLSE() do { \
116 SFRX_ON(); \
117 (X32KCR) = (X32KCR) | (0x01 << 7); \
118 while (!(X32KCR & 0x01)); \
119 SFRX_OFF(); \
120 } while(0)
124#define SYS_DisableOscillatorLSE() do { \
125 SFRX_ON(); \
126 (X32KCR) = (X32KCR) & ~(0x01 << 7); \
127 SFRX_OFF(); \
128 } while(0)
132#define SYS_SetExternal32kHighGain(__STATE__) SFRX_ASSIGN(X32KCR, 6, (__STATE__))
133
138#define SYS_SetSysClockOutputDivider(__DIV__) do { \
139 SFRX_ON(); \
140 (MCLKOCR) = (MCLKOCR) & ~(0x7F) | (__DIV__); \
141 SFRX_OFF(); \
142 } while(0)
143
148#define SYS_SetClockOutputPin(__PORT__) SFRX_ASSIGN(MCLKOCR, 7, (__STATE__))
149
153#define SYS_EnableOscillator48M() do { \
154 SFRX_ON(); \
155 RSTFLAG = 0x07; \
156 (IRC48MCR) = (IRC48MCR) | (0x01 << 7); \
157 while (!(IRC48MCR & 0x01)); \
158 SFRX_OFF(); \
159 } while(0)
163#define SYS_DisableOscillator48M() do { \
164 SFRX_ON(); \
165 (IRC48MCR) = (IRC48MCR) & ~(0x01 << 7); \
166 SFRX_OFF(); \
167 } while(0)
168
169void SYS_SetClock(void);
170void SYS_TrimClock(uint8_t vrtrim, uint8_t irtrim);
171void SYS_Delay(uint16_t t);
172void SYS_DelayUs(uint16_t t);
173
174#endif
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_TrimClock(uint8_t vrtrim, uint8_t irtrim)
Definition: fw_sys.c:58
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
void SYS_DelayUs(uint16_t t)
Definition: fw_sys.c:75
SYS_SysClkOutputPort_t
Definition: fw_sys.h:28
@ SYS_SysClkOutputPort_P16
Definition: fw_sys.h:30
@ SYS_SysClkOutputPort_P54
Definition: fw_sys.h:29
SYS_ExternalOSC_t
Definition: fw_sys.h:22
@ SYS_ExternalOSC_Crystal
Definition: fw_sys.h:24
@ SYS_ExternalOSC_Clock
Definition: fw_sys.h:23
unsigned short uint16_t
Definition: fw_types.h:19
unsigned char uint8_t
Definition: fw_types.h:18