ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_sys.c
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#include "fw_sys.h"
16
22#if defined (__SDCC_SYNTAX_FIX)
23 #define __CLK_REF 10000
24#elif defined (SDCC) || defined (__SDCC)
25 #define __CLK_REF 9000
26#elif defined __CX51__ || defined __C51__
27 #define __CLK_REF 10000
28#endif
29
30__CODE uint16_t ticks_ms = (__CONF_FOSC / ((__CONF_CLKDIV == 0)? 1 : __CONF_CLKDIV) / __CLK_REF);
31__CODE uint8_t ticks_us = (__CONF_FOSC / ((__CONF_CLKDIV == 0)? 1 : __CONF_CLKDIV) / __CLK_REF / 1000);
32
33
40void SYS_SetClock(void)
41{
42#if defined (SDCC) || defined (__SDCC)
43 uint16_t i = 0; uint8_t j = 5;
44 P_SW2 = 0x80;
45 if (CLKDIV != (__CONF_CLKDIV))
46 {
48 do { // Wait a while after clock changed, or it may block the main process
49 while (--i);
50 } while (--j);
51 }
52 P_SW2 = 0x00;
54 while (--i); // Wait
55#endif
56}
57
58void SYS_TrimClock(uint8_t vrtrim, uint8_t irtrim)
59{
60 uint16_t i = 0;
62 while (--i); // Wait
63}
64
66{
67 uint16_t i;
68 do
69 {
70 i = ticks_ms;
71 while (--i);
72 } while (--t);
73}
74
76{
77 uint8_t i;
78 do
79 {
80 i = ticks_us;
81 while (--i);
82 } while (--t);
83}
#define __CONF_IRCBAND
Definition: fw_conf.h:82
#define __CONF_LIRTRIM
Definition: fw_conf.h:94
#define __CONF_CLKDIV
Definition: fw_conf.h:78
#define __CONF_VRTRIM
Definition: fw_conf.h:86
#define __CONF_FOSC
Definition: fw_conf.h:74
#define __CONF_IRTRIM
Definition: fw_conf.h:90
#define CLKDIV
__CODE uint8_t ticks_us
Definition: fw_sys.c:31
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
__CODE uint16_t ticks_ms
Definition: fw_sys.c:30
void SYS_DelayUs(uint16_t t)
Definition: fw_sys.c:75
#define SYS_SetFOSC(__IRCBAND__, __VRTRIM__, __IRTRIM__, __LIRTRIM__)
Definition: fw_sys.h:47
unsigned short uint16_t
Definition: fw_types.h:19
unsigned char uint8_t
Definition: fw_types.h:18
uint8_t __XDATA i