intel_s1000: tests: introduce tests to check features enabled
This patchset carries out basic tests on the features supported on intel_s1000. Currently, Interrupt mechanism, GPIO handling, I2C communication and UART prints are illustrated. Change-Id: I7ea03b5085b7fa8d29635c294038536465a70660 Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com> Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
dadf9e7a81
commit
567482ff35
5
tests/boards/intel_s1000_crb/CMakeLists.txt
Normal file
5
tests/boards/intel_s1000_crb/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(NONE)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
65
tests/boards/intel_s1000_crb/README.txt
Normal file
65
tests/boards/intel_s1000_crb/README.txt
Normal file
|
@ -0,0 +1,65 @@
|
|||
Title: Intel_S1000 tests
|
||||
|
||||
Description:
|
||||
|
||||
This test illustrates the various features enabled on Intel_S1000.
|
||||
|
||||
Features exhibited in this test set
|
||||
============================
|
||||
|
||||
GPIO toggling
|
||||
- GPIO_23 configured as input
|
||||
- GPIO_24 configured as output and interrupt capable
|
||||
- GPIO_23 and GPIO_24 are shorted
|
||||
- Upon toggling GPIO_23, GPIO_24 also changes state appropriately and
|
||||
also calls its callback function if interrupt is configured
|
||||
|
||||
I2C slave communication
|
||||
- Intel_S1000 I2C configured as master, 7 bit mode, standard speed
|
||||
- 2 LED matrices are configured as slaves
|
||||
- The LED matrices are written over I2C to emit blue light and red
|
||||
light alternately
|
||||
- Read functionality verified by reading LED0 after every write and
|
||||
dumping the result on to the console
|
||||
|
||||
Interrupt handling
|
||||
- All peripheral interrupts are enabled by default
|
||||
- Each peripheral interrupt can be disabled by calling irq_disable().
|
||||
For e.g. GPIO IRQ can be disabled by calling "irq_disable(GPIO_DW_0_IRQ);"
|
||||
|
||||
UART prints
|
||||
- Displays the various prints dumped to the console by the above modules
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Building and Running Project:
|
||||
|
||||
This project outputs to the console. It can be built and executed
|
||||
on Intel_S1000 using the flyswatter2 as follows:
|
||||
|
||||
make flash
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Troubleshooting:
|
||||
|
||||
Problems caused by out-dated project information can be addressed by
|
||||
issuing one of the following commands then rebuilding the project:
|
||||
|
||||
make clean # discard results of previous builds
|
||||
# but keep existing configuration info
|
||||
or
|
||||
make pristine # discard results of previous builds
|
||||
# and restore pre-defined configuration info
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Sample Output:
|
||||
|
||||
***** BOOTING ZEPHYR OS v1.9.99-intel_internal - BUILD: Oct 31 2017 14:48:57 *****
|
||||
Sample app running on: xtensa Intel_S1000
|
||||
Reading GPIO_24 = 0
|
||||
LED0 = 10
|
||||
GPIO_24 triggered
|
||||
Reading GPIO_24 = 1
|
||||
LED0 = 41
|
0
tests/boards/intel_s1000_crb/prj.conf
Normal file
0
tests/boards/intel_s1000_crb/prj.conf
Normal file
140
tests/boards/intel_s1000_crb/src/gpio_test.c
Normal file
140
tests/boards/intel_s1000_crb/src/gpio_test.c
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Sample app to utilize GPIO on Intel_S1000.
|
||||
*
|
||||
* Intel_S1000 - Xtensa
|
||||
* --------------------
|
||||
*
|
||||
* The gpio_dw driver is being used.
|
||||
*
|
||||
* This sample app toggles GPIO_23. It also waits for
|
||||
* GPIO_24 to go high and display a message.
|
||||
*
|
||||
* If GPIOs 23 and 24 are connected together, the GPIO should
|
||||
* triggers every 1 second. And you should see this repeatedly
|
||||
* on console:
|
||||
* "
|
||||
* Reading GPIO_24 = 0
|
||||
* GPIO_24 triggered
|
||||
* Reading GPIO_24 = 1
|
||||
* "
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/printk.h>
|
||||
|
||||
#include <device.h>
|
||||
#include <gpio.h>
|
||||
|
||||
#define GPIO_OUT_PIN 23
|
||||
#define GPIO_INT_PIN 24
|
||||
#define GPIO_NAME "GPIO_"
|
||||
#define GPIO_DRV_NAME CONFIG_GPIO_DW_0_NAME
|
||||
|
||||
/* size of stack area used by each thread */
|
||||
#define STACKSIZE 1024
|
||||
|
||||
/* scheduling priority used by each thread */
|
||||
#define PRIORITY 7
|
||||
|
||||
/* delay between greetings (in ms) */
|
||||
#define SLEEPTIME 500
|
||||
|
||||
extern struct k_sem thread_sem;
|
||||
|
||||
void gpio_test_callback(struct device *port,
|
||||
struct gpio_callback *cb, u32_t pins)
|
||||
{
|
||||
printk(GPIO_NAME "%d triggered\n", GPIO_INT_PIN);
|
||||
}
|
||||
|
||||
static struct gpio_callback gpio_cb;
|
||||
|
||||
void setup_gpio(struct device *gpio_dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Setup GPIO output */
|
||||
ret = gpio_pin_configure(gpio_dev, GPIO_OUT_PIN, (GPIO_DIR_OUT));
|
||||
if (ret) {
|
||||
printk("Error configuring " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
|
||||
}
|
||||
|
||||
/* Setup GPIO input, and triggers on rising edge. */
|
||||
ret = gpio_pin_configure(gpio_dev, GPIO_INT_PIN,
|
||||
(GPIO_DIR_IN | GPIO_INT |
|
||||
GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH |
|
||||
GPIO_INT_DEBOUNCE));
|
||||
if (ret) {
|
||||
printk("Error configuring " GPIO_NAME "%d!\n", GPIO_INT_PIN);
|
||||
}
|
||||
|
||||
gpio_init_callback(&gpio_cb, gpio_test_callback, BIT(GPIO_INT_PIN));
|
||||
|
||||
ret = gpio_add_callback(gpio_dev, &gpio_cb);
|
||||
if (ret) {
|
||||
printk("Cannot setup callback!\n");
|
||||
}
|
||||
|
||||
ret = gpio_pin_enable_callback(gpio_dev, GPIO_INT_PIN);
|
||||
if (ret) {
|
||||
printk("Error enabling callback!\n");
|
||||
}
|
||||
|
||||
/* Disable the GPIO interrupt. It is enabled by default */
|
||||
/* irq_disable(GPIO_DW_0_IRQ); */
|
||||
}
|
||||
|
||||
/* gpio_thread is a static thread that is spawned automatically */
|
||||
void gpio_thread(void *dummy1, void *dummy2, void *dummy3)
|
||||
{
|
||||
struct device *gpio_dev;
|
||||
int ret;
|
||||
int toggle = 1;
|
||||
u32_t read_val = 0;
|
||||
|
||||
ARG_UNUSED(dummy1);
|
||||
ARG_UNUSED(dummy2);
|
||||
ARG_UNUSED(dummy3);
|
||||
|
||||
gpio_dev = device_get_binding(GPIO_DRV_NAME);
|
||||
if (!gpio_dev) {
|
||||
printk("Cannot find %s!\n", GPIO_DRV_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
setup_gpio(gpio_dev);
|
||||
|
||||
while (1) {
|
||||
/* take semaphore */
|
||||
k_sem_take(&thread_sem, K_FOREVER);
|
||||
|
||||
if (toggle) {
|
||||
toggle = 0;
|
||||
} else {
|
||||
toggle = 1;
|
||||
}
|
||||
|
||||
ret = gpio_pin_write(gpio_dev, GPIO_OUT_PIN, toggle);
|
||||
if (ret) {
|
||||
printk("Error set " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
|
||||
}
|
||||
|
||||
gpio_pin_read(gpio_dev, GPIO_INT_PIN, &read_val);
|
||||
printk("Reading "GPIO_NAME"%d = %d\n", GPIO_INT_PIN, read_val);
|
||||
|
||||
/* let other threads have a turn */
|
||||
k_sem_give(&thread_sem);
|
||||
|
||||
/* wait a while */
|
||||
k_sleep(SLEEPTIME);
|
||||
}
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(gpio_thread_id, STACKSIZE, gpio_thread, NULL, NULL, NULL,
|
||||
PRIORITY, 0, K_NO_WAIT);
|
147
tests/boards/intel_s1000_crb/src/i2c_test.c
Normal file
147
tests/boards/intel_s1000_crb/src/i2c_test.c
Normal file
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Sample app to illustrate i2c master-slave communication on Intel_S1000.
|
||||
*
|
||||
* Intel_S1000 - Xtensa
|
||||
* --------------------
|
||||
*
|
||||
* The i2c_dw driver is being used.
|
||||
*
|
||||
* In this sample app, the Intel_S1000 master I2C communicates with 2 slave
|
||||
* LED I2C matrices driving them to emit blue light and red light alternately.
|
||||
* While this validates the write functionality, the read functionality is
|
||||
* verified by reading the LED0 values after each write. It would display
|
||||
* the below message repeatedly on the console every 500ms.
|
||||
*
|
||||
* "
|
||||
* Reading LED_0 = 41
|
||||
* Reading LED_0 = 10
|
||||
* "
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/printk.h>
|
||||
|
||||
#include <device.h>
|
||||
#include <i2c.h>
|
||||
|
||||
#define I2C_DEV CONFIG_I2C_0_NAME
|
||||
#define I2C_ADDR_LED_MAT0 0x65
|
||||
#define I2C_ADDR_LED_MAT1 0x69
|
||||
#define LED0 0x02
|
||||
#define LED1 0x03
|
||||
#define LED2 0x04
|
||||
#define LED3 0x05
|
||||
#define LED4 0x06
|
||||
#define LED5 0x07
|
||||
|
||||
/* size of stack area used by each thread */
|
||||
#define STACKSIZE 1024
|
||||
|
||||
/* scheduling priority used by each thread */
|
||||
#define PRIORITY 7
|
||||
|
||||
/* delay between greetings (in ms) */
|
||||
#define SLEEPTIME 500
|
||||
|
||||
extern struct k_sem thread_sem;
|
||||
|
||||
void test_i2c_write_led(struct device *i2c_dev, u16_t i2c_slave_led, u8_t color)
|
||||
{
|
||||
int ret;
|
||||
int led_val[6];
|
||||
|
||||
switch (color) {
|
||||
case 0: /* RED color LED */
|
||||
led_val[0] = 0x10;
|
||||
led_val[1] = 0x04;
|
||||
led_val[2] = 0x41;
|
||||
led_val[3] = 0x10;
|
||||
led_val[4] = 0x04;
|
||||
led_val[5] = 0x41;
|
||||
break;
|
||||
|
||||
case 1: /* BLUE color LED */
|
||||
led_val[0] = 0x41;
|
||||
led_val[1] = 0x10;
|
||||
led_val[2] = 0x04;
|
||||
led_val[3] = 0x41;
|
||||
led_val[4] = 0x10;
|
||||
led_val[5] = 0x04;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ret = i2c_reg_write_byte(i2c_dev, i2c_slave_led, 0x40, 0xFF);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED0, led_val[0]);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED1, led_val[1]);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED2, led_val[2]);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED3, led_val[3]);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED4, led_val[4]);
|
||||
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED5, led_val[5]);
|
||||
if (ret) {
|
||||
printk("Error writing to LED!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_i2c_read_led(struct device *i2c_dev, u16_t i2c_slave_led)
|
||||
{
|
||||
int ret;
|
||||
u8_t data = 0;
|
||||
|
||||
ret = i2c_reg_read_byte(i2c_dev, i2c_slave_led, LED0, &data);
|
||||
if (ret) {
|
||||
printk("Error reading from LED! error code (%d)\n", ret);
|
||||
return;
|
||||
}
|
||||
printk("LED0 = %x\n", data);
|
||||
}
|
||||
|
||||
/* i2c_thread is a static thread that is spawned automatically */
|
||||
void i2c_thread(void *dummy1, void *dummy2, void *dummy3)
|
||||
{
|
||||
struct device *i2c_dev;
|
||||
int toggle = 1;
|
||||
|
||||
ARG_UNUSED(dummy1);
|
||||
ARG_UNUSED(dummy2);
|
||||
ARG_UNUSED(dummy3);
|
||||
|
||||
i2c_dev = device_get_binding(I2C_DEV);
|
||||
if (!i2c_dev) {
|
||||
printk("I2C: Device driver not found.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* take semaphore */
|
||||
k_sem_take(&thread_sem, K_FOREVER);
|
||||
|
||||
if (toggle) {
|
||||
toggle = 0;
|
||||
} else {
|
||||
toggle = 1;
|
||||
}
|
||||
|
||||
test_i2c_write_led(i2c_dev, I2C_ADDR_LED_MAT0, toggle);
|
||||
test_i2c_write_led(i2c_dev, I2C_ADDR_LED_MAT1, toggle);
|
||||
test_i2c_read_led(i2c_dev, I2C_ADDR_LED_MAT0);
|
||||
|
||||
/* let other threads have a turn */
|
||||
k_sem_give(&thread_sem);
|
||||
|
||||
/* wait a while */
|
||||
k_sleep(SLEEPTIME);
|
||||
}
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(i2c_thread_id, STACKSIZE, i2c_thread, NULL, NULL, NULL,
|
||||
PRIORITY, 0, K_NO_WAIT);
|
66
tests/boards/intel_s1000_crb/src/main.c
Normal file
66
tests/boards/intel_s1000_crb/src/main.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/printk.h>
|
||||
|
||||
#define IOMUX_BASE 0x00081C00
|
||||
#define IOMUX_CONTROL0 (IOMUX_BASE + 0x30)
|
||||
#define IOMUX_CONTROL2 (IOMUX_BASE + 0x38)
|
||||
#define TS_POWER_CONFIG 0x00071F90
|
||||
|
||||
/* This semaphore is used to serialize the UART prints dumped by various
|
||||
* modules. This prevents mixing of UART prints across modules. This
|
||||
* semaphore starts off "available".
|
||||
*/
|
||||
K_SEM_DEFINE(thread_sem, 1, 1);
|
||||
|
||||
/* Disable Tensilica power gating */
|
||||
void disable_ts_powergate(void)
|
||||
{
|
||||
volatile u16_t pwrcfg = *(volatile u16_t *)TS_POWER_CONFIG;
|
||||
|
||||
/* Set the below bits to disable power gating:
|
||||
* BIT0 - Tensilica Core Prevent DSP Core Power Gating
|
||||
* BIT4 - Tensilica Core Prevent Controller Power Gating
|
||||
* BIT5 - Ignore D3 / D0i3 Power Gating
|
||||
* BIT6 - Tensilica Core Prevent DSP Common Power Gating
|
||||
*/
|
||||
pwrcfg |= BIT(0) | BIT(4) | BIT(5) | BIT(6);
|
||||
|
||||
*(volatile u16_t *)TS_POWER_CONFIG = pwrcfg;
|
||||
}
|
||||
|
||||
/* Configure the MUX to select GPIO functionality for GPIO 23 and 24 */
|
||||
void iomux_config_ctsrts(void)
|
||||
{
|
||||
volatile u32_t iomux_cntrl0 = *(volatile u32_t *)IOMUX_CONTROL0;
|
||||
|
||||
/* Set bit 16 to convert the pins to normal GPIOs from UART_RTS_CTS */
|
||||
iomux_cntrl0 |= BIT(16);
|
||||
|
||||
*(volatile u32_t *)IOMUX_CONTROL0 = iomux_cntrl0;
|
||||
}
|
||||
|
||||
/* Configure the MUX to select the correct I2C port (I2C1) */
|
||||
void iomux_config_i2c(void)
|
||||
{
|
||||
volatile u32_t iomux_cntrl2 = *(volatile u32_t *)IOMUX_CONTROL2;
|
||||
|
||||
/* Set bit 0 to select i2c1 */
|
||||
iomux_cntrl2 |= BIT(0);
|
||||
|
||||
*(volatile u32_t *)IOMUX_CONTROL2 = iomux_cntrl2;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
printk("Sample app running on: %s Intel_S1000\n", CONFIG_ARCH);
|
||||
|
||||
disable_ts_powergate();
|
||||
iomux_config_i2c();
|
||||
iomux_config_ctsrts();
|
||||
}
|
4
tests/boards/intel_s1000_crb/testcase.yaml
Normal file
4
tests/boards/intel_s1000_crb/testcase.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
tests:
|
||||
test:
|
||||
platform_whitelist: intel_s1000_crb
|
||||
tags: boards
|
Loading…
Reference in a new issue