mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 06:42:32 +08:00
116 lines
4.3 KiB
C
Executable File
116 lines
4.3 KiB
C
Executable File
/****************************************************************************
|
|
* drivers/mtd/mtd_rawnand.c
|
|
*
|
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
*
|
|
* This logic was based largely on Atmel sample code with modifications for
|
|
* better integration with NuttX. The Atmel sample code has a BSD
|
|
* compatibile license that requires this copyright notice:
|
|
*
|
|
* Copyright (c) 2011, 2012, Atmel Corporation
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* 3. Neither the names NuttX nor Atmel nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
#include <nuttx/mtd/nand_config.h>
|
|
|
|
#include <stdint.h>
|
|
#include <assert.h>
|
|
#include <debug.h>
|
|
|
|
#include <nuttx/mtd/nand_raw.h>
|
|
|
|
/****************************************************************************
|
|
* Pre-processor Definitions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Types
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Function Prototypes
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Data
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Private Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: nand_chipid
|
|
*
|
|
* Description:
|
|
* Reads and returns the identifiers of a NAND FLASH chip
|
|
*
|
|
* Input Parameters:
|
|
* raw - Pointer to a struct nand_raw_s instance.
|
|
*
|
|
* Returned Value:
|
|
* id1|(id2<<8)|(id3<<16)|(id4<<24)
|
|
*
|
|
****************************************************************************/
|
|
|
|
uint32_t nand_chipid(struct nand_raw_s *raw)
|
|
{
|
|
uint8_t id[5];
|
|
|
|
DEBUGASSERT(raw);
|
|
|
|
WRITE_COMMAND8(raw, COMMAND_READID);
|
|
WRITE_ADDRESS8(raw, 0);
|
|
|
|
id[0] = READ_DATA8(raw);
|
|
id[1] = READ_DATA8(raw);
|
|
id[2] = READ_DATA8(raw);
|
|
id[3] = READ_DATA8(raw);
|
|
id[4] = READ_DATA8(raw);
|
|
|
|
fvdbg("Chip ID: %02x %02x %02x %02x %02x\n",
|
|
id[0], id[1], id[2], id[3], id[4]);
|
|
|
|
return (uint32_t)id[0] |
|
|
((uint32_t)id[1] << 8) |
|
|
((uint32_t)id[2] << 16) |
|
|
((uint32_t)id[3] << 24);
|
|
}
|