• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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  */
15 
16 #include "duet_cm4.h"
17 #include "duet_common.h"
18 #include "duet.h"
19 #include "duet_boot.h"
20 
duet_cfg_boot_type(void)21 void duet_cfg_boot_type(void)
22 {
23     uint32_t flag1 = RETENTION_SRAM->BOOT_CFG;
24     uint32_t flag2 = REG_RD(AON_RST_CHECK_REG);
25     if ((RET_RAM_SOFT_RST_FLAG == flag1) && (AON_RST_CHECK_FLAG == (flag2 & AON_RST_CHECK_FLAG))) {
26         RETENTION_SRAM->BOOT_TYPE = SOFTWARE_RST;
27     } else if ((RET_RAM_DS_RST_FLAG == flag1) && (AON_RST_CHECK_FLAG == (flag2 & AON_RST_CHECK_FLAG))) {
28         RETENTION_SRAM->BOOT_CFG = RET_RAM_SOFT_RST_FLAG;
29         RETENTION_SRAM->BOOT_TYPE = DEEP_SLEEP_RST;
30     } else if ((RET_RAM_SOFT_RST_FLAG == flag1) && (0 == flag2)) {
31         REG_WR(AON_RST_CHECK_REG, AON_RST_CHECK_FLAG);
32         RETENTION_SRAM->BOOT_TYPE = HARDWARE_PIN_RST;
33     } else if (0 == flag2) {
34         REG_WR(AON_RST_CHECK_REG, AON_RST_CHECK_FLAG);
35         RETENTION_SRAM->BOOT_CFG = RET_RAM_SOFT_RST_FLAG;
36         RETENTION_SRAM->BOOT_TYPE = PWR_ON_RST;
37     } else {
38         REG_WR(AON_RST_CHECK_REG, AON_RST_CHECK_FLAG);
39         RETENTION_SRAM->BOOT_CFG = RET_RAM_SOFT_RST_FLAG;
40         RETENTION_SRAM->BOOT_TYPE = UNKNOWN_RST;
41     }
42 }
43 
duet_set_ds_boot_type(void)44 void duet_set_ds_boot_type(void)
45 {
46     RETENTION_SRAM->BOOT_CFG = RET_RAM_DS_RST_FLAG;
47 }
48 
duet_get_boot_type(void)49 uint32_t duet_get_boot_type(void)
50 {
51     return (RETENTION_SRAM->BOOT_TYPE);
52 }
53