Port Direction qualifier - When and why?

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Port Direction qualifier - When and why?

Post by landon »

I've seen various example code where the port is declared but has no direction qualifier on it.

As an example of what I'm talking about, the module_uart.1v1 and app_uart_example code has:

Code: Select all

on stdcore[0]: port p_rx = PORT_UART_RX;
on stdcore[0]: port p_tx = PORT_UART_TX;
There's no direction qualifier and the functions the port is passed to have no direction qualifier on them either. If you do put a direction qualifier on the port declaration, the functions then require it as well as it's considered a different parameter type.

Is this just to allow the programmer to do some basic in/out enforcement at the compiler level?

What would XMOS device do if passed an input port to a method expecting an output port - such as in the UART case where there's no direction qualifier?

Landon


User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

If you tried to pass another type, the program wouldn't compile. If there is no direction, the port is bi-directional, capable of both input and output.

This could be used, for example, to make sure an input port cannot give out a voltage signal, possibly burning out external hardware.