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,13 @@
Example Description
This example describes how to use GPIO read/write mbed api to generate a pulse and to measure the pulse width.
Requirement Components:
a wire
Pin name PC_4 and PC_5 map to GPIOC_4 and GPIOC_5:
- PC_4 as the interrupt GPIO pin with no pull (High-Z).
- PC_5 as output to generate a pulse.
- Use a wire to connect PC_4 and PC_5
In this example, the UART consol will print out the measured width (in us) of the pulse which generated by PC_5.

View file

@ -0,0 +1,73 @@
/*
* Routines to access hardware
*
* Copyright (c) 2013 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 "diag.h"
#include "us_ticker_api.h"
#include "main.h"
#define GPIO_OUT_PIN PC_5
#define GPIO_IRQ_PIN PC_4
gpio_t gpio_out;
gpio_irq_t gpio_irq;
volatile char irq_rise;
void gpio_demo_irq_handler (uint32_t id, gpio_irq_event event)
{
static unsigned int rise_time;
static unsigned int fall_time;
if (irq_rise) {
rise_time = us_ticker_read();
// Changed as Falling Edge Trigger
gpio_irq_set_event(&gpio_irq, IRQ_FALL);
irq_rise = 0;
} else {
fall_time = us_ticker_read();
// Changed as Rising Edge Trigger
gpio_irq_set_event(&gpio_irq, IRQ_RISE);
irq_rise = 1;
DBG_8195A("%d\n", (fall_time-rise_time));
}
}
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
// Init LED control pin
gpio_init(&gpio_out, GPIO_OUT_PIN);
gpio_dir(&gpio_out, PIN_OUTPUT); // Direction: Output
gpio_mode(&gpio_out, PullNone); // No pull
gpio_write(&gpio_out, 0);
// Initial Push Button pin as interrupt source
gpio_irq_init(&gpio_irq, GPIO_IRQ_PIN, gpio_demo_irq_handler, (uint32_t)(&gpio_irq));
gpio_irq_set(&gpio_irq, IRQ_RISE, 1); // Falling Edge Trigger
irq_rise = 1;
gpio_irq_pull_ctrl(&gpio_irq, PullNone);
gpio_irq_enable(&gpio_irq);
while(1) {
wait_ms(500);
gpio_write(&gpio_out, 1);
wait_us(1000);
gpio_write(&gpio_out, 0);
}
}