Serial system

void serial_null(void)

Void registration routine of a serial driver

Parameters

void

no arguments

Description

This routine implements a void registration routine of a serial driver. The registration routine of a particular driver is aliased to this empty function in case the driver is not compiled into U-Boot.

int on_baudrate(const char *name, const char *value, enum env_op op, int flags)

Update the actual baudrate when the env var changes

Parameters

const char *name

changed environment variable

const char *value

new value of the environment variable

enum env_op op

operation (create, overwrite, or delete)

int flags

attributes of environment variable change, see flags H_* in include/search.h

Description

This will check for a valid baudrate and only apply it if valid.

Return

0 on success, 1 on error

serial_initfunc

serial_initfunc (name)

Forward declare of driver registration routine

Parameters

name

Name of the real driver registration routine.

Description

This macro expands onto forward declaration of a driver registration routine, which is then used below in serial_initialize() function. The declaration is made weak and aliases to serial_null() so in case the driver is not compiled in, the function is still declared and can be used, but aliases to serial_null() and thus is optimized away.

void serial_register(struct serial_device *dev)

Register serial driver with serial driver core

Parameters

struct serial_device *dev

Pointer to the serial driver structure

Description

This function registers the serial driver supplied via dev with serial driver core, thus making U-Boot aware of it and making it available for U-Boot to use. On platforms that still require manual relocation of constant variables, relocation of the supplied structure is performed.

int serial_initialize(void)

Register all compiled-in serial port drivers

Parameters

void

no arguments

Description

This function registers all serial port drivers that are compiled into the U-Boot binary with the serial core, thus making them available to U-Boot to use. Lastly, this function assigns a default serial port to the serial core. That serial port is then used as a default output.

void serial_stdio_init(void)

Register serial ports with STDIO core

Parameters

void

no arguments

Description

This function generates a proxy driver for each serial port driver. These proxy drivers then register with the STDIO core, making the serial drivers available as STDIO devices.

int serial_assign(const char *name)

Select the serial output device by name

Parameters

const char *name

Name of the serial driver to be used as default output

Description

This function configures the serial output multiplexing by selecting which serial device will be used as default. In case the STDIO “serial” device is selected as stdin/stdout/stderr, the serial device previously configured by this function will be used for the particular operation.

Returns 0 on success, negative on error.

void serial_reinit_all(void)

Reinitialize all compiled-in serial ports

Parameters

void

no arguments

Description

This function reinitializes all serial ports that are compiled into U-Boot by calling their serial_start() functions.

struct serial_device *get_current(void)

Return pointer to currently selected serial port

Parameters

void

no arguments

Description

This function returns a pointer to currently selected serial port. The currently selected serial port is altered by serial_assign() function.

In case this function is called before relocation or before any serial port is configured, this function calls default_serial_console() to determine the serial port. Otherwise, the configured serial port is returned.

Returns pointer to the currently selected serial port on success, NULL on error.

int serial_init(void)

Initialize currently selected serial port

Parameters

void

no arguments

Description

This function initializes the currently selected serial port. This usually involves setting up the registers of that particular port, enabling clock and such. This function uses the get_current() call to determine which port is selected.

Returns 0 on success, negative on error.

void serial_setbrg(void)

Configure baud-rate of currently selected serial port

Parameters

void

no arguments

Description

This function configures the baud-rate of the currently selected serial port. The baud-rate is retrieved from global data within the serial port driver. This function uses the get_current() call to determine which port is selected.

Returns 0 on success, negative on error.

int serial_getc(void)

Read character from currently selected serial port

Parameters

void

no arguments

Description

This function retrieves a character from currently selected serial port. In case there is no character waiting on the serial port, this function will block and wait for the character to appear. This function uses the get_current() call to determine which port is selected.

Returns the character on success, negative on error.

int serial_tstc(void)

Test if data is available on currently selected serial port

Parameters

void

no arguments

Description

This function tests if one or more characters are available on currently selected serial port. This function never blocks. This function uses the get_current() call to determine which port is selected.

Returns positive if character is available, zero otherwise.

void serial_putc(const char c)

Output character via currently selected serial port

Parameters

const char c

Single character to be output from the serial port.

Description

This function outputs a character via currently selected serial port. This character is passed to the serial port driver responsible for controlling the hardware. The hardware may still be in process of transmitting another character, therefore this function may block for a short amount of time. This function uses the get_current() call to determine which port is selected.

void serial_puts(const char *s)

Output string via currently selected serial port

Parameters

const char *s

Zero-terminated string to be output from the serial port.

Description

This function outputs a zero-terminated string via currently selected serial port. This function behaves as an accelerator in case the hardware can queue multiple characters for transfer. The whole string that is to be output is available to the function implementing the hardware manipulation. Transmitting the whole string may take some time, thus this function may block for some amount of time. This function uses the get_current() call to determine which port is selected.

void default_serial_puts(const char *s)

Output string by calling serial_putc() in loop

Parameters

const char *s

Zero-terminated string to be output from the serial port.

Description

This function outputs a zero-terminated string by calling serial_putc() in a loop. Most drivers do not support queueing more than one byte for transfer, thus this function precisely implements their serial_puts().

To optimize the number of get_current() calls, this function only calls get_current() once and then directly accesses the putc() call of the struct serial_device .

int uart_post_test(int flags)

Test the currently selected serial port using POST

Parameters

int flags

POST framework flags

Description

Do a loopback test of the currently selected serial port. This function is only useful in the context of the POST testing framwork. The serial port is first configured into loopback mode and then characters are sent through it.

Returns 0 on success, value otherwise.