i2c_test: add a testcase to test i2c api for microchip board
test i2c api on microchip mec15xxevb_assy6853 board by writing and reading data with nxp pca95xx device on board. Signed-off-by: peng1 chen <peng1.chen@intel.com>
This commit is contained in:
parent
d95a5f9b35
commit
1e05bc2300
6 changed files with 111 additions and 1 deletions
|
|
@ -93,7 +93,7 @@
|
|||
label = "GPIO_P0";
|
||||
|
||||
/* Depends on JP53 for device address.
|
||||
* Pin 1-2 = A2, pin 3-4 = A1, pin 5-6 = A0.
|
||||
* Pin 1-2 = A0, pin 3-4 = A1, pin 5-6 = A2.
|
||||
* Address is: 0100<A2><A1><A0>b.
|
||||
*
|
||||
* Default has pin 1-2 on JP53 connected,
|
||||
|
|
|
|||
8
tests/boards/mec15xxevb_assy6853/i2c_api/CMakeLists.txt
Normal file
8
tests/boards/mec15xxevb_assy6853/i2c_api/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(i2c_api)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
23
tests/boards/mec15xxevb_assy6853/i2c_api/README.txt
Normal file
23
tests/boards/mec15xxevb_assy6853/i2c_api/README.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
I2C Test For Microchip board
|
||||
############################
|
||||
|
||||
This application test is used to test the I2C driver on Microchip
|
||||
mec15xxevb_assy6853 board.
|
||||
|
||||
|
||||
Board Hardware Setup
|
||||
####################
|
||||
|
||||
As the I2C slave device NXP pca95xx on mec15xxevb_assy6853 is connected
|
||||
to I2C00 port, however, I2C00 port is shared with UART2 RS232 to TTL
|
||||
converter used to catch serial log, so it's not possible to use UART2
|
||||
and I2C00 port simultaneously.
|
||||
We need to change to use I2C01 port by making some jumpers setting as below:
|
||||
|
||||
* JP99 1-2 Connected Connect I2C01_SDA from CPU to header J5
|
||||
* JP99 13-14 Connected Connect I2C01_SCL from CPU to header J5
|
||||
* JP25 21-22 Connected External pull-up for I2C01_SDA
|
||||
* JP25 23-24 Connected External pull-up for I2C01_SCL
|
||||
*
|
||||
* JP44.1 J5.1 Connected Connect NXP PCA95xx to I2C01
|
||||
* JP44.3 J5.3 Connected Connect NXP PCA95xx to I2C01
|
||||
2
tests/boards/mec15xxevb_assy6853/i2c_api/prj.conf
Normal file
2
tests/boards/mec15xxevb_assy6853/i2c_api/prj.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
CONFIG_I2C=y
|
||||
CONFIG_ZTEST=y
|
||||
71
tests/boards/mec15xxevb_assy6853/i2c_api/src/main.c
Normal file
71
tests/boards/mec15xxevb_assy6853/i2c_api/src/main.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <drivers/i2c.h>
|
||||
#include <zephyr.h>
|
||||
#include <ztest.h>
|
||||
|
||||
#define I2C_DEV_NAME DT_LABEL(DT_ALIAS(i2c1))
|
||||
|
||||
/* command to configure port direction of NXP PCA95xx */
|
||||
#define REG_CONF_PORT0 0x06U
|
||||
|
||||
/* test data used to write into registers */
|
||||
uint8_t test_data[2] = {0xAA, 0xAA};
|
||||
|
||||
/**
|
||||
* @brief Test i2c api by communicating with pca95xx
|
||||
* @details
|
||||
* - get i2c mainline device
|
||||
* - write data into pca95xx
|
||||
* - read data from pca95xx
|
||||
* - check read data whether correct
|
||||
*/
|
||||
void test_i2c_pca95xx(void)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t datas[3];
|
||||
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_MASTER;
|
||||
|
||||
/* get i2c device */
|
||||
const struct device *i2c_dev = device_get_binding(I2C_DEV_NAME);
|
||||
|
||||
zassert_true(i2c_dev, "Cannot get i2c device");
|
||||
|
||||
/* configure i2c device */
|
||||
ret = i2c_configure(i2c_dev, i2c_cfg);
|
||||
zassert_true(ret == 0, "Failed to configure i2c device");
|
||||
|
||||
/* write configuration to register 6 and 7 of PCA95XX*/
|
||||
(void)memset(datas, 0, 3);
|
||||
datas[0] = REG_CONF_PORT0;
|
||||
datas[1] = test_data[0];
|
||||
datas[2] = test_data[1];
|
||||
ret = i2c_write(i2c_dev, datas, 3, 0x26);
|
||||
zassert_true(ret == 0, "Failed to write data to i2c device");
|
||||
|
||||
/* read configuration from register 6 and 7 */
|
||||
(void)memset(datas, 0, 3);
|
||||
datas[0] = REG_CONF_PORT0;
|
||||
ret = i2c_write(i2c_dev, datas, 1, 0x26);
|
||||
zassert_true(ret == 0, "Failed to write data to i2c device");
|
||||
|
||||
(void)memset(datas, 0, 3);
|
||||
ret = i2c_read(i2c_dev, datas, 2, 0x26);
|
||||
zassert_true(ret == 0, "Failed to read data from i2c device");
|
||||
|
||||
/* check read data whether correct */
|
||||
ret = memcmp(datas, test_data, 2);
|
||||
zassert_true(ret == 0, "Read data is different to write data");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(i2c_test,
|
||||
ztest_unit_test(test_i2c_pca95xx)
|
||||
);
|
||||
ztest_run_test_suite(i2c_test);
|
||||
}
|
||||
6
tests/boards/mec15xxevb_assy6853/i2c_api/testcase.yaml
Normal file
6
tests/boards/mec15xxevb_assy6853/i2c_api/testcase.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
tests:
|
||||
boards.mec15xxevb_assy6853.i2c:
|
||||
depends_on: i2c
|
||||
tags: drivers i2c
|
||||
filter: dt_compat_enabled("nxp,pca95xx")
|
||||
platform_allow: mec15xxevb_assy6853
|
||||
Loading…
Reference in a new issue