|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/ztest.h> |
| 8 | +#include <zephyr/usb/usbh.h> |
| 9 | +#include <zephyr/usb/usbh.h> |
| 10 | + |
| 11 | +#include "usbh_ch9.h" |
| 12 | +#include "usbh_host.h" |
| 13 | + |
| 14 | +#include <zephyr/logging/log.h> |
| 15 | +LOG_MODULE_REGISTER(usb_test, LOG_LEVEL_INF); |
| 16 | + |
| 17 | +USBH_CONTROLLER_DEFINE(uhs_ctx, DEVICE_DT_GET(DT_NODELABEL(zephyr_uhc0))); |
| 18 | + |
| 19 | +static void *usb_test_enable(void) |
| 20 | +{ |
| 21 | + int ret; |
| 22 | + |
| 23 | + ret = usbh_init(&uhs_ctx); |
| 24 | + zassert_ok(ret, "Failed to initialize USB host (%d)", ret); |
| 25 | + |
| 26 | + ret = usbh_enable(&uhs_ctx); |
| 27 | + zassert_ok(ret, "Failed to enable USB host (%d)", ret); |
| 28 | + |
| 29 | + ret = uhc_bus_reset(uhs_ctx.dev); |
| 30 | + zassert_ok(ret, "Failed to signal bus reset (%d)", ret); |
| 31 | + |
| 32 | + ret = uhc_bus_resume(uhs_ctx.dev); |
| 33 | + zassert_ok(ret, "Failed to signal bus resume (%d)", ret); |
| 34 | + |
| 35 | + ret = uhc_sof_enable(uhs_ctx.dev); |
| 36 | + zassert_ok(ret, "Failed to enable SoF generator (%d)", ret); |
| 37 | + |
| 38 | + LOG_INF("Host controller enabled"); |
| 39 | + |
| 40 | + /* Allow the host time to reset the host. */ |
| 41 | + k_msleep(200); |
| 42 | + |
| 43 | + return NULL; |
| 44 | +} |
| 45 | + |
| 46 | +static void usb_test_shutdown(void *f) |
| 47 | +{ |
| 48 | + int ret; |
| 49 | + |
| 50 | + ret = usbh_disable(&uhs_ctx); |
| 51 | + zassert_ok(ret, "Failed to enable host support (%d)", ret); |
| 52 | + |
| 53 | + ret = usbh_shutdown(&uhs_ctx); |
| 54 | + zassert_ok(ret, "Failed to shutdown host support (%d)", ret); |
| 55 | + |
| 56 | + LOG_INF("Host controller disabled"); |
| 57 | +} |
| 58 | + |
| 59 | +ZTEST_SUITE(host, NULL, usb_test_enable, NULL, NULL, usb_test_shutdown); |
0 commit comments