Using QuRT API’s in Standalone Hexagon Programs

Using QuRT API’s in Standalone Hexagon Programs

Modify Local Toolchain:

Locate the QuRT headers and libraries in your installed SDK.

RubikPI is a V68 Hexagon so they are here:

$HEXAGON_SDK_ROOT/rtos/qurt/computev68

  • Copy all the headers from this directory to the location on the target where the hexagon toolchian’s headers are stored. By default this is $HOME/Qualcomm/HEXAGON_Tools/19.0.06/Tools/target/hexagon/include

scp $HEXAGON_SDK_ROOT/rtos/qurt/computev68/include/qurt/* ubuntu@rubikpi:Qualcomm/HEXAGON_Tools/19.0.06/Tools/target/hexagon/include

  • Copy the QuRT libraries

scp $HEXAGON_SDK_ROOT/rtos/qurt/computev68/lib/pic/* ubuntu@rubikpi:Qualcomm/HEXAGON_Tools/19.0.06/Tools/target/hexagon/lib/v68/G0/pic


The QuRT API’s should be available.

  • Add #include <qurt.h> to access the API’s

  • Add -lqurt to bind with the qurt libraries.

Trivial example:

#include <stdio.h>
#include <stdlib.h>
#include <qurt.h>

int main() {
    FILE *fd = fopen("output.txt", "w");
    if (fd == NULL) {
        return EXIT_FAILURE;
    }
    qurt_arch_version_t vers;
    int rc =  qurt_sysenv_get_arch_version (&vers);
    if (!rc) {
	    fprintf(fd, "Architecture Version = 0x%x\n", vers.arch_version);
    }
/*
 * sleep for 1 second, or 1000000 microseconds
 */   
    unsigned long long int A = qurt_sysclock_get_hw_ticks();
    qurt_timer_sleep(
    unsigned long long int B = qurt_sysclock_get_hw_ticks();
    fprintf(fd, "Approximate hw ticks/sec = %lld\n", B - A);

    fprintf(fd, "Done\n");
    fclose(fd);

    return EXIT_SUCCESS;
}

Makefile:

CC=$(HOME)/Qualcomm/HEXAGON_Tools/19.0.06/Tools/bin/hexagon-clang

qurt.so: qurt.c
	$(CC) -shared -fpic -mv68 qurt.c -o $@ -lqurt

run: qurt.so
	./run_main_on_hexagon 3 qurt.so stack_size=0x50000
	cat output.txt

clean:
	rm qurt.so

Sample Output:


make run

./run_main_on_hexagon 3 qurt.so stack_size=0x50000

Attempting to run on unsigned PD on domain 3

RPC to Hexagon DSP with args: "qurt.so stack_size=0x50000 "

Successfully called main() on Hexagon DSP and received return value of 0.

cat output.txt

Architecture Version = 0x8a68

Approximate hw ticks/sec = 19200575

Done


The above example assums that you have run_main_on_hexagon and librun_main_on_hexagon_skel.so in the same directory. These are copied from the SDK and discussed here: Hexagon compilation and debug

The rest of the QuRT API’s are documented in the SDK’s docs/pdf/80-VB419-178_D_Qualcomm_Hexagon_QuRT_RTOS_User_Guide_SDK.pdf