spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
sark_io.c File Reference

Simple character I/O library for Spinnaker. More...

#include <sark.h>
#include <stdarg.h>

Data Structures

struct  iobuf_t
 

Functions

static sdp_msg_tio_std_init (void)
 Initialises the IO_STD implementation.
 
static iobuf_tio_buf_init (void)
 Initialises a memory chunk for the IO_BUF implementation.
 
void sark_io_buf_reset (void)
 Routine to reset the IOBUF for the core.
 
void io_put_char (char *stream, uint c)
 Routine to put a character to an output stream.
 
void io_printf (char *stream, char *f,...)
 A simple "printf" routine.
 
Format implementations

Routines to deal with the various printf formats. All end up calling io_put_char() to do the write of individual characters.

static void io_put_str (char *stream, char *s, int d)
 Put a string possibly left-padding with spaces.
 
static void io_put_int (char *stream, int n, uint d, uint pad)
 Put an integer (signed) in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!.
 
static void io_put_uint (char *stream, uint n, uint d, uint pad)
 Put an integer (unsigned) in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!.
 
static void io_put_zhex (char *stream, uint n, uint d)
 Put a hex number in exactly the number of characters specified. Truncates high digits if need be.
 
static void io_put_hex (char *stream, uint n, uint d, uint pad)
 Put an integer in hex in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!
 
static void io_put_fixed (char *stream, uint n, uint d, uint a, uint pad, int neg)
 Format for 16.16 fixed point.
 
static void io_put_sfixed (char *stream, int n, uint d, uint a, uint pad)
 Format for s16.15 fixed point.
 
static void io_put_ufixed (char *stream, uint n, uint d, uint a, uint pad)
 Format for u16.16 fixed point.
 

Variables

static uint sp_ptr
 Buffer pointer for 'sprintf'.
 
static uint buf_ptr
 Buffer pointer for IO_BUF.
 
static sdp_msg_tio_msg
 Points to SDP buffer.
 
static iobuf_tio_buf
 Points to SDRAM buffer.
 
static const char hex [] = "0123456789abcdef"
 Hexadecimal characters.
 

Detailed Description

Simple character I/O library for Spinnaker.

Author
Steve Temple, APT Group, School of Computer Science. Fixed point formats by Paul Richmond (Univ. of Sheffield) and Dave Lester (APT Group)

Data Structure Documentation

◆ iobuf_t

struct iobuf_t

Struct containing information about each iobuf entry in the linked list of iobuf entries.

Data Fields
struct iobuf * next
uint unix_time
uint time_ms
uint ptr
uchar buf[]

Function Documentation

◆ io_std_init()

static sdp_msg_t * io_std_init ( void  )
static

Initialises the IO_STD implementation.

Returns
a pointer to the message buffer to use to send to host

◆ io_buf_init()

static iobuf_t * io_buf_init ( void  )
static

Initialises a memory chunk for the IO_BUF implementation.

Returns
a pointer to the chunk

◆ sark_io_buf_reset()

void sark_io_buf_reset ( void  )

Routine to reset the IOBUF for the core.

Frees additional allocated IOBUF blocks in the system heap.

◆ io_put_char()

void io_put_char ( char *  stream,
uint  c 
)

Routine to put a character to an output stream.

Has different behaviour for four possible streams:

  • IO_STD: Streamed out to a tubotron instance via SDP.
  • IO_BUF: Stored in a buffer in memory for later retrieval by host
  • IO_NULL: Ignores the write
  • "sprintf" strings: writes into the provided buffer.

For IO_STD and IO_BUF the character is placed in a holding buffer which is flushed on buffer-full or newline or NULL.

Parameters
streamconstant (IO_BUF, IO_STD, IO_NULL) or pointer to char array
ca character

◆ io_put_str()

static void io_put_str ( char *  stream,
char *  s,
int  d 
)
static

Put a string possibly left-padding with spaces.

Parameters
[in]streamWhere to write to
[in]sThe string to write
[in]dThe number of characters to write
Note
Always pads with spaces (where any padding is required)

◆ io_put_int()

static void io_put_int ( char *  stream,
int  n,
uint  d,
uint  pad 
)
static

Put an integer (signed) in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!.

Parameters
[in]streamWhere to write to
[in]nThe word to write
[in]dThe number of digits to write
[in]padThe padding character to use

◆ io_put_uint()

static void io_put_uint ( char *  stream,
uint  n,
uint  d,
uint  pad 
)
static

Put an integer (unsigned) in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!.

Parameters
[in]streamWhere to write to
[in]nThe word to write
[in]dThe number of digits to write
[in]padThe padding character to use

◆ io_put_zhex()

static void io_put_zhex ( char *  stream,
uint  n,
uint  d 
)
static

Put a hex number in exactly the number of characters specified. Truncates high digits if need be.

Parameters
[in]streamWhere to write to
[in]nThe word to write
[in]dThe number of digits to write

◆ io_put_hex()

static void io_put_hex ( char *  stream,
uint  n,
uint  d,
uint  pad 
)
static

Put an integer in hex in given field width, left-padding with spaces. Entire field is assumed to fit in 16 chars!

Parameters
[in]streamWhere to write to
[in]nThe word to write
[in]dThe number of digits to write
[in]padThe padding character to use

◆ io_put_fixed()

static void io_put_fixed ( char *  stream,
uint  n,
uint  d,
uint  a,
uint  pad,
int  neg 
)
static

Format for 16.16 fixed point.

Author
Paul Richmond
Dave Lester
Parameters
[in]streamWhere to write to
[in]nunsigned accum, as unsigned integer
[in]dField width
[in]aPrecision
[in]padPadding character
[in]negTrue if a minus sign needs to be written

◆ io_put_sfixed()

static void io_put_sfixed ( char *  stream,
int  n,
uint  d,
uint  a,
uint  pad 
)
static

Format for s16.15 fixed point.

Delegates to io_put_fixed()

Parameters
[in]streamWhere to write to
[in]nsigned accum, as signed integer
[in]dField width
[in]aPrecision
[in]padPadding character

◆ io_put_ufixed()

static void io_put_ufixed ( char *  stream,
uint  n,
uint  d,
uint  a,
uint  pad 
)
static

Format for u16.16 fixed point.

Delegates to io_put_fixed()

Parameters
[in]streamWhere to write to
[in]nunsigned accum, as unsigned integer
[in]dField width
[in]aPrecision
[in]padPadding character

◆ io_printf()

void io_printf ( char *  stream,
char *  format,
  ... 
)

A simple "printf" routine.

The first argument is a 'stream' which is either a constant (IO_BUF, IO_STD, IO_DBG, IO_NULL) or a pointer to a character array which will be filled in as in "sprintf". No checks for buffer overflow are made for this latter case! The range of formats is very limited to minimise code size. The maximum width for integer fields is 16.The maximum width for the 16.16 fixed point format is 25. Don't exceed these maxima!

The four constants provide 4 possible output streams for the output string. IO_STD will send the string as an SDP packet back to the host. IO_BUF will place the string in a buffer in SDRAM while IO_NULL will ignore the string. IO_DBG is not currently implemented.

Formats are:

  • %c - character
  • %s - string - can be eg %8s for right justification
  • %d - signed integer (also %8d, %06d, etc)
  • %u - signed integer (also %4u, %06u, etc)
  • %x - integer in hex (also %4x, %08x, etc)
  • %z - integer in hex, exactly N digits
  • %n.mf - 16.16 fixed point with width n, precision m
Parameters
streamconstant (IO_BUF, IO_STD, IO_DBG, IO_NULL) or pointer to char array
formata format string
...arguments to be formatted