Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | /*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @addtogroup t_pinmux_basic
* @{
* @defgroup t_pinmux_gpio test_pinmux_gpio
* @brief TestPurpose: verify PINMUX works on GPIO port
* @details
* - Test Steps (Quark_se_c1000_devboard)
* -# Connect pin_53(GPIO_19) and pin_50(GPIO_16).
* -# Configure GPIO_19 as output pin and set init LOW.
* -# Configure GPIO_16 as input pin and set LEVEL HIGH interrupt.
* -# Set pin_50 to PINMUX_FUNC_A and test GPIO functionality.
* -# Set pin_50 to PINMUX_FUNC_B and test GPIO functionality.
* - Expected Results
* -# When set pin_50 to PINMUX_FUNC_A, pin_50 works as GPIO and gpio
* callback will be triggered.
* -# When set pin_50 to PINMUX_FUNC_B, pin_50 works as I2S and gpio
* callback will not be triggered.
* @}
*/
#include <gpio.h>
#include <pinmux.h>
#include <ztest.h>
#define PINMUX_NAME CONFIG_PINMUX_NAME
#if defined(CONFIG_BOARD_QUARK_SE_C1000_DEVBOARD)
#define GPIO_DEV_NAME CONFIG_GPIO_QMSI_0_NAME
#define GPIO_OUT 15 /* GPIO15_I2S_RXD */
#define GPIO_IN 16 /* GPIO16_I2S_RSCK */
#define PIN_IN 50 /* GPIO16_I2S_RSCK */
#elif defined(CONFIG_BOARD_QUARK_SE_C1000_DEVBOARD_SS)
#define GPIO_DEV_NAME CONFIG_GPIO_QMSI_SS_0_NAME
#define GPIO_OUT 4 /* GPIO_SS_AIN_12 */
#define GPIO_IN 5 /* GPIO_SS_AIN_13 */
#define PIN_IN 13 /* GPIO_SS_AIN_13 */
#elif defined(CONFIG_BOARD_ARDUINO_101)
#define GPIO_DEV_NAME CONFIG_GPIO_QMSI_0_NAME
#define GPIO_OUT 16 /* IO8 */
#define GPIO_IN 19 /* IO4 */
#define PIN_IN 53 /* IO4 */
#elif defined(CONFIG_BOARD_ARDUINO_101_SSS)
#define GPIO_DEV_NAME CONFIG_GPIO_QMSI_SS_0_NAME
#define GPIO_OUT 2 /* AD0 */
#define GPIO_IN 3 /* AD1 */
#define PIN_IN 11 /* AD1 */
#elif defined(CONFIG_BOARD_QUARK_D2000_CRB)
#define GPIO_DEV_NAME CONFIG_GPIO_QMSI_0_NAME
#define GPIO_OUT 8 /* DIO7 */
#define GPIO_IN 9 /* DIO8 */
#define PIN_IN 9 /* DIO8 */
#endif
#define MAX_INT_CNT 10
static bool cb_triggered;
static void callback(struct device *dev,
struct gpio_callback *gpio_cb, u32_t pins)
{
static int cb_cnt;
TC_PRINT("callback triggered: %d\n", ++cb_cnt);
if (cb_cnt >= MAX_INT_CNT) {
cb_triggered = true;
gpio_pin_write(dev, GPIO_OUT, 0);
}
}
static int test_gpio(u32_t pin, u32_t func)
{
u32_t function;
struct gpio_callback gpio_cb;
struct device *pinmux = device_get_binding(PINMUX_NAME);
if (!pinmux) {
TC_PRINT("Cannot get PINMUX\n");
return TC_FAIL;
}
struct device *gpio_dev = device_get_binding(GPIO_DEV_NAME);
if (!gpio_dev) {
TC_PRINT("Cannot get GPIO device\n");
return TC_FAIL;
}
cb_triggered = false;
/* 1. Configure PIN_OUT and set init voltage */
if (gpio_pin_configure(gpio_dev, GPIO_OUT, GPIO_DIR_OUT)) {
TC_PRINT("PIN_OUT configure fail\n");
return TC_FAIL;
}
if (gpio_pin_write(gpio_dev, GPIO_OUT, 0)) {
TC_PRINT("Set PIN_OUT init LOW fail\n");
return TC_FAIL;
}
/* 2. Configure PIN_IN and set callback */
if (gpio_pin_configure(gpio_dev, GPIO_IN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_DEBOUNCE |
GPIO_INT_LEVEL | GPIO_INT_ACTIVE_HIGH)) {
TC_PRINT("PIN_IN configure fail\n");
return TC_FAIL;
}
gpio_init_callback(&gpio_cb, callback, BIT(GPIO_IN));
if (gpio_add_callback(gpio_dev, &gpio_cb)) {
TC_PRINT("Set PIN_IN callback fail\n");
return TC_FAIL;
}
gpio_pin_enable_callback(gpio_dev, GPIO_IN);
/* 3. Verify pinmux_pin_set() */
if (pinmux_pin_set(pinmux, pin, func)) {
TC_PRINT("Fail to set pin func, %u : %u\n", pin, func);
return TC_FAIL;
}
/* 4. Verify pinmux_pin_get() */
if (pinmux_pin_get(pinmux, pin, &function)) {
TC_PRINT("Fail to get pin func\n");
return TC_FAIL;
}
/* 5. Verify the setting works */
if (function != func) {
TC_PRINT("Error. PINMUX get doesn't match PINMUX set\n");
return TC_FAIL;
}
/* 6. Set PIN_OUT HIGH and verify pin func works */
if (gpio_pin_write(gpio_dev, GPIO_OUT, 1)) {
TC_PRINT("Set PIN_OUT HIGH fail\n");
return TC_FAIL;
}
k_sleep(1000);
if (cb_triggered) {
TC_PRINT("GPIO callback is triggered\n");
return TC_PASS;
} else {
TC_PRINT("GPIO callback is not triggered\n");
return TC_FAIL;
}
}
void test_pinmux_gpio(void)
{
zassert_true(test_gpio(PIN_IN, PINMUX_FUNC_A) == TC_PASS, NULL);
zassert_true(test_gpio(PIN_IN, PINMUX_FUNC_B) == TC_FAIL, NULL);
}
|