From: Nathael Pajani Date: Mon, 3 Oct 2016 15:13:03 +0000 (+0200) Subject: Simple Deep power down example. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=66672bfdf52e826558e532a137917fd12fb9f0c7;p=soft%2Flpc122x%2Fexamples Simple Deep power down example. --- diff --git a/power_down/Makefile b/power_down/Makefile new file mode 100644 index 0000000..da44d1f --- /dev/null +++ b/power_down/Makefile @@ -0,0 +1,12 @@ +# Makefile for "base" apps + +MODULE = $(shell basename $(shell cd .. && pwd && cd -)) +NAME = $(shell basename $(CURDIR)) + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../../.. --no-print-directory NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@ + +clean mrproper: + @make -C ../../.. --no-print-directory $@ + diff --git a/power_down/README b/power_down/README new file mode 100644 index 0000000..bd469ec --- /dev/null +++ b/power_down/README @@ -0,0 +1,34 @@ +Deep power down support example + +Copyright 2016 Nathael Pajani + + +/* **************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +This example shows the support of the deep power down functionnality of the +LPC1224 micro-controller. + +Once in deep power down, the LPC1224 can only be woken up by an RTC interrupt +or the WAKEUP pin going LOW (pin 39, GPIO1_3). +Even the RESET pin going Low will not reset the micro-controller. + +In this example, the LPC1224 goes to deep power down mode when ISP button is +released. +You must either add an external pull-up and a button to the GPIO1_3 (AD5) Pin +of the LPC1224-BO Board, or Power the board OFF and ON again. + + diff --git a/power_down/main.c b/power_down/main.c new file mode 100644 index 0000000..2277837 --- /dev/null +++ b/power_down/main.c @@ -0,0 +1,117 @@ +/**************************************************************************** + * apps/base/power_down/main.c + * + * Deep power down example + * + * Copyright 2016 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +#include "core/system.h" +#include "core/systick.h" +#include "core/pio.h" +#include "lib/stdio.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "extdrv/status_led.h" + +#define MODULE_VERSION 0x03 +#define MODULE_NAME "LPC1224-BO" + +#define SELECTED_FREQ FREQ_SEL_48MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL }, + { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL }, + /* GPIO */ + { LPC_GPIO_0_12, (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL) }, + ARRAY_LAST_PIO, +}; + +const struct pio button = LPC_GPIO_0_12; + +const struct pio status_led_green = LPC_GPIO_1_4; +const struct pio status_led_red = LPC_GPIO_1_5; + + +/***************************************************************************** */ +void system_init() +{ + /* Stop the watchdog */ + startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ + system_brown_out_detection_config(0); /* No ADC used */ + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + gpio_on(); + status_led_config(&status_led_green, &status_led_red); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. This one is not mandatory, the dummy fault handler + * will be used when it's not overridden here. + * Note : The default one does a simple infinite loop. If the watchdog is deactivated + * the system will hang. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + +uint32_t isp_btn_request = 0; +void isp_btn(uint32_t gpio) +{ + isp_btn_request++; +} + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + set_gpio_callback(&isp_btn, &button, EDGE_RISING); + + uprintf(UART0, "Config done.\n"); + + isp_btn_request = 0; + while (1) { + chenillard(100); + if (isp_btn_request == 1) { + uprintf(UART0, "ISP Button\n"); + serial_flush(UART0); + gpio_clear(status_led_green); + gpio_clear(status_led_red); + msleep(50); + enter_deep_power_down(); + } + } + + return 0; +} +