This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F1611: Using .cpp header for .c file.

Part Number: MSP430F1611


Tool/software: TI C/C++ Compiler

Dear all, 

my msp430f1611, I am trying to compile a C code that uses a header of .cpp.

When I try to compile it using sconscript, I get an error saying that unknow type name 'class', I have google this issue and yet, still haven't really figured out how to go about with this.

I attached codes on here, any help will be greatly appreciated.

Thank you

Kind regards

Yong Kim

IpMtWrapper.cpp

IpMtWrapper.h

#include "board.h"
#include "IpMtWrapper.h"
#include "dn_ipmt.h"

struct IpMtWrapper       *ipmtwrapper;

//========================== "variables" ===================================


//===================== "functions declarations" ==============================

void timeIndication_Cb(dn_ipmt_timeIndication_nt* timeIndication);
void init_board(void);


//=========================== "main" ==========================================

int main(void) {
   
     ipmtwrapper.setup(timeIndication_Cb);

}

void loop() {


    ipmtwrapper.loop();
}

//=========================== "functions" =====================================

void timeIndication_Cb(dn_ipmt_timeIndication_nt* timeIndication) {

    uint32_t elapsed_since_trigger;
    uint32_t time_to_next_flip_reset;
    uint32_t time_to_next_time_n_trigger;
    uint32_t utcSecs;
    uint32_t now;

    //calculate_new_drift(timeIndication);
    dn_read_uint32_t(&utcSecs, &timeIndication->utcSecs[4]);

    //elapsed_since_trigger = static_cast<uint32_t> (nano_clock.ticksToNanos(static_cast<uint64_t> (nano_clock.getClockTicks() - last_trigger_timerTimestamp))/1000.);

    //time_to_next_flip_reset = (1000000 - timeIndication->utcUsecs - elapsed_since_trigger)*drift_coef;
    //pin_flipper.scheduleReset(time_to_next_flip_reset, drift_coef);

    // TODO: this line is not working well. Do something about it
    now = (utcSecs*1000*1000 + timeIndication->utcUsecs + elapsed_since_trigger)%(SYNCHRONIZATION_RATE*1000*1000);

    uint32_t OFFSET = 0;

    time_to_next_time_n_trigger = static_cast<uint32_t> ((SYNCHRONIZATION_RATE)*1000*1000 - now)*drift_coef;
    if (SYNCHRONIZATION_RATE*1000*1000 - now < OFFSET*1000*1000) {
        time_to_next_time_n_trigger += SYNCHRONIZATION_RATE*1000*1000;
    }

    reschedule_timer_n_timer(time_to_next_time_n_trigger);
}


//brief This function is called when the TimerA interrupt fires.
#pragma vector = TIMERA0_VECTOR
__interrupt void TIMERA0_ISR (void) {
    P2OUT ^= 0x08;                      // toggle P2.3 - trig
    __delay_cycles(250);
    P2OUT ^= 0x08;
    last_trigger_timerTimestamp = nano_clock.getClockTicks();
}

/*
void setup_time_n_timer() {
    SimpleTimer::setCallback(4, time_n_trigger_handler);
    SimpleTimer::configure(4, 2, 5*42*1000*1000);
    SimpleTimer::start(4);
}

void reschedule_timer_n_timer(uint new_periode_us) {
    SimpleTimer::configure(4, 2, new_periode_us*42);
    SimpleTimer::start(4);
}

void calculate_new_drift(dn_ipmt_timeIndication_nt* timeIndication) {
    static uint32_t last_sync;
    uint32_t utcSecs;
    double new_drift;

    dn_read_uint32_t(&utcSecs, &timeIndication->utcSecs[4]);

    // calculate deltas;
    local_delta = nano_clock.ticksToNanos(static_cast<uint64_t> (last_trigger_timerTimestamp - last_sync))/1000.;
    source_delta = static_cast<double> ((utcSecs - last_source_secs)*1000*1000 + timeIndication->utcUsecs - last_source_usecs);

    if (last_source_secs != 0 && last_source_usecs != 0) {
        drifter.addSyncData(local_delta, source_delta);
        new_drift = drifter.processSyncData();
        if (new_drift != 0) {
            Serial.print("New drift: ");
            Serial.println((new_drift-1)*1000000);
            drift_coef = new_drift;
        }
    }

    Serial.print("delta utcSecs: ");
    Serial.println(utcSecs-last_source_secs);
    Serial.print("delta utcSecs: ");
    Serial.print(timeIndication->utcUsecs-last_source_usecs);
    Serial.print("   ");
    Serial.println(last_source_usecs - timeIndication->utcUsecs);

    last_sync = last_trigger_timerTimestamp;
    last_source_secs = utcSecs;
    last_source_usecs = timeIndication->utcUsecs;
} */

  • The compiler uses the file name extension to know whether a source file contains C code, or C++ code.  Usually, .c means C code, and .cpp means C++ code.  The file extension, or the contents, of any #include file does not change this behavior.  In your case, you are building a .c file, so the compiler presumes it contains C code.  This .c file later #include's a .h file that has C++ code in it.  

    For further detail, see the section titled Specifying Filenames in the MSP430 compiler manual.

    Thanks and regards,

    -George