/******************************************************************************\ * Copyright (C) 2000 Texas Instruments Incorporated. * All Rights Reserved *------------------------------------------------------------------------------ * FILENAME...... bsl_flash.c * DATE CREATED.. Thu 06/15/2001 * LAST MODIFIED. Thu 06/15/2001 * \******************************************************************************/ #define _FLASH_MOD_ #define _BOARD_MOD_ /****************************************\ * include files \****************************************/ #include "bsl_flash.h" #if (FLASH_SUPPORT) /******************************************************************************\ * L O C A L S E C T I O N \******************************************************************************/ /****************************************\ * FLASH static macro declarations \****************************************/ #if (BOARD_6711DSK | BOARD_6211DSK) #define FLASH_ADR1 0x90005555 /* Used to access the FLASH ROM */ #define FLASH_ADR2 0x90002AAA /* Used to access the FLASH ROM */ #define FLASH_PROGRAM_KEY1 0xAA /* Used to access the FLASH ROM */ #define FLASH_PROGRAM_KEY2 0x55 /* Used to access the FLASH ROM */ #define FLASH_PROGRAM_KEY3 0xA0 /* Used to access the FLASH ROM */ #define FLASH_ERASE_KEY1 0xAA /* Used to chip erase the FLASH ROM */ #define FLASH_ERASE_KEY2 0x55 /* Used to chip erase the FLASH ROM */ #define FLASH_ERASE_KEY3 0x80 /* Used to chip erase the FLASH ROM */ #define FLASH_ERASE_KEY4 0xAA /* Used to chip erase the FLASH ROM */ #define FLASH_ERASE_KEY5 0x55 /* Used to chip erase the FLASH ROM */ #define FLASH_ERASE_KEY6 0x10 /* Used to chip erase the FLASH ROM */ #define PAGE_NUMBER(x) ((x - FLASH_START_ADDR) / FLASH_PAGE_SIZE) #endif /****************************************\ * FLASH static typedef declarations \****************************************/ /****************************************\ * FLASH static function declarations \****************************************/ static inline int page_boundary_FLASH(char *flash_ptr, Uint32 page_size); static int validate_FLASH(Uint32 flahsAddr, Uint32 length); static inline void program_id_FLASH(); static void chip_erase_FLASH(); static inline void buffer_page_FLASH(Uint32 flashptr,char *bufferptr); /****************************************\ * FLASH static variable definitions \****************************************/ static char page_buffer[FLASH_PAGE_SIZE]; /****************************************\ * FLASH static function definitions \****************************************/ /*----------------------------------------------------------------------------*/ int page_boundary_FLASH(char *flash_ptr, Uint32 page_size){ int flag0 = ((int)flash_ptr) % page_size; return (!(flag0)); } /*----------------------------------------------------------------------------*/ int validate_FLASH(Uint32 flashAddr, Uint32 length){ int flag = 1; unsigned int depth; /* distance into memory */ depth = flashAddr - FLASH_START_ADDR + (unsigned int)length; /* check for valid FLASH range */ if ((flashAddr < FLASH_START_ADDR) || (flashAddr>=FLASH_END_ADDR)) flag = 0; /* check to make sure depth doesn't exceed FLASH_SIZE */ if (depth >FLASH_SIZE) flag = 0; return (flag); } /*----------------------------------------------------------------------------*/ void program_id_FLASH(){ *(volatile char *)FLASH_ADR1 = FLASH_PROGRAM_KEY1; *(volatile char *)FLASH_ADR2 = FLASH_PROGRAM_KEY2; *(volatile char *)FLASH_ADR1 = FLASH_PROGRAM_KEY3; } /*----------------------------------------------------------------------------*/ void chip_erase_FLASH(){ *(volatile char *)FLASH_ADR1 = FLASH_ERASE_KEY1; *(volatile char *)FLASH_ADR2 = FLASH_ERASE_KEY2; *(volatile char *)FLASH_ADR1 = FLASH_ERASE_KEY3; *(volatile char *)FLASH_ADR1 = FLASH_ERASE_KEY4; *(volatile char *)FLASH_ADR2 = FLASH_ERASE_KEY5; *(volatile char *)FLASH_ADR1 = FLASH_ERASE_KEY6; } /*----------------------------------------------------------------------------*/ void buffer_page_FLASH(Uint32 flashptr,char *bufferptr){ char *page_ptr = (char *)flashptr; char *buffer_ptr = bufferptr; int i; for (i=0;i