概述
本示例,只要介绍,如何使用WDG,又离成功进了一步 ^_^。
一、环境
1、硬件 (RTL8762DK + 128M Bits Falsh)
2、软件(keil IDE)
二、WDG的使用
1、创建工程步骤,请参考第二篇文章。
1)、添加wdg驱动文件
2、wdg.h
/**
*********************************************************************************************************
* Copyright(c) 2018, Realtek Semiconductor Corporation. All rights reserved.
*********************************************************************************************************
* @file wdg.h
* @brief
* @details
* @author yuan
* @date 2018-12-07
* @version v1.0
*********************************************************************************************************
*/
#ifndef __WDG_H
#define __WDG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "rtl876x_rcc.h"
#include "rtl876x_wdg.h"
/* Defines ------------------------------------------------------------------*/
void driver_wdg_init(void);
void wdg_feed(void);
#ifdef __cplusplus
}
#endif
#endif
3、wdg.c
/**
*********************************************************************************************************
* Copyright(c) 2018, Realtek Semiconductor Corporation. All rights reserved.
**********************************************************************************************************
* @file wdg.c
* @brief This file provides demo code of WDG.
Not feeding the dog before the wdg timer timeout,then reset system.
Press KEY0 to feed dog, the timer restart.Then it does not reset system.
* @details
* @author yuan
* @date 2018-02-05
* @version v1.0
*********************************************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "wdg.h"
/**
* @brief Initialize WDG.
* @param No parameter.
* @return void
*/
void driver_wdg_init(void)
{
WDG_ClockEnable();
/* WDG timing time = ((77+1)/32000)*( 2^(11+1) - 1) , about 10S
* Reset mode following:
* INTERRUPT_CPU: interrupt CPU
* RESET_ALL_EXCEPT_AON: reset all except aon
* RESET_CORE_DOMAIN: reset core domain
* RESET_ALL: reset all
*/
WDG_Config(77, 11, RESET_ALL);
WDG_Enable();
}
/**
* @brief Feeding dog.
* @param No parameter.
* @return void
*/
void wdg_feed(void)
{
WDG_Restart();
}
/******************* (C) COPYRIGHT 2018 Realtek Semiconductor Corporation *****END OF FILE****/
4、io_gpio.h
/**
*********************************************************************************************************
* Copyright(c) 2018, Realtek Semiconductor Corporation. All rights reserved.
*********************************************************************************************************
* @file io_gpio.h
* @brief
* @details
* @author yuan
* @date 2018-12-07
* @version v1.0
*********************************************************************************************************
*/
#ifndef __IO_GPIO_H
#define __IO_GPIO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "rtl876x_gpio.h"
#include "rtl876x_nvic.h"
#include "rtl876x_pinmux.h"
#include "rtl876x_rcc.h"
#include "board.h"
/* Defines ------------------------------------------------------------------*/
void board_gpio_init(void);
void driver_gpio_init(void);
#ifdef __cplusplus
}
#endif
#endif
5、io_gpio.c
/**
*********************************************************************************************************
* Copyright(c) 2018, Realtek Semiconductor Corporation. All rights reserved.
*********************************************************************************************************
* @file io_gpio.c
* @brief This file provides demo code of gpio interrupt mode.
* @details
* @author yuan
* @date 2018-12-07
* @version v1.0
*********************************************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "io_gpio.h"
#include "app_task.h"
/**
* @brief Initialization of pinmux settings and pad settings.
* @param No parameter.
* @return void
*/
void board_gpio_init(void)
{
Pad_Config(GPIO_INPUT_PIN_0, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_UP, PAD_OUT_DISABLE,
PAD_OUT_HIGH);
Pinmux_Config(GPIO_INPUT_PIN_0, DWGPIO);
}
/**
* @brief Initialize GPIO peripheral.
* @param No parameter.
* @return void
*/
void driver_gpio_init(void)
{
/* Initialize GPIO peripheral */
RCC_PeriphClockCmd(APBPeriph_GPIO, APBPeriph_GPIO_CLOCK, ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_PIN_INPUT;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_ITCmd = ENABLE;
GPIO_InitStruct.GPIO_ITTrigger = GPIO_INT_Trigger_EDGE;
GPIO_InitStruct.GPIO_ITPolarity = GPIO_INT_POLARITY_ACTIVE_LOW;
GPIO_InitStruct.GPIO_ITDebounce = GPIO_INT_DEBOUNCE_ENABLE;
GPIO_InitStruct.GPIO_DebounceTime = 10;/* unit:ms , can be 1~64 ms */
GPIO_Init(&GPIO_InitStruct);
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = GPIO_PIN_INPUT_IRQN;
NVIC_InitStruct.NVIC_IRQChannelPriority = 3;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
GPIO_MaskINTConfig(GPIO_PIN_INPUT, DISABLE);
GPIO_INTConfig(GPIO_PIN_INPUT, ENABLE);
}
/**
* @brief GPIO interrupt handler function.
* @param No parameter.
* @return void
*/
void GPIO_Input_Handler(void)
{
GPIO_INTConfig(GPIO_PIN_INPUT, DISABLE);
GPIO_MaskINTConfig(GPIO_PIN_INPUT, ENABLE);
T_IO_MSG int_gpio_msg;
int_gpio_msg.type = IO_MSG_TYPE_GPIO;
int_gpio_msg.subtype = 0;
if (false == app_send_msg_to_apptask(&int_gpio_msg))
{
APP_PRINT_ERROR0("[io_gpio] GPIO_Input_Handler: Send int_gpio_msg failed!");
//Add user code here!
GPIO_ClearINTPendingBit(GPIO_PIN_INPUT);
return;
}
GPIO_ClearINTPendingBit(GPIO_PIN_INPUT);
GPIO_MaskINTConfig(GPIO_PIN_INPUT, DISABLE);
GPIO_INTConfig(GPIO_PIN_INPUT, ENABLE);
}
/******************* (C) COPYRIGHT 2018 Realtek Semiconductor Corporation *****END OF FILE****/
6、peripheral_app.c
/**
*****************************************************************************************
* Copyright(c) 2017, Realtek Semiconductor Corporation. All rights reserved.
*****************************************************************************************
* @file peripheral_app.c
* @brief This file handles BLE peripheral application routines.
* @author jane
* @date 2017-06-06
* @version v1.0
**************************************************************************************
* @attention
* <h2><center>© COPYRIGHT 2017 Realtek Semiconductor Corporation</center></h2>
**************************************************************************************
*/
/*============================================================================*
* Header Files
*=================