|
|
@@ -8,30 +8,30 @@ void rtc_init(rtc_run_t *rtc_run)
|
|
|
{
|
|
|
PeriClk_MutEnable(PeriClk_Rtc);
|
|
|
|
|
|
- M0P_RTC->CR0 = (1<<14) | // 0:PRDS; 1:PRDX;
|
|
|
- #ifdef RTC_INTERRUPT_TIME_5_S//add by yuewei 20260306
|
|
|
- (9<< 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
- #else
|
|
|
- (1<< 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
- #endif
|
|
|
- (0<< 7) | // start, 0:stop; 1:start;
|
|
|
- (0<< 6) | // HZ1SEL, 0:normal; 1:high precision
|
|
|
- (0<< 5) | // HZ1OE, 0:disable output 1Hz; 1:enable
|
|
|
- (1<< 3) | // AMPM, 0:12-hour; 1:24-hour;
|
|
|
- (0<< 0); // PRDS, 0:disable; 1:0.5s; 2:1s; 3:1m; 4:1h; 5:1d; 6:1m;
|
|
|
-
|
|
|
- M0P_RTC->CR1 = (0<< 8) | // 0,1:XTL; 2,3:RCL; 4:XTH=4M; 5:XTH=8M; 6:XTH=16M; 7:XTH=32M;
|
|
|
- (0<< 7) | // ALMEN, 0:disable alarm function; 1:enable
|
|
|
- (0<< 6); // ALMIE, 0:disable alarm interrupt; 1:enable
|
|
|
+ M0P_RTC->CR0 = (1 << 14) | // 0:PRDS; 1:PRDX;
|
|
|
+#ifdef RTC_INTERRUPT_TIME_5_S // add by yuewei 20260306
|
|
|
+ (9 << 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
+#else
|
|
|
+ (1 << 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
+#endif
|
|
|
+ (0 << 7) | // start, 0:stop; 1:start;
|
|
|
+ (0 << 6) | // HZ1SEL, 0:normal; 1:high precision
|
|
|
+ (0 << 5) | // HZ1OE, 0:disable output 1Hz; 1:enable
|
|
|
+ (1 << 3) | // AMPM, 0:12-hour; 1:24-hour;
|
|
|
+ (0 << 0); // PRDS, 0:disable; 1:0.5s; 2:1s; 3:1m; 4:1h; 5:1d; 6:1m;
|
|
|
+
|
|
|
+ M0P_RTC->CR1 = (0 << 8) | // 0,1:XTL; 2,3:RCL; 4:XTH=4M; 5:XTH=8M; 6:XTH=16M; 7:XTH=32M;
|
|
|
+ (0 << 7) | // ALMEN, 0:disable alarm function; 1:enable
|
|
|
+ (0 << 6); // ALMIE, 0:disable alarm interrupt; 1:enable
|
|
|
|
|
|
pRtcRun = rtc_run;
|
|
|
- M0P_RTC->SEC = OctToBcd(rtc_run->second); // BCD
|
|
|
- M0P_RTC->MIN = OctToBcd(rtc_run->minute); // BCD
|
|
|
- M0P_RTC->HOUR = OctToBcd(rtc_run->hour); // BCD
|
|
|
- M0P_RTC->DAY = OctToBcd(rtc_run->day); // BCD
|
|
|
- M0P_RTC->WEEK = OctToBcd(rtc_run->week); // DEC 0~6
|
|
|
- M0P_RTC->MON = OctToBcd(rtc_run->month); // BCD
|
|
|
- M0P_RTC->YEAR = OctToBcd(rtc_run->year); // BCD
|
|
|
+ M0P_RTC->SEC = OctToBcd(rtc_run->second); // BCD
|
|
|
+ M0P_RTC->MIN = OctToBcd(rtc_run->minute); // BCD
|
|
|
+ M0P_RTC->HOUR = OctToBcd(rtc_run->hour); // BCD
|
|
|
+ M0P_RTC->DAY = OctToBcd(rtc_run->day); // BCD
|
|
|
+ M0P_RTC->WEEK = OctToBcd(rtc_run->week); // DEC 0~6
|
|
|
+ M0P_RTC->MON = OctToBcd(rtc_run->month); // BCD
|
|
|
+ M0P_RTC->YEAR = OctToBcd(rtc_run->year); // BCD
|
|
|
|
|
|
M0P_RTC->CR0_f.START = 1;
|
|
|
|
|
|
@@ -39,7 +39,7 @@ void rtc_init(rtc_run_t *rtc_run)
|
|
|
IRQMutEnable(RTC_IRQn, NVIC_PRIO_0);
|
|
|
}
|
|
|
|
|
|
-//add by yuewei 20260519
|
|
|
+// add by yuewei 20260519
|
|
|
/**
|
|
|
* @brief 设置RTC:多少秒钟进入一次中断
|
|
|
* @param time:0.5s, 1.0s, 1.5s, 2.0s...
|
|
|
@@ -47,22 +47,22 @@ void rtc_init(rtc_run_t *rtc_run)
|
|
|
*/
|
|
|
void set_rtc_interrupt_time(float time)
|
|
|
{
|
|
|
- uint8_t prdx_val = (uint8_t)(time * 2 - 1); // 公式:cycle = (prdx_val + 1) * 0.5s
|
|
|
-
|
|
|
- M0P_RTC->CR0 = (1<<14) | // 0:PRDS; 1:PRDX;
|
|
|
- (prdx_val << 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
- (1<< 7) | // start, 0:stop; 1:start;
|
|
|
- (0<< 6) | // HZ1SEL, 0:normal; 1:high precision
|
|
|
- (0<< 5) | // HZ1OE, 0:disable output 1Hz; 1:enable
|
|
|
- (1<< 3) | // AMPM, 0:12-hour; 1:24-hour;
|
|
|
- (0<< 0); // PRDS, 0:disable; 1:0.5s; 2:1s; 3:1m; 4:1h; 5:1d; 6:1m;
|
|
|
+ uint8_t prdx_val = (uint8_t)(time * 2 - 1); // 公式:cycle = (prdx_val + 1) * 0.5s
|
|
|
+
|
|
|
+ M0P_RTC->CR0 = (1 << 14) | // 0:PRDS; 1:PRDX;
|
|
|
+ (prdx_val << 8) | // PRDX, 0:0.5s; 1:1s; 2:1.5s .... 63:32S
|
|
|
+ (1 << 7) | // start, 0:stop; 1:start;
|
|
|
+ (0 << 6) | // HZ1SEL, 0:normal; 1:high precision
|
|
|
+ (0 << 5) | // HZ1OE, 0:disable output 1Hz; 1:enable
|
|
|
+ (1 << 3) | // AMPM, 0:12-hour; 1:24-hour;
|
|
|
+ (0 << 0); // PRDS, 0:disable; 1:0.5s; 2:1s; 3:1m; 4:1h; 5:1d; 6:1m;
|
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
|
-* 函数名:RTC_GetIrqSeconds
|
|
|
-* 功能 :
|
|
|
-* 返回 :
|
|
|
-**********************************************************************/
|
|
|
+ * 函数名:RTC_GetIrqSeconds
|
|
|
+ * 功能 :
|
|
|
+ * 返回 :
|
|
|
+ **********************************************************************/
|
|
|
/**
|
|
|
* @brief 从 RTC->CR0 读取 PRDX 值,返回中断间隔秒数
|
|
|
* @param 无
|
|
|
@@ -71,11 +71,11 @@ void set_rtc_interrupt_time(float time)
|
|
|
float get_rtc_interrupt_time(void)
|
|
|
{
|
|
|
// 从 CR0 寄存器取出 [13:8] 位的 PRDX 值
|
|
|
- uint8_t prdx_val = (M0P_RTC->CR0 >> 8) & 0x3F; // 0x3F = 6位掩码
|
|
|
-
|
|
|
+ uint8_t prdx_val = (M0P_RTC->CR0 >> 8) & 0x3F; // 0x3F = 6位掩码
|
|
|
+
|
|
|
// 按规则计算秒数
|
|
|
float seconds = (prdx_val + 1) * 0.5f;
|
|
|
-
|
|
|
+
|
|
|
return seconds;
|
|
|
}
|
|
|
|
|
|
@@ -83,67 +83,82 @@ void update_rtc_run(void)
|
|
|
{
|
|
|
rtc_run_t *rr = pRtcRun;
|
|
|
|
|
|
- if (rr->second != BcdToOct(M0P_RTC->SEC)) {
|
|
|
+ if (rr->second != BcdToOct(M0P_RTC->SEC))
|
|
|
+ {
|
|
|
rr->flag_1s = 1;
|
|
|
- rr->second = BcdToOct(M0P_RTC->SEC);
|
|
|
+ rr->second = BcdToOct(M0P_RTC->SEC);
|
|
|
}
|
|
|
|
|
|
- if (rr->minute != BcdToOct(M0P_RTC->MIN)) {
|
|
|
+ if (rr->minute != BcdToOct(M0P_RTC->MIN))
|
|
|
+ {
|
|
|
rr->flag_1m = 1;
|
|
|
- rr->minute = BcdToOct(M0P_RTC->MIN);
|
|
|
+ rr->minute = BcdToOct(M0P_RTC->MIN);
|
|
|
}
|
|
|
|
|
|
- rr->hour = BcdToOct(M0P_RTC->HOUR);
|
|
|
- rr->day = BcdToOct(M0P_RTC->DAY);
|
|
|
+ rr->hour = BcdToOct(M0P_RTC->HOUR);
|
|
|
+ rr->day = BcdToOct(M0P_RTC->DAY);
|
|
|
rr->month = BcdToOct(M0P_RTC->MON);
|
|
|
- rr->year = BcdToOct(M0P_RTC->YEAR);
|
|
|
- rr->week = BcdToOct(M0P_RTC->WEEK);
|
|
|
+ rr->year = BcdToOct(M0P_RTC->YEAR);
|
|
|
+ rr->week = BcdToOct(M0P_RTC->WEEK);
|
|
|
}
|
|
|
|
|
|
-void set_rtc_date(uint8_t year, uint8_t month, uint8_t day) {
|
|
|
+void set_rtc_date(uint8_t year, uint8_t month, uint8_t day)
|
|
|
+{
|
|
|
M0P_RTC->YEAR = year;
|
|
|
- M0P_RTC->MON = month;
|
|
|
- M0P_RTC->DAY = day;
|
|
|
+ M0P_RTC->MON = month;
|
|
|
+ M0P_RTC->DAY = day;
|
|
|
}
|
|
|
|
|
|
-void get_rtc_date(uint8_t *year, uint8_t *month, uint8_t *day) {
|
|
|
- *year = M0P_RTC->YEAR;
|
|
|
+void get_rtc_date(uint8_t *year, uint8_t *month, uint8_t *day)
|
|
|
+{
|
|
|
+ *year = M0P_RTC->YEAR;
|
|
|
*month = M0P_RTC->MON;
|
|
|
- *day = M0P_RTC->DAY;
|
|
|
+ *day = M0P_RTC->DAY;
|
|
|
}
|
|
|
|
|
|
-void set_rtc_time(uint8_t hour, uint8_t min, uint8_t sec) {
|
|
|
+void set_rtc_time(uint8_t hour, uint8_t min, uint8_t sec)
|
|
|
+{
|
|
|
M0P_RTC->HOUR = hour;
|
|
|
- M0P_RTC->MIN = min;
|
|
|
- M0P_RTC->SEC = sec;
|
|
|
+ M0P_RTC->MIN = min;
|
|
|
+ M0P_RTC->SEC = sec;
|
|
|
}
|
|
|
|
|
|
-void get_rtc_time(uint8_t *hour, uint8_t *min, uint8_t *sec) {
|
|
|
+void get_rtc_time(uint8_t *hour, uint8_t *min, uint8_t *sec)
|
|
|
+{
|
|
|
*hour = M0P_RTC->HOUR;
|
|
|
- *min = M0P_RTC->MIN;
|
|
|
- *sec = M0P_RTC->SEC;
|
|
|
+ *min = M0P_RTC->MIN;
|
|
|
+ *sec = M0P_RTC->SEC;
|
|
|
}
|
|
|
|
|
|
uint32_t RTC_CntInt;
|
|
|
-uint32_t get_rtc_cnt_int(void) {
|
|
|
+uint32_t get_rtc_cnt_int(void)
|
|
|
+{
|
|
|
return RTC_CntInt;
|
|
|
}
|
|
|
|
|
|
-void set_rtc_cnt_int(uint32_t cnt_int) {
|
|
|
+void set_rtc_cnt_int(uint32_t cnt_int)
|
|
|
+{
|
|
|
RTC_CntInt = cnt_int;
|
|
|
}
|
|
|
|
|
|
static uint32_t TdcRwErrCnt = 0;
|
|
|
-uint32_t get_tdc_rw_err_cnt(void) {
|
|
|
+uint32_t get_tdc_rw_err_cnt(void)
|
|
|
+{
|
|
|
return TdcRwErrCnt;
|
|
|
}
|
|
|
|
|
|
-uint32_t GetChIdx(uint32_t cnt) {
|
|
|
- if (pTdcItf->ch_num == 1) {
|
|
|
+uint32_t GetChIdx(uint32_t cnt)
|
|
|
+{
|
|
|
+ if (pTdcItf->ch_num == 1)
|
|
|
+ {
|
|
|
return 0;
|
|
|
- } else if (pTdcItf->ch_num == 2) {
|
|
|
+ }
|
|
|
+ else if (pTdcItf->ch_num == 2)
|
|
|
+ {
|
|
|
return (cnt & 0x00000001);
|
|
|
- } else if (pTdcItf->ch_num == 4) {
|
|
|
+ }
|
|
|
+ else if (pTdcItf->ch_num == 4)
|
|
|
+ {
|
|
|
return (cnt & 0x00000003);
|
|
|
}
|
|
|
|
|
|
@@ -156,73 +171,75 @@ void RTC_IRQHandler(void)
|
|
|
{
|
|
|
|
|
|
uint32_t ISR;
|
|
|
-
|
|
|
+
|
|
|
ISR = M0P_RTC->CR1;
|
|
|
M0P_RTC->CR1 = ISR & (~0x18u);
|
|
|
|
|
|
- //if(NB_RUN_UPDATE_FLAG == 1)return; //2026-4-8 wuxiaolin
|
|
|
- //add by yuewei 20260309 to deal hongwai long data
|
|
|
- if(HONGWAI_LONG_RX_FLAG == 1)return;
|
|
|
- extern uint8_t finsh_txing_flag;
|
|
|
- if(finsh_txing_flag == 1)return;
|
|
|
- //LOG("---------------------------------0\n");
|
|
|
- extern uint8_t finsh_txing_flag; //modify by HBR 20260914 ,防止在红外通信时卡死ms1031
|
|
|
- if(finsh_txing_flag==1) return;
|
|
|
-
|
|
|
- //return;
|
|
|
- //us_delay(2000);//!!!!!do not modify!!!!!
|
|
|
- //rt_thread_delay(5);//!!!!!do not modify!!!!!
|
|
|
-
|
|
|
- // get_internal_time();
|
|
|
+ // if(NB_RUN_UPDATE_FLAG == 1)return; //2026-4-8 wuxiaolin
|
|
|
+ // add by yuewei 20260309 to deal hongwai long data
|
|
|
+ if (HONGWAI_LONG_RX_FLAG == 1)
|
|
|
+ return;
|
|
|
+ extern uint8_t finsh_txing_flag;
|
|
|
+ if (finsh_txing_flag == 1)
|
|
|
+ return;
|
|
|
+ // LOG("---------------------------------0\n");
|
|
|
+ // extern uint8_t finsh_txing_flag; //modify by HBR 20260914 ,防止在红外通信时卡死ms1031
|
|
|
+ // if(finsh_txing_flag==1) return;
|
|
|
+
|
|
|
+ // return;
|
|
|
+ // us_delay(2000);//!!!!!do not modify!!!!!
|
|
|
+ // rt_thread_delay(5);//!!!!!do not modify!!!!!
|
|
|
+
|
|
|
+ // get_internal_time();
|
|
|
if (ISR & 0x08u)
|
|
|
{
|
|
|
- rt_sem_release(&rtc_isr_sem);
|
|
|
+ rt_sem_release(&rtc_isr_sem);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void rtc_interrupt_deal_tdc(void)
|
|
|
{
|
|
|
- uint32_t Tu32;
|
|
|
-
|
|
|
- update_rtc_run();
|
|
|
- if (tof_state&(TOF_ST_METER | TOF_ST_CALIB | TOF_ST_VOID))
|
|
|
+ uint32_t Tu32;
|
|
|
+
|
|
|
+ update_rtc_run();
|
|
|
+ if (tof_state & (TOF_ST_METER | TOF_ST_CALIB | TOF_ST_VOID))
|
|
|
+ {
|
|
|
+ if (pTdcItf->mux_switch && ((RTC_CntInt & 0x00000001u) == 0) && pTdcItf->ch_num > 1)
|
|
|
{
|
|
|
- if (pTdcItf->mux_switch && ((RTC_CntInt & 0x00000001u) == 0) && pTdcItf->ch_num > 1)
|
|
|
- {
|
|
|
- uint32_t idx = GetChIdx(MUX_SwitchInt);
|
|
|
- set_mux_ch(pTdcItf->mux_ch_no[idx]);
|
|
|
- MUX_SwitchInt++;
|
|
|
- us_delay(50);
|
|
|
- }
|
|
|
- //LOG("---------------------------------1\n");
|
|
|
- RTC_CntInt++;
|
|
|
+ uint32_t idx = GetChIdx(MUX_SwitchInt);
|
|
|
+ set_mux_ch(pTdcItf->mux_ch_no[idx]);
|
|
|
+ MUX_SwitchInt++;
|
|
|
+ us_delay(50);
|
|
|
}
|
|
|
+ // LOG("---------------------------------1\n");
|
|
|
+ RTC_CntInt++;
|
|
|
+ }
|
|
|
|
|
|
- if (pTdcItf->blank_flag == pTdcItf->ch_bit_map)
|
|
|
+ if (pTdcItf->blank_flag == pTdcItf->ch_bit_map)
|
|
|
+ {
|
|
|
+ if (tof_state & TOF_ST_METER)
|
|
|
{
|
|
|
- if (tof_state&TOF_ST_METER)
|
|
|
- {
|
|
|
- tof_state = TOF_ST_VOID;
|
|
|
- }
|
|
|
+ tof_state = TOF_ST_VOID;
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (tof_state & TOF_ST_VOID)
|
|
|
{
|
|
|
- if (tof_state&TOF_ST_VOID)
|
|
|
- {
|
|
|
- tof_state = TOF_ST_METER;
|
|
|
- }
|
|
|
+ tof_state = TOF_ST_METER;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if ((tof_state&(TOF_ST_METER|TOF_ST_CALIB)) || (tof_state&TOF_ST_VOID))
|
|
|
+ if ((tof_state & (TOF_ST_METER | TOF_ST_CALIB)) || (tof_state & TOF_ST_VOID))
|
|
|
{
|
|
|
tof_flag &= ~TOF_FLAG_BLANK_PIPE;
|
|
|
- if (TdcIntStep!=0xFFu)
|
|
|
+ if (TdcIntStep != 0xFFu)
|
|
|
{
|
|
|
tof_flag |= TOF_FLAG_TDC_FAULT;
|
|
|
}
|
|
|
|
|
|
- //空管状态会关闭MS1031的高频时钟,先打开MS1031的高频时钟才能进行后续操作
|
|
|
- if(alarm_status(ERR_BLANK_PIPE))
|
|
|
+ // 空管状态会关闭MS1031的高频时钟,先打开MS1031的高频时钟才能进行后续操作
|
|
|
+ if (alarm_status(ERR_BLANK_PIPE))
|
|
|
{
|
|
|
tdc_turn_on_off_high_clk(1);
|
|
|
}
|
|
|
@@ -255,5 +272,4 @@ void rtc_interrupt_deal_tdc(void)
|
|
|
TdcIntStep = 0x03u;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|