IAP

For in application programming the IAP routine should be called with a word pointer in register r0 pointing to memory (RAM) containing command code and parameters. Result of the IAP command is returned in the result table pointed to by register r1. The user can reuse the command table for result by passing the same pointer in registers r0 and r1. The parameter table should be big enough to hold all the results in case the number of results are more than number of parameters. Parameter passing is illustrated in the IAP parameter passing. The number of parameters and results vary according to the IAP command. The maximum number of parameters is 5, passed to the "Copy RAM to FLASH" command. The maximum number of results is 4, returned by the "ReadUID" command. The command handler sends the status code INVALID_COMMAND when an undefined command is received. The IAP routine resides at 0x1FFF 1FF0 location and it is thumb code.

To call an IAP function, do the following:

Define the IAP location entry point. Since the 0th bit of the IAP location is set there will be a change to Thumb instruction set when the program counter branches to this address.

#define IAP_LOCATION 0x1fff1ff1-->

Define data structure or pointers to pass IAP command table and result table to the IAP function:

unsigned int command_param[5];-->
unsigned int status_result[4];-->

or

unsigned int * command_param;-->
unsigned int * status_result;-->
command_param = (unsigned int *) 0x...-->
status_result =(unsigned int *) 0x...-->

Define pointer to function type, which takes two parameters and returns void. Note the IAP returns the result with the base address of the table residing in R1.

typedef void (*IAP)(unsigned int [],unsignedint[]);-->
IAP iap_entry;-->

Setting the function pointer:

iap_entry=(IAP) IAP_LOCATION;-->

To call the IAP, use the following statement.

iap_entry (command_param,status_result);-->

As per the ARM specification (The ARM Thumb Procedure Call Standard SWS ESPC 0002 A-05) up to 4 parameters can be passed in the r0, r1, r2 and r3 registers respectively. Additional parameters are passed on the stack. Up to 4 parameters can be returned in the r0, r1, r2 and r3 registers respectively. Additional parameters are returned indirectly via memory. Some of the IAP calls require more than 4 parameters. If the ARM suggested scheme is used for the parameter passing/returning then it might create problems due to difference in the C compiler implementation from different vendors. The suggested parameter passing scheme reduces such risk.

The flash memory is not accessible during a write or erase operation. IAP commands, which results in a flash write/erase operation, use 32 bytes of space in the top portion of the on-chip RAM for execution. The user program should not be use this space if IAP flash programming is permitted in the application.

Table 1. ISP-IAP API IAP Command Summary
IAP Command Command Code Described in
Prepare sector(s) for write operation 50 (decimal) ISP-IAP API IAP Prepare sector(s) for write operation command
Copy RAM to flash 51 (decimal) ISP-IAP API IAP Copy RAM to flash command
Erase sector(s) 52 (decimal) ISP-IAP API IAP Erase Sector(s) command
Blank check sector(s) 53 (decimal) ISP-IAP API IAP Blank check sector(s) command
Read Part ID 54 (decimal)_ ISP-IAP API IAP Read Part Identification command
Read Boot code version 55 (decimal) ISP-IAP API IAP Read Boot Code version number command
Compare 56 (decimal) ISP-IAP API IAP Compare command
Reinvoke ISP 57 (decimal) ISP-IAP API IAP Reinvoke ISP
Read UID 58 (decimal) ISP-IAP API IAP ReadUID command
Erase page 59 (decimal) ISP-IAP API IAP Erase page command


IAP parameter passing


-->