passing xc pointer to c function Topic is solved

If you have a simple question and just want an answer.
shaileshwankhede
Experienced Member
Posts: 65
Joined: Fri Dec 02, 2016 1:30 pm

passing xc pointer to c function

Postby shaileshwankhede » Wed Feb 01, 2017 3:46 pm

Hi,
I am trying to use some memory between two parallel tasks and I am ensuring that same memory regions are never used at same time in these two threads.
But xc compiler throws parallel usage rules error. After going through some post, I decided to add c functionality to write to and read from memory regions.
To do this I am trying to pass unsafe pointer from xc file to C function, but then I get function mismatch error because of xC pointer and C pointer.
How to fix this?

Below is my simple code base:
In xc file:

Code: Select all

unsafe void bufferData(mic_array_frame_time_domain * unsafe audio)
{
   static uint16_t wrIdx = 0;
   fillMicData((mic_array_frame_time_domain*)audio, wrIdx);   //ERROR here!!!
   if(wrIdx < BUFFER_SIZE-1)
        wrIdx++;
    else {
        wrIdx = 0;
   }
}
in .h file

Code: Select all

void fillMicData(mic_array_frame_time_domain* audio, uint16_t wrIdx);


Thanks,
Shailesh
View Solution
peter
XCore Addict
Posts: 217
Joined: Wed Mar 10, 2010 12:46 pm

Postby peter » Fri Feb 03, 2017 12:31 pm

Pointers in C are always unsafe pointer equivalents. You need to ensure that when you include a C-header from an XC file that the function prototypes will be correctly interpreted. The easiest way is to use the extern "C" in your header so that XC knows the function is a C function:

Code: Select all

#ifdef __XC__
extern "C" {
#endif

// Your C-function declarations
void fillMicData(mic_array_frame_time_domain* audio, uint16_t wrIdx);

#ifdef __XC__
} // extern "C"
#endif

shaileshwankhede
Experienced Member
Posts: 65
Joined: Fri Dec 02, 2016 1:30 pm

Postby shaileshwankhede » Fri Feb 03, 2017 2:24 pm

Thanks Peter,

Its working like a charm!

(Is option to mark thread as solved removed in new UI? I can't see that.)

Regards,
Shailesh
peter
XCore Addict
Posts: 217
Joined: Wed Mar 10, 2010 12:46 pm

Postby peter » Fri Feb 03, 2017 2:40 pm

Glad that helped. I think you can press the green tick (top right of my answer).

Peter
shaileshwankhede
Experienced Member
Posts: 65
Joined: Fri Dec 02, 2016 1:30 pm

Postby shaileshwankhede » Fri Feb 03, 2017 2:48 pm

There is no green tick in new UI.
You can check the screenshot.

Thanks,
Shailesh
Attachments
forum.png
(46.28 KiB) Not downloaded yet
forum.png
(46.28 KiB) Not downloaded yet
User avatar
migueljds
Active Member
Posts: 50
Joined: Thu Dec 10, 2009 7:08 pm
Contact:

Postby migueljds » Fri Feb 03, 2017 4:14 pm

Hi there, Sorry, about that.
I found the issue. It was a configuration setting that wasn't correctly set. Before only moderators could mark a topic as answered.
I've updated the settings so both moderators and the topic author can mark a particular topic as answered.
Thanks,
Miguel

Return to “Q&A”

Who is online

Users browsing this forum: No registered users and 3 guests