-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright (c) 2021 Alethea Katherine Flowers. | ||
Published under the standard MIT License. | ||
Full text available at: https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
#include "gem_bod.h" | ||
#include "sam.h" | ||
|
||
void gem_wait_for_stable_voltage() { | ||
/* | ||
Configure the BOD to monitor for at least 3.0 volts and wait for | ||
VDD to reach that level. | ||
*/ | ||
SYSCTRL->BOD33.bit.ENABLE = 0; | ||
while (!SYSCTRL->PCLKSR.bit.B33SRDY) {}; | ||
|
||
SYSCTRL->BOD33.reg = ( | ||
/* VBOD-: 3.0, VBOD+: 3.3 See datasheet Table 37-21. */ | ||
SYSCTRL_BOD33_LEVEL(48) | | ||
/* Don't reset */ | ||
SYSCTRL_BOD33_ACTION_NONE | | ||
/* Enable hysteresis */ | ||
SYSCTRL_BOD33_HYST); | ||
|
||
/* Wait for the voltage to stabilize. */ | ||
SYSCTRL->BOD33.bit.ENABLE = 1; | ||
while (!SYSCTRL->PCLKSR.bit.BOD33RDY) {} | ||
while (SYSCTRL->PCLKSR.bit.BOD33DET) {} | ||
|
||
/* | ||
Everything is good, let the BOD33 reset the microcontroller if the | ||
voltage falls below 3.0 volts. | ||
*/ | ||
|
||
SYSCTRL->BOD33.bit.ENABLE = 0; | ||
while (!SYSCTRL->PCLKSR.bit.B33SRDY) {}; | ||
SYSCTRL->BOD33.reg |= SYSCTRL_BOD33_ACTION_RESET; | ||
SYSCTRL->BOD33.bit.ENABLE = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Copyright (c) 2021 Alethea Katherine Flowers. | ||
Published under the standard MIT License. | ||
Full text available at: https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
/* Routines for interacting with the SAM D21's brown out detector (BOD33) */ | ||
|
||
void gem_wait_for_stable_voltage(); |