Menu

Clear RAM - your solution approach is needed

Anobium
2024-03-10
2024-03-10
  • Anobium

    Anobium - 2024-03-10

    Your solution to clearing all RAM to zero is needed.

    The challenge is that I ( we )need an approach that supports all PICs.

    Here is a solution for a PIC16F1829.

    #CHIP 16f1829
    #OPTION EXPLICIT 
    
    InitSysClearRAMStart:   ; code sequence initialises all GPR's to 0x00                           
        MOVLW   CHIPSHAREDRAM        ; initialise pointer to RAM start address
        MOVWF   FSR0L
        CLRF    FSR0H
    
    InitSysClearRAMLoop:
        CLRF    INDF0       ; clear INDF0 register
        INCF    FSR0L, F    ; inc pointer
        BTFSS   FSR0L, 7    ; all done?
        GOTO    InitSysClearRAMLoop        
    

    What I need are the methods to cater for all PICs and all memory sizes.

    We have a number of constants like CHIPSHAREDRAM ( and CHIPSHAREDRAM_H) and CHIPRAM ( and CHIPRAM_H), we can test for the various chip families with IF CHIPFAMILY =.

    The solution must not require any variables and must leave all the RAM set to ZERO.

    Your approach please.


    Here is the solution I implemented for the LGT ( aka AVR) chips, as a reference. I uses CHIPSUBFAMILY as CHIPFAMILY 12 was not definitive to the LGT.

    #IF ChipSubFamily = 12000 
    
          'Clear down the RAM for ChipSubFamily 12000
            eor r1, r1
            ldi r18, HIGH(RAMEND) -1
            ldi r26, 0x00 ; 0
            ldi r27, 0x01 ; 1
            rjmp IniySysClearRAMStart
    
            InitSysClearRAMLoop:
            st  X+, r1
    
            IniySysClearRAMStart:
            cpi r26, LOW(RAMEND)
            cpc r27, r18
            brne  InitSysClearRAMLoop
            st  X+, r1
    
    #ENDIF
    
     
  • Chris Roper

    Chris Roper - 2024-03-10

    Provided that GCBasic startup code initialises RAM then all you should need is a
    "GOTO 0x0000" i.e. a soft reset.

    You could also use the watchdog timer to force a reset but that would be a lot more complex than a single ASM Instruction.

    In both cases, however, RAM and SFR's may be preserved, hence depending on the GCBASIC initialisation to perform the erese when variables are declared.

    Cheers
    Chris

     
    • Anobium

      Anobium - 2024-03-10

      The requirement is to set the RAM to zero, a known state.

      The RAM must be cleared to a known state.

       
      • Chris Roper

        Chris Roper - 2024-03-10

        If any code is run the only way to guarantee a known state is a power on reset and that, whilst doable, would require an external hardware mod to be under software control.

         
        • Anobium

          Anobium - 2024-03-10

          As with the AVR and LGT the compiler sets all RAM to 0x00.

          There is a clear rationale for this and this is an ask for help to do this.

          We, Clint, Jim and I, are maxed out on building the next release, hence, the ask for help.

           
  • Chris Roper

    Chris Roper - 2024-03-10

    OK,

    I was under the impression that GCBasic already claerd all ram as part of the initialisation process.
    I never questioned it as most of the code I wrote in ASM or C did its own initialization.

    I suggest you give goto 0x0000 a try and see what happens, I have used it before but not specifically to clear RAM so you would have to verify that though testing.

     

Log in to post a comment.