Skip to content

Commit

Permalink
定时器计数正常,但无法进入中断服务函数
Browse files Browse the repository at this point in the history
  • Loading branch information
losehu committed Jan 29, 2024
1 parent 806f58a commit 9d92a67
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 141 deletions.
66 changes: 39 additions & 27 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ENABLE_SQUELCH_MORE_SENSITIVE ?= 1
ENABLE_FASTER_CHANNEL_SCAN ?= 1
ENABLE_RSSI_BAR ?= 1
ENABLE_COPY_CHAN_TO_VFO ?= 1
ENABLE_SPECTRUM ?= 1
ENABLE_SPECTRUM ?= 0
ENABLE_REDUCE_LOW_MID_TX_POWER?= 0
ENABLE_BYP_RAW_DEMODULATORS ?= 0
ENABLE_BLMIN_TMP_OFF ?= 0
Expand All @@ -50,7 +50,7 @@ ENABLE_MDC1200_CONTACT ?= 1
ENABLE_UART_RW_BK_REGS ?= 0
ENABLE_AUDIO_BAR_DEFAULT ?= 0
ENABLE_EEPROM_TYPE = 0
ENABLE_CHINESE_FULL = 4
ENABLE_CHINESE_FULL = 0
ENABLE_DOCK ?= 0
ENABLE_CUSTOM_SIDEFUNCTIONS ?= 1
ENABLE_SIDEFUNCTIONS_SEND ?= 1
Expand All @@ -59,13 +59,13 @@ ENABLE_GB2312 = 0
# ---- DEBUGGING ----
ENABLE_AM_FIX_SHOW_DATA ?= 0
ENABLE_AGC_SHOW_DATA ?= 0
ENABLE_TIMER ?= 0
ENABLE_TIMER ?= 1
ENABLE_WARNING ?= 1
ENABLE_MESSENGER ?=1
ENABLE_MESSENGER_DELIVERY_NOTIFICATION ?= 1
ENABLE_MESSENGER_NOTIFICATION ?= 1
#############################################################
PACKED_FILE_SUFFIX = LOSEHU118
PACKED_FILE_SUFFIX = LOSEHU118T
ifeq ($(ENABLE_CHINESE_FULL),1)
$(info font1)
PACKED_FILE_SUFFIX = font1
Expand Down
32 changes: 10 additions & 22 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void HandleIncoming(void)
DTMF_clear_RX();
#endif
if (gCurrentFunction != FUNCTION_FOREGROUND) {
FUNCTION_Select(FUNCTION_FOREGROUND);
FUNCTION_Select(FUNCTION_FOREGROUND); //OK
gUpdateDisplay = true;
}
return;
Expand Down Expand Up @@ -755,7 +755,7 @@ void APP_EndTransmission(bool inmediately)
gFlagReconfigureVfos = true;
}
if (inmediately || gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) {
FUNCTION_Select(FUNCTION_FOREGROUND);
FUNCTION_Select(FUNCTION_FOREGROUND);//OK
} else {
gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10;
}
Expand Down Expand Up @@ -812,7 +812,7 @@ static void HandleVox(void)
gVOX_NoiseDetected = true;

if (gCurrentFunction == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
FUNCTION_Select(FUNCTION_FOREGROUND); //OK
if (gCurrentFunction != FUNCTION_TRANSMIT && !SerialConfigInProgress())
{
#ifdef ENABLE_DTMF_CALLING
Expand Down Expand Up @@ -1245,16 +1245,10 @@ gAlarmState = ALARM_STATE_SITE_ALARM;
#endif

// repeater tail tone elimination
if (gRTTECountdown > 0)
{
if (--gRTTECountdown == 0)
{
//if (gCurrentFunction != FUNCTION_FOREGROUND)
FUNCTION_Select(FUNCTION_FOREGROUND);

gUpdateStatus = true;
gUpdateDisplay = true;
}
if (gRTTECountdown > 0 && gRTTECountdown-- == 0) {
FUNCTION_Select(FUNCTION_FOREGROUND); //OK
gUpdateStatus = true;
gUpdateDisplay = true;
}
}

Expand Down Expand Up @@ -1570,7 +1564,7 @@ static void ALARM_Off(void)
gEnableSpeaker = false;

if (gAlarmState == ALARM_STATE_TXALARM || gAlarmState == ALARM_STATE_TX1750) {
RADIO_SendEndOfTransmission();
APP_EndTransmission(false); //OK
}

gAlarmState = ALARM_STATE_OFF;
Expand Down Expand Up @@ -1600,7 +1594,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}

if (gCurrentFunction == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
FUNCTION_Select(FUNCTION_FOREGROUND); //OK

gBatterySaveCountdown_10ms = battery_save_count_10ms;

Expand Down Expand Up @@ -1881,15 +1875,9 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
else if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed)) {
ALARM_Off();

if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0)
FUNCTION_Select(FUNCTION_FOREGROUND);
else
gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10;

