Skip to content

Commit

Permalink
[dif/gpio] migrate srcs to use autogen'd IRQ DIFs
Browse files Browse the repository at this point in the history
This partially addresses #8142.

Signed-off-by: Timothy Trippel <ttrippel@google.com>
  • Loading branch information
timothytrippel authored and moidx committed Sep 27, 2021
1 parent 6713749 commit c0e0286
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 676 deletions.
7 changes: 3 additions & 4 deletions sw/device/boot_rom/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ static bool bootstrap_requested(void) {

// Initialize GPIO device.
dif_gpio_t gpio;
dif_gpio_params_t gpio_params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR)};
CHECK(dif_gpio_init(gpio_params, &gpio) == kDifGpioOk);
CHECK(dif_gpio_init(mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR),
&gpio) == kDifOk);

dif_gpio_state_t gpio_in;
CHECK(dif_gpio_read_all(&gpio, &gpio_in) == kDifGpioOk);
CHECK(dif_gpio_read_all(&gpio, &gpio_in) == kDifOk);
return (gpio_in & GPIO_BOOTSTRAP_BIT_MASK) != 0;
}

Expand Down
10 changes: 5 additions & 5 deletions sw/device/examples/demos.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ void demo_gpio_startup(dif_gpio_t *gpio) {
LOG_INFO("Watch the LEDs!");

// Give a LED pattern as startup indicator for 5 seconds.
CHECK(dif_gpio_write_all(gpio, 0xff00) == kDifGpioOk);
CHECK(dif_gpio_write_all(gpio, 0xff00) == kDifOk);
for (int i = 0; i < 32; ++i) {
usleep(5 * 1000); // 5 ms
CHECK(dif_gpio_write(gpio, 8 + (i % 8), (i / 8) % 2) == kDifGpioOk);
CHECK(dif_gpio_write(gpio, 8 + (i % 8), (i / 8) % 2) == kDifOk);
}
CHECK(dif_gpio_write_all(gpio, 0x0000) == kDifGpioOk); // All LEDs off.
CHECK(dif_gpio_write_all(gpio, 0x0000) == kDifOk); // All LEDs off.
}

