24
A detailed look at the IAP example implementation
The previous example uses two code bundles; UART8032_C and UART1_C. Note that UART2_C is essentially the
same as UART1_C for the purposes of this discussion. The discussion will take the same course as the previous demos
and explain what occurs behind the scenes. Lets take a walk through the code to see how it works.
For purposes of this discussion, the code is broken into three components as listed below.
1. Top level flow charts for UART8032_C and UART1_C
2. Top level flow for return from main memory execution
3. Detailed flows for startup.a51 for the UART8032_C and UART1_c
Top level functional flow
Lets start with the top level flows. As an aside, the main action occurs in the startup.a51 file, but lets leave that till last.
Notice the symmetry between UART8032_C and UART1_C. They are identical except the test and check for
run_execution_source that is in UART8032_C but not in UART1_C.
Now lets see what keeps execution in UART8032 in the BOOT area. The value of the variable source (base+0x70)
resides in the FS0 segment that, on a new part, is 0xff since its erased. This value indicates to execute from BOOT
FLASH. As you can see, the if statement in this case is false so execution continues from the BOOT area. That is,
exe_main() is not executed. So, when UART8032_C boots, the if statement is not true and execution remains in the
BOOT area. This is the state after the ISP download and before IAP download. If power is cycled, the code always
does executes from the BOOT area.
startup
evl_init()
psd_init()
run_execution_source \\ check execution source
if source=0 \\
exe_main() \\
PSDload_init() \\ init comm parameters
main()
UART8032_c flow
UART1_C flow
startup
evl_init()
psd_init()
\\ source check not necessary
\\
\\
\\ init comm parameters and lcd
main()
Figure 25 Top Level flows, UART8032_C and UART1_C
The next thing that occurs is the IAP download. UART1_C code is downloaded via the serial channel to FS0(MAIN
FLASH area). At this point, no functional changes are observed on the display. The new code is resident in FS0 but not
active. As a component of this download, the value of source has changed to 00. Now, when the Reset command is
issued from PSDload, the if statement in UART8032_C flow is true and the routine exe_main() executes. This changes
the values of the VM and PAGE register to enable the main area to execute and clears out the stack so that UART1_C
can continue to run. These details are discussed later.
Note that in the UART1_C flow there is no source check. That is, run_execution_source() is not included. This is
because the manipulations required for MAIN FLASH to run have already been taken care of since the variable
source=00.
Now, the UART1_C code is running as evidenced by the display. Note that, in this code, only a subset of the serial
functionality is included( ASP and RST ). This limitation was pursued in order to make UART1_C able to be compiled
with the evaluation version of the Keil compiler(2k exe).