Jaime Rodriguez

Loader by CAN Protocol

Discussion created by Jaime Rodriguez on Jan 13, 2009
Latest reply on Jan 29, 2009 by Robert Bailey
 I am writing a code to reprogram a S08DZ60 by CAN protocol.
 If I send a specific CAN command, the program goes to a function called
 BootLoad where it will stay in order to receive all the bytes from the
 new program. This is the function:
 
 #pragma CODE_SEG DEF_BOOTLOADER
void BootLoad()
{
   int w,k;
   byte buff[]={0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D}; //ES EL ACKNOWLEDGE
   dword messageID = 0x1C; //Necesita ser la direccion de la MASTER CORTEX
   w = 0;
   CanFlag = FALSE;
   CAN1_SendFrameExt(messageID, DATA_FRAME, 1, buff);
   while(1)
   {
      if(CanFlag)
      {
          switch( CanMessage[ 0 ] )
          {
            case (0xB6):
                         IFsh1_EraseSector( MAKE_WORD( CanMessage[1],CanMessage[2] ) );
                         CAN1_SendFrameExt(messageID, DATA_FRAME, 1, buff);
                         CanFlag = FALSE;
                         break;
            case (0xB5):
                        for(k = 0; k < CanMessage[ 1 ] ; w++,k++)
                        {
                           ArrayToWrite[ w ] = CanMessage[k + 2];
                        }
                        CAN1_SendFrameExt(messageID, DATA_FRAME, 8, buff);
                        CanFlag = FALSE;
                        break;
            case (0xB7): WriteS19Line( w, ArrayToWrite, MAKE_WORD( CanMessage[1],CanMessage[2] ) );
                        w = 0 ;
                        CAN1_SendFrameExt(messageID, DATA_FRAME, 8, buff);
                        CanFlag = FALSE;
                        break;
            
          }
                    
      }
   }
}

void WriteS19Line( int Length, byte *Data, word Direccion)
{
    int k;
    for(k = 0; k < Length; k+=2, Direccion+=2)
    {
        IFsh1_SetWordFlash(Direccion, MAKE_WORD(Data[ k ],Data[ k+1 ]) );
    }
    
}

#pragma CODE_SEG DEFAULT
 
 
 The function is located in a protected Flash Memory segment as well as
 the Flash and CAN functions. This is the Memory map for my device:
 SECTIONS
    BOOTLOADER               =  READ_ONLY    0xF400 TO 0xFFAD;
    RELOC_VECT_TAB           =  READ_ONLY    0xF3C0 TO 0xF3FF;
    ROM                      =  READ_ONLY    0x1900 TO 0xF3BF;
    EEPROM                   =  READ_ONLY    0x1400 TO 0x17FF;
    RAM                      =  READ_WRITE   0x00A0 TO 0x107F;
    Z_RAM                    =  READ_WRITE   0x0080 TO 0x009F;
 END

PLACEMENT
    DEFAULT_RAM                         /* non-zero page variables */
                                        INTO  RAM;
    DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM;
    _DATA_ZEROPAGE,                     /* zero page variables */
    MY_ZEROPAGE                         INTO  Z_RAM;
    DEF_BOOTLOADER                      INTO  BOOTLOADER;
    DEF_VECT_TAB                        INTO  RELOC_VECT_TAB;
END

 The problem is that the CAN comunication gets lost when I erase sector
 0x1900 to 0x1C00. I am running out of ideas and I really need help with
 this project. I am using Freecale CAN bean and Internal Flash bean. I located
 the code from these beans in DEF_BOOTLOADER using  #pragma CODE_SEG DEF_BOOTLOADER.
 Why is my program failing if I am not writing or erasing CAN or/and Flash Routines
 and those routines are not located in the sectors where I am writing/erasing?
 

Outcomes