Skip to content

Commit 567482f

Browse files
rgundiAnas Nashif
authored and
Anas Nashif
committed
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 <[email protected]> Signed-off-by: Anas Nashif <[email protected]>
1 parent dadf9e7 commit 567482f

File tree

7 files changed

+427
-0
lines changed

7 files changed

+427
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
2+
project(NONE)
3+
4+
FILE(GLOB app_sources src/*.c)
5+
target_sources(app PRIVATE ${app_sources})
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Title: Intel_S1000 tests
2+
3+
Description:
4+
5+
This test illustrates the various features enabled on Intel_S1000.
6+
7+
Features exhibited in this test set
8+
============================
9+
10+
GPIO toggling
11+
- GPIO_23 configured as input
12+
- GPIO_24 configured as output and interrupt capable
13+
- GPIO_23 and GPIO_24 are shorted
14+
- Upon toggling GPIO_23, GPIO_24 also changes state appropriately and
15+
also calls its callback function if interrupt is configured
16+
17+
I2C slave communication
18+
- Intel_S1000 I2C configured as master, 7 bit mode, standard speed
19+
- 2 LED matrices are configured as slaves
20+
- The LED matrices are written over I2C to emit blue light and red
21+
light alternately
22+
- Read functionality verified by reading LED0 after every write and
23+
dumping the result on to the console
24+
25+
Interrupt handling
26+
- All peripheral interrupts are enabled by default
27+
- Each peripheral interrupt can be disabled by calling irq_disable().
28+
For e.g. GPIO IRQ can be disabled by calling "irq_disable(GPIO_DW_0_IRQ);"
29+
30+
UART prints
31+
- Displays the various prints dumped to the console by the above modules
32+
33+
---------------------------------------------------------------------------
34+
35+
Building and Running Project:
36+
37+
This project outputs to the console. It can be built and executed
38+
on Intel_S1000 using the flyswatter2 as follows:
39+
40+
make flash
41+
42+
---------------------------------------------------------------------------
43+
44+
Troubleshooting:
45+
46+
Problems caused by out-dated project information can be addressed by
47+
issuing one of the following commands then rebuilding the project:
48+
49+
make clean # discard results of previous builds
50+
# but keep existing configuration info
51+
or
52+
make pristine # discard results of previous builds
53+
# and restore pre-defined configuration info
54+
55+
---------------------------------------------------------------------------
56+
57+
Sample Output:
58+
59+
***** BOOTING ZEPHYR OS v1.9.99-intel_internal - BUILD: Oct 31 2017 14:48:57 *****
60+
Sample app running on: xtensa Intel_S1000
61+
Reading GPIO_24 = 0
62+
LED0 = 10
63+
GPIO_24 triggered
64+
Reading GPIO_24 = 1
65+
LED0 = 41

tests/boards/intel_s1000_crb/prj.conf

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 2017 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file Sample app to utilize GPIO on Intel_S1000.
9+
*
10+
* Intel_S1000 - Xtensa
11+
* --------------------
12+
*
13+
* The gpio_dw driver is being used.
14+
*
15+
* This sample app toggles GPIO_23. It also waits for
16+
* GPIO_24 to go high and display a message.
17+
*
18+
* If GPIOs 23 and 24 are connected together, the GPIO should
19+
* triggers every 1 second. And you should see this repeatedly
20+
* on console:
21+
* "
22+
* Reading GPIO_24 = 0
23+
* GPIO_24 triggered
24+
* Reading GPIO_24 = 1
25+
* "
26+
*/
27+
28+
#include <zephyr.h>
29+
#include <misc/printk.h>
30+
31+
#include <device.h>
32+
#include <gpio.h>
33+
34+
#define GPIO_OUT_PIN 23
35+
#define GPIO_INT_PIN 24
36+
#define GPIO_NAME "GPIO_"
37+
#define GPIO_DRV_NAME CONFIG_GPIO_DW_0_NAME
38+
39+
/* size of stack area used by each thread */
40+
#define STACKSIZE 1024
41+
42+
/* scheduling priority used by each thread */
43+
#define PRIORITY 7
44+
45+
/* delay between greetings (in ms) */
46+
#define SLEEPTIME 500
47+
48+
extern struct k_sem thread_sem;
49+
50+
void gpio_test_callback(struct device *port,
51+
struct gpio_callback *cb, u32_t pins)
52+
{
53+
printk(GPIO_NAME "%d triggered\n", GPIO_INT_PIN);
54+
}
55+
56+
static struct gpio_callback gpio_cb;
57+
58+
void setup_gpio(struct device *gpio_dev)
59+
{
60+
int ret;
61+
62+
/* Setup GPIO output */
63+
ret = gpio_pin_configure(gpio_dev, GPIO_OUT_PIN, (GPIO_DIR_OUT));
64+
if (ret) {
65+
printk("Error configuring " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
66+
}
67+
68+
/* Setup GPIO input, and triggers on rising edge. */
69+
ret = gpio_pin_configure(gpio_dev, GPIO_INT_PIN,
70+
(GPIO_DIR_IN | GPIO_INT |
71+
GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH |
72+
GPIO_INT_DEBOUNCE));
73+
if (ret) {
74+
printk("Error configuring " GPIO_NAME "%d!\n", GPIO_INT_PIN);
75+
}
76+
77+
gpio_init_callback(&gpio_cb, gpio_test_callback, BIT(GPIO_INT_PIN));
78+
79+
ret = gpio_add_callback(gpio_dev, &gpio_cb);
80+
if (ret) {
81+
printk("Cannot setup callback!\n");
82+
}
83+
84+
ret = gpio_pin_enable_callback(gpio_dev, GPIO_INT_PIN);
85+
if (ret) {
86+
printk("Error enabling callback!\n");
87+
}
88+
89+
/* Disable the GPIO interrupt. It is enabled by default */
90+
/* irq_disable(GPIO_DW_0_IRQ); */
91+
}
92+
93+
/* gpio_thread is a static thread that is spawned automatically */
94+
void gpio_thread(void *dummy1, void *dummy2, void *dummy3)
95+
{
96+
struct device *gpio_dev;
97+
int ret;
98+
int toggle = 1;
99+
u32_t read_val = 0;
100+
101+
ARG_UNUSED(dummy1);
102+
ARG_UNUSED(dummy2);
103+
ARG_UNUSED(dummy3);
104+
105+
gpio_dev = device_get_binding(GPIO_DRV_NAME);
106+
if (!gpio_dev) {
107+
printk("Cannot find %s!\n", GPIO_DRV_NAME);
108+
return;
109+
}
110+
111+
setup_gpio(gpio_dev);
112+
113+
while (1) {
114+
/* take semaphore */
115+
k_sem_take(&thread_sem, K_FOREVER);
116+
117+
if (toggle) {
118+
toggle = 0;
119+
} else {
120+
toggle = 1;
121+
}
122+
123+
ret = gpio_pin_write(gpio_dev, GPIO_OUT_PIN, toggle);
124+
if (ret) {
125+
printk("Error set " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
126+
}
127+
128+
gpio_pin_read(gpio_dev, GPIO_INT_PIN, &read_val);
129+
printk("Reading "GPIO_NAME"%d = %d\n", GPIO_INT_PIN, read_val);
130+
131+
/* let other threads have a turn */
132+
k_sem_give(&thread_sem);
133+
134+
/* wait a while */
135+
k_sleep(SLEEPTIME);
136+
}
137+
}
138+
139+
K_THREAD_DEFINE(gpio_thread_id, STACKSIZE, gpio_thread, NULL, NULL, NULL,
140+
PRIORITY, 0, K_NO_WAIT);
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright (c) 2017 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file Sample app to illustrate i2c master-slave communication on Intel_S1000.
9+
*
10+
* Intel_S1000 - Xtensa
11+
* --------------------
12+
*
13+
* The i2c_dw driver is being used.
14+
*
15+
* In this sample app, the Intel_S1000 master I2C communicates with 2 slave
16+
* LED I2C matrices driving them to emit blue light and red light alternately.
17+
* While this validates the write functionality, the read functionality is
18+
* verified by reading the LED0 values after each write. It would display
19+
* the below message repeatedly on the console every 500ms.
20+
*
21+
* "
22+
* Reading LED_0 = 41
23+
* Reading LED_0 = 10
24+
* "
25+
*/
26+
27+
#include <zephyr.h>
28+
#include <misc/printk.h>
29+
30+
#include <device.h>
31+
#include <i2c.h>
32+
33+
#define I2C_DEV CONFIG_I2C_0_NAME
34+
#define I2C_ADDR_LED_MAT0 0x65
35+
#define I2C_ADDR_LED_MAT1 0x69
36+
#define LED0 0x02
37+
#define LED1 0x03
38+
#define LED2 0x04
39+
#define LED3 0x05
40+
#define LED4 0x06
41+
#define LED5 0x07
42+
43+
/* size of stack area used by each thread */
44+
#define STACKSIZE 1024
45+
46+
/* scheduling priority used by each thread */
47+
#define PRIORITY 7
48+
49+
/* delay between greetings (in ms) */
50+
#define SLEEPTIME 500
51+
52+
extern struct k_sem thread_sem;
53+
54+
void test_i2c_write_led(struct device *i2c_dev, u16_t i2c_slave_led, u8_t color)
55+
{
56+
int ret;
57+
int led_val[6];
58+
59+
switch (color) {
60+
case 0: /* RED color LED */
61+
led_val[0] = 0x10;
62+
led_val[1] = 0x04;
63+
led_val[2] = 0x41;
64+
led_val[3] = 0x10;
65+
led_val[4] = 0x04;
66+
led_val[5] = 0x41;
67+
break;
68+
69+
case 1: /* BLUE color LED */
70+
led_val[0] = 0x41;
71+
led_val[1] = 0x10;
72+
led_val[2] = 0x04;
73+
led_val[3] = 0x41;
74+
led_val[4] = 0x10;
75+
led_val[5] = 0x04;
76+
break;
77+
78+
default:
79+
break;
80+
}
81+
82+
ret = i2c_reg_write_byte(i2c_dev, i2c_slave_led, 0x40, 0xFF);
83+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED0, led_val[0]);
84+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED1, led_val[1]);
85+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED2, led_val[2]);
86+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED3, led_val[3]);
87+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED4, led_val[4]);
88+
ret |= i2c_reg_write_byte(i2c_dev, i2c_slave_led, LED5, led_val[5]);
89+
if (ret) {
90+
printk("Error writing to LED!\n");
91+
return;
92+
}
93+
}
94+
95+
void test_i2c_read_led(struct device *i2c_dev, u16_t i2c_slave_led)
96+
{
97+
int ret;
98+
u8_t data = 0;
99+
100+
ret = i2c_reg_read_byte(i2c_dev, i2c_slave_led, LED0, &data);
101+
if (ret) {
102+
printk("Error reading from LED! error code (%d)\n", ret);
103+
return;
104+
}
105+
printk("LED0 = %x\n", data);
106+
}
107+
108+
/* i2c_thread is a static thread that is spawned automatically */
109+
void i2c_thread(void *dummy1, void *dummy2, void *dummy3)
110+
{
111+
struct device *i2c_dev;
112+
int toggle = 1;
113+
114+
ARG_UNUSED(dummy1);
115+
ARG_UNUSED(dummy2);
116+
ARG_UNUSED(dummy3);
117+
118+
i2c_dev = device_get_binding(I2C_DEV);
119+
if (!i2c_dev) {
120+
printk("I2C: Device driver not found.\n");
121+
return;
122+
}
123+
124+
while (1) {
125+
/* take semaphore */
126+
k_sem_take(&thread_sem, K_FOREVER);
127+
128+
if (toggle) {
129+
toggle = 0;
130+
} else {
131+
toggle = 1;
132+
}
133+
134+
test_i2c_write_led(i2c_dev, I2C_ADDR_LED_MAT0, toggle);
135+
test_i2c_write_led(i2c_dev, I2C_ADDR_LED_MAT1, toggle);
136+
test_i2c_read_led(i2c_dev, I2C_ADDR_LED_MAT0);
137+
138+
/* let other threads have a turn */
139+
k_sem_give(&thread_sem);
140+
141+
/* wait a while */
142+
k_sleep(SLEEPTIME);
143+
}
144+
}
145+
146+
K_THREAD_DEFINE(i2c_thread_id, STACKSIZE, i2c_thread, NULL, NULL, NULL,
147+
PRIORITY, 0, K_NO_WAIT);

0 commit comments

Comments
 (0)