电子文章 | 电子资料下载 | 家电维修 | 维修资料下载 | 加入收藏 | 全站地图
您现在所在位置:电子爱好者电子文章嵌入式系统Calling Utility ROM Functions

Calling Utility ROM Functions

11-20 17:12:21 | http://www.5idzw.com | 嵌入式系统 | 人气:754
标签:嵌入式系统开发,嵌入式开发,http://www.5idzw.com Calling Utility ROM Functions,http://www.5idzw.com
Abstract: Data stored in program memory cannot be accessed directly on MAXQ® microcontrollers. Instead, the IAR Embedded Workbench® is used to call special functions in C code, which are provided for this task in the microcontroller's ROM. This application note explains the steps required to make calls into the ROM from application code.

Overview

Programmers commonly use lookup tables in application code when working with microcontrollers. Because of the nature of the MAXQ core, however, application software cannot read directly from code space and, therefore, cannot directly access any tables defined within the application code. To alleviate this issue, all MAXQ microcontrollers implement what is called a "pseudo von Neumann" architecture: developers can store data and tables in program space, but only by using special Utility ROM routines. Besides these core functions, the ROM for each MAXQ microcontroller can have routines specific to that device. This application note describes the steps one must take with the IAR Embedded Workbench to access these Utility ROM functions from code.

Specifying the Function Addresses and Prototypes

The first step in utilizing the ROM functions is determining where these functions are located. The User's Guide Supplement for MAXQ devices lists the Utility ROM user functions, their addresses, inputs, and outputs. Use this information to find the entry points for the functions that you will be calling. As an example, Table 1 below (Table 48 from the MAXQ2000 supplement) shows that the flashWrite function is located at word address 08461h.

Table 1. Utility ROM User Functions (for Utility ROM Version 1.01)
FUNCTION NUMBER FUNCTION NAME ENTRY POINT SUMMARY
0 flashWrite 08461h Programs a single word of flash memory.
1 flashErasePage 08467h Erases (programs to FFFFh) a 256-word sector of flash memory.
2 frashEraseAll 08478h Erases (programs to FFFFh) all flash memory.
3 moveDP0 08487h Reads a byte/word at DP[0]
4 moveDP0inc 0848Ah Reads a byte/word at DP[0], then increments DP[0].
5 moveDP0dec 0848Dh Reads a byte/word atDP[0], then decrements DP[0].
6 moveDP1 08490h Reads a byte/word at DP[1].
7 moveDP1inc 08493h Reads a byte/word at DP[1], then increments DP[0].
8 moveDP1dec 08496h Reads a byte/word at DP[1], then decrements DP[0].
9 moveFB 08499h Reads a byte/word at BP[Offs].
10 moveFPinc 0849Ch Reads a byte/word at BP[Offs], then increments Offs.
11 moveFPdec 0849Fh Reads a byte/word at BP[Offs], then decrements Offs.
12 copyBuffer 084A2h Copies LC[0] values from DP[0] to BP[Offs].

Now that the entry points for the various functions are known, the IAR Embedded Workbench can be configured to use these addresses. Select Options from the Project menu. In the dialog box that appears, select Linker from the Category list. Click on the Extra Options tab and make sure the box labeled "Use command line options" is checked. In the list of options, you must add an item for every Utility ROM function that you intend to use; specify the address of that function. The options should have the following format:
-D<function_name>=<hexadecimal_byte_address>
The <function_name> is the function name that you will call from your application code. It does not have to match the name given in the table above, but it must be a valid C code function name. <hexadecimal_byte_address> is the byte address of the ROM function's entry point. Since the table lists word addresses, you will need to multiply them by two to convert them to byte addresses. Below is an example (Figure 1) of the options for a MAXQ2000 project that uses three of the provided ROM functions.

Figure 1. A MAXQ2000 project example uses three ROM functions.
Figure 1. A MAXQ2000 project example uses three ROM functions.

To make these functions accessible through your application code, declare prototypes for each one, using the same names as you specified in the Options screen. The parameter passing is discussed in the following section, so for now declare each prototype as accepting no arguments and having no return value.
extern void utilFlashWrite(void);
extern void utilFlashErasePage(void);
extern void utilMoveDP0(void);

Creating Wrapper Functions

It is now possible to call the ROM functions directly from application code. There is, however, a caveat. Since the functions usually accept their input parameters in registers different from those used by IAR's compiler, the functions could destroy registers upon which the compiler depends. The functions may also need to execute with interrupts disabled. Consequently, you should create some helper functions to handle these issues. For each ROM function that you want to call, determine: what inputs it accepts; the outputs it provides; and the registers it destroys. All of this information can be found in the User's Guide Supplement for your MAXQ device.

Continuing our example from above, you can see that the flashErasePage function for the MAXQ2000 has the following description:

Function: flashErasePage
Summary: Erases (programs to 0FFFFh) a 265-word page of flash memory.
Inputs: A[0]: Word address located in the page to be erased. (The page number is the high byte of A[0].)
Outputs: Carry: Set on error and cleared on success.
Destroys: PSF, LC[1], GR, AP, APC

Notes:
  1. If the watchdog reset function is active, it should be disabled before calling this function.
  2. When calling this function from flash, care should be taken that the return address is not in the page that is being erased.

[1] [2]  下一页

,Calling Utility ROM Functions
关于《Calling Utility ROM Functions》的更多文章