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.

exit.c file when call function in debug session



Hello,

I have been using Tiva C Launch Pad TM4C123G, my code  is:

#include <stdint.h>

#include <stdbool.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <math.h>

#include <invert.h>

int main (void) {

int i=0;

float p=3.141;

for(i=0;i<15;i++){

 y[i]=sin(2*p*102);

}

invert(y,16);

}

in the file.c :

#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#include <math.h>

#include <invert.h>

void invert (double x[] int m){

}

My problem is that in the debug session, at the line invert(y,16) I get an exit.c file:

#include <stdlib.h>

#include <_lock.h>

void (*__TI_cleanup_ptr)(void) = NULL;

void _DATA_ACCESS (*__TI_dtors_ptr)(int) = NULL;

/****************************************************************************/

/* */

/* LOADER_EXIT - */

/* */

/* SET C$$EXIT LABEL SO THE DEBUGGER KNOWS WHEN THE C++ PROGRAM HAS */

/* COMPLETED. THIS CAN BE REMOVED IF THE DEBUGGER IS NOT USED. */

/* */

/****************************************************************************/

static void loader_exit(void)

{

#if defined(EMBED_CIO_BP)

__asm(" .global C$$EXITE");

#if defined(__32bis__)

__asm("C$$EXITE:.word 0xDEFED0FE");

#else

__asm(" .align 4");

#if defined(__big_endian__)

__asm("C$$EXITE:.half 0xDEFE");

#else

__asm("C$$EXITE:.half 0xD0FE");

#endif /* __big_endian__ */

#endif /* __32bis__ */

#else /* !EMBED_CIO_BP */

__asm(" .global C$$EXIT");

__asm("C$$EXIT: nop");

#endif

}

/****************************************************************************/

/* EXIT() - NORMAL PROGRAM TERMINATION. */

/****************************************************************************/

extern void exit(int status)

{

/*-------------------------------------------------------------------*/

/* MUST LOCK WHEN ACCESSING GLOBALS, like __TI_dtors_ptr, */

/* __TI_cleanup_ptr */

/*-------------------------------------------------------------------*/

_lock();

/*-------------------------------------------------------------------*/

/* BOTH ATEXIT FUNCTIONS AND STATIC OBJECT DESTRUCTORS ARE */

/* REGISTERED IN A LINK LIST TO BE PROCESSED BY THE FUNCTION POINTED */

/* TO BY __TI_dtors_ptr. PROCESS THEM NOW. */

/*-------------------------------------------------------------------*/

if (__TI_dtors_ptr) (*__TI_dtors_ptr)(status);

#if defined(_C_IN_NS)

/*-------------------------------------------------------------------*/

/* _C_IN_NS IS A FLAG WE SET ONLY IN DINKUMWARE HEADERS. SO US IT TO */

/* TELL IF IT IS IN DINKUMWARE. */

/* FOR DINKUMWARE LIBRARY, CALL CLOSEALL() TO CLOSE ALL IO STREAMS. */

/* CLOSEALL() is a DINKUMWARE FUNCTION DEFINED IN FCLOSE.C TO CLOSE */

/* ALL OPENED IOSTREAMS. */

/*-------------------------------------------------------------------*/

closeall();

#else

/*-------------------------------------------------------------------*/

/* IF FILES ARE POSSIBLY OPEN, __TI_cleanup_ptr() WILL BE SETUP TO */

/* CLOSE THEM. */

/*-------------------------------------------------------------------*/

if (__TI_cleanup_ptr) (*__TI_cleanup_ptr)();

#endif

_unlock();

abort();

}

/****************************************************************************/

/* ABORT - ABNORMAL PROGRAM TERMINATION. CURRENTLY JUST HALTS EXECUTION. */

/****************************************************************************/

void abort(void)

{

loader_exit();

for (;;); /* SPINS FOREVER */

}

 I also created an hearder file, invert.h :

#ifndef __INVERT_H__
#define __INVERT_H__

extern void invert (double x [], int y );

#endif

which I saved in :C\ti\Tivaware_C_Series-2.1.0.12573\inc, and add it in Properties->ARM Compiler->Include Options.

Why this is happening? What's the reason?

Thanks in advance.

  • Hi,

    Several problems:

    a) don't use doubles - these are not supported by the hardware, and are supported by some software - see other recent discussions about this subject. Best is not to use it.

    b) unlike PC programs, here, on microcontrollers shouldn't be any exit from main,because there is not an operating system support available - the exit if any is in "landscape". Use a while(1) loop in main to avoid that.

    c) not seen - but your invert function call does correspond to the function's prototype - or at least the code posted is incomplete and i cannot see the reasons why your first parameter is just "y".

    d)  in Tiva/examples/boards/dk-tm4c123g/sine_demo/sine_demo.c file there is an example how to use the floats and sinf functions. Take care this board has a display - . Also see the initialization, init lazy stacking...

  • But once I call the function in a while(1), it's okey usa a file c or it's better to write the function at the end of the programm and declaring the function's prototype at the beginning?
    But if I want to process the data after ADC sampling, with this code:
    uint32_t x[4];
    void invert(uint32_t adc[],int m);
    int main (void) {
    uint32_t ADC0Value[1];
    .
    .
    .
    while(1)
    { ADCProcessorTrigger(ADC0_BASE, 3);
    while(!ADCIntStatus(ADC0_BASE, 3, false))
    { }

    ADCIntClear(ADC0_BASE, 3);

    ADCSequenceDataGet(ADC0_BASE,3,ADC0Value);
    x[i]=ADC0Value[0];
    i++;
    if(i==127){/* cambiarlo*/

    invert(x,128);
    }
    }
    }
    void invert (uint32_t x[],int m)
    {
    uint32_t t1;
    t1=x[0];
    x[0]=x[m-1];
    x[m-1]=t1;
    }
    why I have the same problem? Should I do another while(1) when I call the function??
  • Hi,

    If you add some more files to your project, do it in your local src folder (create such if not having one) and place there all your files, even those *.h; do not mix the driverlib/inc with your own files, this is not a good practice.

    You have an example in Tiva/examples/peripherals/adc/single_ended.c -make a project with this one, examine it to see only *one* while(1) block. 

    If the file is not too big, you may add your functions there and declare them in a separate .h file. The new .h file should start with name prefixed with only one underscore (the end may be with two underscores); usually those with two underscores belongs to tools/compiler and their purpose is to avoid names clobbering. 

    Take care also to faults interrupts. Check the names and their purposes in your code. Do not use a meaningless "x" - preferable to say "sample_buf" or similar instead. Use different names to avoid compiler misunderstanding.