ibex/examples/sw/led/led.c
Tobias Wölfel 76f6a3d4c3 Use shared code for Arty A7-100T example
Move Xilinx specific code into shared folder so it can be re-used by
different examples.
Use the shared RAM code and make use of byte enable signal.
Fixes lowrisc/ibex#144
2019-11-14 13:20:19 +01:00

47 lines
1.2 KiB
C

// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#include <stdint.h>
#define CLK_FIXED_FREQ_HZ (50ULL * 1000 * 1000)
/**
* Delay loop executing within 8 cycles on ibex
*/
static void delay_loop_ibex(unsigned long loops) {
int out; /* only to notify compiler of modifications to |loops| */
asm volatile(
"1: nop \n" // 1 cycle
" nop \n" // 1 cycle
" nop \n" // 1 cycle
" nop \n" // 1 cycle
" addi %1, %1, -1 \n" // 1 cycle
" bnez %1, 1b \n" // 3 cycles
: "=&r" (out)
: "0" (loops)
);
}
static int usleep_ibex(unsigned long usec) {
unsigned long usec_cycles;
usec_cycles = CLK_FIXED_FREQ_HZ * usec / 1000 / 1000 / 8;
delay_loop_ibex(usec_cycles);
return 0;
}
static int usleep(unsigned long usec) {
return usleep_ibex(usec);
}
int main(int argc, char **argv) {
// The lowest four bits of the highest byte written to the memory region named
// "stack" are connected to the LEDs of the board.
volatile uint8_t *var = (volatile uint8_t *) 0x0000c010;
*var = 0x0a;
while (1) {
usleep(1000 * 1000); // 1000 ms
*var = ~(*var);
}
}