freescale

来自「Freescale 系列单片机常用模块与综合系统设计」· 代码 · 共 174 行

TXT
174
字号
/*================================================================*/
/**                                                 
 * Copyright (c) 2002, Motorola Inc.
 * Motorola Reference Design
 *
 * File name    : taxi_flash.h
 * Project name : Taximeter Reference Design
 * Author       : Mauricio Capistran-Garza
 * Department   : Guadalajara - SPS
 *
 * Description  : Flash programming header file.
 *
 * History      :
 */
/*================================================================*/

#ifndef _TAXI_FLASH_H__
#define _TAXI_FLASH_H__

/************************************************************
							DEFINES
************************************************************/

#define OSC			0x05            // Bus Operation Frequency * 4

/* Virtual Registers needed in order to use ROM resident 
   routines to program flash memory 
 */
#define CTRLBYT	    (*(volatile unsigned char*)(0x88))
#define CPUSPD      (*(volatile unsigned char*)(0x89))
#define LADDRH      (*(volatile unsigned char*)(0x8A))
#define LADDRL      (*(volatile unsigned char*)(0x8B))
#define RAM_START   (*(volatile unsigned char*)(0x8C))
     
/* ROM-resident Routines */     
#define GETBYTE()   {__asm jsr 0xFC00;}
#define RDVRRNG()   {__asm jsr 0xFC03;}
#define ERARNGE()   {__asm jsr 0xFC06;}
#define PRGRNGE()   {__asm jsr 0xFC09;}
#define GET_BIT()   {__asm jsr 0xFF00;}

/* FlashManager Constants */
#define RESIDENT_ROM_ROUTINES 0xFC00
#define PROG        0x01
#define ERASE       0x02
#define SEND        0x03
#define COPY        0x04

/* FlashManager and BackupAccumulators Constants */
#define DATA_START               0xEC00  // to 0xECBE  -> 191 bytes
#define PAGE0_OFFSET             0x00
#define PAGE0_OFFSET_END         0x3F
#define PAGE1_OFFSET             0x40
#define PAGE1_OFFSET_END         0x7F
#define PAGE2_OFFSET             0x80
#define PAGE2_OFFSET_END         0xBF
#define ACCUMULATORS_OFFSET      0x80
#define ACCUMULATORS_OFFSET_END  0xBF
#define BACKUP_FLASH             0xECC0  // to 0xECFF  ->  64 bytes
#define BACKUP_FLASH_OFFSET      0xC0
#define BACKUP_FLASH_OFFSET_END  0xFF
#define PAGE_SIZE                64      // number of bytes in one page of flash; flash gets erased on a page basis
#define ROW                      32      // number of bytes in one row
#define ROW_LIMIT                31      // ending limit of a row

/************************************************************
					FUNCTION PROTOTYPES
************************************************************/
/**
 * FlashManager: It manages most ROM-Resident Routines for
 *               flash reprogramming. There are four basic
 *               ROM-Resident Routines:
 *               + Program Range (PROG): it programs a range
 *                   of flash memory. The starting address to
 *                   be programmed must be defined in resiters
 *                   H:X, and the ending address in the virtual
 *                   registers LADDRH:LADDRL (0x8A:0x8B). This
 *                   range is programmmed with the RAM content
 *                   starting in address 0x8C.
 *               + Erase Page (ERASE): it erases a page (64
 *                   bytes) of flash memory. To specify the
 *                   page to be erased, you must load H:X with
 *                   any address within that page.
 *                   Calling this routine automatically disables
 *                   all interrupts.
 *               + Read and Verify Range (COPY | SEND): it
 *                   reads flash memory and compares it against
 *                   RAM content (starting at address 0x8C).
 *                   The first address to be compared must be
 *                   loaded in registers H:X and the last
 *                   address in virtual registers LADDRH:LADDRL
 *                   (0x8A:0x8B).
 *                   There are two variants of this routine
 *                   depending on the value of the Acc. If
 *                   the Acc is cleared, after comparing each
 *                   byte, the RAM will be overwritten. So this
 *                   routine can be used to COPY a range of flash
 *                   and place it into RAM. If the Acc is set,
 *                   after comparing each byte, this byte will
 *                   be sent serially through the communication
 *                   port (PTB0). So this routine can be used
 *                   to SEND data to the taximeter programmer.
 *               + Read Byte: this ROM-Resident routine is not
 *                   managed by FlashManager.
 *
 *               There are also other virtual registers that
 *               all ROM-Resident routines use: 
 *                  + CTRLBYT - 0x0088 (RAM)
 *                  + CPUSPD  - 0x0089 (RAM)
 *               The contents of these virtual registers
 *               and LADDRH:LADDRL should be backed up before 
 *               calling FlashManager.
 * 
 *               For more information on ROM-Resident Routines
 *               read AN1831.
 *
 * Entry Coditions:    Back up virtual registers or they'll be
 *                     overwritten.
 *
 * Exit Conditions:    PTB0 configured as input.
 *                     If ERASE is called, interrupts are disabled.
 *
 * Parameters:         _type - What you want to do with the flash:
 *                         PROG, ERASE, COPY, SEND
 *                     _start_offset - memory offset from DATA_START
 *                         at which you want to start the process
 *                         chosen in _type. DATA_START is defined
 *                         at the beginning of a 64-bytes page.
 * Implicit Parameters: _end_offset - any process chosen in
 *                         _type (excepting ERASE) begins in
 *                         _start_offset and ends 32 bytes later.
 *                      _accumulator - routines for COPY and SEND
 *                         require special values of Acc. This
 *                         are set implicitly.
 *                     
 * Variables read:     none.
 *
 * Variables modified: Any variable located between 0x88 and 0x8B.
 *
 * Subfunctions:       PRGRNGE(); Resident ROM routine
 *                     ERARNGE(); Resident ROM routine
 *                     RDVRRNG(); Resident ROM routine
 *
 * Return: void
 */
void FlashManager(Byte _type, Byte _start_offset);
 
/**
 * BackupAccumulators: it backs up in flash the following
 *     accumulators: TOTAL_DISTANCE_TRAVELED  
 *					 TOTAL_DISTANCE_IN_SERVICE
 *					 TOTAL_NUMBER_TRAVELS     
 *					 TOTAL_NUMBER_INCREMENTS  
 *					 TOTAL_INCOME 
 *
 * Parameters:         none.  
 *                     
 * Variables read:     accumulator_distance_traveled.
 *                     accumulator_trip.
 *                     accumulator_inc.
 *
 * Variables modified: total_distance_traveled.
 *                     total_distance_traveled_in_service.
 *                     total_number_travels.
 *                     total_number_increments.
 *                     total_income.
 *
 * Subfunctions:       FlashManager().
 *
 * Return: void
 */
void BackupAccumulators(void);

#endif  // _TAXI_FLASH_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?