if (Key == KEY_PTT)
gPttWasPressed = true;
else
if (!bKeyHeld)
else if (!bKeyHeld)
gPttWasReleased = true;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion app/messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void MSG_Send(const char *txMessage, bool bServiceMessage) {

//SYSTEM_DelayMs(100);

APP_EndTransmission(true);
APP_EndTransmission(true); //OK

RADIO_SetVfoState(VFO_STATE_NORMAL);

Expand Down
2 changes: 1 addition & 1 deletion app/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static void CMD_052F(const uint8_t *pBuffer) {
#endif

if (gCurrentFunction == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
FUNCTION_Select(FUNCTION_FOREGROUND); //OK

gSerialConfigCountDown_500ms = 12; // 6 sec

Expand Down
14 changes: 1 addition & 13 deletions bsp/dp32g030/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <stdint.h>

#define TIMERBASE0_ADD 0x40064000
#define TIMERBASE1_ADD 0x40064800
//TIMER0
#define TIMERBASE0_EN_ADD (0X00+TIMERBASE0_ADD)
#define TIMERBASE0_DIV_ADD (0X04+TIMERBASE0_ADD)
Expand All @@ -28,21 +27,10 @@
#define TIMERBASE0_LOW_CNT (*(volatile uint32_t *)TIMERBASE0_LOW_CNT_ADD)


//TIMER1
#define TIMERBASE1_EN_ADD 0X00+TIMERBASE1_ADD
#define TIMERBASE1_DIV_ADD 0X04+TIMERBASE1_ADD
#define TIMERBASE1_IE_ADD 0X10+TIMERBASE1_ADD
#define TIMERBASE1_IF_ADD 0X14+TIMERBASE1_ADD
#define TIMERBASE1_HIGH_LOAD_ADD 0X20+TIMERBASE1_ADD
#define TIMERBASE1_HIGH_CNT_ADD 0X24+TIMERBASE1_ADD
#define TIMERBASE1_LOW_LOAD_ADD 0X30+TIMERBASE1_ADD
#define TIMERBASE1_LOW_CNT_ADD 0X34+TIMERBASE1_ADD


extern uint32_t TIM0_CNT;

extern uint8_t TIM0_CNT;
void TIM0_INIT();
void TIM0_SET_ARR(uint16_t Arr) ;

void TIM0_SET_PSC(uint16_t prescaler) ;
#endif //UV_K5_FIRMWARE_CUSTOM_0_17_TIMER_H
64 changes: 18 additions & 46 deletions driver/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,36 @@
#include "bsp/dp32g030/timer.h"
#include "ARMCM0.h"

uint8_t TIM0_CNT=0;

void TIM0_ISR()
{
TIM0_CNT++;

TIMERBASE0_IF |= (1 << 0); // 写1清零 清除定时器中断状态

}
void TIM0_SET_PSC(uint16_t prescaler) {
// 确保传入的分频系数在合法范围内(0 到 0xFFFF)
if (prescaler <= 0xFFFF) {
// 清除 DIV 位域
TIMERBASE0_DIV &= ~(0xFFFF); // 通过与操作清除 DIV 位域的内容
// 设置 DIV 位域为传入的分频系数
TIMERBASE0_DIV |= prescaler;
}
}
void TIM0_SET_ARR(uint16_t Arr) {
// 确保传入的分频系数在合法范围内(0 到 0xFFFF)
if (Arr <= 0xFFFF) {
// 清除 DIV 位域
TIMERBASE0_LOW_LOAD &= ~(0xFFFF); // 通过与操作清除 DIV 位域的内容
// 设置 DIV 位域为传入的分频系数
TIMERBASE0_LOW_LOAD |= Arr;
}

}
void TIM0_INIT()
{
// Define TIMERBASE0 base address
#define TIMERBASE0_BASE 0x40064000


#define TIMERBASE_EN_OFFSET 0x00
#define TIMERBASE_IE_OFFSET 0x10
#define TIMERBASE_IF_OFFSET 0x14

TIMERBASE0_DIV=48000;
TIMERBASE0_LOW_LOAD=10000;
TIMERBASE0_HIGH_LOAD=3000;

// Enable TIMERBASE0
*((volatile unsigned int *)(TIMERBASE0_BASE + TIMERBASE_EN_OFFSET)) |= 0x1; // Enable LOW_EN
// Enable TIMERBASE0
NVIC_SetPriority (Interrupt5_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */

// Enable Timer0 interrupt
*((volatile unsigned int *)(TIMERBASE0_BASE + TIMERBASE_IE_OFFSET)) |= 0x1; // Enable LOW_IE
TIMERBASE0_IF = 0x03 ; // 写1清零 清除定时器中断状态
TIMERBASE0_IE|= 0x03;

// Enable global interrupts (assuming your MCU supports this)
__enable_irq(); // Function to enable interrupts
TIMERBASE0_EN|= 0x03;
__enable_irq(); // Function to enable interrupts


//
// TIM0_SET_PSC(480-1);//48000000/480/100=1000
// TIM0_SET_ARR(1000);//10ms
// TIMERBASE0_IF |= (1 << 1) | (1 << 0); // 写1清零 清除定时器中断状态
// TIMERBASE0_IE |= (1 << 1) | (1 << 0); // 1高 0低 使能定时器中断
// TIMERBASE0_EN |=(1 << 1) | (1 << 0);//1高 0低 使能定时器
//
// __enable_irq();
}

uint32_t TIM0_CNT=0;
void TIM0Handler(void);

void TIM0Handler(void)
{
TIM0_CNT++;
TIMERBASE0_IF =0; // 写1清零 清除定时器中断状态

}


Loading

0 comments on commit 9d92a67

Please sign in to comment.