I'm trying to use the XMOS UART library from C code (i.e. .C file, not XC file). It's my first time trying to mix C and XC code.
However, I get a build warnings and an error. The warning is:
warning: implicit declaration of function 'uart_tx_streaming_write_byte' is invalid in C99 [-Wimplicit-function-declaration]
[build] uart_tx_streaming_write_byte(c_tx, 'A');
The reason for that is, that the library header file uart.h contains #ifdef __XC__ and so there's no function prototype for the C code to see. How should I be including the uart library header file?
The main error I get, I'm not really sure where I've gone wrong; I think I have used the PAR_JOBS syntax as described in the user docs, but I may be missing something : (
Code: Select all
error: variable has incomplete type 'const struct __xcore_ugs_uart_rx_streaming__xcore_args'
[build] PAR_JOBS(
[build] ^
[build] C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/parallel.h:150:23: note: expanded from macro 'PAR_JOBS'
[build] #define PAR_JOBS(...) _XCORE_JPAR_JOBS(_XCORE_UNIQUE_LABEL(_Par), __VA_ARGS__)
[build] ^
[build] C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_parallel_impl.h:436:22: note: expanded from macro '_XCORE_JPAR_JOBS'
[build] _XCORE_JPAR_JOBS_I(_XCORE_JPAR_GET_IMLP(__VA_ARGS__), \
[build] ^
[build] C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_parallel_impl.h:433:86: note: expanded from macro '_XCORE_JPAR_GET_IMLP'
[build] #define _XCORE_JPAR_GET_IMLP(...) _XCORE_IF_EMPTY_LIST_ELSE(_XCORE_JPAR_JOBS_SINGLE, _XCORE_JPAR_JOBS_PAR, __VA_ARGS__)
Many thanks.
Code: Select all
// includes
#include <platform.h>
#include <xcore/port.h>
#include <syscall.h>
#include <print.h>
#include <xccompat.h>
#include <uart.h>
#include <xcore/parallel.h>
// defines
#define TICKS_PER_BIT 20
// global variables
port_t led_port = XS1_PORT_4C;
port_t p_uart_rx = XS1_PORT_1A;
port_t p_uart_tx = XS1_PORT_1B;
// functions
void app(streaming_chanend_t c_tx, streaming_chanend_t c_rx) {
int led_state = 0;
while(1) {
port_out(led_port, led_state);
led_state = !led_state;
uart_tx_streaming_write_byte(c_tx, 'A');
delay_milliseconds(1000);
}
}
//main function
int main() {
int led_state = 0;
port_timestamp_t tstamp;
streaming_chanend_t c_tx; // = s_chan_alloc();
streaming_chanend_t c_rx; // = s_chan_alloc();
//streaming chan c_tx = s_chan_alloc();
//streaming chan c_rx = s_chan_alloc();
printstr("UART Example is Running\n");
// enable resources before any other operations on them
port_enable(led_port);
PAR_JOBS(
PJOB(uart_tx_streaming, (p_uart_tx, c_tx, TICKS_PER_BIT)),
PJOB(uart_rx_streaming, (p_uart_rx, c_rx, TICKS_PER_BIT)),
PJOB(app, (c_tx, c_rx)));
return(0);
}