Thread: How to Free All Memory ?

  1. #16
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Code:
    #include <conio.h>
    #include "..\..\lib\7188e.h"
    
    void (far *Reset_Program)(void)=0xFFFF0000L;    //Program start address.
    
    void main(void)
    { 
        InitLib();
        
        Print("Press any ket to begin\n\r");
        Print("and press any key can reset the program.\n\r");
        Getch();
        
        for(;;)
        {
            if(Kbhit())
            {
                Print("7188E have reseted by software."); 
                DelayMs(10);    //Delay 10 ms to wait for all data is sent to COM port.
                
                Reset_Program();    //You can call the function or 
                                    //replace it by following 3 asam codes. 
                           
                                    //_asm push 0xffff
                                    //_asm push 0
                                    //_asm retf
            }
            else
                Print("*"); //Print '*' while the program is running.
        }
    }
    My program reset code, to ICP-i7188 sended by the support.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > but this not a pc
    > is a icp-i7188E3
    So what part of ProcessaChamado() ABSOLUTELY MUST be run on the target?

    I mean, you could (IMO) easily test this on your PC as a console program, by having
    Code:
    int main ( ) {
        printf( "Result=%d\n", ProcessaChamado ("hello", 5) );
    }
    and a whole host of other tests.
    You can use the debugger to crawl all over it to make sure there are no leaks and no overruns.

    By writing functions which don't depend on the target platform at all, you can very easily test them on your PC.

    A set of other functions, you can easily write a library of stub functions.
    For example, if you've got a target specific LightLED( int id ); function, you can simply create a stub function for the PC which is simply
    Code:
    void LightLED ( int id ) {
      printf( "LightLED(%d) called\n", id );
    }
    By the time you get your code on the target, you should have a pretty good idea that 95% of it has already been tested.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by sergioms View Post
    I love debug,

    but this not a pc
    is a icp-i7188E3

    and, use a Serial RS-232 to communicate with a balance
    a serial 485 to send text to a led display
    socket to communicate with a listen socket software
    and Digital I/O

    when the program crash
    it closed all outputs, and no send a message about the error.

    Have you put some printfs into your program to give you an idea of what is wrong?

  4. #19
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Quote Originally Posted by esbo View Post
    Have you put some printfs into your program to give you an idea of what is wrong?
    when the program crashs, all outputs stop, and stop execution.

  5. #20
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yes but if you do it before certain key areas you may find out the line that's crashing.

    ie,
    Code:
    printf("%p\n", (void *) ptr);
    
    ptr->foo = 10;

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Like Salem says, you can actually simulate most of these interactions on a PC - there are tools for particularly detecting overruns on memory and such things on the PC, which may not exist on your embedded system, so whilst there is a LITTLE bit of extra work required to get the code working on a PC, you will almost certainly regain all of that and more again by finding logical/memory management problems earlier and easier.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Ok, its function is ok at my ICP, whatever, some times next execute it,
    the program send to socket ....... when i try to send OPSL.

    The functions actual on ICP:

    Code:
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec){
     unsigned char cDispPacote [52];
     int iComDisplay = 2;
     unsigned int iLims;
     unsigned int iLenMsg, iLenCont, iContIndex;
     int iBcc;
     
     iDisplaySend = 1;
     if (pDelaySec > 0)
      Delay(pDelaySec * 1000);
     
     iLims  = 46;
     
     cDispPacote [0] = 129;
     cDispPacote [1] = 126;
     cDispPacote [2] = iLims % 256;
     cDispPacote [3] = iLims / 256;
     cDispPacote [4] = 1 % 256;
     cDispPacote [5] = 1 / 256;
     cDispPacote [6] = 0 % 256;
     cDispPacote [7] = 0 / 256;
     cDispPacote [8] = 76;
     cDispPacote [9] = 202;
      
     iLenMsg = strlen (pMensagem);
     if (iLenMsg > 40)
      iLenMsg = 40;
     if (iLenMsg < 40){
      for(iLenCont=iLenMsg; iLenCont<40; iLenCont++)
       strcat (pMensagem, ".");
     }
     
     for(iLenCont=0; iLenCont<40; iLenCont++){
      iContIndex = iLenCont + 10;
      cDispPacote [iContIndex] = pMensagem [iLenCont];
     }
     
     iBcc = cDispPacote [4];
     cDispPacote [50] = iBcc;
     cDispPacote [51] = '\0';
     
     for(iContIndex=0; iContIndex<=51; iContIndex++){
      ToCom (iComDisplay, cDispPacote[iContIndex]);
     }
     
     iDisplaySend=0;
    }
    this function in pc, not is ok, all crazy chars in cDispPacote

    I try change to this:

    Code:
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec);
    void main(void)
    { 
     EscreveDisplay ("SERGIO", 0);
    }
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec){
     unsigned char cDispPacote [52];
     unsigned int iLims;
     unsigned int iLenMsg, iLenCont, iContIndex;
     int iBcc;
     iLims  = 46;
     
     cDispPacote [0] = 129;
     cDispPacote [1] = 126;
     cDispPacote [2] = iLims % 256;
     cDispPacote [3] = iLims / 256;
     cDispPacote [4] = 1 % 256;
     cDispPacote [5] = 1 / 256;
     cDispPacote [6] = 0 % 256;
     cDispPacote [7] = 0 / 256;
     cDispPacote [8] = 76;
     cDispPacote [9] = 202;
      
     iLenMsg = strlen (pMensagem);
     
     for (iLenCont=10; iLenCont<=49; iLenCont++)
      cDispPacote [iLenCont] = '.';
     
     for(iLenCont=0; iLenCont<iLenMsg; iLenCont++){
      iContIndex = iLenCont + 10;
      cDispPacote [iContIndex] = pMensagem [iLenCont];
     }
     
     iBcc = cDispPacote [4];
     cDispPacote [50] = iBcc;
     cDispPacote [51] = '\0';
     
     printf ("Linha 1: \n");
     
     for(iContIndex=0; iContIndex<=51; iContIndex++){
      printf ("[%i] %c\n",iContIndex,cDispPacote[iContIndex]);
     }
     
     printf ("\n");
     getch ();
    }
    Like some this, but in pc is ok, but no in my ICP
    :S

  8. #23
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, this is definitely WRONG:
    Code:
     if (iLenMsg < 40){
      for(iLenCont=iLenMsg; iLenCont<40; iLenCont++)
       strcat (pMensagem, ".");
     }
    [By the way, you don't actually need the if (iLenMsg...) - it is done as part of the for-loop, so you won't enter the loop if it's iLenMsg >= 40.]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #24
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    Code:
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec){
    	unsigned char cDispPacote [52];
    	int iComDisplay = 2;
    	unsigned int iLims;
    	unsigned int iLenMsg, iLenCont, iContIndex;
    	int iBcc;
    	
    	iDisplaySend = 1;
    	if (pDelaySec > 0)
    		Delay(pDelaySec * 1000);
    	
    	iLims  = 46;
    	
    	cDispPacote [0] = 129;
    	cDispPacote [1] = 126;
    	cDispPacote [2] = iLims % 256;
    	cDispPacote [3] = iLims / 256;
    	cDispPacote [4] = 1 % 256;
    	cDispPacote [5] = 1 / 256;
    	cDispPacote [6] = 0 % 256;
    	cDispPacote [7] = 0 / 256;
    	cDispPacote [8] = 76;
    	cDispPacote [9] = 202;
    	
    	iLenMsg = strlen (pMensagem);
     
    	 for (iLenCont=10; iLenCont<=49; iLenCont++)
    		cDispPacote [iLenCont] = '.';
    	 
    	 for(iLenCont=0; iLenCont<iLenMsg - 1; iLenCont++){
    		iContIndex = iLenCont + 10;
    		cDispPacote [iContIndex] = pMensagem [iLenCont];
    	 }
    	
    	iBcc = cDispPacote [4];
    	cDispPacote [50] = iBcc;
    	cDispPacote [51] = '\0';
    	
    	for(iContIndex=0; iContIndex<=51; iContIndex++){
    		ToCom (iComDisplay, cDispPacote[iContIndex]);
    		DelayMs (2);
    	}
    	
    	iDisplaySend=0;
    }
    EscreveDisplay ("LENKE AUTOMACAO", 0);

    ok, i had no checked for len, and changed the code.

    why this not ok ?
    some \0 or like similliar ?

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What, exactly, do you get as output? (and what do you expect?)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    EscreveDisplay ("LENKE AUTOMACAO", 0);

    output need be:

    [10 chars prefix (0 to 9)]LENKE AUTOMACAO.........................[BCC][/0]

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by sergioms View Post
    EscreveDisplay ("LENKE AUTOMACAO", 0);

    output need be:

    [10 chars prefix (0 to 9)]LENKE AUTOMACAO.........................[BCC][/0]
    Yes, and what do you get? [Sorry, I don't have time at this point to compile your code and test it myself].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #28
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    [0]
    [1] ~
    [2] .
    [3]
    [4] 
    [5]
    [6]
    [7]
    [8] L
    [9] Ê
    [10] L
    [11] E
    [12] N
    [13] K
    [14] E
    [15]
    [16] A
    [17] U
    [18] T
    [19] O
    [20] M
    [21] A
    [22] C
    [23] A
    [24] O
    [25] .
    [26]
    [27]
    [28] [
    [29] %
    [30] i
    [31] ]
    [32]
    [33] %
    [34] c
    [35]

    [36]
    [37]

    [38]
    [39]
    [40]
    [41]
    [42] G
    [43] #
    [44] ;
    [45] 
    [46] Â
    [47] 
    [48] ;
    [49] 
    [50] 
    [51]

  14. #29
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And exactly what code are you using for this - I copied your seconds sample code (the one with main), and adapted it to compile with gcc (remove conio.h and a few other bits like that), and it works just fine.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #30
    Registered User
    Join Date
    Nov 2008
    Location
    Santa Catarina - Brasil
    Posts
    184
    this code, i has guide by your tips...

    Code:
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec);
    
    void main(void)
    { 
        
       // printf("Press any ket to begin\n\r");
       // printf("and press any key can reset the program.\n\r");
       // getch();
        
    	EscreveDisplay ("LENKE AUTOMACAO", 0);
    }
    
    void EscreveDisplay (unsigned char *pMensagem, unsigned int pDelaySec){
    	unsigned char cDispPacote [52];
    	int iComDisplay = 2;
    	unsigned int iLims;
    	unsigned int iLenMsg, iLenCont, iContIndex;
    	int iBcc;
    	
           //	iDisplaySend = 1;
           //	if (pDelaySec > 0)
           //		Delay(pDelaySec * 1000);
    	
    	iLims  = 46;
    	
    	cDispPacote [0] = 129;
    	cDispPacote [1] = 126;
    	cDispPacote [2] = iLims % 256;
    	cDispPacote [3] = iLims / 256;
    	cDispPacote [4] = 1 % 256;
    	cDispPacote [5] = 1 / 256;
    	cDispPacote [6] = 0 % 256;
    	cDispPacote [7] = 0 / 256;
    	cDispPacote [8] = 76;
    	cDispPacote [9] = 202;
    
    	iLenMsg = strlen (pMensagem);
    
    	for(iLenCont=iLenMsg; iLenCont<40; iLenCont++)
    		strcat (pMensagem, ".");
    	
    	for(iLenCont=0; iLenCont<40; iLenCont++){
    		iContIndex = iLenCont + 10;
    		cDispPacote [iContIndex] = pMensagem [iLenCont];
    	}
    	
    	iBcc = cDispPacote [4];
    	cDispPacote [50] = iBcc;
    	cDispPacote [51] = '\0';
    	
    	for(iContIndex=0; iContIndex<=51; iContIndex++){
    		printf ("[%i] %c\n",iContIndex,cDispPacote[iContIndex]);
    	       //	DelayMs (2);
    	}
    	
    	printf ("\n");
    	getch ();
    }
    Last edited by sergioms; 01-15-2009 at 09:23 AM. Reason: obs.: This code show text ok in the display but in pc the result is above output.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  3. Memory leak with detached pthreads - how to free?
    By rfk in forum Linux Programming
    Replies: 2
    Last Post: 08-17-2007, 06:50 AM
  4. free memory in structure
    By franziss in forum C++ Programming
    Replies: 22
    Last Post: 01-08-2007, 05:16 PM
  5. free allocated memory on interrupts
    By scrappy in forum C Programming
    Replies: 4
    Last Post: 02-20-2004, 11:13 AM