OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [blink_led/] [main.c] - Diff between revs 23 and 37

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 23 Rev 37
Line 46... Line 46...
 * @name User configuration
 * @name User configuration
 **************************************************************************/
 **************************************************************************/
/**@{*/
/**@{*/
/** UART BAUD rate */
/** UART BAUD rate */
#define BAUD_RATE 19200
#define BAUD_RATE 19200
/** Use the custom ASM version for blinking the LEDs if != 0 */
/** Use the custom ASM version for blinking the LEDs defined (= uncommented) */
#define USE_ASM_VERSION 0
//#define USE_ASM_VERSION
/**@}*/
/**@}*/
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * ASM function to blink LEDs (if enabled)
 * ASM function to blink LEDs
 **************************************************************************/
 **************************************************************************/
extern void blink_led_asm(uint32_t gpio_out_addr);
extern void blink_led_asm(uint32_t gpio_out_addr);
 
 
 
/**********************************************************************//**
 
 * C function to blink LEDs
 
 **************************************************************************/
 
void blink_led_c(void);
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Main function; shows an incrementing 8-bit counter on GPIO.output(7:0).
 * Main function; shows an incrementing 8-bit counter on GPIO.output(7:0).
 *
 *
 * @note This program requires the GPIO controller to be synthesized (the UART is optional).
 * @note This program requires the GPIO controller to be synthesized (the UART is optional).
Line 83... Line 88...
 
 
  // say hello
  // say hello
  neorv32_uart_print("Blinking LED demo program\n");
  neorv32_uart_print("Blinking LED demo program\n");
 
 
 
 
 
// use ASM version of LED blinking (file: blink_led_in_asm.S)
 
#ifdef USE_ASM_VERSION
 
 
 
  blink_led_asm((uint32_t)(&GPIO_OUTPUT));
 
 
// use C version of LED blinking
// use C version of LED blinking
#if (USE_ASM_VERSION == 0)
#else
 
 
 
  blink_led_c();
 
 
 
#endif
 
  return 0;
 
}
 
 
 
 
 
/**********************************************************************//**
 
 * C-version of blinky LED counter
 
 **************************************************************************/
 
void blink_led_c(void) {
 
 
  neorv32_gpio_port_set(0); // clear gpio output put
  neorv32_gpio_port_set(0); // clear gpio output put
 
 
  int cnt = 0;
  int cnt = 0;
 
 
  while (1) {
  while (1) {
    neorv32_gpio_port_set(cnt++ & 0xFF); // increment counter and mask for lowest 8 bit
    neorv32_gpio_port_set(cnt++ & 0xFF); // increment counter and mask for lowest 8 bit
    neorv32_cpu_delay_ms(200); // wait 200ms using busy wait
    neorv32_cpu_delay_ms(200); // wait 200ms using busy wait
  }
  }
 
 
// use ASM version of LED blinking (file: blink_led_in_asm.S)
 
#else
 
 
 
  blink_led_asm((uint32_t)(&GPIO_OUTPUT));
 
 
 
#endif
 
  return 0;
 
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.