flash29GL1GDrvLib.c
资源名称:mpc8548.rar [点击查看]
上传用户:dqzhongke1
上传日期:2022-06-26
资源大小:667k
文件大小:7k
源码类别:
VxWorks
开发平台:
C/C++
- /*
- * $Id: flash29GL1GDrvLib.c,v 1.3 Broadcom SDK $
- * $Copyright: Copyright 2008 Broadcom Corporation.
- * This program is the proprietary software of Broadcom Corporation
- * and/or its licensors, and may only be used, duplicated, modified
- * or distributed pursuant to the terms and conditions of a separate,
- * written license agreement executed between you and Broadcom
- * (an "Authorized License"). Except as set forth in an Authorized
- * License, Broadcom grants no license (express or implied), right
- * to use, or waiver of any kind with respect to the Software, and
- * Broadcom expressly reserves all rights in and to the Software
- * and all intellectual property rights therein. IF YOU HAVE
- * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
- * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
- * ALL USE OF THE SOFTWARE.
- *
- * Except as expressly set forth in the Authorized License,
- *
- * 1. This program, including its structure, sequence and organization,
- * constitutes the valuable trade secrets of Broadcom, and you shall use
- * all reasonable efforts to protect the confidentiality thereof,
- * and to use this information only in connection with your use of
- * Broadcom integrated circuit products.
- *
- * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
- * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
- * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
- * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY
- * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
- * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
- * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
- * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
- * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
- *
- * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
- * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
- * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
- * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
- * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
- * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1,
- * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
- * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
- */
- #include "vxWorks.h"
- #include "taskLib.h"
- #include "stdlib.h"
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- #include "config.h"
- #include "flashDrvLib.h"
- #define xor_val 0x0
- #define FLASH_WIDTH UINT16*
- #define FLASH_ADDR(dev, addr)
- ((volatile UINT16 *) ((FLASH_WIDTH)dev + addr))
- #define FLASH_WRITE(dev, addr, value)
- (*FLASH_ADDR(dev, addr) = (value))
- #define FLASH_READ(dev, addr)
- (*FLASH_ADDR(dev, addr))
- LOCAL void
- flashReadReset(void)
- {
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xf0);
- }
- LOCAL void
- flashAutoSelect(FLASH_TYPES *dev, FLASH_VENDORS *vendor)
- {
- flashReadReset();
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xaa);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x2aa, 0x55);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0x90);
- *vendor = FLASH_READ(FLASH_BASE_ADDRESS, 0);
- *vendor = FLASH_READ(FLASH_BASE_ADDRESS, 0);
- *dev = FLASH_READ(FLASH_BASE_ADDRESS, 1);
- if (flashVerbose)
- printf("flashAutoSelect(): dev = 0x%x, vendor = 0x%xn",
- (int)*dev, (int)*vendor);
- flashReadReset();
- if ((*dev != FLASH_29GL1G) || (*vendor != AMD)) {
- *vendor = *dev = 0xFF;
- }
- }
- LOCAL int
- flashEraseDevices(volatile unsigned char *sectorBasePtr)
- {
- int i;
- unsigned int tmp;
- if (flashVerbose) {
- printf("Erasing Sector @ 0x%08xn",(unsigned int)sectorBasePtr);
- }
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xaa);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x2aa, 0x55);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0x80);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xaa);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x2aa, 0x55);
- FLASH_WRITE(sectorBasePtr, 0x0, 0x30);
- for (i = 0; i < FLASH_ERASE_TIMEOUT_COUNT; i++) {
- taskDelay(FLASH_ERASE_TIMEOUT_TICKS);
- tmp = FLASH_READ(sectorBasePtr, 0x0);
- if ((tmp & 0x80) == 0x80) {
- if (flashVerbose > 1)
- printf("flashEraseDevices(): all devices erasedn");
- return (OK);
- }
- }
- if ((tmp & 0x20) == 0x20) {
- printf("flashEraseDevices(): addr 0x%08x erase failedn",
- (int)sectorBasePtr);
- } else {
- printf("flashEraseDevices(): addr 0x%08x erase timed outn",
- (int)sectorBasePtr);
- }
- flashReadReset();
- return (ERROR);
- }
- LOCAL int
- flashEraseSector(int sectorNum)
- {
- unsigned char *sectorBasePtr =
- (unsigned char *)FLASH_SECTOR_ADDRESS(sectorNum);
- if (sectorNum < 0 || sectorNum >= flashSectorCount) {
- printf("flashEraseSector(): Sector %d invalidn", sectorNum);
- return (ERROR);
- }
- if (flashEraseDevices(sectorBasePtr) == ERROR) {
- printf("flashEraseSector(): erase devices failed sector=%dn",
- sectorNum);
- return (ERROR);
- }
- if (flashVerbose)
- printf("flashEraseSector(): Sector %d erasedn", sectorNum);
- return (OK);
- }
- LOCAL int
- flashRead(int sectorNum, char *buff, unsigned int offset, unsigned int count)
- {
- if (sectorNum < 0 || sectorNum >= flashSectorCount) {
- printf("flashRead(): Illegal sector %dn", sectorNum);
- return (ERROR);
- }
- bcopy((char *)(FLASH_SECTOR_ADDRESS(sectorNum) + offset), buff, count);
- return (0);
- }
- LOCAL int
- flashProgramDevices(volatile unsigned short *addr, unsigned short val)
- {
- int polls;
- unsigned char tmp;
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xaa);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x2aa, 0x55);
- FLASH_WRITE(FLASH_BASE_ADDRESS, 0x555, 0xa0);
- /* FLASH_WRITE(addr, 0x0, val);*/
- *addr = val;
- for (polls = 0; polls < FLASH_PROGRAM_TIMEOUT_POLLS; polls++) {
- tmp = *addr;
- if ((tmp & 0x80) == (val & 0x80)) {
- if (flashVerbose > 2)
- printf("flashProgramDevices(): devices programmedn");
- return (OK);
- }
- }
- if ((tmp & 0x20) != 0) {
- /*
- * We've already waited so long that chances are nil that the
- * 0x80 bits will change again. Don't bother re-checking them.
- */
- printf("flashProgramDevices(): Address 0x%08x program failedn",
- (int)addr);
- } else {
- printf("flashProgramDevices(): timed outn");
- }
- flashReadReset();
- return (ERROR);
- }
- LOCAL int
- flashWrite(int sectorNum, char *buff, unsigned int offset, unsigned int count)
- {
- unsigned short *curBuffPtr, *flashBuffPtr;
- int i;
- curBuffPtr = (unsigned short *)buff;
- flashBuffPtr = (unsigned short *)(FLASH_SECTOR_ADDRESS(sectorNum) + offset);
- count = (count + 1)/2;
- for (i = 0; i < count; i++) {
- if (flashProgramDevices(flashBuffPtr, *curBuffPtr) == ERROR) {
- printf("flashWrite(): Failed: Sector %d, address 0x%xn",
- sectorNum, (int)flashBuffPtr);
- return (ERROR);
- }
- flashBuffPtr++;
- curBuffPtr++;
- }
- return (0);
- }
- struct flash_drv_funcs_s flash29GL1G = {
- FLASH_29GL1G, AMD,
- flashAutoSelect,
- flashEraseSector,
- flashRead,
- flashWrite
- };