/**
Expand All @@ -39,7 +39,7 @@ static const uint32_t kFtdiMask = 0x10000;

uint32_t demo_gpio_to_log_echo(dif_gpio_t *gpio, uint32_t prev_gpio_state) {
uint32_t gpio_state;
CHECK(dif_gpio_read_all(gpio, &gpio_state) == kDifGpioOk);
CHECK(dif_gpio_read_all(gpio, &gpio_state) == kDifOk);
gpio_state &= kGpioMask;

uint32_t state_delta = prev_gpio_state ^ gpio_state;
Expand Down Expand Up @@ -86,6 +86,6 @@ void demo_uart_to_uart_and_gpio_echo(dif_uart_t *uart, dif_gpio_t *gpio) {
uint8_t rcv_char;
CHECK(dif_uart_bytes_receive(uart, 1, &rcv_char, NULL) == kDifOk);
CHECK(dif_uart_byte_send_polled(uart, rcv_char) == kDifOk);
CHECK(dif_gpio_write_all(gpio, rcv_char << 8) == kDifGpioOk);
CHECK(dif_gpio_write_all(gpio, rcv_char << 8) == kDifOk);
}
}
12 changes: 5 additions & 7 deletions sw/device/examples/hello_usbdev/hello_usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@ int main(int argc, char **argv) {
.tx_fifo_len = kDifSpiDeviceBufferLen / 2,
}) == kDifSpiDeviceOk);

dif_gpio_params_t gpio_params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR),
};
CHECK(dif_gpio_init(gpio_params, &gpio) == kDifGpioOk);
CHECK(dif_gpio_init(mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR),
&gpio) == kDifOk);
// Enable GPIO: 0-7 and 16 is input; 8-15 is output.
CHECK(dif_gpio_output_set_enabled_all(&gpio, 0x0ff00) == kDifGpioOk);
CHECK(dif_gpio_output_set_enabled_all(&gpio, 0x0ff00) == kDifOk);

LOG_INFO("Hello, USB!");
LOG_INFO("Built at: " __DATE__ ", " __TIME__);
Expand All @@ -153,7 +151,7 @@ int main(int argc, char **argv) {
// simulation has finished all of the printing, which takes a while
// if `--trace` was passed in.
uint32_t gpio_state;
CHECK(dif_gpio_read_all(&gpio, &gpio_state) == kDifGpioOk);
CHECK(dif_gpio_read_all(&gpio, &gpio_state) == kDifOk);
bool pinflip = gpio_state & kPinflipMask ? true : false;
bool differential = gpio_state & kDiffMask ? true : false;
bool uphy = gpio_state & kUPhyMask ? true : false;
Expand Down Expand Up @@ -189,7 +187,7 @@ int main(int argc, char **argv) {
CHECK(dif_uart_bytes_receive(&uart, 1, &rcv_char, NULL) == kDifOk);
CHECK(dif_uart_byte_send_polled(&uart, rcv_char) == kDifOk);

CHECK(dif_gpio_write_all(&gpio, rcv_char << 8) == kDifGpioOk);
CHECK(dif_gpio_write_all(&gpio, rcv_char << 8) == kDifOk);

if (rcv_char == '/') {
uint32_t usb_irq_state =
Expand Down
10 changes: 4 additions & 6 deletions sw/device/examples/hello_world/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ int main(int argc, char **argv) {
.tx_fifo_len = kDifSpiDeviceBufferLen / 2,
}) == kDifSpiDeviceOk);

dif_gpio_params_t gpio_params = {
.base_addr = mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR),
};
CHECK(dif_gpio_init(gpio_params, &gpio) == kDifGpioOk);
CHECK(dif_gpio_init(mmio_region_from_addr(TOP_EARLGREY_GPIO_BASE_ADDR),
&gpio) == kDifOk);
// Enable GPIO: 0-7 and 16 is input; 8-15 is output.
CHECK(dif_gpio_output_set_enabled_all(&gpio, 0x0ff00) == kDifGpioOk);
CHECK(dif_gpio_output_set_enabled_all(&gpio, 0x0ff00) == kDifOk);

// Add DATE and TIME because I keep fooling myself with old versions
LOG_INFO("Hello World!");
Expand All @@ -65,7 +63,7 @@ int main(int argc, char **argv) {

// Now have UART <-> Buttons/LEDs demo
// all LEDs off
CHECK(dif_gpio_write_all(&gpio, 0x0000) == kDifGpioOk);
CHECK(dif_gpio_write_all(&gpio, 0x0000) == kDifOk);
LOG_INFO("Try out the switches on the board");
LOG_INFO("or type anything into the console window.");
LOG_INFO("The LEDs show the ASCII code of the last character.");
Expand Down
14 changes: 14 additions & 0 deletions sw/device/lib/dif/autogen/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

# Autogen GPIO DIF library
sw_lib_dif_autogen_gpio = declare_dependency(
link_with: static_library(
'sw_lib_dif_autogen_gpio',
sources: [
hw_ip_gpio_reg_h,
'dif_gpio_autogen.c',
],
dependencies: [
sw_lib_mmio,
],
)
)

# Autogen AES DIF library
sw_lib_dif_autogen_aes = declare_dependency(
link_with: static_library(
Expand Down
8 changes: 4 additions & 4 deletions sw/device/lib/dif/dif_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ typedef enum dif_result {
*/
typedef enum dif_toggle {
/**
* The "enabled" state.
* The "disabled" state.
*/
kDifToggleEnabled,
kDifToggleDisabled = 0,
/**
* The "disabled" state.
* The "enabled" state.
*/
kDifToggleDisabled,
kDifToggleEnabled = 1,
} dif_toggle_t;

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit c0e0286

Please sign in to comment.