summaryrefslogtreecommitdiff
path: root/bsp/at32/libraries/AT32F413_Firmware_Library/drivers/src/at32f413_wdt.c
blob: 94d779c7a82e3ca4a6daa4350562d80d0aae4ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
  **************************************************************************
  * @file     at32f413_wdt.c
  * @version  v2.0.5
  * @date     2022-05-20
  * @brief    contains all the functions for the wdt firmware library
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#include "at32f413_conf.h"

/** @addtogroup AT32F413_periph_driver
  * @{
  */

/** @defgroup WDT
  * @brief WDT driver modules
  * @{
  */

#ifdef WDT_MODULE_ENABLED

/** @defgroup WDT_private_functions
  * @{
  */

/**
  * @brief  wdt enable ,the reload value will be sent to the counter
  * @param  none
  * @retval none
  */
void wdt_enable(void)
{
  WDT->cmd = WDT_CMD_ENABLE;
}

/**
  * @brief  reload wdt counter
  * @param  none
  * @retval none
  */
void wdt_counter_reload(void)
{
  WDT->cmd = WDT_CMD_RELOAD;
}

/**
  * @brief  set wdt counter reload value
  * @param  reload_value (0x0000~0x0FFF)
  * @retval none
  */
void wdt_reload_value_set(uint16_t reload_value)
{
  WDT->rld = reload_value;
}

/**
  * @brief  set wdt division divider
  * @param  division
  *         this parameter can be one of the following values:
  *         - WDT_CLK_DIV_4
  *         - WDT_CLK_DIV_8
  *         - WDT_CLK_DIV_16
  *         - WDT_CLK_DIV_32
  *         - WDT_CLK_DIV_64
  *         - WDT_CLK_DIV_128
  *         - WDT_CLK_DIV_256
  * @retval none
  */
void wdt_divider_set(wdt_division_type division)
{
  WDT->div_bit.div = division;
}

/**
  * @brief  enable or disable wdt cmd register write
  * @param  new_state (TRUE or FALSE)
  * @retval none
  */
void wdt_register_write_enable( confirm_state new_state)
{
  if(new_state == FALSE)
  {
    WDT->cmd = WDT_CMD_LOCK;
  }
  else
  {
    WDT->cmd = WDT_CMD_UNLOCK;
  }
}

/**
  * @brief  get wdt flag
  * @param  wdt_flag
  *         this parameter can be one of the following values:
  *         - WDT_DIVF_UPDATE_FLAG: division value update complete flag.
  *         - WDT_RLDF_UPDATE_FLAG: reload value update complete flag.
  * @retval state of wdt flag
  */
flag_status wdt_flag_get(uint16_t wdt_flag)
{
  flag_status status = RESET;

  if ((WDT->sts & wdt_flag) != (uint16_t)RESET)
  {
    status = SET;
  }
  else
  {
    status = RESET;
  }

  return status;
}

/**
  * @}
  */

#endif

/**
  * @}
  */

/**
  * @}
  */