neorv32/sw/example/demo_blink_led/main.c
stnolting ece8380e4f [sw/lib] add simple busy-wait delay function
that do not rely on any specific CPU hardware
2025-02-17 20:54:32 +01:00

49 lines
1.9 KiB
C

// ================================================================================ //
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
// Copyright (c) NEORV32 contributors. //
// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
// SPDX-License-Identifier: BSD-3-Clause //
// ================================================================================ //
/**********************************************************************//**
* @file demo_blink_led/main.c
* @author Stephan Nolting
* @brief Minimal blinking LED demo program using the lowest 8 bits of the GPIO.output port.
**************************************************************************/
#include <neorv32.h>
/**********************************************************************//**
* Simple bus-wait helper.
*
* @param[in] time_ms Time in ms to wait (unsigned 32-bit).
**************************************************************************/
void delay_ms(uint32_t time_ms) {
neorv32_aux_delay_ms(neorv32_sysinfo_get_clk(), time_ms);
}
/**********************************************************************//**
* Main function; shows an incrementing 8-bit counter on GPIO.output(7:0).
*
* @note This program requires the GPIO controller to be synthesized.
*
* @return Will never return.
**************************************************************************/
int main() {
// clear GPIO output (set all bits to 0)
neorv32_gpio_port_set(0);
int cnt = 0;
while (1) {
neorv32_gpio_port_set(cnt++ & 0xFF); // increment counter and mask for lowest 8 bit
delay_ms(250); // wait 250ms using busy wait
}
// this should never be reached
return 0;
}