add examples

This commit is contained in:
pvvx 2016-12-14 04:21:37 +03:00
parent 265d41b6a3
commit 4128624f93
112 changed files with 158017 additions and 0 deletions

View file

@ -0,0 +1,18 @@
Example Description
This example describes how to use sleep api.
Requirement Components:
a LED
a push button
Pin name PC_4 and PC_5 map to GPIOC_4 and GPIOC_5:
- PC_4 as input with internal pull-high, connect a push button to this pin and ground.
- PC_5 as output, connect a LED to this pin and ground.
In this example, LED is turned on after device initialize.
User push the button to turn off LED and trigger device enter sleep mode for 10s.
If user push button before sleep timeout, the system will resume.
LED is turned on again after system resume without restart PC.
It can be easily measure power consumption in normal mode and sleep mode before/after push the putton.

View file

@ -0,0 +1,86 @@
/*
* Routines to access hardware
*
* Copyright (c) 2015 Realtek Semiconductor Corp.
*
* This module is a confidential and proprietary property of RealTek and
* possession or use of this module requires written permission of RealTek.
*/
#include "device.h"
#include "gpio_api.h" // mbed
#include "gpio_irq_api.h" // mbed
#include "sleep_ex_api.h"
#include "sys_api.h"
#include "diag.h"
#include "main.h"
#define GPIO_LED_PIN PC_5
#define GPIO_IRQ_PIN PC_4
int led_ctrl = 0;
gpio_t gpio_led;
int put_to_sleep = 0;
void gpio_demo_irq_handler (uint32_t id, gpio_irq_event event)
{
gpio_t *gpio_led;
gpio_led = (gpio_t *)id;
if (led_ctrl == 1) {
led_ctrl = 0;
gpio_write(gpio_led, led_ctrl);
put_to_sleep = 1;
} else {
led_ctrl = 1;
gpio_write(gpio_led, led_ctrl);
}
}
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
gpio_irq_t gpio_btn;
int IsDramOn = 1;
DBG_INFO_MSG_OFF(_DBG_GPIO_);
// Init LED control pin
gpio_init(&gpio_led, GPIO_LED_PIN);
gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output
gpio_mode(&gpio_led, PullNone); // No pull
// Initial Push Button pin as interrupt source
gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler, (uint32_t)(&gpio_led));
gpio_irq_set(&gpio_btn, IRQ_FALL, 1);
gpio_irq_enable(&gpio_btn);
led_ctrl = 1;
gpio_write(&gpio_led, led_ctrl);
DBG_8195A("Push button to enter sleep\r\n");
//system will hang when it tries to suspend SDRAM for 8711AF
if ( sys_is_sdram_power_on() == 0 ) {
IsDramOn = 0;
}
put_to_sleep = 0;
while(1) {
if (put_to_sleep) {
DBG_8195A("Sleep 8s or push button to resume system...\r\n");
sys_log_uart_off();
sleep_ex_selective(SLP_GPIO | SLEEP_WAKEUP_BY_STIMER, 8000, 0, IsDramOn); // sleep_ex can't be put in irq handler
sys_log_uart_on();
DBG_8195A("System resume\r\n");
put_to_sleep = 0;
led_ctrl = 1;
gpio_write(&gpio_led, led_ctrl);
}
}
}