add micro control unit I2C layer and debug LEDs (TS board only).

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/twl_wrapsdk/trunk@256 4ee2a332-4b2b-5046-8439-1ba90f034370
This commit is contained in:
yutaka 2007-08-28 09:38:40 +00:00
parent 23135ddd77
commit ce92b15f3b
7 changed files with 287 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------*
Project: TwlSDK - libraties - i2c
Project: TwlSDK - libralies - i2c
File: i2c_instruction.c
Copyright 2007 Nintendo. All rights reserved.
@ -10,7 +10,7 @@
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: I2C_.c,v $
$Log: $
$NoKeywords: $
*---------------------------------------------------------------------------*/
#include <twl.h>
@ -28,7 +28,7 @@
#endif
#ifdef PRINT_DEBUG_MINI
#include <nitro/os/common/printf.h>
#define DBG_PRINT_FUNC() OS_TPrintf("%s(0x%02X, 0x%02X, ...);\n", __func__, I2C_DeviceAddrTable[id], reg)
#define DBG_PRINT_FUNC() OS_TPrintf("%s(0x%02X, 0x%02X, ...);\n", __func__, deviceAddrTable[id], reg)
#define DBG_PRINT_ERR() OS_TPrintf(" Failed(%d) @ %d\n", error, r)
#else
#define DBG_PRINT_FUNC() ((void)0)
@ -37,17 +37,31 @@
#define RETRY_COUNT 8
static u8 I2C_DeviceAddrTable[I2C_SLAVE_NUM] = {
static const u8 deviceAddrTable[I2C_SLAVE_NUM] = {
I2C_ADDR_CODEC,
I2C_ADDR_CAMERA_MICRON_IN,
I2C_ADDR_CAMERA_MICRON_OUT,
I2C_ADDR_CAMERA_SHARP_IN,
I2C_ADDR_CAMERA_SHARP_OUT,
};
I2C_ADDR_MICRO_CONTROLLER,
I2C_ADDR_DEBUG_LED,
};
/*static const*/ s32 I2CSlowRateTable[I2C_SLAVE_NUM] = {
0, // CODEC
0, // CAMERA_MICRON_IN
0, // CAMERA_MICRON_OUT
0, // CAMERA_SHARP_IN
0, // CAMERA_SHARP_OUT
0x90, // MICRO_CONTROLLER
0, // DEBUG_LED
};
static OSMutex mutex;
static BOOL isInitialized = FALSE;
static BOOL slowRate = 0;
static inline void I2Ci_Start( void )
{
reg_EXI_I2CCNT = (u8)((1 << REG_EXI_I2CCNT_E_SHIFT) |
@ -89,6 +103,26 @@ static inline void I2Ci_StopPhase2( void )
(1 << REG_EXI_I2CCNT_NT_SHIFT));
}
static inline void I2Ci_WaitEx( void ) // support slowRate
{
I2Ci_Wait();
SVC_WaitByLoop(slowRate);
}
static inline void I2Ci_StopEx( I2CReadWrite rw ) // support slowRate
{
if (slowRate)
{
I2Ci_StopPhase1(rw);
I2Ci_Wait();
SVC_WaitByLoop(slowRate);
I2Ci_StopPhase2();
}
else
{
I2Ci_Stop(rw);
}
}
static inline void I2Ci_SetData( u8 data )
{
@ -105,23 +139,23 @@ static inline u8 I2Ci_GetData( void )
static inline BOOL I2Ci_GetResult( void )
{
I2Ci_Wait();
I2Ci_WaitEx();
DBG_PRINTF("%c", (reg_EXI_I2CCNT & REG_EXI_I2CCNT_ACK_MASK) ? '.' : '*');
return (BOOL)((reg_EXI_I2CCNT & REG_EXI_I2CCNT_ACK_MASK) >> REG_EXI_I2CCNT_ACK_SHIFT);
}
static inline BOOL I2Ci_SendStart( I2CSlave id )
{
DBG_PRINTF("\n");
slowRate = I2CSlowRateTable[id];
I2Ci_Wait();
I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | (u8)I2C_WRITE) );
I2Ci_SetData( (u8)(deviceAddrTable[id] | I2C_WRITE) );
I2Ci_Start();
return I2Ci_GetResult();
}
static inline BOOL I2Ci_SendMiddle( u8 data )
{
I2Ci_Wait();
I2Ci_WaitEx();
I2Ci_SetData( data );
I2Ci_Continue( I2C_WRITE );
return I2Ci_GetResult();
@ -129,43 +163,43 @@ static inline BOOL I2Ci_SendMiddle( u8 data )
static inline BOOL I2Ci_SendLast( u8 data )
{
I2Ci_Wait();
I2Ci_WaitEx();
I2Ci_SetData( data );
I2Ci_Stop( I2C_WRITE );
I2Ci_StopEx( I2C_WRITE );
return I2Ci_GetResult();
}
static inline BOOL I2Ci_ReceiveStart( I2CSlave id )
{
I2Ci_Wait();
I2Ci_SetData( (u8)(I2C_DeviceAddrTable[id] | I2C_READ) );
I2Ci_WaitEx();
I2Ci_SetData( (u8)(deviceAddrTable[id] | I2C_READ) );
I2Ci_Start();
return I2Ci_GetResult();
}
static inline void I2Ci_ReceiveMiddle( void )
{
I2Ci_Wait();
I2Ci_WaitEx();
I2Ci_Continue( I2C_READ );
}
static inline void I2Ci_ReceiveLast( void )
{
I2Ci_Wait();
I2Ci_Stop( I2C_READ );
I2Ci_WaitEx();
I2Ci_StopEx( I2C_READ );
}
static inline u8 I2Ci_WaitReceiveMiddle( void )
{
I2Ci_ReceiveMiddle();
I2Ci_Wait();
I2Ci_WaitEx();
return I2Ci_GetData();
}
static inline u8 I2Ci_WaitReceiveLast( void )
{
I2Ci_ReceiveLast();
I2Ci_Wait();
I2Ci_WaitEx();
return I2Ci_GetData();
}

View File

@ -25,6 +25,7 @@
#include <twl/mic.h>
#include <twl/camera.h>
#include <twl/dsp.h>
#include <twl/mcu.h>
#ifdef SDK_DEBUGGER_KMC
#include <twl/vlink.h>
#endif // SDK_DEBUGGER_KMC

View File

@ -36,6 +36,8 @@ typedef enum
I2C_SLAVE_CAMERA_MICRON_OUT,
I2C_SLAVE_CAMERA_SHARP_IN,
I2C_SLAVE_CAMERA_SHARP_OUT,
I2C_SLAVE_MICRO_CONTROLLER,
I2C_SLAVE_DEBUG_LED,
I2C_SLAVE_NUM
}
I2CSlave;
@ -55,6 +57,8 @@ I2CReadWrite;
#define I2C_ADDR_CAMERA_MICRON_OUT 0x78 // MICRON
#define I2C_ADDR_CAMERA_SHARP_IN 0xE0 // SHARP
#define I2C_ADDR_CAMERA_SHARP_OUT 0xA0 // SHARP
#define I2C_ADDR_MICRO_CONTROLLER 0x4A
#define I2C_ADDR_DEBUG_LED (0x20 << 1)
//----------------------------------------------------------------
// subroutine definition

