/* ------------------------------------------
* Copyright (c) 2016, Synopsys, Inc. All rights reserved.
* Redistribu
tion and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1) Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* version 2016.01
* date 2014-12-17
* author Wayne Ren(
Wei.Ren@synopsys.com)
--------------------------------------------- */
/**
* defgroup EMBARC_APP_GPIO embARC GPIO Example
* ingroup EMBARC_APPS_TOTAL
* ingroup EMBARC_APPS_BOARD_EMSK
* ingroup EMBARC_APPS_BAREMETAL
* rief embARC Example for testing designware gpio module
*
* details
* ### Extra Required Tools
*
* ### Extra Required Peripherals
*
* ### Design Concept
* This example is designed to show how to use device [GPIO HAL API](dev_gpio.h) in embARC.
*
* ### Usage Manual
* Test cases for DW GPIO driver. In this example, the functions of the LEDs, buttons, and DIP switches are tested.
* ![ScreenShot of gpio under baremetal](pic/images/example/emsk/emsk_gpio.jpg)
*
* ### Extra Comments
*
*/
/**
* file
* ingroup EMBARC_APP_GPIO
* rief example of timer0 and gpio
*/
/**
* addtogroup EMBARC_APP_GPIO
* @{
*/
#include "embARC.h"
#include "embARC_debug.h"
static volatile int t0 = 0;
static volatile int t1 = 0;
static DEV_GPIO_PTR port_th;
/**
* rief timer0 interrupt service routine
* param[in] *ptr interrupt handler param
*/
/*static void timer0_isr(void *ptr)
{
uint32_t data1;
timer_int_clear(TIMER_0);
t0++;*/
// EMBARC_PRINTF("t0:%d
",t0);
// port_th->gpio_write(0x1,0xF);//给地址位0xF写数据0x1
// port_th->gpio_read(&data1,0xF);
// EMBARC_PRINTF("data1 value : 0x%x
", data1);
//}
static void delay(uint32_t z)
{
uint32_t i,j;
for(i=360;i>0;i--)
{
for(j=z;j>0;j--);
}
}
static void init1()
{
port_th = gpio_get_dev(DW_GPIO_PORT_D);//
port_th->gpio_open(0xF);
port_th->gpio_write(0x3,0xF);//给地址位0xF写数据0x3,初始化,数据总线拉高
// port_th->gpio_read(&data,0xF);
}
static void init2()
{
port_th = gpio_get_dev(DW_GPIO_PORT_D);//
port_th->gpio_open(0xF);
port_th->gpio_write(0x1,0xF);//给地址位0xF写数据0x1,输入数据,数据总线拉低
// port_th->gpio_read(&data,0xF);
}
int main(void)
{
uint32_t sensor_data[4];
cpu_lock();
board_init(); /* board init */
uint32_t data;
long t;
while(1)
{
init1();//初始化,数据总线拉高
delay(500);
init2();//数据总线拉低,1ms
delay(50);
init1();//数据总线拉高,20us
delay(1);
init2();//数据总线拉低,80us
delay(4);
init1();//数据总线拉高,80us
// delay(4);
/* init2();//数据总线拉低,50us
delay(3);
init1();//数据总线拉高,26us
delay(2);
init2();//数据总线拉低,50us */
port_th->gpio_read(sensor_data[0],0xF);
EMBARC_PRINTF("sensor_data[0]:0x%x
",sensor_data[0]);
// delay(3);
// init1();//给地址位0xF写数据0x3,即响应主机的起始信号,拉高70us
//写读数据的指令,读传感器地址位的数据,然后以10进制数读出
// port_th->gpio_read(sensor_data[0],0xF);
port_th->gpio_read(sensor_data[1],0xF);
t = ((long)sensor_data[0] << 8) + ((long)sensor_data[1] & 0xF8);
t >>= 3;
//conversion (t = t*0,0625) in Degrees
t *= 6250;
EMBARC_PRINTF("Temp: %2d.%2d C
", (int)(t/100000), (int)(((t-(t/100000)*100000))/1000) );
port_th->gpio_read(sensor_data[2],0xF);
port_th->gpio_read(sensor_data[3],0xF);
t = ((long)sensor_data[2] << 8) + ((long)sensor_data[3] & 0xF8);
t >>= 3;
//conversion (t = t*0,0625) in Degrees
t *= 6250;
EMBARC_PRINTF("Temp: %2d.%2d C
", (int)(t/100000), (int)(((t-(t/100000)*100000))/1000) );
delay(700);
}
cpu_unlock(); /* unlock system */
while (1);
return E_SYS;
}
/** @} */
一周热门 更多>