It is currently 20 Apr 2018 04:03

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: 14 Feb 2018 14:45 
Offline

Joined: 01 Mar 2016 15:39
Posts: 33
I'm writing a library (effectively a serial driver) for the RN2903 Lora module which is mostly comprised of string manipulation functions either a)prepping data to be sent out a UART port to the RN2903, or b)parsing data coming back in.

Depending on the circuit and uC architecture, the RN2903 could be on UART1, UART2, etc. Thus, I can't hard-code the UART calling functions in the library.

My solution is to write registration functions such as below:

//************************************
//Library code
//************************************
//Function pointer holder
char (*fn_data_ready)();

//Registration function
void register_data_ready_fn(char (*fn)()) {
   fn_data_ready = fn;
}

//Function internally called by the library
char run_data_ready_function() {
    return (*fn_data_ready)();
}

.....

char RN2903_get_some_data() {

    //Is there data?
    while (run_data_ready_function()) {
        //Do some stuff
    }
}

.........

//************************************
//main code
//************************************
main() {

    //Register the UART2 (for example) data ready function
    register_data_ready_fn( &UART2_Data_Ready);

    ......
}



But there appears to be a problem: because (in this example) UART2_Data_Ready is never called directly, the optimizer excludes it from being compiled. How do I fix this?

Also, does anyone have a better overall solution to writing a serial driver like this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Baidu [Spider] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: