• Post author:
  • Reading time:4 mins read
  • Post category:Tutorials

Core Local Interrupter (CLINT) has a fixed priority scheme which implements Software, Timer, and External interrupts. Software preemption is only available between privilege levels using the CLINT. For example, while in Supervisor mode, a Machine mode interrupt will immediately take priority and preempt Supervisor mode operation. Preemption within a privilege level is not supported with the CLINT. The interrupt ID represents the fixed priority value of each interrupt, and is not configurable.

There are two different CLINT modes of operation, direct mode and vectored mode

In this article we see a CLINT counter that is configured for a time period and on expiry, the timer interrupt handler handles the interrupt. Then the CLINT counter is configured for subsequent operation.

Step 1: What You Will Need

For this you will need:-

Step 2: The Circuit

Connect the Arty7 board with the system which has a complete SHAKTI ecosystem.

Step 3: Code

Please click here to have a look at the code of CLINT counter


Code can be compiled and run using the following ways,


Step 4.1: Manual Method

4.1.1 Compile and build

  • Move to shakti-sdk
cd shakti-sdk
  • Compile using make software PROGRAM=? TARGET=?. Type make list_applns to list all the applications available in the SDK. Target can be either parashu, pinaka or vajra.

For instance, Use target as parashu,

make software PROGRAM=counter TARGET=parashu

4.1.2 Execution:

Once the application is built, the executable is generated in the output folder. The executable is in ELF file format and they have the extension .shakti. Now, open three terminals, one for each of the following,

  • One terminal for UART terminal display (miniterm)
  • Another for OpenOCD.
  • And the last one for GDB server.

Terminal 1: Firstly, Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.

For instance,

$ sudo miniterm.py /dev/ttyUSB1 19200

Note:

  • “/dev/ttyUSB1” – ttyUSB means “USB serial port adapter”
  • The “1” (“0” or “1” or “2”“here means the USB device number on your system. The FPGA board is connected to that USB device number.

Terminal 2: After that, Connect to the FPGA board by using the OpenOCD provided by shakti-tools and its respective configuration file.  (Read how OpenOCD and RISC-V GDB work together to establish a connection between our PC and the Microprocessor)

For instance, if we use parashu,

$ cd shakti-sdk
$ cd ./bsp/third_party/parashu
$ sudo $(which openocd) -f ftdi.cfg

For pinaka and vajra, Goto cd ./bsp/third_party/<pinaka or vajra>


Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e riscv32-unknown-elf-gdb or riscv64-unknown-elf-gdb respectively from shakti-tools. Load up the .shakti file by following the below steps,

$ riscv64-unknown-elf-gdb
(gdb) set remotetimeout unlimited
(gdb) target remote localhost:3333
(gdb) file path/to/executable
(gdb) load
(gdb) c

4.1.3 Upload to flash

Steps to generate standalone user application:

The SHAKTI-SDK has a uploader tool that is used to load a content (such as ELF) to flash, after building the image.

  • Goto the right directory.
    cd shakti-sdk
  • The make upload command is used to build and upload the application to the flash automatically.
make upload PROGRAM=counter TARGET=parashu

PROGRAM is the new bare metal user application that is created. Type make list_applns to list all the applications available in the SDK.

Step 4.2: Using Platform IO

We can use IDE’s like Platform IO to compile, build, run, upload and debug. Please read the article on Platform IO on SHAKTI to understand the steps.


Miniterm Output:

--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---                  ((                                          
                                    ,(((((
                                *((((((
                           ./(((((((
                       ./((((((((
                    *(((((((((
                .(((((((((((
             ,((((((((((((
           ((((((((((((((
          .((((((((((((((
              *(((((((((((
                   /(((((((
                  *((((((((
                     *(((((((
                       (((((((((
                        ((((((((((
                         (((((((((((((
                         ((((((((((((((
                        ((((((((((((
                      *((((((((((
                    (((((((((               
              *(((((((
           *((((((
       .(((((
   ./(((  
SHAKTI PROCESSORS 
Booting… vspi1.0
Booting on Parashu! hart 0 
Parashu is a SoC build on top of Artix7 100T.
The core belongs to Shakti E class, 32 bit.
Supported ISA: RV32ACIMNU.
Processor Arch ID: 0.
Device ID 1 
extracted device id 2018 
. . . . . . .
Control transferred to RAM
mip value = 8
mtimecmp value = 104615234
mtime value = 54617602
mtimecmp value = 129847298
mtime value = 79848342
mtimecmp value = 155078037
mtime value = 105079081
mtimecmp value = 180308878
mtime value = 130309922
mtimecmp value = 205539720
mtime value = 155540764
mtimecmp value = 230770561
mtime value = 180771605

Miniterm Output (Upload)

Erasing…
Erase complete.
Writing......
Write complete.
Please reset.
  • Now press Reset Button on board
                                        ((                                          
                                    ,(((((
                                *((((((
                           ./(((((((
                       ./((((((((
                    *(((((((((
                .(((((((((((
             ,((((((((((((
           ((((((((((((((
          .((((((((((((((
              *(((((((((((
                   /(((((((
                  *((((((((
                     *(((((((
                       (((((((((
                        ((((((((((
                         (((((((((((((
                         ((((((((((((((
                        ((((((((((((
                      *((((((((((
                    (((((((((               
              *(((((((
           *((((((
       .(((((
   ./(((  
SHAKTI PROCESSORS 
Booting… vspi1.0
Booting on Parashu! hart 0 
Parashu is a SoC build on top of Artix7 100T.
The core belongs to Shakti E class, 32 bit.
Supported ISA: RV32ACIMNU.
Processor Arch ID: 0.
Device ID 1 
extracted device id 2018 
. . . . . . .
Control transferred to RAM
mip value = 8
mtimecmp value = 104615234
mtime value = 54617602
mtimecmp value = 129847298
mtime value = 79848342
mtimecmp value = 155078037
mtime value = 105079081
mtimecmp value = 180308878
mtime value = 130309922
mtimecmp value = 205539720
mtime value = 155540764
mtimecmp value = 230770561
mtime value = 180771605
mtimecmp value = 256001403
mtime value = 206002446

Leave a Reply