fw_wdt.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ___FW_WDT_H___
  15. #define ___FW_WDT_H___
  16. #include "fw_conf.h"
  17. #include "fw_types.h"
  18. /********************************************************
  19. * STC8 watchdog behavior is different from STC15
  20. *
  21. * STC8 watchdog will ALWAYS reset chip from ISP code region inspite of the
  22. * setting of SWBS in IAP_CONTR
  23. *
  24. */
  25. /**
  26. * Start watchdog.
  27. * It cannot be stopped in code once it is started
  28. */
  29. #define WDT_StartWatchDog() SFR_SET(WDT_CONTR, 5)
  30. /**
  31. * Reset watchdog counter to avoid reset
  32. */
  33. #define WDT_ResetCounter() SFR_SET(WDT_CONTR, 4)
  34. /**
  35. * Enable or disable watchdog counter in idle mode
  36. */
  37. #define WDT_EnableCounterWhenIdle(__STATE__) SFR_ASSIGN(WDT_CONTR, 3, __STATE__)
  38. /**
  39. * Set counter prescaler. The higher this value is, the longer counter overflow will take place
  40. *
  41. * Toverflow (in seconds) = 12 * 32768 * 2^(__PRE_SCALER__ + 1) / SYSCLK
  42. */
  43. #define WDT_SetCounterPrescaler(__PRE_SCALER__) (WDT_CONTR = WDT_CONTR & ~0x07 | (__PRE_SCALER__ & 0x07))
  44. #endif