25
include/twl/mcu.h Normal file
View File

@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------*
Project: TwlSDK - include - MCU
File: mcu.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_MCU_H_
#define TWL_MCU_H_
#ifdef SDK_ARM7
#include <twl/mcu/ARM7/i2c.h>
#endif
/* TWL_MCU_H_ */
#endif

172
include/twl/mcu/ARM7/i2c.h Normal file
View File

@ -0,0 +1,172 @@
/*---------------------------------------------------------------------------*
Project: TwlSDK - libraries - mcu
File: i2c.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_MCU_I2C_COMMON_H_
#define TWL_MCU_I2C_COMMON_H_
#include <twl/types.h>
#include <twl/i2c/ARM7/i2c.h>
#ifdef _cplusplus
extern "C" {
#endif
//================================================================================
// I2C ACCESS
//================================================================================
/*---------------------------------------------------------------------------*
Name: MCUi_WriteRegister
Description: set value to decive register through I2C.
Arguments: reg : decive register
data : value to be written
Returns: None
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_WriteRegister( u8 reg, u8 data )
{
return I2Ci_WriteRegister( I2C_SLAVE_MICRO_CONTROLLER, reg, data );
}
static inline BOOL MCU_WriteRegister( u8 reg, u8 data )
{
return I2C_WriteRegister( I2C_SLAVE_MICRO_CONTROLLER, reg, data );
}
/*---------------------------------------------------------------------------*
Name: MCUi_ReadRegister
Description: get value from decive register through I2C.
Arguments: reg : decive register
Returns: value which is read from specified decive register
*---------------------------------------------------------------------------*/
static inline u8 MCUi_ReadRegister( u8 reg )
{
return I2Ci_ReadRegister( I2C_SLAVE_MICRO_CONTROLLER, reg );
}
static inline u8 MCU_ReadRegister( u8 reg )
{
return I2C_ReadRegister( I2C_SLAVE_MICRO_CONTROLLER, reg );
}
/*---------------------------------------------------------------------------*
Name: MCUi_WriteRegisters
Description: set value to decive registers through I2C.
Arguments: reg : decive register
bufp : data array to be written
size : data size
Returns: None
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_WriteRegisters( u8 reg, const u8 *bufp, size_t size )
{
return I2Ci_WriteRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size );
}
static inline BOOL MCU_WriteRegisters( u8 reg, const u8 *bufp, size_t size )
{
return I2C_WriteRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size );
}
/*---------------------------------------------------------------------------*
Name: MCUi_ReadRegisters
Description: get value from decive registers through I2C.
Arguments: reg : decive register
bufp : data array to be read
size : data size
Returns: value which is read from specified decive register
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_ReadRegisters( u8 reg, u8 *bufp, size_t size )
{
return I2Ci_ReadRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size );
}
static inline BOOL MCU_ReadRegisters( u8 reg, u8 *bufp, size_t size )
{
return I2C_ReadRegisters( I2C_SLAVE_MICRO_CONTROLLER, reg, bufp, size );
}
//================================================================================
// I2C BIT CONTROL
//================================================================================
/*---------------------------------------------------------------------------*
Name: MCUi_SetParams
Description: set control bit to device register
Arguments: reg : device register
setBits : bits to set
maskBits : bits to mask
Returns: None
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_SetParams( u8 reg, u8 setBits, u8 maskBits )
{
return I2Ci_SetParams( I2C_SLAVE_MICRO_CONTROLLER, reg, setBits, maskBits );
}
static inline BOOL MCU_SetParams( u8 reg, u8 setBits, u8 maskBits )
{
return I2C_SetParams( I2C_SLAVE_MICRO_CONTROLLER, reg, setBits, maskBits );
}
/*---------------------------------------------------------------------------*
Name: MCUi_SetFlags
Description: set control bit to device register
Arguments: reg : device register
setBits : bits to set
Returns: None
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_SetFlags( u8 reg, u8 setBits )
{
return MCUi_SetParams( reg, setBits, setBits );
}
static inline BOOL MCU_SetFlags( u8 reg, u8 setBits )
{
return MCU_SetParams( reg, setBits, setBits );
}
/*---------------------------------------------------------------------------*
Name: MCUi_ClearFlags
Description: clear control bit to device register
Arguments: reg : device register
clrBits : bits to clear
Returns: None
*---------------------------------------------------------------------------*/
static inline BOOL MCUi_ClearFlags( u8 reg, u8 clrBits )
{
return MCUi_SetParams( reg, 0, clrBits );
}
static inline BOOL MCU_ClearFlags( u8 reg, u8 clrBits )
{
return MCU_SetParams( reg, 0, clrBits );
}
#ifdef _cplusplus
} /* extern "C" */
#endif
/* TWL_MCU_I2C_COMMON_H_ */
#endif

View File

@ -25,6 +25,8 @@
#ifdef SDK_ARM9
#include <twl/os/ARM9/cache_tag.h>
#else
#include <twl/os/ARM7/debugLED.h>
#endif // SDK_ARM9
#ifdef SDK_DEBUGGER_KMC

View File

@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------*
Project: TwlSDK - OS - include
File: debugLED.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.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#ifndef TWL_OS_DEBUG_LED_H_
#define TWL_OS_DEBUG_LED_H_
//#if PLATFORM == TS
#include <twl/i2c/ARM7/i2c.h>
#define OS_InitDebugLED() I2C_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00)
#define OS_SetDebugLED(pattern) I2C_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern))
#define OS_GetDebugLED() I2C_ReadRegister(I2C_SLAVE_DEBUG_LED, 0x01)
//#endif // PLATFORM == TS
/* TWL_OS_DEBUG_LED_H_ */
#endif