99 #define wdt_reset() __asm__ __volatile__ ("wdr") 104 # define _WD_PS3_MASK _BV(WDP3) 106 # define _WD_PS3_MASK 0x00 110 # define _WD_CONTROL_REG WDTCSR 112 # define _WD_CONTROL_REG WDTCR 114 # define _WD_CONTROL_REG WDT 118 #define _WD_CHANGE_BIT WDTOE 120 #define _WD_CHANGE_BIT WDCE 138 #if defined(__AVR_XMEGA__) 152 #define wdt_enable(timeout) \ 155 __asm__ __volatile__ ( \ 156 "in __tmp_reg__, %[rampd]" "\n\t" \ 157 "out %[rampd], __zero_reg__" "\n\t" \ 158 "out %[ccp_reg], %[ioreg_cen_mask]" "\n\t" \ 159 "sts %[wdt_reg], %[wdt_enable_timeout]" "\n\t" \ 160 "1:lds %[tmp], %[wdt_status_reg]" "\n\t" \ 161 "sbrc %[tmp], %[wdt_syncbusy_bit]" "\n\t" \ 163 "out %[rampd], __tmp_reg__" "\n\t" \ 164 : [tmp] "=r" (temp) \ 165 : [rampd] "I" (_SFR_IO_ADDR(RAMPD)), \ 166 [ccp_reg] "I" (_SFR_IO_ADDR(CCP)), \ 167 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc), \ 168 [wdt_reg] "n" (_SFR_MEM_ADDR(WDT_CTRL)), \ 169 [wdt_enable_timeout] "r" ((uint8_t)(WDT_CEN_bm | WDT_ENABLE_bm | timeout)), \ 170 [wdt_status_reg] "n" (_SFR_MEM_ADDR(WDT_STATUS)), \ 171 [wdt_syncbusy_bit] "I" (WDT_SYNCBUSY_bm) \ 176 #define wdt_disable() \ 177 __asm__ __volatile__ ( \ 178 "in __tmp_reg__, %[rampd]" "\n\t" \ 179 "out %[rampd], __zero_reg__" "\n\t" \ 180 "out %[ccp_reg], %[ioreg_cen_mask]" "\n\t" \ 181 "sts %[wdt_reg], %[disable_mask]" "\n\t" \ 182 "out %[rampd], __tmp_reg__" "\n\t" \ 184 : [rampd] "I" (_SFR_IO_ADDR(RAMPD)), \ 185 [ccp_reg] "I" (_SFR_IO_ADDR(CCP)), \ 186 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc), \ 187 [wdt_reg] "n" (_SFR_MEM_ADDR(WDT_CTRL)), \ 188 [disable_mask] "r" ((uint8_t)((~WDT_ENABLE_bm) | WDT_CEN_bm)) \ 192 #elif defined(__AVR_TINY__) 194 #define wdt_enable(value) \ 195 __asm__ __volatile__ ( \ 196 "in __tmp_reg__,__SREG__" "\n\t" \ 199 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" \ 200 "out %[WDTREG],%[WDVALUE]" "\n\t" \ 201 "out __SREG__,__tmp_reg__" "\n\t" \ 203 : [CCPADDRESS] "I" (_SFR_IO_ADDR(CCP)), \ 204 [SIGNATURE] "r" ((uint8_t)0xD8), \ 205 [WDTREG] "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \ 206 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) \ 207 | _BV(WDE) | (value & 0x07) )) \ 211 #define wdt_disable() \ 214 __asm__ __volatile__ ( \ 215 "in __tmp_reg__,__SREG__" "\n\t" \ 218 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" \ 219 "in %[TEMP_WD],%[WDTREG]" "\n\t" \ 220 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t" \ 221 "out %[WDTREG],%[TEMP_WD]" "\n\t" \ 222 "out __SREG__,__tmp_reg__" "\n\t" \ 224 : [CCPADDRESS] "I" (_SFR_IO_ADDR(CCP)), \ 225 [SIGNATURE] "r" ((uint8_t)0xD8), \ 226 [WDTREG] "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \ 227 [TEMP_WD] "d" (temp_wd), \ 228 [WDVALUE] "n" (1 << WDE) \ 237 void wdt_enable (
const uint8_t value)
239 if (!_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P (_WD_CONTROL_REG))
241 __asm__ __volatile__ (
242 "in __tmp_reg__,__SREG__" "\n\t" 245 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t" 246 "sts %[WDTREG],%[WDVALUE]" "\n\t" 247 "out __SREG__,__tmp_reg__" "\n\t" 249 : [CCPADDRESS]
"n" (_SFR_MEM_ADDR(CCP)),
250 [SIGNATURE]
"r" ((
uint8_t)0xD8),
251 [WDTREG]
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
252 [WDVALUE]
"r" ((
uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
253 |
_BV(WDE) | (value & 0x07) ))
257 else if (!_SFR_IO_REG_P (CCP) && _SFR_IO_REG_P (_WD_CONTROL_REG))
259 __asm__ __volatile__ (
260 "in __tmp_reg__,__SREG__" "\n\t" 263 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t" 264 "out %[WDTREG],%[WDVALUE]" "\n\t" 265 "out __SREG__,__tmp_reg__" "\n\t" 267 : [CCPADDRESS]
"n" (_SFR_MEM_ADDR(CCP)),
268 [SIGNATURE]
"r" ((
uint8_t)0xD8),
269 [WDTREG]
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
270 [WDVALUE]
"r" ((
uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
271 |
_BV(WDE) | (value & 0x07) ))
275 else if (_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P (_WD_CONTROL_REG))
277 __asm__ __volatile__ (
278 "in __tmp_reg__,__SREG__" "\n\t" 281 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" 282 "sts %[WDTREG],%[WDVALUE]" "\n\t" 283 "out __SREG__,__tmp_reg__" "\n\t" 285 : [CCPADDRESS]
"I" (_SFR_IO_ADDR(CCP)),
286 [SIGNATURE]
"r" ((
uint8_t)0xD8),
287 [WDTREG]
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
288 [WDVALUE]
"r" ((
uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
289 |
_BV(WDE) | (value & 0x07) ))
295 __asm__ __volatile__ (
296 "in __tmp_reg__,__SREG__" "\n\t" 299 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" 300 "out %[WDTREG],%[WDVALUE]" "\n\t" 301 "out __SREG__,__tmp_reg__" "\n\t" 303 : [CCPADDRESS]
"I" (_SFR_IO_ADDR(CCP)),
304 [SIGNATURE]
"r" ((
uint8_t)0xD8),
305 [WDTREG]
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
306 [WDVALUE]
"r" ((
uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
307 |
_BV(WDE) | (value & 0x07) ))
315 void wdt_disable (
void)
317 if (!_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P(_WD_CONTROL_REG))
320 __asm__ __volatile__ (
321 "in __tmp_reg__,__SREG__" "\n\t" 324 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t" 325 "lds %[TEMP_WD],%[WDTREG]" "\n\t" 326 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t" 327 "sts %[WDTREG],%[TEMP_WD]" "\n\t" 328 "out __SREG__,__tmp_reg__" "\n\t" 330 : [CCPADDRESS]
"n" (_SFR_MEM_ADDR(CCP)),
331 [SIGNATURE]
"r" ((
uint8_t)0xD8),
332 [WDTREG]
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
333 [TEMP_WD]
"d" (temp_wd),
334 [WDVALUE]
"n" (1 << WDE)
338 else if (!_SFR_IO_REG_P (CCP) && _SFR_IO_REG_P(_WD_CONTROL_REG))
341 __asm__ __volatile__ (
342 "in __tmp_reg__,__SREG__" "\n\t" 345 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t" 346 "in %[TEMP_WD],%[WDTREG]" "\n\t" 347 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t" 348 "out %[WDTREG],%[TEMP_WD]" "\n\t" 349 "out __SREG__,__tmp_reg__" "\n\t" 351 : [CCPADDRESS]
"n" (_SFR_MEM_ADDR(CCP)),
352 [SIGNATURE]
"r" ((
uint8_t)0xD8),
353 [WDTREG]
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
354 [TEMP_WD]
"d" (temp_wd),
355 [WDVALUE]
"n" (1 << WDE)
359 else if (_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P(_WD_CONTROL_REG))
362 __asm__ __volatile__ (
363 "in __tmp_reg__,__SREG__" "\n\t" 366 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" 367 "lds %[TEMP_WD],%[WDTREG]" "\n\t" 368 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t" 369 "sts %[WDTREG],%[TEMP_WD]" "\n\t" 370 "out __SREG__,__tmp_reg__" "\n\t" 372 : [CCPADDRESS]
"I" (_SFR_IO_ADDR(CCP)),
373 [SIGNATURE]
"r" ((
uint8_t)0xD8),
374 [WDTREG]
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
375 [TEMP_WD]
"d" (temp_wd),
376 [WDVALUE]
"n" (1 << WDE)
383 __asm__ __volatile__ (
384 "in __tmp_reg__,__SREG__" "\n\t" 387 "out %[CCPADDRESS],%[SIGNATURE]" "\n\t" 388 "in %[TEMP_WD],%[WDTREG]" "\n\t" 389 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t" 390 "out %[WDTREG],%[TEMP_WD]" "\n\t" 391 "out __SREG__,__tmp_reg__" "\n\t" 393 : [CCPADDRESS]
"I" (_SFR_IO_ADDR(CCP)),
394 [SIGNATURE]
"r" ((
uint8_t)0xD8),
395 [WDTREG]
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
396 [TEMP_WD]
"d" (temp_wd),
397 [WDVALUE]
"n" (1 << WDE)
407 void wdt_enable (
const uint8_t value)
409 if (_SFR_IO_REG_P (_WD_CONTROL_REG))
411 __asm__ __volatile__ (
412 "in __tmp_reg__,__SREG__" "\n\t" 416 "out __SREG__,__tmp_reg__" "\n\t" 419 :
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
421 "r" ((
uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
422 _BV(WDE) | (value & 0x07)) )
428 __asm__ __volatile__ (
429 "in __tmp_reg__,__SREG__" "\n\t" 433 "out __SREG__,__tmp_reg__" "\n\t" 436 :
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
438 "r" ((
uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) |
439 _BV(WDE) | (value & 0x07)) )
447 void wdt_disable (
void)
449 if (_SFR_IO_REG_P (_WD_CONTROL_REG))
452 __asm__ __volatile__ (
453 "in __tmp_reg__,__SREG__" "\n\t" 456 "in %[TEMPREG],%[WDTREG]" "\n\t" 457 "ori %[TEMPREG],%[WDCE_WDE]" "\n\t" 458 "out %[WDTREG],%[TEMPREG]" "\n\t" 459 "out %[WDTREG],__zero_reg__" "\n\t" 460 "out __SREG__,__tmp_reg__" "\n\t" 461 : [TEMPREG]
"=d" (temp_reg)
462 : [WDTREG]
"I" (_SFR_IO_ADDR(_WD_CONTROL_REG)),
470 __asm__ __volatile__ (
471 "in __tmp_reg__,__SREG__" "\n\t" 474 "lds %[TEMPREG],%[WDTREG]" "\n\t" 475 "ori %[TEMPREG],%[WDCE_WDE]" "\n\t" 476 "sts %[WDTREG],%[TEMPREG]" "\n\t" 477 "sts %[WDTREG],__zero_reg__" "\n\t" 478 "out __SREG__,__tmp_reg__" "\n\t" 479 : [TEMPREG]
"=d" (temp_reg)
480 : [WDTREG]
"n" (_SFR_MEM_ADDR(_WD_CONTROL_REG)),
541 #if defined(__DOXYGEN__) || defined(WDP3)
unsigned char uint8_t
Definition: stdint.h:83
#define _BV(bit)
Definition: sfr_defs.h:208
static __inline__ __attribute__((__always_inline__)) void wdt_enable(const uint8_t value)
Definition: wdt.h:406