memory gets cleared on reset?

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

memory gets cleared on reset?

Postby shazan » Wed Dec 18, 2013 9:16 pm

Hi
I am adding a fail safe routine to my system, which will require that the system reset after an fault is encountered. The number of times the reset takes place is to be limited, so I should be able to count the resets. I thought a simple character memory variable would do the job, with a jump to 0000h, but it looks like the memory var gets cleared after I jump to 0000h. Is my reading of the situation right? or do I need to look at my own code again?
shazan
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 19
Joined: Fri Aug 08, 2008 9:44 am

Re: memory gets cleared on reset?

Postby Blackfin » Thu Dec 19, 2013 5:26 pm

Open up boot.asm and see what's happening before the processor gets to your code. You might be surprised how much is happening.
Blackfin
The Big Cheese
The Big Cheese
 
Posts: 284
Joined: Thu Jun 07, 2007 10:28 am

Re: memory gets cleared on reset?

Postby danadak » Fri Dec 20, 2013 12:36 pm

This might help -

http://www.cypress.com/?rID=58522 AN73617

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: memory gets cleared on reset?

Postby graaja » Thu Jan 02, 2014 3:36 am

In the boot.asm file, there is the following code:

Code: Select all
IF   (TOOLCHAIN & HITECH)
; The C compiler will customize the startup code - it's not required here

C_LANGUAGE_SUPPORT:              equ 0
ELSE
C_LANGUAGE_SUPPORT:              equ 1
ENDIF


The second C_LANGUAGE_SUPPORT constant is used by the PSoC Designer for ImageCraft compiler. If this constant is 1, the following code is included in boot.asm

Code: Select all
    ;-----------------------------------
    ; Initialize C Run-Time Environment
    ;-----------------------------------
IF ( C_LANGUAGE_SUPPORT )
IF ( SYSTEM_SMALL_MEMORY_MODEL )
    mov  A,0                           ; clear the 'bss' segment to zero
    mov  [__r0],<__bss_start
BssLoop:
    cmp  [__r0],<__bss_end
    jz   BssDone
    mvi  [__r0],A
    jmp  BssLoop
BssDone:
    mov  A,>__idata_start              ; copy idata to data segment
    mov  X,<__idata_start
    mov  [__r0],<__data_start
IDataLoop:
    cmp  [__r0],<__data_end
    jz   C_RTE_Done
    push A
    romx
    mvi  [__r0],A
    pop  A
    inc  X
    adc  A,0
    jmp  IDataLoop


This code initializes all variables in the area bss to 0. If you define the reset counter variable in assembly in the bss area, or if you define this variable in C, the variable will be automatically initialized to 0. The simplest solution to get around this problem is to open boot.tpl file in the project folder and set the C_LANGUAGE_SUPPORT to 0. This will result in the compiler not initializing the variables to zero and your reset count variable will be preserved. The side effect is that you will have to explicitly initialize all your global variables in your code.
User avatar
graaja
PSoC Master
PSoC Master
 
Posts: 3084
Joined: Thu Dec 18, 2003 4:35 pm
Website: http://www.planetpsoc.com
Location: India

Re: memory gets cleared on reset? Solved

Postby shazan » Fri Jan 24, 2014 7:09 pm

Hi all
Thank you for your answers.
I hopped over this issue by making my jump to _main instead of 0000h :P
shazan
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 19
Joined: Fri Aug 08, 2008 9:44 am

Re: memory gets cleared on reset?

Postby Mr_E » Thu Jan 30, 2014 6:25 am

Don't forget to reset your stack if you are going to jump back to main(). You may also need to reset other registers...
User avatar
Mr_E
The Big Cheese
The Big Cheese
 
Posts: 297
Joined: Wed Aug 11, 2004 7:08 am
Website: http://www.microframecorp.com
Location: Oklahoma, USA


Return to “%s” PSoC1 General

Who is online

Users browsing this forum: No registered users and 2 guests