Files
kunlun/bb_cpu/common/bb_cpu_timer.c
2024-09-28 14:24:04 +08:00

74 lines
2.4 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#include "bb_cpu_timer.h"
#include "hw_reg_api.h"
#include "rfplc_reg_base.h"
#include "rf_mac_reg.h"
#include "mac_sys_reg.h"
#include "mac_rf_isr.h"
extern rf_mac_isr_ctx_t g_rf_mac_isr_1;
uint32_t bb_cpu_timer_get_timeout_id()
{
return RF_MAC_READ_REG(CFG_RF_MAC_COMMON_TIMER_REG_7_ADDR);
}
void bb_cpu_timer_clr_timeout_id(uint32_t timer_sts)
{
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_5_ADDR, timer_sts);
}
void bb_cpu_timer_enable()
{
g_rf_mac_isr_1.isr_timer_mask = RF_MAC_COMMON_TIMER_CLR_CPU1_MASK;
/* enable all timer */
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_1_ADDR,
g_rf_mac_isr_1.isr_timer_mask);
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_9_ADDR,
g_rf_mac_isr_1.isr_timer_mask);
}
void bb_cpu_timer_disable()
{
g_rf_mac_isr_1.isr_timer_mask = 0;
/* disable all common timer */
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_1_ADDR, 0);
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_9_ADDR, 0);
/* clear all status */
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_5_ADDR,
RF_MAC_COMMON_TIMER_CLR_CPU1_MASK);
}
void bb_cpu_timer_start(uint32_t timer_id)
{
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_3_ADDR, (1 << timer_id));
}
void bb_cpu_timer_stop(uint32_t timer_id)
{
RF_MAC_WRITE_REG(CFG_RF_MAC_COMMON_TIMER_REG_5_ADDR, (1 << timer_id));
}
void bb_cpu_timer_set(uint32_t timer_id, uint32_t time_us)
{
IOT_ASSERT(timer_id < BB_CPU_TIMER_MAX_ID &&
time_us < BB_CPU_TIMER_MAX_TIME_US);
uint32_t addr_base = CFG_RF_MAC_COMMON_TIMER_REG_42_ADDR;
RF_MAC_WRITE_REG(addr_base + (timer_id * 4), (time_us * 25));
}