I have a question. How to know maximum stack of my program and stack overflow? beacause my program can lock when power have unstatable.
Hi, The stack behaviour 8051 based core is little bit different from others. Here stack is used for: 1. Storing return address from function as well as ISR 2. Saving and Restoring Registers used in interrupt, if no register bank is defined for storing default register bank 3. Saving and restoring intermideate results All local and global variables as well as function arguments will be stored on seperate memory (RAM). Stack will be allocated from idata which is 255 byte long, so there is a very little chance to have overflow in stack. But one can find out manually the stack usage by filling idata with 0xFF and observe the max. usage. There is not way to detect overflow runtime. -SP
Thank you very much. I will try it. If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong?
See also: http://www.keil.com/support/docs/192.htm
"my program can lock when power have unstatable" That's very likely nothing to do with stack overflow, then. Are you using a proper supervisor and reset generator chip? Using a simple RC reset circuit will give you problems if you have "unstable" power!
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong? That assumption is unfounded. If you have unstable power, a wandering stack pointer is the very least of your problems. Once the power becomes unstable (i.e. drops below the minimum allowed by the datasheet of your micro), anything can happen. You don't want to go there. You're asking the wrong question. You should be asking yourself how to stabilize your power source, or how to survive any remaining instability. Forget the stack pointer, learn about power watchdogs and proper reset generation instead.
Once the power becomes unstable, anything can happen A point worth emphasizing. For example, the SP could still be correct, but the memory to which is points changes values due to lack of power. Or the ALU gets the correct SP, and mangles the value while processing the instruction. There's just no way to guarantee that the chip will work correctly in this situation, or even that it will fail the same way every time. If you have external devices on the board, you don't even know whether or not they have valid power, either; even if the processor core works, the rest of the board might not. If handling loss of power is a design requirement, then the power supply has to deliver a power-fail signal to the CPU before falling below the minimum Vcc, and also guarantee enough capacitance in the supply to keep that voltage above the minimum for long enough for the CPU to shut down cleanly. Trying to detect power failure by having the CPU monitor itself for improper behavior won't work.
If I assume that stack pointer point to wrong address in unstable power, how to know stack pointer be right or wrong rephrasing the question "how can I fix hardware in software" answer "you can't" Erik
"having the CPU monitor itself for improper behavior won't work" Not only are you trying to have the CPU monitor itself for improper behaviour, but you are trying to have the CPU monitor itself for improper behaviour whilst behaving improperly!!! :-0 The word "Doomed!" springs to mind...