Software APIs
gpio_pinmux_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include <stdbool.h>
6 #include <stdint.h>
7 
8 #include "sw/device/lib/base/status.h"
12 #include "sw/device/lib/testing/json/command.h"
13 #include "sw/device/lib/testing/json/gpio.h"
14 #include "sw/device/lib/testing/json/pinmux_config.h"
15 #include "sw/device/lib/testing/test_framework/check.h"
17 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
18 #include "sw/device/lib/ujson/ujson.h"
19 
21 
22 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
23 
24 static dif_gpio_t gpio;
25 static dif_pinmux_t pinmux;
26 
27 status_t command_processor(ujson_t *uj) {
28  while (true) {
29  test_command_t command;
30  TRY(ujson_deserialize_test_command_t(uj, &command));
31  switch (command) {
32  case kTestCommandGpioSet:
33  RESP_ERR(uj, gpio_set(uj, &gpio));
34  break;
35  case kTestCommandGpioGet:
36  RESP_ERR(uj, gpio_get(uj, &gpio));
37  break;
38  case kTestCommandPinmuxConfig:
39  RESP_ERR(uj, pinmux_config(uj, &pinmux));
40  break;
41  default:
42  LOG_ERROR("Unrecognized command: %d", command);
43  RESP_ERR(uj, INVALID_ARGUMENT());
44  }
45  }
46  // We should never reach here.
47  return INTERNAL();
48 }
49 
50 bool test_main(void) {
51  CHECK_DIF_OK(dif_pinmux_init(
53  CHECK_DIF_OK(
54  dif_gpio_init(mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR), &gpio));
55  ujson_t uj = ujson_ottf_console();
56 
57  status_t s = command_processor(&uj);
58  LOG_INFO("status = %r", s);
59  return status_ok(s);
60 }