From 1420be55777189fd25f06ffde174c8abe6882186 Mon Sep 17 00:00:00 2001 From: Silvio Gissi Date: Mon, 27 Oct 2014 22:01:34 +0000 Subject: [PATCH] lpc17xx: power: basic peripheral power functions and defns --- include/libopencm3/lpc17xx/pwr.h | 102 +++++++++++++++++++++++++++++++ lib/lpc17xx/Makefile | 2 +- lib/lpc17xx/pwr.c | 48 +++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 include/libopencm3/lpc17xx/pwr.h create mode 100644 lib/lpc17xx/pwr.c diff --git a/include/libopencm3/lpc17xx/pwr.h b/include/libopencm3/lpc17xx/pwr.h new file mode 100644 index 00000000..7b42b632 --- /dev/null +++ b/include/libopencm3/lpc17xx/pwr.h @@ -0,0 +1,102 @@ +/** @defgroup pwr_defines Power Defines + +@brief Defined Constants and Types for the LPC17xx Power Control + +@ingroup LPC17xx_defines + +@version 1.0.0 + +@author @htmlonly © @endhtmlonly 2013 Silvio Gissi + +@date 17 August 2013 + +LGPL License Terms @ref lgpl_license + */ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2012 Silvio Gissi + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#ifndef LPC17XX_POWER_H +#define LPC17XX_POWER_H + +#include +#include + +/* --- Clock registers ----------------------------------------------------- */ +/* Power Control */ +#define PWR_PCON MMIO32(SYSCON_BASE + 0x0c0) +#define PWR_PCONP MMIO32(SYSCON_BASE + 0x0c4) + +/* PWR_PCON Values */ +#define PWR_PCON_MODE_SLEEP 0x00 +#define PWR_PCON_MODE_POWER_DOWN 0x01 +/* PWR_PCON_MODE_RESERVED 0x02*/ +#define PWR_PCON_MODE_DEEPSLEEP 0x03 +#define PWR_PCON_BODRPM (1 << 2) +#define PWR_PCON_BOGD (1 << 3) +#define PWR_PCON_BORD (1 << 4) +/* Reserved: [7:5] */ +#define PWR_PCON_SMFLAG (1 << 8) +#define PWR_PCON_DSFLAG (1 << 9) +#define PWR_PCON_PDFLAG (1 << 10) +#define PWR_PCON_DPDFLAG (1 << 11) +/* Reserved: [31:12] */ + +/* PWR_PCONP Values */ +/* Reserved: [0] */ +#define PWR_PCONP_TIMER0 (1 << 1) +#define PWR_PCONP_TIMER1 (1 << 2) +#define PWR_PCONP_UART0 (1 << 3) +#define PWR_PCONP_UART1 (1 << 4) +/* Reserved: [5] */ +#define PWR_PCONP_PWM1 (1 << 6) +#define PWR_PCONP_I2C0 (1 << 7) +#define PWR_PCONP_SPI (1 << 8) +#define PWR_PCONP_RTC (1 << 9) +#define PWR_PCONP_SSP1 (1 << 10) +/* Reserved: [11] */ +#define PWR_PCONP_ADC (1 << 12) +#define PWR_PCONP_CAN1 (1 << 13) +#define PWR_PCONP_CAN2 (1 << 14) +#define PWR_PCONP_GPIO (1 << 15) +#define PWR_PCONP_RIT (1 << 16) +#define PWR_PCONP_MCPWM (1 << 17) +#define PWR_PCONP_QEI (1 << 18) +#define PWR_PCONP_I2C1 (1 << 19) +/* Reserved: [20] */ +#define PWR_PCONP_SSP0 (1 << 21) +#define PWR_PCONP_TIMER2 (1 << 22) +#define PWR_PCONP_TIMER3 (1 << 23) +#define PWR_PCONP_UART2 (1 << 24) +#define PWR_PCONP_UART3 (1 << 25) +#define PWR_PCONP_I2C2 (1 << 26) +#define PWR_PCONP_I2S (1 << 27) +/* Reserved: [28] */ +#define PWR_PCONP_GPDMA (1 << 29) +#define PWR_PCONP_ETHERNET (1 << 30) +#define PWR_PCONP_USB (1 << 31) + +BEGIN_DECLS + +void pwr_enable_peripherals(uint32_t peripherals); +void pwr_disable_peripherals(uint32_t peripherals); +/* TODO Sleep, Deep Sleep, Power Down and Deep Power Down modes */ + +END_DECLS + +#endif diff --git a/lib/lpc17xx/Makefile b/lib/lpc17xx/Makefile index 4b49df40..126ad445 100644 --- a/lib/lpc17xx/Makefile +++ b/lib/lpc17xx/Makefile @@ -33,7 +33,7 @@ CFLAGS = -O0 -g \ -ffunction-sections -fdata-sections -MD -DLPC17XX # ARFLAGS = rcsv ARFLAGS = rcs -OBJS = gpio.o +OBJS = gpio.o pwr.o VPATH += ../cm3 diff --git a/lib/lpc17xx/pwr.c b/lib/lpc17xx/pwr.c new file mode 100644 index 00000000..cbe794ce --- /dev/null +++ b/lib/lpc17xx/pwr.c @@ -0,0 +1,48 @@ +/** @defgroup pwr-file PWR + +@ingroup LPC17xx + +@brief libopencm3 LPC17xx Power Control + +@version 1.0.0 + +@author @htmlonly © @endhtmlonly 2013 Silvio Gissi + +LGPL License Terms @ref lgpl_license +*/ + +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2013 Silvio Gissi + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +/**@{*/ + +#include + +void pwr_enable_peripherals(uint32_t peripherals) +{ + PWR_PCONP |= peripherals; +} + +void pwr_disable_peripherals(uint32_t peripherals) +{ + PWR_PCONP &= ~peripherals; +} + +/**@}*/ +