查看: 1630|回复: 4

[求助] 前辈们NXP的sdk中关于WWDT的例程,timeout、warning、window都指...

[复制链接]
  • TA的每日心情
    郁闷
    2019-11-7 11:26
  • 签到天数: 1 天

    [LV.1]初来乍到

    4

    主题

    16

    帖子

    0

    注册会员

    Rank: 2

    积分
    95
    最后登录
    2020-9-28
    发表于 2019-12-18 08:44:17 | 显示全部楼层 |阅读模式
    本帖最后由 l52571314 于 2019-12-18 08:53 编辑
    1. /*
    2. * The Clear BSD License
    3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
    4. * Copyright 2016-2017 NXP
    5. * All rights reserved.
    6. *
    7. * Redistribution and use in source and binary forms, with or without modification,
    8. * are permitted (subject to the limitations in the disclaimer below) provided
    9. *  that the following conditions are met:
    10. *
    11. * o Redistributions of source code must retain the above copyright notice, this list
    12. *   of conditions and the following disclaimer.
    13. *
    14. * o Redistributions in binary form must reproduce the above copyright notice, this
    15. *   list of conditions and the following disclaimer in the documentation and/or
    16. *   other materials provided with the distribution.
    17. *
    18. * o Neither the name of the copyright holder nor the names of its
    19. *   contributors may be used to endorse or promote products derived from this
    20. *   software without specific prior written permission.
    21. *
    22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
    23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
    27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    33. */

    34. /*******************************************************************************
    35. * Includes
    36. ******************************************************************************/

    37. #include "fsl_debug_console.h"
    38. #include "board.h"
    39. #include "fsl_wwdt.h"
    40. #include "fsl_power.h"

    41. #include "pin_mux.h"
    42. #include <stdbool.h>
    43. /*******************************************************************************
    44. * Definitions
    45. ******************************************************************************/
    46. #define APP_LED_INIT (LED3_INIT(1));
    47. #define APP_LED_ON (LED3_ON());
    48. #define APP_LED_TOGGLE (LED3_TOGGLE());
    49. #define APP_WDT_IRQn WDT_BOD_IRQn
    50. #define APP_WDT_IRQ_HANDLER WDT_BOD_IRQHandler
    51. #define WDT_CLK_FREQ CLOCK_GetFreq(kCLOCK_WdtOsc)

    52. /*******************************************************************************
    53. * Prototypes
    54. ******************************************************************************/

    55. /*******************************************************************************
    56. * Variables
    57. ******************************************************************************/
    58. static volatile uint8_t wdt_update_count;

    59. /*******************************************************************************
    60. * Code
    61. ******************************************************************************/

    62. void APP_WDT_IRQ_HANDLER(void)
    63. {
    64.     uint32_t wdtStatus = WWDT_GetStatusFlags(WWDT);

    65.     APP_LED_TOGGLE;

    66.     /* The chip will reset before this happens */
    67.     if (wdtStatus & kWWDT_TimeoutFlag)
    68.     {
    69.         /* A watchdog feed didn't occur prior to window timeout */
    70.         /* Stop WDT */
    71.         WWDT_Disable(WWDT);
    72.         WWDT_ClearStatusFlags(WWDT, kWWDT_TimeoutFlag);
    73.         /* Needs restart */
    74.         WWDT_Enable(WWDT);
    75.     }

    76.     /* Handle warning interrupt */
    77.     if (wdtStatus & kWWDT_WarningFlag)
    78.     {
    79.         if (wdt_update_count < 5)
    80.         {
    81.             while (WWDT->TV >= WWDT->WARNINT)
    82.             {
    83.             }
    84.             /* Feed only for the first 5 warnings then allow for a WDT reset to occur */
    85.             WWDT_Refresh(WWDT);
    86.             wdt_update_count++;
    87.         }
    88.         while (WWDT->TV < WWDT->WARNINT)
    89.         {
    90.         }
    91.         /* A watchdog feed didn't occur prior to warning timeout */
    92.         WWDT_ClearStatusFlags(WWDT, kWWDT_WarningFlag);
    93.     }
    94.     /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
    95.       exception return operation might vector to incorrect interrupt */
    96. #if defined __CORTEX_M && (__CORTEX_M == 4U)
    97.     __DSB();
    98. #endif
    99. }

    100. /*!
    101. * @brief Main function
    102. */
    103. int main(void)
    104. {
    105.     wwdt_config_t config;
    106.     uint32_t wdtFreq;

    107.     /* Init hardware*/
    108.     CLOCK_EnableClock(kCLOCK_Gpio0);
    109.     CLOCK_EnableClock(kCLOCK_Gpio2);
    110.     /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
    111.     CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    112.     BOARD_InitPins();
    113.     BOARD_BootClockFROHF48M();
    114.     BOARD_InitDebugConsole();

    115.     /* Set Red LED to initially be high */
    116.     APP_LED_INIT;

    117. #if !defined (FSL_FEATURE_WWDT_HAS_NO_PDCFG) || (!FSL_FEATURE_WWDT_HAS_NO_PDCFG)
    118.     POWER_DisablePD(kPDRUNCFG_PD_WDT_OSC);
    119. #endif

    120.     /* The WDT divides the input frequency into it by 4 */
    121.     wdtFreq = WDT_CLK_FREQ / 4;

    122.     NVIC_EnableIRQ(APP_WDT_IRQn);

    123.     WWDT_GetDefaultConfig(&config);

    124.     /* Check if reset is due to Watchdog */
    125.     if (WWDT_GetStatusFlags(WWDT) & kWWDT_TimeoutFlag)
    126.     {
    127.         APP_LED_ON;
    128.         PRINTF("Watchdog reset occurred\r\n");
    129.     }

    130.     /*
    131.      * Set watchdog feed time constant to approximately 2s
    132.      * Set watchdog warning time to 512 ticks after feed time constant
    133.      * Set watchdog window time to 1s
    134.      */
    135.     config.timeoutValue = wdtFreq * 2;
    136.     config.warningValue = 512;
    137.     config.windowValue = wdtFreq * 1;
    138.     /* Configure WWDT to reset on timeout */
    139.     config.enableWatchdogReset = true;

    140.     /* wdog refresh test in window mode */
    141.     PRINTF("\r\n--- Window mode refresh test start---\r\n");
    142.     WWDT_Init(WWDT, &config);

    143.     while (1)
    144.     {
    145.     }
    146. }

    复制代码

    我知道答案 目前已有4人回答
    无标题.png
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    郁闷
    2019-11-7 11:26
  • 签到天数: 1 天

    [LV.1]初来乍到

    4

    主题

    16

    帖子

    0

    注册会员

    Rank: 2

    积分
    95
    最后登录
    2020-9-28
     楼主| 发表于 2019-12-18 08:54:43 | 显示全部楼层
    目前我的理解就是上图,但是我搞不清楚的是window的上限和下限值是多少,根据芯片来定的吗,还有这个warining例程中说的是after feed time 有点不太明白
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    郁闷
    2019-11-7 11:26
  • 签到天数: 1 天

    [LV.1]初来乍到

    4

    主题

    16

    帖子

    0

    注册会员

    Rank: 2

    积分
    95
    最后登录
    2020-9-28
     楼主| 发表于 2019-12-18 09:18:03 | 显示全部楼层
    在芯片手册中看到这个下限值是256tick,是这个意思吗? 所以上限值就是256+所设定的windows的值?
    7GVV_$Z1P0TR(5QX[2)J$]4.png
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    656

    主题

    6312

    帖子

    0

    超级版主

    Rank: 8Rank: 8

    积分
    20232
    最后登录
    2024-5-13
    发表于 2019-12-23 14:01:55 | 显示全部楼层
    楼主你好,你用的是LPC哪款芯片,请给出芯片型号。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    1

    主题

    3

    帖子

    0

    新手上路

    Rank: 1

    积分
    8
    最后登录
    2022-5-18
    发表于 2022-5-17 21:46:10 | 显示全部楼层
    有尝试,关闭看门狗吗? 怎么关闭?
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-5-14 06:59 , Processed in 0.131176 second(s), 26 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表