Studio Technix API
This reference document contains the definition of the Studio Technix C API functions.
A guide on how to use this API can be found in the Traffic Light Controller tutorial.
Download:
Digital input and output (GPIO)
tx_gpio_pin_get
Gets the value of a digital output with given port id port_id
and pin id pin_id
.
Definition
bool tx_gpio_pin_get(uint32_t port_id, uint32_t pin_id);
Parameters
port_id
: Identification number of the port.pin_id
: Identification number of the pin of the given port.
Returns
Value of the digital port. True
means on, False
means off.
tx_gpio_pin_set
Sets the value of a digital output with given port id port_id
and pin id pin_id
.
Definition
void tx_gpio_pin_set(uint32_t port_id, uint32_t pin_id, bool value);
Parameters
port_id
: Identification number of the port.pin_id
: Identification number of the pin of the given port.value
:True
to turn on the digital port,False
to turn off.
Analog to Digital Converter (ADC)
tx_adc_read
Reads the converted value of a single channel of the ADC with given id. Analog and digital range of the ADC is defined in the ADC definition of the Application component.
Definition
uint32_t tx_adc_read(uint32_t adc_id, uint32_t channel_id);
Parameters
adc_id
: Identification ADC pheripheral.channel_id
: Index of the channel of the given ADC pheripheral.
Returns
Digital representation of the value of the analog input.
Digital to Analog Converter (DAC)
tx_dac_write
Sets the value a single channel of the DAC with given id. Analog and digital range of the DAC is defined in the DAC definition of the Application component.
Definition
void tx_dac_write(uint32_t dac_id, uint32_t channel_id, int32_t value);
Parameters
dac_id
: Identification DAC pheripheral.channel_id
: Index of the channel of the given DAC pheripheral.value
: Digital representation of the value of the analog output.
Serial Communication (UART)
tx_uart_receive
Receives a single byte of the UART with given id.
Definition
uint8_t tx_uart_receive(uint32_t uart_id);
Parameters
uart_id
: Identification of the UART pheripheral.
Returns
A single byte of data.
tx_uart_send
Sends a single byte over the UART with given id.
Definition
void tx_uart_send(uint32_t uart_id, uint8_t data);
Parameters
uart_id
: Identification of the UART pheripheral.data
: A single byte of data.
Serial Peripheral Interface (SPI)
tx_spi_receive
Receives a single byte of the SPI with given id.
Definition
uint8_t tx_spi_receive(uint32_t spi_id);
Parameters
spi_id
: Identification of the SPI pheripheral.
Returns
A single byte of data.
tx_spi_send
Sends a single byte over the SPI with given id.
Definition
void tx_spi_send(uint32_t spi_id, uint8_t data);
Parameters
spi_id
: Identification of the SPI pheripheral.data
: A single byte of data.
Time functions
tx_time
Gets the time since device startup, in the given time unit.
Definition
uint32_t tx_time_seconds();
uint32_t tx_time_millis();
uint32_t tx_time_micros();
uint32_t tx_time_nanos();
uint32_t tx_time_quanta();
Returns
Number of seconds, milliseconds, etc since device startup.
tx_delay
Sleeps for a given period.
Definition
void tx_delay_seconds(uint32_t delay);
void tx_delay_millis(uint32_t delay);
void tx_delay_micros(uint32_t delay);
void tx_delay_nanos(uint32_t delay);
void tx_delay_quanta(uint32_t delay);
Parameters
delay
: Number of seconds, milliseconds, etc to sleep.
Other functions
tx_cycle
The tx_cycle
function must be placed in busy loops (= loops that do not contain a tx_delay
call). This function ensures that the simulation time can progress.
If this function is absent from a busy loop, the simulator will get stuck, since no opportunity is present for the simulator to simulate the effect of the application code on the external environment.
Definition
void tx_cycle();
Example
while (true)
{
tx_cycle();
if (tx_gpio_pin_get(PUSH_BUTTON_PORT, PUSH_BUTTON_PIN))
{
tx_gpio_pin_set(LIGHT_PORT, LIGHT_PIN, true)
}
else
{
tx_gpio_pin_set(LIGHT_PORT, LIGHT_PIN, false)
}
}