wiki:library_stdio

Version 4 (modified by alain, 10 years ago) (diff)

--

The stdio Library

The stdio.c and stdio.h files contains all system calls provided to user applications by the GIET-VM. They are generally prefixed by giet_.

1) Access to processor protected register

  • int giet_procid()

This function returns the global processor identifier gpid, depending on (X,Y,L) where X,Y are the cluster coordinates, and L is the local processor index. The format is gpid = X<<Y_WIDTH + Y) * NB_PROCS_MAX) + L

  • int giet_proctime()

This function returns the local processor time (number of cycles from reset.

  • int giet_rand()

This function returns a pseudo-random value derived from both the processor cycle count and the processor index. This value is comprised between 0 & 65535.

2) Informations stored in the running task context

  • int giet_proc_task_id();

This functions returns the local task index, identifying the task amongst all task running on the same processor.

  • int giet_global_task_id()

This functions returns the global task id, unique in the system.

  • int giet_thread_id()

This functions returns the thread index, identiying the task in a given vspace.

3) Access to TTY terminal

  • void giet_tty_printf( char* format, ... )

This function print formated text on a private terminal that must have been allocated to the calling task in the mapping (use_tty argument). Therefore, it does not take the TTY lock. In case or error, it makes a giet_exit().

Only a limited number of formats are supported:

  • %d : signed decimal
  • %u : unsigned decimal
  • %x : 32 bits hexadecimal
  • %l : 64 bits hexadecimal
  • %c : char
  • %s : string
  • void giet_shr_printf( char* format, ... )

This function print formated text on the shared terminal arbitrarily allocated by the kernel, taking the TTY lock for exclusive access. It supports the same formats as the giet_tty_printf() function. In case or error, it makes a giet_exit().

  • void giet_tty_getc( char* byte )

This blocking function fetches a single character from the private terminal that must have been allocated to the calling task in the application mapping. It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer. In case or error, it makes a giet_exit().

  • void giet_tty_getw( unsigned int* val )

This blocking function fetches a string of decimal characters (most significant digit first) to build a 32-bits unsigned integer from the private TTY terminal that must have been allocated to the calling task in the application mapping. It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer. The non-blocking system function _tty_read is called several times, and the decimal characters are written in a 32 characters buffer until a <LF> character is read. It ignores non-decimal characters, and displays an echo system function) for each decimal character. The <DEL> character is interpreted, and previous characters can be cancelled. When the <LF> character is received, the string is converted to an unsigned int value. If the number of decimal digit is too large for the 32 bits range, the zero value is returned. In case or error, it makes a giet_exit().

  • giet_tty_gets( char* buf, unsigned int bufsize )

This blocking function fetches a string from the private terminal that must have been allocated to the calling task in the application mapping. It writes the string to a fixed length buffer. It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer. Up to (bufsize - 1) characters (including the non printable characters) are copied into buffer, and the string is completed by a NUL character. The <LF> character is interpreted, and the function close the string with a NUL character if <LF> is read. The <DEL> character is interpreted, and the corresponding character(s) are removed from the target buffer. It does not provide an echo. In case or error, it makes a giet_exit().