NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_semihosting.h File Reference

RISC-V semihosting header file. More...

#include <stdint.h>

Go to the source code of this file.

Enumerations

Host service request IDs
enum  NEORV32_SEMIHOSTING_SYS_enum {
  SEMIHOSTING_SYS_OPEN = 0x01 , SEMIHOSTING_SYS_CLOSE = 0x02 , SEMIHOSTING_SYS_WRITEC = 0x03 , SEMIHOSTING_SYS_WRITE0 = 0x04 ,
  SEMIHOSTING_SYS_WRITE = 0x05 , SEMIHOSTING_SYS_READ = 0x06 , SEMIHOSTING_SYS_READC = 0x07 , SEMIHOSTING_SYS_ISTTY = 0x09 ,
  SEMIHOSTING_SYS_SEEK = 0x0A , SEMIHOSTING_SYS_FLEN = 0x0C , SEMIHOSTING_SYS_TMPNAME = 0x0D , SEMIHOSTING_SYS_REMOVE = 0x0E ,
  SEMIHOSTING_SYS_RENAME = 0x0F , SEMIHOSTING_SYS_CLOCK = 0x10 , SEMIHOSTING_SYS_TIME = 0x11 , SEMIHOSTING_SYS_SYSTEM = 0x12 ,
  SEMIHOSTING_SYS_ERRNO = 0x13 , SEMIHOSTING_SYS_GET_CMDLINE = 0x15 , SEMIHOSTING_SYS_HEAPINFO = 0x16 , SEMIHOSTING_SYS_EXCEPTION = 0x18 ,
  SEMIHOSTING_SYS_ELLAPSED = 0x30 , SEMIHOSTING_SYS_TICKFREQ = 0x31
}
 

Functions

int neorv32_semihosting_req (int id, void *arg)
 
Prototypes
void neorv32_semihosting_putc (char c)
 
void neorv32_semihosting_puts (const char *pnt)
 
char neorv32_semihosting_getc (void)
 
int neorv32_semihosting_open (char *path, int mode)
 
int neorv32_semihosting_close (int file)
 
int neorv32_semihosting_write (int file, char *buffer, int len)
 
int neorv32_semihosting_read (int file, char *buffer, int len)
 
int neorv32_semihosting_istty (int file)
 
int neorv32_semihosting_seek (int file, int pos)
 
int neorv32_semihosting_flen (int file)
 
int neorv32_semihosting_time (void)
 
int neorv32_semihosting_system (char *cmd)
 

Detailed Description

RISC-V semihosting header file.

Enumeration Type Documentation

◆ NEORV32_SEMIHOSTING_SYS_enum

Enumerator
SEMIHOSTING_SYS_OPEN 

open a file

SEMIHOSTING_SYS_CLOSE 

close a file

SEMIHOSTING_SYS_WRITEC 

write a character byte, pointed

SEMIHOSTING_SYS_WRITE0 

writes a null terminated string

SEMIHOSTING_SYS_WRITE 

write data to a file

SEMIHOSTING_SYS_READ 

read data from a file

SEMIHOSTING_SYS_READC 

read a character from stdin

SEMIHOSTING_SYS_ISTTY 

check if it is a TTY

SEMIHOSTING_SYS_SEEK 

move current file position

SEMIHOSTING_SYS_FLEN 

tell the file length

SEMIHOSTING_SYS_TMPNAME 

get a temporary file handle

SEMIHOSTING_SYS_REMOVE 

remove a file

SEMIHOSTING_SYS_RENAME 

rename a file

SEMIHOSTING_SYS_CLOCK 

returns the number of centi-seconds since execution started

SEMIHOSTING_SYS_TIME 

time in seconds since Jan 1st 1970

SEMIHOSTING_SYS_SYSTEM 

passes a command to the host command-line interpreter

SEMIHOSTING_SYS_ERRNO 

get the current error number

SEMIHOSTING_SYS_GET_CMDLINE 

returns the command line used for the call to the executable

SEMIHOSTING_SYS_HEAPINFO 

returns the system stack and heap parameters

SEMIHOSTING_SYS_EXCEPTION 

exit application

SEMIHOSTING_SYS_ELLAPSED 

returns the number of elapsed target ticks since execution started

SEMIHOSTING_SYS_TICKFREQ 

returns the tick frequency

Function Documentation

◆ neorv32_semihosting_close()

int neorv32_semihosting_close ( int file)

Close file on host system.

Parameters
[in]fileFile handle.
Returns
0 if the call is successful, -1 if the call is not successful.

◆ neorv32_semihosting_flen()

int neorv32_semihosting_flen ( int file)

Returns the length of a specified file.

Parameters
[in]fileFile handle.
Returns
The current length of the file object, -1 if call fails.

◆ neorv32_semihosting_getc()

char neorv32_semihosting_getc ( void )

Read single character from host's STDIN.

Warning
This function is blocking.
Returns
Received character.

◆ neorv32_semihosting_istty()

int neorv32_semihosting_istty ( int file)

Checks if a host file is connected to an interactive device.

Parameters
[in]fileFile handle.
Returns
1 if the handle identifies an interactive device, 0 if the handle identifies a file, a value other than 1 or 0 if an error occurs.

◆ neorv32_semihosting_open()

int neorv32_semihosting_open ( char * path,
int mode )

Open file on host system.

Parameters
[in]pathPath/file name (zero-terminated string).
[in]modeFile access mode (ISO C).
Returns
File handle.

◆ neorv32_semihosting_putc()

void neorv32_semihosting_putc ( char c)

Print single character to host's STDOUT.

Parameters
[in]cCharacter to print.

◆ neorv32_semihosting_puts()

void neorv32_semihosting_puts ( const char * pnt)

Print zero-terminated string to host's STDOUT.

Parameters
[in]pntPointer to zero-terminated string.

◆ neorv32_semihosting_read()

int neorv32_semihosting_read ( int file,
char * buffer,
int len )

Read data buffer from host's file handle.

Parameters
[in]fileFile handle (stream; should be 0 = STDIN).
[in]bufferPointer to data buffer.
[in]lenLength of data to read.
Returns
Number of characters NOT read.

◆ neorv32_semihosting_req()

int neorv32_semihosting_req ( int id,
void * arg )
inline

Send a semihosting request to the host.

Parameters
[in]idService request ID (NEORV32_SEMIHOSTING_SYS_enum).
[in]argArgument / pointer to data array.
Returns
Host return value.

◆ neorv32_semihosting_seek()

int neorv32_semihosting_seek ( int file,
int pos )

Seeks to a specified position in a file.

Parameters
[in]fileFile handle.
[in]posOffset specified from the start of the file
Returns
0 if the request is successful.

◆ neorv32_semihosting_system()

int neorv32_semihosting_system ( char * cmd)

Execute command in host's console.

Warning
Be careful!
Parameters
[in]cmdPointer to zero-terminated command string.
Returns
Host command's exit status.

◆ neorv32_semihosting_time()

int neorv32_semihosting_time ( void )

Get host's current system time.

Returns
Unix timestamp (time in seconds since Jan 1st 1970)

◆ neorv32_semihosting_write()

int neorv32_semihosting_write ( int file,
char * buffer,
int len )

Write data buffer to host's file handle.

Parameters
[in]fileFile handle (stream; should be 1 = STDOUT).
[in]bufferPointer to data buffer.
[in]lenLength of data to write.
Returns
Number of characters NOT send.