本帖最后由 蜗牛蜗牛 于 2017-8-12 08:56 编辑
现在情况是这样的,主程序时间50秒左右,期间开启了定时器定时器时间是20ms ,一直是在定时器中喂狗 喂狗值是(4.625),也就是1秒,现在发现程序运行几天还会莫名其妙的死机(我猜测是主程序死了,但是定时器一直在运行所以单片机不复位),
按复位键就好另外主程序里面还有个小程序,小程序运行时间大约是1分钟,不过主程序的小程序,满足条件后才触发,一般也不触发,运行1年也就触发几次 ,
现在我想解决方法:主程序到处喂狗,直到满足不使单片机复位位置为止,
还有没有好的,喂狗方法,?定时器中断喂狗好像不行,
星期一要是没有好的解决方案,就按喂狗时间5折到处喂狗了
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
不过一弄好了你在这个类型的产品都可以一劳永逸了。磨刀不误砍柴功,架构就相当于你的刀。
以lz目前的状况,不易上系统,搞个状态机就ok了,
直接在这段执行40秒或100秒的代码中插入清看门狗的语句不就行了嘛,你不要说在这个地方插不进去……以上是应急的方法。
估计要你重写架构也会勉为其难的,目前还是凑合着,修修补补用着吧。
#include "string.h"
#define BSP_AUDIO_DMA_BUFFER_SIZE 512
static CBREAD readfile;
static void *filehandle;
static u8 isplaying = 0;
static u8 buffer[BSP_AUDIO_DMA_BUFFER_SIZE];
#define DAC_DHR8R1_ADDRESS 0x40007410
void bsp_audio_init(u16 sr)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
DAC_InitTypeDef DAC_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//AMP ShutDown
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 90000000 / sr;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_DMACmd(TIM4, TIM_DMA_Update, ENABLE);
DAC_DeInit();
DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);
//DAC_DMACmd(DAC_Channel_1, ENABLE);
DMA_DeInit(DMA1_Stream6);
DMA_InitStructure.DMA_Channel = DMA_Channel_2;
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&buffer;
DMA_InitStructure.DMA_BufferSize = BSP_AUDIO_DMA_BUFFER_SIZE;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream6, &DMA_InitStructure);
DMA_ITConfig(DMA1_Stream6, DMA_IT_TC | DMA_IT_HT, ENABLE);
DMA_Cmd(DMA1_Stream6, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
u8 bsp_audio_isbusy(void)
{
return isplaying;
}
void bsp_audio_start(CBREAD read, void *phandle)
{
u32 readlen;
if(isplaying == 1)
{
return;
}
readfile = read;
filehandle = phandle;
readlen = readfile(filehandle, buffer, BSP_AUDIO_DMA_BUFFER_SIZE);
if(readlen == 0)
{
return;
}
TIM_Cmd(TIM4, ENABLE);
AUDIO_AMP_ON;
isplaying = 1;
}
void bsp_audio_stop(void)
{
TIM_Cmd(TIM4, DISABLE);
memset(buffer, 0x80, sizeof(buffer));
isplaying = 0;
AUDIO_AMP_OFF;
}
void DMA1_Stream6_IRQHandler(void)
{
u32 readlen;
if(DMA_GetITStatus(DMA1_Stream6, DMA_IT_HTIF6) == SET)
{
readlen = readfile(filehandle, buffer, BSP_AUDIO_DMA_BUFFER_SIZE / 2);
if(readlen == 0)
{
bsp_audio_stop();
}
}
else if(DMA_GetITStatus(DMA1_Stream6, DMA_IT_TCIF6) == SET)
{
readlen = readfile(filehandle, buffer + BSP_AUDIO_DMA_BUFFER_SIZE / 2, BSP_AUDIO_DMA_BUFFER_SIZE / 2);
if(readlen == 0)
{
bsp_audio_stop();
}
}
DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6 | DMA_IT_HTIF6);
}
一周热门 更多>