Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
38
Ver.1.0.0
In BLE SDK, we recommend using crystal clock.
In initialization, call API below to configure system clock and choose the corresponding
clock from the definition of enumeration variable SYS_CLK_TYPEDEF:
void
clock_init
(
SYS_CLK_TYPEDEF
SYS_CLK)
As 5316 System Timer is different from system clock, users need to know whether the
clock of each MCU hardware module is derived from system clock or System Timer.
Taking a system clock of 32MHz crystal for example, the system clock is 32MHz while
System Timer is 16MHz.
The definitions of system clock and S, mS, uS
in “app_config.h” are as follows:
#define
CLOCK_SYS_CLOCK_HZ 16000000
enum
{
CLOCK_SYS_CLOCK_1S
= CLOCK_SYS_CLOCK_HZ,
CLOCK_SYS_CLOCK_1MS
= (
CLOCK_SYS_CLOCK_1S
/ 1000),
CLOCK_SYS_CLOCK_1US
= (
CLOCK_SYS_CLOCK_1S
/ 1000000),
};
All the clock sources are the hardware modules of system clock. When setting the clock
for a module, only CLOCK_SYS_CLOCK_HZ, CLOCK_SYS_CLOCK_1S can be used.
In other words, if a user see that the above definitions are used for clock setting, it means
the clock source of this module is system clock.
If the setting of PWM cycle and duty ratio in PWM driver is as follows, it means the clock
source of PWM is system clock.
pwm_set_cycle_and_duty(
PWM0_ID
, (
u16
) (1000 *
CLOCK_SYS_CLOCK_1US
),
(
u16
) (500 *
CLOCK_SYS_CLOCK_1US
) );
As System Timer is fixed 16MHz, for it SDK code uses the values below for S, mS and
uS.
//system timer clock source is constant 16M, never change
enum
{
CLOCK_16M_SYS_TIMER_CLK_1S
= 16000000,
CLOCK_16M_SYS_TIMER_CLK_1MS
= 16000,
CLOCK_16M_SYS_TIMER_CLK_1US
= 16,
};
The following APIs in SDK is related to System Timer, therefore, time of these API
operations is showed in a similar way as “
CLOCK_16M_SYS_TIMER_CLK_xxx
”.
void
sleep_us(
unsigned long
us);
unsigned int
clock_time(void);
int
clock_time_exceed(
unsigned int
ref,
unsigned int
span_us);
#define
WaitUs sleep_us
#define
WaitMs(t) sleep_us((t)*1000)