Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
power_ctrl.c
00001 /** 00002 * @file power_ctrl.c 00003 * @brief power control sequence logic for Musca A 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include "string.h" 00023 #include "stdio.h" 00024 #include "stdint.h" 00025 #include "syscon.h" 00026 #include "gpio.h" 00027 #include "utils.h" 00028 #include "uart.h" 00029 00030 // Configure SCC 00031 void configure_syscon(unsigned int pc) 00032 { 00033 unsigned int din; 00034 00035 // Dummy read 00036 syscon_readreg(0x004, &din); 00037 00038 // CPU0 boot from QSPI or SRAM 00039 syscon_writereg(0x020, pc); 00040 00041 // CPU1 boot from QSPI or SRAM 00042 syscon_writereg(0x028, pc); 00043 00044 // Set IO drive strength and slew rate 00045 syscon_writereg(0x068, 0x03F00000); 00046 syscon_writereg(0x06C, 0x000FFFFF); 00047 syscon_writereg(0x078, 0xFFFFFFFF); 00048 } 00049 00050 // Brown Out Detect 00051 void enable_BOD(int enable) 00052 { 00053 if (enable) 00054 { 00055 // Set BOD interrupt to 2.80-2.90V 00056 LPC_SYSCON->BODCTRL |= 0x1C; 00057 NVIC_EnableIRQ(BOD_IRQn ); /* Enable BOD interrupt */ 00058 } 00059 else 00060 { 00061 LPC_SYSCON->BODCTRL = 0x00; 00062 NVIC_DisableIRQ(BOD_IRQn ); 00063 NVIC_ClearPendingIRQ(BOD_IRQn ); 00064 } 00065 } 00066 00067 //Power off / shutdown sequence 00068 void power_off_sequence() 00069 { 00070 // Disable Brown Out Detection 00071 enable_BOD(0); 00072 00073 // Apply CS_nSRST 00074 LPC_GPIO->CLR[PIN_nRESET_PORT] = PIN_nRESET; 00075 00076 // Wait 10ms 00077 delay(10); 00078 00079 // Apply CB_nRST 00080 LPC_GPIO->CLR[PIN_CB_nRST_PORT] = PIN_CB_nRST; 00081 // Wait 10ms 00082 delay(10); 00083 00084 // Apply CFG_nRST 00085 LPC_GPIO->CLR[PIN_CFG_nRST_PORT] = PIN_CFG_nRST; 00086 00087 // Wait 10ms 00088 delay(10); 00089 } 00090 00091 //Power on sequence 00092 void power_on_sequence() 00093 { 00094 // Drive SCC signals 00095 LPC_GPIO->DIR[PIN_SCC_CLK_PORT] |= PIN_SCC_CLK; 00096 LPC_GPIO->DIR[PIN_SCC_DATAIN_PORT] |= PIN_SCC_DATAIN; 00097 LPC_GPIO->DIR[PIN_SCC_DATAOUT_PORT] &= ~PIN_SCC_DATAOUT; 00098 LPC_GPIO->DIR[PIN_SCC_WNR_PORT] |= PIN_SCC_WNR; 00099 LPC_GPIO->DIR[PIN_SCC_LOAD_PORT] |= PIN_SCC_LOAD; 00100 00101 // Wait 10ms 00102 delay(10); 00103 00104 // Release CFG_nRST to allow SCC config 00105 LPC_GPIO->SET[PIN_CFG_nRST_PORT] = PIN_CFG_nRST; 00106 00107 // Wait 10ms 00108 delay(10); 00109 00110 // Configure SCC 00111 configure_syscon(0x10200000); 00112 00113 // Wait 10ms 00114 delay(10); 00115 00116 // Release SCC signals 00117 LPC_GPIO->DIR[PIN_SCC_CLK_PORT] &= ~PIN_SCC_CLK; 00118 LPC_GPIO->DIR[PIN_SCC_DATAIN_PORT] &= ~PIN_SCC_DATAIN; 00119 LPC_GPIO->DIR[PIN_SCC_DATAOUT_PORT] &= ~PIN_SCC_DATAOUT; 00120 LPC_GPIO->DIR[PIN_SCC_WNR_PORT] &= ~PIN_SCC_WNR; 00121 LPC_GPIO->DIR[PIN_SCC_LOAD_PORT] &= ~PIN_SCC_LOAD; 00122 00123 // Wait 10ms 00124 delay(10); 00125 00126 // Release CB_nRST 00127 LPC_GPIO->SET[PIN_CB_nRST_PORT] = PIN_CB_nRST; 00128 00129 // Wait 10ms 00130 delay(10); 00131 00132 // Release CS_nSRST 00133 LPC_GPIO->SET[PIN_nRESET_PORT] = PIN_nRESET; 00134 00135 // Wait 10ms 00136 delay(10); 00137 00138 // Enable Brown Out Detection 00139 enable_BOD(1); 00140 } 00141 00142 // BOD Interrupt Service Routine 00143 void BOD_IRQHandler(void) 00144 { 00145 NVIC_DisableIRQ(BOD_IRQn ); 00146 gpio_set_cdc_led(GPIO_LED_OFF); // ON GREEN 00147 00148 // go into controlled shutdown 00149 power_off_sequence(); 00150 00151 while(1) 00152 { 00153 delay(100); 00154 gpio_set_hid_led(GPIO_LED_ON); 00155 delay(100); 00156 gpio_set_hid_led(GPIO_LED_OFF); 00157 } 00158 } 00159 00160 // Function to wait till PBON button is pressed and released 00161 void wait_for_pbon(void) 00162 { 00163 // Standby - wait for PBON 00164 while (!gpio_get_pbon_btn()) 00165 { 00166 // Do something with leds? 00167 gpio_set_cdc_led(GPIO_LED_ON); 00168 delay(100); 00169 gpio_set_cdc_led(GPIO_LED_OFF); 00170 delay(100); 00171 } 00172 // Wait for PBON to go low then high 00173 while (gpio_get_pbon_btn()) 00174 { 00175 // Do something with leds? 00176 gpio_set_hid_led(GPIO_LED_ON); 00177 delay(100); 00178 gpio_set_hid_led(GPIO_LED_OFF); 00179 delay(100); 00180 } 00181 // Wait 10ms 00182 delay(10); 00183 00184 }
Generated on Tue Jul 12 2022 15:37:21 by
1.7.2