mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-24 06:07:52 -04:00
added simple example for mixing C & ASM (assembly version of blink_led)
This commit is contained in:
parent
6644b0fa09
commit
4560c4d72c
2 changed files with 55 additions and 0 deletions
37
sw/example/blink_led/blink_led_in_asm.S
Normal file
37
sw/example/blink_led/blink_led_in_asm.S
Normal file
|
@ -0,0 +1,37 @@
|
|||
.file "blink_led_in_asm.S"
|
||||
.section .text
|
||||
.balign 4
|
||||
.global blink_led_asm
|
||||
|
||||
blink_led_asm:
|
||||
|
||||
/* base address of GPIO controller's output port is passed as argument (in a0)*/
|
||||
sw zero, 0(a0) /* clear output port */
|
||||
|
||||
li t1, 0 /* initialize counter */
|
||||
|
||||
|
||||
blink_loop:
|
||||
andi t1, t1, 255 /* apply 8-bit mask */
|
||||
sw t1, 0(a0) /* output current counter value */
|
||||
addi t1, t1, 1 /* increment counter */
|
||||
|
||||
jal ra, blink_delay /* call delay function */
|
||||
|
||||
j blink_loop
|
||||
|
||||
|
||||
blink_delay:
|
||||
li t2, 0xfffff /* delay time */
|
||||
|
||||
blink_delay_loop:
|
||||
beq t2, zero, blink_delay_end
|
||||
addi t2, t2, -1
|
||||
nop
|
||||
nop
|
||||
j blink_delay_loop
|
||||
|
||||
blink_delay_end:
|
||||
ret
|
||||
|
||||
.end
|
|
@ -48,9 +48,17 @@
|
|||
/**@{*/
|
||||
/** UART BAUD rate */
|
||||
#define BAUD_RATE 19200
|
||||
/** Use the custom ASM version for blinking the LEDs if != 0 */
|
||||
#define USE_ASM_VERSION 0
|
||||
/**@}*/
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* ASM function to blink LEDs (if enabled)
|
||||
**************************************************************************/
|
||||
extern void blink_led_asm(uint32_t gpio_out_addr);
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Main function; shows an incrementing 8-bit counter on GPIO.output(7:0).
|
||||
*
|
||||
|
@ -76,6 +84,10 @@ int main() {
|
|||
// say hello
|
||||
neorv32_uart_print("Blinking LED demo program\n");
|
||||
|
||||
|
||||
// use C version of LED blinking
|
||||
#if (USE_ASM_VERSION == 0)
|
||||
|
||||
neorv32_gpio_port_set(0); // clear gpio output put
|
||||
|
||||
int cnt = 0;
|
||||
|
@ -85,5 +97,11 @@ int main() {
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue