Skip to content

Commit

Permalink
[rem later] Simple LPM application
Browse files Browse the repository at this point in the history
  • Loading branch information
fnack committed Feb 7, 2015
1 parent 8d540bf commit de29ce0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/lpm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# name of your application
APPLICATION = lpm_example

# If no BOARD is found in the environment, use this default:
BOARD ?= msbiot

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

# Define default pin mappings for some boards:
ifneq (,$(filter stm32f4discovery,$(BOARD)))
export WKUP_GPIO ?= GPIO_0
endif
ifneq (,$(filter msbiot,$(BOARD)))
export WKUP_GPIO ?= GPIO_8
endif

ifneq (,$(WKUP_GPIO))
CFLAGS += -DWKUP_GPIO=$(WKUP_GPIO)
else
# set random default
CFLAGS += -DWKUP_GPIO=GPIO_0
endif

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
CFLAGS += -DDEVELHELP

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

include $(RIOTBASE)/Makefile.include
64 changes: 64 additions & 0 deletions examples/lpm/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief LPM example application
*
* @author Fabian Nack <nack@inf.fu-berlin.de>
*
* @}
*/

#ifndef WKUP_GPIO
#error "WKUP_GPIO not defined"
#endif

#include <stdio.h>

#include "cpu-conf.h"
#include "periph/gpio.h"
#include "arch/lpm_arch.h"

static void button_handler(void *args)
{
lpm_arch_awake();
}

int main(void)
{
puts("LPM example application");

gpio_init_int(WKUP_GPIO, GPIO_NOPULL, GPIO_RISING, &button_handler, 0);

/* Check whether the device was reset from standby */
if (PWR->CSR & PWR_CSR_SBF) {
puts("LPM tests successful");
PWR->CR |= PWR_CR_CSBF;
return 0;
}

lpm_arch_init();

puts("Entering LPM_IDLE");
lpm_arch_set(LPM_IDLE);
puts("Successfully awoke from LPM_IDLE");

puts("Entering LPM_SLEEP");
lpm_arch_set(LPM_SLEEP);
puts("Successfully awoke from LPM_SLEEP");

puts("Entering LPM_POWERDOWN");
lpm_arch_set(LPM_POWERDOWN);

/* Never reached */
return 0;
}

0 comments on commit de29ce0

Please sign in to comment.