Skip to content

Commit 55662a7

Browse files
Ramakrishna PallalaAnas Nashif
authored andcommitted
tests: boards: altera_max10: Add test for Nios-II i2c core
Add test application for Nios-II i2c core on Altera MAX10 board. This test uses ADV7513 HDMI I2C slave module on Altera MAX10 board to perform i2c read and write operations. For more details on ADV7513 HDMI module, please refer to the following link. https://ez.analog.com/docs/DOC-1986 Signed-off-by: Ramakrishna Pallala <[email protected]>
1 parent 3eb62bc commit 55662a7

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed
Lines changed: 5 additions & 0 deletions
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})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Build test for:
2+
Altera Nios-II I2C master soft IP core.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_I2C=y
2+
CONFIG_I2C_NIOS2=y
3+
CONFIG_I2C_INIT_PRIORITY=60
4+
CONFIG_I2C_0=y
5+
CONFIG_I2C_0_NAME="I2C_0"
6+
CONFIG_I2C_0_DEFAULT_CFG=0x0
7+
CONFIG_I2C_0_IRQ_PRI=10
8+
CONFIG_ZTEST=y
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <i2c.h>
8+
#include <zephyr.h>
9+
#include <ztest.h>
10+
11+
/*
12+
* For ADV7513 Programming details, please
13+
* refer to the following link.
14+
* https://ez.analog.com/docs/DOC-1986
15+
*/
16+
17+
#define ADV7513_HDMI_I2C_SLAVE_ADDR 0x39
18+
19+
#define ADV7513_CHIP_REVISION_REG 0x0
20+
#define CHIP_REVISION_VAL 0x13
21+
22+
#define ADV7513_MAIN_POWER_REG 0x41
23+
#define POWER_ON_VAL 0x10
24+
25+
#define ADV7513_HPD_CTRL_REG 0xD6
26+
#define HPD_CTRL_VAL 0xC0
27+
28+
#define ADV7513_WRITE_TEST_REG 0x2
29+
#define WRITE_TEST_VAL 0x66
30+
31+
static int powerup_adv7513(struct device *i2c_dev)
32+
{
33+
u8_t data;
34+
35+
TC_PRINT("Powering up ADV7513\n");
36+
/* write to HPD control registers */
37+
if (i2c_reg_write_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
38+
ADV7513_HPD_CTRL_REG, HPD_CTRL_VAL)) {
39+
TC_PRINT("i2c write fail\n");
40+
return TC_FAIL;
41+
}
42+
if (i2c_reg_read_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
43+
0xD6, &data)) {
44+
TC_PRINT("failed to read HPD control\n");
45+
return TC_FAIL;
46+
}
47+
TC_PRINT("HPD control 0x%x\n", data);
48+
49+
/* write to power control registers */
50+
if (i2c_reg_write_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
51+
ADV7513_MAIN_POWER_REG, POWER_ON_VAL)) {
52+
TC_PRINT("i2c write fail\n");
53+
return TC_FAIL;
54+
}
55+
56+
if (i2c_reg_read_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
57+
0x41, &data)) {
58+
TC_PRINT("failed to read Power state\n");
59+
return TC_FAIL;
60+
}
61+
TC_PRINT("Power state 0x%x\n", data);
62+
63+
return TC_PASS;
64+
}
65+
66+
static int test_i2c_adv7513(void)
67+
{
68+
struct device *i2c_dev = device_get_binding(CONFIG_I2C_0_NAME);
69+
u32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_MASTER;
70+
u8_t data;
71+
72+
if (!i2c_dev) {
73+
TC_PRINT("cannot get i2c device\n");
74+
return TC_FAIL;
75+
}
76+
77+
/* Test i2c_configure() */
78+
if (i2c_configure(i2c_dev, i2c_cfg)) {
79+
TC_PRINT("i2c config failed\n");
80+
return TC_FAIL;
81+
}
82+
83+
/* Power up ADV7513 */
84+
zassert_true(powerup_adv7513(i2c_dev) == TC_PASS,
85+
"ADV7513 power up failed");
86+
87+
TC_PRINT("*** Running i2c read/write tests ***\n");
88+
/* Test i2c byte read */
89+
data = 0x0;
90+
if (i2c_reg_read_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
91+
ADV7513_CHIP_REVISION_REG, &data)) {
92+
TC_PRINT("failed to read chip revision\n");
93+
return TC_FAIL;
94+
}
95+
if (data != CHIP_REVISION_VAL) {
96+
TC_PRINT("chip revision does not match 0x%x\n", data);
97+
return TC_FAIL;
98+
}
99+
TC_PRINT("i2c read test passed\n");
100+
101+
102+
/* Test i2c byte write */
103+
data = WRITE_TEST_VAL;
104+
if (i2c_reg_write_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
105+
ADV7513_WRITE_TEST_REG, data)) {
106+
TC_PRINT("i2c write fail\n");
107+
return TC_FAIL;
108+
}
109+
data = 0x0;
110+
if (i2c_reg_read_byte(i2c_dev, ADV7513_HDMI_I2C_SLAVE_ADDR,
111+
ADV7513_WRITE_TEST_REG, &data)) {
112+
TC_PRINT("i2c read fail\n");
113+
return TC_FAIL;
114+
}
115+
if (data != WRITE_TEST_VAL) {
116+
TC_PRINT("i2c write test failed 0x%x\n", data);
117+
return TC_FAIL;
118+
}
119+
TC_PRINT("i2c write & verify test passed\n");
120+
121+
return TC_PASS;
122+
}
123+
124+
void test_i2c_master(void)
125+
{
126+
zassert_true(test_i2c_adv7513() == TC_PASS, NULL);
127+
}
128+
129+
void test_main(void)
130+
{
131+
ztest_test_suite(nios2_i2c_master_test,
132+
ztest_unit_test(test_i2c_master));
133+
ztest_run_test_suite(nios2_i2c_master_test);
134+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tests:
2+
test:
3+
platform_whitelist: altera_max10
4+
tags: i2c

0 commit comments

Comments
 (0)