Examples of XC<->C argument passing?

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

Examples of XC<->C argument passing?

Post by landon »

Where can I find out more information on how to pass various XC constructs to my C functions and use them there? By XC constructs I mean things like channels and ports.

For example, I'd like a C function running in one thread to be able to insert data into a channel to a UART implemented in XC which takes a channel for input. Specifically, the C function will do some floating point computations, convert the results to a string and output them over a UART - there may be multiple threads doing this. In the example below, compute_some_numbers() is a C function and test_uart() is an XC function.

Code: Select all

int compute_task(chanend uart1)
{
	while (1)
	{
		compute_some_numbers(uart1);
	}
}

int main_core0()
{ 
  chan uart1;

  test_flash();
  p_leds_3_0 <: 1;
  
  par
  {
	test_uart(UART_19200, uart1);
	compute_task(uart1); 
  }
  
  return 0;
}
Of course over in C-land, compute_some_numbers() gets a compile error when a 'chanend' type is used as a parameter.

Also, once in C-land, assuming I could pass the channel to a C function, how can it be used for input or output? I'm hoping someone could point me to some examples of XC<->C channel communication or should these constructs never mix? I could see implementing this so the C function is called and a string or array returned, then output in XC, but that seems more indirect that it could be if the C function writes into the channel itself.

A related question is: where can I find out how to manipulate an XC port from a C function? How do/can things like timers and @time functionality work within a C function? or do they?

Still learning. Thanks,

Landon


User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Post by paul »

http://xcore.com/wiki/index.php/Using_c ... _C/C%2B%2B

Anything that uses XC features i.e. channels, ports, port time stamping etc will need custom functions written in XC that can be called from C (similar to the channel example in the above link)

This entry talks about using functions that utilise pointers in C: http://xcore.com/wiki/index.php/Calling ... _arguments
Paul

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Thanks, Paul, for the good pointers. I will read up....I can see I need to immerse myself in the wiki - I was mostly going off the PDF docs up until now.

Thanks again,

Landon