ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_wdt.c
1 
14 #ifdef __ICCARM__
15 /*
16 * IAR MISRA C 2004 error suppressions.
17 *
18 *
19 * Pm011 (rule 6.3): the basic types of char, int, short, long, float, and double should not be used
20 * Necessary for stdbool.
21 *
22 * Pm073 (rule 14.7): a function should have a single point of exit
23 * Pm143 (rule 14.7): a function should have a single point of exit at the end of the function
24 * Multiple returns are used for error handling.
25 *
26 * Pm140 (Rule 11.4): a cast should not be performed between a pointer type and an integral type
27 * This violation appears when deferencing the pointer to the register typedef. No way around this.
28 */
29 #pragma diag_suppress=Pm011,Pm073,Pm140,Pm143
30 #endif /* __ICCARM__ */
31 
32 
44 #include <stdlib.h>
45 #include <adi_processor.h>
46 #include <rtos_map/adi_rtos_map.h>
47 #include <adi_wdt_config.h>
48 #include <drivers/wdt/adi_wdt.h>
49 
53 #define ADI_WDT_SYNC_BITS ((0x1u << BITP_WDT_STAT_COUNTING) | (0x1u << BITP_WDT_STAT_LOADING) | (0x1u << BITP_WDT_STAT_CLRIRQ))
54 
56 #define ADI_WDT_CLR_VALUE (0xCCCCu)
57 
59 #if (ADI_WDT_CONTROL_TIMEOUT_MODE == 1u)
60 static ADI_CALLBACK gAppCallback;
61 #endif
62 
65 /*********************************************************************************
66  API IMPLEMENTATIONS
67 *********************************************************************************/
68 
69 
84 ADI_WDT_RESULT adi_wdt_Enable(bool const bEnable, ADI_CALLBACK const pfCallback) {
85  /* IF(Device is enabled, application can't modify it) */
86  if ((pADI_WDT0->STAT & ((uint16_t) BITM_WDT_STAT_LOCKED)) != ((uint16_t) 0x0u)) {
88  } /* ENDIF */
89 
90  /* Setup interrupts if we are in interrupt mode */
91 #if (ADI_WDT_CONTROL_TIMEOUT_MODE == 1u)
92  gAppCallback = pfCallback;
93  /* IF(We are enabling the WDT) */
94  if (bEnable == true) {
95  NVIC_EnableIRQ (WDT_EXP_IRQn);
96  /* ELSE (We are disabling the WDT, this might not be necessary, depends on startup config) */
97  } else {
98  NVIC_DisableIRQ(WDT_EXP_IRQn);
99  } /* ENDIF */
100 #endif
101 
102  /* WHILE(Bus sync is underway) */
103  while((pADI_WDT0->STAT & ADI_WDT_SYNC_BITS) != 0u) {
104  ;
105  } /* ENDWHILE */
106 
107 
108  ADI_INT_STATUS_ALLOC();
109  ADI_ENTER_CRITICAL_REGION();
110 
111  pADI_WDT0->LOAD = ADI_WDT_LOAD_VALUE;
112 
113  /* IF(Turning the WDT on) */
114  if (bEnable == true) {
115  pADI_WDT0->CTL = (ADI_WDT_CONTROL_TIMER_MODE << BITP_WDT_CTL_MODE) |
116  (0x1u << BITP_WDT_CTL_EN ) |
117  (ADI_WDT_CONTROL_CLOCK_PRESCALER << BITP_WDT_CTL_PRE ) |
118  (ADI_WDT_CONTROL_TIMEOUT_MODE << BITP_WDT_CTL_IRQ ) |
120  /* ELSE(Turning the WDT off) */
121  } else {
122  pADI_WDT0->CTL = (ADI_WDT_CONTROL_TIMER_MODE << BITP_WDT_CTL_MODE) |
123  (0x0u << BITP_WDT_CTL_EN ) |
124  (ADI_WDT_CONTROL_CLOCK_PRESCALER << BITP_WDT_CTL_PRE ) |
125  (ADI_WDT_CONTROL_TIMEOUT_MODE << BITP_WDT_CTL_IRQ ) |
127  } /* ENDIF */
128 
129  ADI_EXIT_CRITICAL_REGION();
130 
131  return ADI_WDT_SUCCESS;
132 }
133 
141 void adi_wdt_Kick(void) {
142  /* WHILE(Bus sync is underway) */
143  while((pADI_WDT0->STAT & ADI_WDT_SYNC_BITS) != 0u) {
144  ;
145  } /* ENDWHILE */
146 
147  /* Kick the dog! */
148  pADI_WDT0->RESTART = ADI_WDT_CLR_VALUE;
149 }
150 
160 void adi_wdt_GetCount(uint16_t * const pCurCount) {
161  /* Read the count */
162  *pCurCount = pADI_WDT0->CCNT;
163 }
164 
177 #if (ADI_WDT_CONTROL_TIMEOUT_MODE == 1u)
178 extern void WDog_Tmr_Int_Handler(void);
179 void WDog_Tmr_Int_Handler(void) {
180  ISR_PROLOG()
181  /* Kick the dog */
182  adi_wdt_Kick();
183  /* IF(Application supplied a callback) */
184  if(gAppCallback != NULL) {
185  /* Call the callback */
186  gAppCallback(NULL, 0x0u, NULL);
187  } /* ENDIF */
188  ISR_EPILOG()
189 }
190 #endif /* (ADI_WDT_CONTROL_TIMEOUT_MODE == 1u) */
191 
#define ADI_WDT_CONTROL_CLOCK_PRESCALER
ADI_WDT_RESULT adi_wdt_Enable(bool const bEnable, ADI_CALLBACK const pfCallback)
WDT Enable.
Definition: adi_wdt.c:84
#define ADI_WDT_CONTROL_TIMER_MODE
#define ADI_WDT_CONTROL_TIMEOUT_MODE
void adi_wdt_Kick(void)
WDT Reset.
Definition: adi_wdt.c:141
#define ADI_WDT_LOAD_VALUE
void adi_wdt_GetCount(uint16_t *const pCurCount)
WDT Read Count.
Definition: adi_wdt.c:160
#define ADI_WDT_CONTROL_POWER_MODE
ADI_WDT_RESULT
Definition: adi_wdt.h:30