WXK
2025-02-11 e328ebef585cea2351b37117b2d5ac4978ecd3c0
keil/include/drivers/mk_misc.h
@@ -40,24 +40,38 @@
#ifndef MK_MISC_H_
#define MK_MISC_H_
#include "mk_common.h"
#include "mk_clock.h"
/**
 * @addtogroup MK8000_MISC
 * @{
 */
// DIV = 1    (max: ~68.8s,     resolution: ~16ns)
// DIV = 16   (max: ~1101.2s,   resolution: ~256ns)
// DIV = 256  (max: ~17620.3s   resolution: ~65us)
#define SYS_TIMER_DIV 1
/** System timer frequency */
#if SYS_TIMER_DIV == 1
#define SYS_TIMER_FREQ (62400000 >> (AHB_DIV + APB_DIV))
#elif SYS_TIMER_DIV == 16
#define SYS_TIMER_FREQ (3900000 >> (AHB_DIV + APB_DIV))
#else
#define SYS_TIMER_FREQ (243750 >> (AHB_DIV + APB_DIV))
#endif
/** us to system tick converter, us < 68,829us */
#define __US_TO_TICKS(us) (((us) * ((sys_timer_freq) / 1000)) / 1000)
#define __US_TO_TICKS(us) (((us) * ((SYS_TIMER_FREQ) / 1000)) / 1000)
/** system tick to us converter */
#define __TICKS_TO_US(tick) ((tick) / (((sys_timer_freq) / 1000) / 1000))
#define __TICKS_TO_US(tick) ((tick) / (((SYS_TIMER_FREQ) / 1000) / 1000))
/** system tick to us converter, allow long long type multiply operation to promote precision */
#define __TICKS_TO_US_LL(tick) (uint32_t)(((uint64_t)(tick)*1000) / (sys timer freg / 1000))
#define __TICKS_TO_US_LL(tick) (uint32_t)(((uint64_t)(tick)*1000) / (SYS_TIMER_FREQ / 1000))
/** ms to system tick converter, ms < 68,829ms */
#define __MS_TO_TICKS(ms) ((ms) * ((sys_timer_freq) / 1000))
#define __MS_TO_TICKS(ms) ((ms) * ((SYS_TIMER_FREQ) / 1000))
/** system tick to ms converter */
#define __TICKS_TO_MS(tick) ((tick) / ((sys_timer_freq) / 1000))
#define __TICKS_TO_MS(tick) ((tick) / ((SYS_TIMER_FREQ) / 1000))
/** ms to sleep timer count converter */
#define __MS_TO_32K_CNT(ms) ((uint32_t)((float)(ms)*32768.0f / 1000.0f))
@@ -157,8 +171,6 @@
void bor_close(void);
/* SYS Timer */
/** System timer frequency */
extern uint32_t sys_timer_freq;
/**
 * @brief Open the system timer, system timer is a free running counter, using the Dual timer 0.
@@ -174,7 +186,11 @@
 * @brief Get the system timer count.
 * @return the system timer count
 */
#if defined(__ICCARM__)
uint32_t sys_timer_get(void);
#else
uint32_t RAM_FUNC sys_timer_get(void);
#endif
/**
 * @brief Delay us.
@@ -217,7 +233,7 @@
    uint32_t load;
    uint32_t val;
    uint32_t elapse;
    void (*callback)(void);
    void (*callback)(uint32_t elapsed_ticks);
};
/**
@@ -249,12 +265,13 @@
 * @return elapsed time in ms
 */
uint32_t sys_tick_elapse_ms(void);
uint32_t sys_tick_elapse_ticks(void);
/**
 * @brief Register callback function for systick timer.
 * @return callback systick timer callback function
 */
void sys_tick_callback_set(void (*callback)(void));
void sys_tick_callback_set(void (*callback)(uint32_t elapsed_ticks));
/**
 * @brief Pause the systick timer.