add SPI 8MHz.

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@6 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
nakasima 2007-04-02 11:49:45 +00:00
parent 882a1b0319
commit b02cefe996
7 changed files with 535 additions and 0 deletions

View File

@ -134,6 +134,7 @@ TWL_LIBS ?= \
libos_sp$(TWL_LIBSUFFIX).a \
libmi_sp$(TWL_LIBSUFFIX).a \
libvlink_sp$(TWL_LIBSUFFIX).a \
libnvram_sp$(TWL_LIBSUFFIX).a \
ifdef TWL_PROFILE_TYPE
TWL_LIBS += libos_sp.$(TWL_PROFILE_TYPE)$(TWL_LIBSUFFIX).a
@ -148,6 +149,16 @@ include $(NITROSDK_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
ifeq ($(NITRO_PROVATE),TRUE)
TWL_PROVATE := TRUE
endif
ifeq ($(NITRO_WITH_ARM7),TRUE)
TWL_WITH_ARM7 := TRUE
endif
#----------------------------------------------------------------------------
### Global Library resettings
GINCLUDES := $(TWL_INCDIR) $(GINCLUDES)
@ -155,6 +166,7 @@ GLIBRARY_DIRS := $(TWL_LIBDIR) $(GLIBRARY_DIRS)
GLIBRARIES := $(TWL_LIBS) \
$(filter-out libos$(NITRO_LIBSUFFIX).a libos_sp$(NITRO_LIBSUFFIX).a \
libmi$(NITRO_LIBSUFFIX).a libmi_sp$(NITRO_LIBSUFFIX).a \
libnvram_sp$(NITRO_LIBSUFFIX).a \
,$(GLIBRARIES))

View File

@ -25,6 +25,7 @@ SUBDIRS = \
os \
mi \
vlink \
spi \
#----------------------------------------------------------------------------

View File

@ -0,0 +1,52 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - libraries - spi
# File: Makefile
#
# Copyright 2007 Nintendo. All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law. They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
SUBDIRS = nvram # tp mic pm
#----------------------------------------------------------------------------
# build ARM & THUMB libraries
TWL_CODEGEN_ALL ?= True
TWL_PROC = ARM7
# SRCS = spi_sp.c
# TARGET_LIB = libspi_sp$(TWL_LIBSUFFIX).a
INCDIR = $(TWL_NITROSDK_ROOT)/build/libraries/spi/ARM7/include
#----------------------------------------------------------------------------
# DEBUG版ビルドの場合、RELEASE版でビルドして
# DEBUG版のライブラリを装います。
ifdef NITRO_DEBUG
NITRO_BUILD_TYPE = RELEASE
endif
include $(TWLSDK_ROOT)/build/buildtools/commondefs
INSTALL_TARGETS = $(TARGETS)
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
#----------------------------------------------------------------------------
# do-build: $(TARGETS)
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,180 @@
/*---------------------------------------------------------------------------*
Project: NitroSDK - libraries - spi
File: nvram_sp.h
Copyright 2003-2006 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Log: nvram_sp.h,v $
Revision 1.6 2006/01/18 02:11:30 kitase_hirotake
do-indent
Revision 1.5 2005/02/28 05:26:27 yosizaki
do-indent.
Revision 1.4 2004/10/07 06:49:34 terui
NVRAMについて別メーカー製の場合のコマンド追加に伴う修正
Revision 1.3 2004/09/16 04:56:40 terui
NVRAMのステータスレジスタに関する定義を追加
Revision 1.2 2004/09/07 00:34:27 takano_makoto
SDK_SMALL_BUILD定義時にSDK_NVRAM_USE_READ_HIGHER_SPEEDを未定義にするよう変更
Revision 1.1 2004/09/06 12:54:18 terui
libraries/spi/includeからlibraries/spi/ARM7/includeに移動
SPI処理予約方式の実装に伴う修正
Revision 1.5 2004/05/25 00:58:01 terui
SPI各デバイス用ライブラリ細分化に伴う修正
Revision 1.4 2004/05/12 10:51:44 terui
MI関数にて行うコンパイルスイッチを追加
ReadHigherSpeedインストラクションのみ切り離すコンパイルスイッチを追加
Revision 1.3 2004/04/29 10:26:09 terui
Revision 1.2 2004/04/14 06:26:46 terui
SPIライブラリのソース整理に伴う更新
Revision 1.1 2004/04/05 04:46:37 terui
Initial upload.
$NoKeywords: $
*---------------------------------------------------------------------------*/
#ifndef LIBRARIES_NVRAM_SP_H_
#define LIBRARIES_NVRAM_SP_H_
#include <nitro/types.h>
#include "spi_sp.h"
#ifdef __cplusplus
extern "C" {
#endif
/*===========================================================================*/
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
// 高速読み出しコマンドにも対応する場合はdefineする
#ifndef SDK_SMALL_BUILD
#define SDK_NVRAM_USE_READ_HIGHER_SPEED
#endif
// LE25FW203Tに特有のinstructionが必要な場合はdefineする
#define SDK_NVRAM_ANOTHER_MAKER
// メインメモリへのアクセスをMIのバイトアクセス関数を使って省コードする場合にdefine
#define SDK_SPI_LOW_SPEED_LOW_CODE_SIZE
// NVRAM操作コマンド定義
#define NVRAM_INSTRUCTION_DUMMY 0x00 // 応答取得用のダミー命令
#define NVRAM_INSTRUCTION_WREN 0x06 // 書き込み許可
#define NVRAM_INSTRUCTION_WRDI 0x04 // 書き込み禁止
#define NVRAM_INSTRUCTION_RDSR 0x05 // ステータスレジスタ読み出し
#define NVRAM_INSTRUCTION_READ 0x03 // 読み出し
#define NVRAM_INSTRUCTION_FAST_READ 0x0b // 高速読み出し
#define NVRAM_INSTRUCTION_PW 0x0a // ページ書き込み
#define NVRAM_INSTRUCTION_PP 0x02 // ページ書き込み(条件付)
#define NVRAM_INSTRUCTION_PE 0xdb // ページ消去
#define NVRAM_INSTRUCTION_SE 0xd8 // セクタ消去
#define NVRAM_INSTRUCTION_DP 0xb9 // 省電力
#define NVRAM_INSTRUCTION_RDP 0xab // 省電力から復帰
#ifdef SDK_NVRAM_ANOTHER_MAKER
#define NVRAM_INSTRUCTION_CE 0xc7 // チップイレース
#define NVRAM_INSTRUCTION_RSI 0x9f // シリコンID読み出し
#define NVRAM_INSTRUCTION_SR 0xff // ソフトウェアリセット
#endif
// NVRAMステータスレジスタ内ビット定義
#define NVRAM_STATUS_REGISTER_WIP 0x01
#define NVRAM_STATUS_REGISTER_WEL 0x02
#ifdef SDK_NVRAM_ANOTHER_MAKER
#define NVRAM_STATUS_REGISTER_ERSER 0x20
#endif
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
// NVRAM用ワーク構造体
typedef struct NVRAMWork
{
u16 command[SPI_PXI_CONTINUOUS_PACKET_MAX];
}
NVRAMWork;
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
void NVRAM_Init();
void NVRAM_AnalyzeCommand(u32 data);
void NVRAM_ExecuteProcess(SPIEntry * entry);
void NVRAM_WriteEnable(void);
void NVRAM_WriteDisable(void);
void NVRAM_ReadStatusRegister(u8 *buf);
void NVRAM_ReadDataBytes(u32 address, u32 size, u8 *buf);
#ifdef SDK_NVRAM_USE_READ_HIGHER_SPEED
void NVRAM_ReadDataBytesAtHigherSpeed(u32 address, u32 size, u8 *buf);
#endif
void NVRAM_PageWrite(u32 address, u16 size, const u8 *buf);
void NVRAM_PageProgram(u32 address, u16 size, const u8 *buf);
void NVRAM_PageErase(u32 address);
void NVRAM_SectorErase(u32 address);
void NVRAM_DeepPowerDown(void);
void NVRAM_ReleaseFromDeepPowerDown(void);
#ifdef SDK_NVRAM_ANOTHER_MAKER
void NVRAM_ChipErase(void);
void NVRAM_ReadSiliconId(u8 *buf);
void NVRAM_SoftwareReset(void);
#endif
/*---------------------------------------------------------------------------*
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
Name: NVRAM_SPIChangeMode
Description: SPIコントロールレジスタを編集してNVRAM用にコマンド転送準備を整える
SPI連続クロック発振モードを切り替える
Arguments: continuous - SPI連続クロック発振可否'1'1byte通信の都度CSを上げ
1'0'
1byte転送モードにしないと永久にCSが上がらない
Returns: None.
*---------------------------------------------------------------------------*/
static inline void NVRAM_SPIChangeMode(SPITransMode continuous)
{
reg_SPI_SPICNT = (u16)((0x0001 << REG_SPI_SPICNT_E_SHIFT) |
(0x0000 << REG_SPI_SPICNT_I_SHIFT) |
(SPI_COMMPARTNER_EEPROM << REG_SPI_SPICNT_SEL_SHIFT) |
(continuous << REG_SPI_SPICNT_MODE_SHIFT) |
(0x0000 << REG_SPI_SPICNT_BUSY_SHIFT) |
(SPI_BAUDRATE_4MHZ << REG_SPI_SPICNT_BAUDRATE_SHIFT));
}
/*===========================================================================*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LIBRARIES_NVRAM_SP_H_ */
/*---------------------------------------------------------------------------*
End of file
*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,55 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - libraries - spi
# File: Makefile
#
# Copyright 2007 Nintendo. All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law. They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
SUBDIRS =
#----------------------------------------------------------------------------
# build ARM & THUMB libraries
TWL_CODEGEN_ALL ?= True
TWL_PROC = ARM7
SRCDIR = .
SRCDIR += $(TWL_NITROSDK_ROOT)/build/libraries/spi/ARM7/nvram/src \
SRCS = nvram_sp.c nvram_instruction.c
TARGET_LIB = libnvram_sp$(TWL_LIBSUFFIX).a
INCDIR = $(TWL_NITROSDK_ROOT)/build/libraries/spi/ARM7/include
#----------------------------------------------------------------------------
# DEBUG版ビルドの場合、RELEASE版でビルドして
# DEBUG版のライブラリを装います。
ifdef NITRO_DEBUG
NITRO_BUILD_TYPE = RELEASE
endif
include $(TWLSDK_ROOT)/build/buildtools/commondefs
INSTALL_TARGETS = $(TARGETS)
INSTALL_DIR = $(TWL_INSTALL_LIBDIR)
#----------------------------------------------------------------------------
do-build: $(TARGETS)
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,34 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlSDK - libraries - spi
# File: Makefile
#
# Copyright 2007 Nintendo. All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law. They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
# $Log: $
# $NoKeywords: $
#----------------------------------------------------------------------------
include $(TWLSDK_ROOT)/build/buildtools/commondefs
#----------------------------------------------------------------------------
# SUBDIRS = ARM9
ifdef TWL_WITH_ARM7
SUBDIRS += ARM7
endif
#----------------------------------------------------------------------------
include $(TWLSDK_ROOT)/build/buildtools/modulerules
#===== End of Makefile =====

View File

@ -0,0 +1,201 @@
/*---------------------------------------------------------------------------*
Project: TwlSDK - SPI
File: spi.h
Copyright 2007 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Log: $
$NoKeywords: $
*---------------------------------------------------------------------------*/
#ifndef TWL_SPI_SPI_H_
#define TWL_SPI_SPI_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <nitro/ioreg.h>
#include <nitro/hw/ARM7/ioreg_SPI.h>
//----------------------------------------------------------------
// enums
//
//---- SPI baud rate
typedef enum
{
SPI_BAUDRATE_4MHZ = 0,
SPI_BAUDRATE_2MHZ = 1,
SPI_BAUDRATE_1MHZ = 2,
SPI_BAUDRATE_512KHZ = 3,
SPI_BAUDRATE_8MHZ = 4
}
SPIBaudRate;
//---- SPI baud rate
typedef enum
{
SPI_TRANSMODE_1BYTE = 0,
SPI_TRANSMODE_CONTINUOUS = 1
}
SPITransMode;
//---- Clock mode
#ifdef SDK_TS
typedef enum
{
SPI_CLKMODE_8CLK = 0,
SPI_CLKMODE_16CLK = 1
}
SPIClockMode;
#endif
//---- communication partner
#ifdef SDK_TS
typedef enum
{
SPI_COMMPARTNER_PMIC = 0,
SPI_COMMPARTNER_EEPROM = 1,
SPI_COMMPARTNER_TP = 2
}
SPICommPartner;
#else /* !SDK_TS */
typedef enum
{
SPI_COMMPARTNER_PMIC = 0,
SPI_COMMPARTNER_EEPROM = 1
}
SPICommPartner;
#define SPI_COMMPARTNER_TP (SPI_COMMPARTNER_PMIC)
#endif
//----------------------------------------------------------------
// assertion definition
//
#define SPI_COMMPARTNER_ASSERT( x ) SDK_ASSERT( (u32)x <= SPI_COMMPARTNER_EEPROM )
#define SPI_TRANSMODE_ASSERT( x ) SDK_ASSERT( (u32)x <= SPI_TRANSMODE_CONTINUOUS )
#define SPI_BAUDRATE_ASSERT( x ) SDK_ASSERT( (u32)x <= SPI_BAUDRATE_512KHZ )
//----------------------------------------------------------------
//---- enable/disable/restore SPIEnable
static inline BOOL SPI_Enable(void)
{
BOOL pre = (reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK) >> REG_SPI_SPICNT_E_SHIFT;
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK) | (1UL << REG_SPI_SPICNT_E_SHIFT));
return pre;
}
static inline BOOL SPI_Disable(void)
{
BOOL pre = (reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK) >> REG_SPI_SPICNT_E_SHIFT;
reg_SPI_SPICNT = (u16)((reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK));
return pre;
}
static inline BOOL SPI_Restore(BOOL flag)
{
BOOL pre = (reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK) >> REG_SPI_SPICNT_E_SHIFT;
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & ~REG_SPI_SPICNT_E_MASK) |
(flag ? 1UL << REG_SPI_SPICNT_E_SHIFT : 0));
return pre;
}
//----------------------------------------------------------------
//---- Set/Get Interrupt
static inline void SPI_SetInterrupt(BOOL e)
{
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & REG_SPI_SPICNT_I_MASK) | (e ? 1UL << REG_SPI_SPICNT_I_SHIFT : 0));
}
static inline BOOL SPI_GetInterrupt(void)
{
return (BOOL)((reg_SPI_SPICNT & REG_SPI_SPICNT_I_MASK) >> REG_SPI_SPICNT_I_SHIFT);
}
//----------------------------------------------------------------
//---- Set/Get comminucation partner
static inline void SPI_SetCommPartner(SPICommPartner p)
{
SPI_COMMPARTNER_ASSERT(p);
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & REG_SPI_SPICNT_SEL_MASK) | (p << REG_SPI_SPICNT_SEL_SHIFT));
}
static inline SPICommPartner SPI_GetCommPartner(void)
{
return (SPICommPartner)((reg_SPI_SPICNT & REG_SPI_SPICNT_SEL_MASK) >> REG_SPI_SPICNT_SEL_SHIFT);
}
//----------------------------------------------------------------
//---- set/Get Transfer mode
static inline void SPI_SetTransMode(SPITransMode mode)
{
SPI_TRANSMODE_ASSERT(mode);
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & REG_SPI_SPICNT_MODE_MASK) | (mode << REG_SPI_SPICNT_MODE_SHIFT));
}
static inline SPITransMode SPI_GetTransMode(void)
{
return (SPITransMode)((reg_SPI_SPICNT & REG_SPI_SPICNT_MODE_MASK) >> REG_SPI_SPICNT_MODE_SHIFT);
}
//----------------------------------------------------------------
//---- check SPI is busy
static inline BOOL SPI_IsBusy(void)
{
return (BOOL)((reg_SPI_SPICNT & REG_SPI_SPICNT_BUSY_MASK) >> REG_SPI_SPICNT_BUSY_SHIFT);
}
//----------------------------------------------------------------
//---- set/get Baudrate
static inline void SPI_SetBaudRate(SPIBaudRate baud)
{
SPI_BAUDRATE_ASSERT(baud);
reg_SPI_SPICNT =
(u16)((reg_SPI_SPICNT & REG_SPI_SPICNT_BAUDRATE_MASK) |
(baud << REG_SPI_SPICNT_BAUDRATE_SHIFT));
}
static inline SPIBaudRate SPI_GetBaudRate(void)
{
return (SPIBaudRate)((reg_SPI_SPICNT & REG_SPI_SPICNT_BAUDRATE_MASK) >>
REG_SPI_SPICNT_BAUDRATE_SHIFT);
}
//----------------------------------------------------------------
//---- set/get data to/from SPI
static inline void SPI_SendData(u8 data)
{
reg_SPI_SPID = (u16)data;
}
static inline u8 SPI_GetData(void)
{
return (u8)(reg_SPI_SPICNT & 0xff);
}
//----------------------------------------------------------------
// subroutine definition
//
void SPI_Init(u32 prio);
#ifdef __cplusplus
} /* extern "C" */
#endif
/* TWL_SPI_SPI_H_ */
#endif