diff --git a/build/libraries/i2c/ARM7/src/i2c_instruction.c b/build/libraries/i2c/ARM7/src/i2c_instruction.c index 40e0f1a..b3f4db9 100644 --- a/build/libraries/i2c/ARM7/src/i2c_instruction.c +++ b/build/libraries/i2c/ARM7/src/i2c_instruction.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - libralies - i2c + Project: TwlSDK - libraties - i2c File: i2c_instruction.c Copyright 2007 Nintendo. All rights reserved. @@ -10,8 +10,9 @@ 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: $ + $Date:: 2007-09-19#$ + $Rev: 1004 $ + $Author: yutaka $ *---------------------------------------------------------------------------*/ #include #include @@ -29,7 +30,7 @@ #ifdef PRINT_DEBUG_MINI #include #define DBG_PRINT_FUNC() OS_TPrintf("%s(0x%02X, 0x%02X);\n", __func__, deviceAddrTable[id], reg) -#define DBG_PRINT_FUNC1(data) OS_TPrintf("%s(0x%02X, 0x%02X, 0x%02X, ...);\n", __func__, deviceAddrTable[id], reg, (data)) +#define DBG_PRINT_FUNC1(data) OS_TPrintf("%s(0x%02X, 0x%02X, 0x%02X);\n", __func__, deviceAddrTable[id], reg, (data)) #define DBG_PRINT_ERR() OS_TPrintf(" Failed(%d) @ %d\n", error, r) #else #define DBG_PRINT_FUNC() ((void)0) @@ -49,13 +50,13 @@ static const u8 deviceAddrTable[I2C_SLAVE_NUM] = { I2C_ADDR_DEBUG_LED, }; -/*static const*/ s32 I2CSlowRateTable[I2C_SLAVE_NUM] = { +/*static const*/ s32 slowRateTable[I2C_SLAVE_NUM] = { /* チューニングのため一時グローバル変数化 */ 0, // CODEC 0, // CAMERA_MICRON_IN 0, // CAMERA_MICRON_OUT 0, // CAMERA_SHARP_IN 0, // CAMERA_SHARP_OUT - 0x98, // MICRO_CONTROLLER + 0x100, // MICRO_CONTROLLER 0, // DEBUG_LED }; @@ -132,7 +133,6 @@ static inline void I2Ci_SetData( u8 data ) reg_EXI_I2CD = data; } - static inline u8 I2Ci_GetData( void ) { I2Ci_Wait(); @@ -146,10 +146,11 @@ static inline BOOL I2Ci_GetResult( void ) 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]; + slowRate = slowRateTable[id]; // set new value I2Ci_Wait(); I2Ci_SetData( (u8)(deviceAddrTable[id] | I2C_WRITE) ); I2Ci_Start(); @@ -218,12 +219,14 @@ static inline BOOL I2Ci_SendLast16( u16 data ) static inline u16 I2Ci_WaitReceiveMiddle16( void ) { - return (u16)((I2Ci_WaitReceiveMiddle() << 8) | I2Ci_WaitReceiveMiddle()); + u8 data = I2Ci_WaitReceiveMiddle(); + return (u16)((data << 8) | I2Ci_WaitReceiveMiddle()); } static inline u16 I2Ci_WaitReceiveLast16( void ) { - return (u16)((I2Ci_WaitReceiveMiddle() << 8) | I2Ci_WaitReceiveLast()); + u8 data = I2Ci_WaitReceiveMiddle(); + return (u16)((data << 8) | I2Ci_WaitReceiveLast()); } /*---------------------------------------------------------------------------* @@ -256,8 +259,10 @@ BOOL I2C_Init( void ) *---------------------------------------------------------------------------*/ BOOL I2C_Lock( void ) // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を取得する { - if( isInitialized == FALSE ) { - if( FALSE == I2C_Init() ) { + if( isInitialized == FALSE ) + { + if( FALSE == I2C_Init() ) + { return FALSE; } } @@ -276,8 +281,10 @@ BOOL I2C_Lock( void ) // *---------------------------------------------------------------------------*/ BOOL I2C_Unlock( void ) // 外部スレッドから呼ばれ、I2Cデバイスの操作権利を解放する { - if( isInitialized == FALSE ) { - if( FALSE == I2C_Init() ) { + if( isInitialized == FALSE ) + { + if( FALSE == I2C_Init() ) + { return FALSE; } } diff --git a/build/tests/mcu/mcu-1/ARM7/src/main.c b/build/tests/mcu/mcu-1/ARM7/src/main.c index a0f4b4a..8c2fc57 100644 --- a/build/tests/mcu/mcu-1/ARM7/src/main.c +++ b/build/tests/mcu/mcu-1/ARM7/src/main.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - MCU - demos - mcu-1 + Project: TwlSDK - tests - mcu - mcu-1 File: main.c Copyright 2007 Nintendo. All rights reserved. @@ -10,12 +10,15 @@ 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: main.c,v $ - $NoKeywords: $ + $Date:: $ + $Rev$ + $Author$ *---------------------------------------------------------------------------*/ -#include -//================================================================================ +#include +#include + + static void dump(const char *str, void *ptr, u32 length) { u8 *rdata = (u8*)ptr; @@ -29,47 +32,97 @@ static void dump(const char *str, void *ptr, u32 length) OS_TPrintf("\n"); } -extern s32 I2CSlowRateTable[]; - static void test_normal(void) { + u8 state; OS_TPrintf("\n\n[%s]\n\n", __func__); - OS_TPrintf("MCU_IsResetRequest: %s\n", MCU_IsResetRequest() ? "TRUE" : "FALSE"); + state = (u8)MCU_IsResetRequest(); + OS_TPrintf("MCU_IsResetRequest() : %s\n", state ? "TRUE" : "FALSE"); OS_TPrintf("\n"); - OS_TPrintf("MCU_IsWifi : %s\n", MCU_IsWifi() ? "TRUE" : "FALSE"); - OS_TPrintf("MCU_SetWifi(TRUE) : %s\n", MCU_SetWifi(TRUE) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_IsWifi : %s\n", MCU_IsWifi() ? "TRUE" : "FALSE"); + state = (u8)MCU_GetWifiLedStatus(); + OS_TPrintf("MCU_GetWifiLedStatus() : %s\n", state ? "TRUE" : "FALSE"); + state = (u8)MCU_SetWifiLedStatus(TRUE); + OS_TPrintf("MCU_SetWifiLedStatus(TRUE) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetWifiLedStatus(); + OS_TPrintf("MCU_GetWifiLedStatus() : %s\n", state ? "TRUE" : "FALSE"); SVC_WaitByLoop(0x100000); - OS_TPrintf("MCU_SetWifi(FALSE): %s\n", MCU_SetWifi(FALSE) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_IsWifi : %s\n", MCU_IsWifi() ? "TRUE" : "FALSE"); + state = (u8)MCU_SetWifiLedStatus(FALSE); + OS_TPrintf("MCU_SetWifiLedStatus(FALSE) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetWifiLedStatus(); + OS_TPrintf("MCU_GetWifiLedStatus() : %s\n", state ? "TRUE" : "FALSE"); OS_TPrintf("\n"); - OS_TPrintf("MCU_GetCameraPattern : %s\n", MCU_GetCameraPattern() ? "Blink" : "None"); - OS_TPrintf("MCU_SetCameraPattern(MCU_CAMERA_PATTERN_BLINK): %s\n", MCU_SetCameraPattern(MCU_CAMERA_PATTERN_BLINK) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_GetCameraPattern : %s\n", MCU_GetCameraPattern() ? "Blink" : "None"); - OS_TPrintf("MCU_SetCameraPattern(MCU_CAMERA_PATTERN_NONE) : %s\n", MCU_SetCameraPattern(MCU_CAMERA_PATTERN_NONE) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_GetCameraPattern : %s\n", MCU_GetCameraPattern() ? "Blink" : "None"); + state = (u8)MCU_GetCameraLedPattern(); + OS_TPrintf("MCU_GetCameraLedPattern() : %s\n", state ? "Blink" : "None"); + state = (u8)MCU_SetCameraLedPattern(MCU_CAMLED_PATTERN_BLINK); + OS_TPrintf("MCU_SetCameraLedPattern(BLINK) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCameraLedPattern(); + OS_TPrintf("MCU_GetCameraLedPattern() : %s\n", state ? "Blink" : "None"); + state = (u8)MCU_SetCameraLedPattern(MCU_CAMLED_PATTERN_NONE); + OS_TPrintf("MCU_SetCameraLedPattern(NONE) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCameraLedPattern(); + OS_TPrintf("MCU_GetCameraLedPattern() : %s\n", state ? "Blink" : "None"); OS_TPrintf("\n"); - OS_TPrintf("MCU_GetVolume : %d\n", MCU_GetVolume()); - OS_TPrintf("MCU_SetVolume(15): %s\n", MCU_SetVolume(15) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_GetVolume : %d\n", MCU_GetVolume()); - OS_TPrintf("MCU_SetVolume(31): %s\n", MCU_SetVolume(31) ? "SUCCESS" : "FAILED"); - OS_TPrintf("MCU_GetVolume : %d\n", MCU_GetVolume()); + state = (u8)MCU_GetCardLedStatus(1); + OS_TPrintf("MCU_GetCardLedStatus(1) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); + state = (u8)MCU_SetCardLedStatus(1, MCU_CARDLED_STATUS_ON); + OS_TPrintf("MCU_SetCardLedStatus(1, ON) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCardLedStatus(1); + OS_TPrintf("MCU_GetCardLedStatus(1) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); + SVC_WaitByLoop(0x100000); + state = (u8)MCU_SetCardLedStatus(1, MCU_CARDLED_STATUS_AUTO); + OS_TPrintf("MCU_SetCardLedStatus(1, AUTO) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCardLedStatus(1); + OS_TPrintf("MCU_GetCardLedStatus(1) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); OS_TPrintf("\n"); - OS_TPrintf("MCU_GetVersion : %d\n", MCU_GetVersion()); - OS_TPrintf("MCU_GetRevision: %d\n", MCU_GetRevision()); + state = (u8)MCU_GetCardLedStatus(2); + OS_TPrintf("MCU_GetCardLedStatus(2) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); + state = (u8)MCU_SetCardLedStatus(2, MCU_CARDLED_STATUS_ON); + OS_TPrintf("MCU_SetCardLedStatus(2, ON) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCardLedStatus(2); + OS_TPrintf("MCU_GetCardLedStatus(2) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); + SVC_WaitByLoop(0x100000); + state = (u8)MCU_SetCardLedStatus(2, MCU_CARDLED_STATUS_AUTO); + OS_TPrintf("MCU_SetCardLedStatus(2, AUTO) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetCardLedStatus(2); + OS_TPrintf("MCU_GetCardLedStatus(2) : %s\n", state == 0 ? "Auto" : (state == 1 ? "Off" : "On")); + OS_TPrintf("\n"); + + state = (u8)MCU_GetVolume(); + OS_TPrintf("MCU_GetVolume() : %d\n", state); + state = (u8)MCU_SetVolume(15); + OS_TPrintf("MCU_SetVolume(15) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetVolume(); + OS_TPrintf("MCU_GetVolume() : %d\n", state); + state = (u8)MCU_SetVolume(31); + OS_TPrintf("MCU_SetVolume(31) : %s\n", state ? "SUCCESS" : "FAILED"); + state = (u8)MCU_GetVolume(); + OS_TPrintf("MCU_GetVolume() : %d\n", state); + OS_TPrintf("\n"); + + state = (u8)MCU_GetVersion(); + OS_TPrintf("MCU_GetVersion() : %d\n", state); + state = (u8)MCU_GetRevision(); + OS_TPrintf("MCU_GetRevision() : %d\n", state); OS_TPrintf("\n"); } +/* + slowRateTableは、I2Cライブラリの一部で、パラメータ調整用に + 一時的にグローバル変数にしている。 + 最終的にstatic変数にするか、残すなら名前を変える必要がある。 +*/ +extern s32 slowRateTable[]; + static void test_tuning(void) { u8 rdata[10]; u8 wdata[10]; - s32 *pInterval = &I2CSlowRateTable[I2C_SLAVE_MICRO_CONTROLLER]; + s32 *pInterval = &slowRateTable[I2C_SLAVE_MICRO_CONTROLLER]; const u8 offset = 0x0; const u32 nums = sizeof(rdata); const int times = 200; @@ -85,7 +138,7 @@ static void test_tuning(void) } // rough tuning - for (i = 6; i < 30; i++) + for (i = 4; i < 30; i++) { *pInterval = 1 << i; SVC_WaitByLoop(0x200); @@ -95,7 +148,7 @@ static void test_tuning(void) wdata[j]++; } - if (MCU_GetFreeRegisters(offset, wdata, nums) && MCU_SetFreeRegisters(offset, rdata, nums)) + if (MCU_SetFreeRegisters(offset, wdata, nums) && MCU_GetFreeRegisters(offset, rdata, nums)) { for (j = 0; j < nums; j++) { @@ -124,7 +177,7 @@ static void test_tuning(void) wdata[j]++; } - if (!MCU_GetFreeRegisters(offset, wdata, nums) || !MCU_SetFreeRegisters(offset, rdata, nums)) + if (!MCU_SetFreeRegisters(offset, wdata, nums) || !MCU_GetFreeRegisters(offset, rdata, nums)) { break; } @@ -152,7 +205,7 @@ static void test_tuning(void) wdata[j] = (u8)(nums + j + k); } - if (MCU_GetFreeRegisters(offset, wdata, nums) && MCU_SetFreeRegisters(offset, rdata, nums)) + if (MCU_SetFreeRegisters(offset, wdata, nums) && MCU_GetFreeRegisters(offset, rdata, nums)) { for (j = 0; j < nums; j++) { @@ -182,18 +235,20 @@ static void test_tuning(void) SVC_WaitByLoop(max); OS_TPrintf("== %d usec\n", (int)OS_TicksToMicroSeconds(OS_GetTick()-begin)); } + // aging OS_TPrintf("\naging..."); for (k = 0; k < times; k++) { for (j = 0; j < nums; j++) { - wdata[j]++; + wdata[j]--; } - - if (!MCU_GetFreeRegisters(offset, wdata, nums) || !MCU_SetFreeRegisters(offset, rdata, nums)) + if (!MCU_SetFreeRegisters(offset, wdata, nums) || !MCU_GetFreeRegisters(offset, rdata, nums)) { (*pInterval)++; + k = 0; + SVC_WaitByLoop(0x100); continue; } for (j = 0; j < nums; j++) @@ -201,6 +256,8 @@ static void test_tuning(void) if (wdata[j] != rdata[j]) { (*pInterval)++; + k = 0; + SVC_WaitByLoop(0x100); continue; } } @@ -217,7 +274,7 @@ static void test_tuning(void) } /*---------------------------------------------------------------------------* - Name: TwlMain + Name: TwlSpMain Description: main @@ -225,7 +282,7 @@ static void test_tuning(void) Returns: None *---------------------------------------------------------------------------*/ -void TwlMain() +void TwlSpMain() { OS_Init(); diff --git a/include/twl/mcu/ARM7/mcu.h b/include/twl/mcu/ARM7/mcu.h index cad44ce..83d082b 100644 --- a/include/twl/mcu/ARM7/mcu.h +++ b/include/twl/mcu/ARM7/mcu.h @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - libraries - mcu - File: i2c.h + Project: TwlSDK - mcu - include + File: control.h Copyright 2007 Nintendo. All rights reserved. @@ -10,16 +10,21 @@ 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: $ + $Date:: $ + $Rev$ + $Author$ *---------------------------------------------------------------------------*/ -#ifndef TWL_MCU_ARM7_MCU_H_ -#define TWL_MCU_ARM7_MCU_H_ +#ifndef TWL_MCU_CONTROL_H_ +#define TWL_MCU_CONTROL_H_ #include #include #include +#ifdef _cplusplus +extern "C" { +#endif + typedef enum { MCU_SYSTEMMODE_NITRO = 0, @@ -29,16 +34,57 @@ MCUSystemMode; typedef enum { - MCU_CAMERA_PATTERN_NONE = 0, - MCU_CAMERA_PATTERN_BLINK = 1 + MCU_CAMLED_PATTERN_NONE = 0, + MCU_CAMLED_PATTERN_BLINK = 1 } -MCUCameraPattern; +MCUCameraLedPattern; -#define MCU_CAMLED_BLINK 1 +typedef enum +{ + MCU_CARDLED_STATUS_AUTO = 0, + MCU_CARDLED_STATUS_OFF = 1, + MCU_CARDLED_STATUS_ON = 2, + MCU_CARDLED_STATUS_ERROR = 3 /* MCU is treated as ON */ +} +MCUCardLedStatus; -#ifdef _cplusplus -extern "C" { -#endif +/*---------------------------------------------------------------------------* + Name: MCU_GetVersion + + Description: get version. + + Arguments: None + + Returns: 0xFF if error, otherwise version (0-3) + *---------------------------------------------------------------------------*/ +static inline u8 MCU_GetVersion( void ) +{ + u8 data; + if ( MCU_ReadRegisters( MCU_REG_INFO_ADDR, &data, 1 ) ) + { + return (u8)( ( data & MCU_REG_INFO_VERSION_MASK ) >> MCU_REG_INFO_VERSION_SHIFT ); + } + return 0xFF; // error +} + +/*---------------------------------------------------------------------------* + Name: MCU_GetRevision + + Description: get revision. + + Arguments: None + + Returns: 0xFF if error, otherwise revision (0-3) + *---------------------------------------------------------------------------*/ +static inline u8 MCU_GetRevision( void ) +{ + u8 data; + if ( MCU_ReadRegisters( MCU_REG_INFO_ADDR, &data, 1 ) ) + { + return (u8)( ( data & MCU_REG_INFO_REVISION_MASK ) >> MCU_REG_INFO_REVISION_SHIFT ); + } + return 0xFF; // error +} /*---------------------------------------------------------------------------* Name: MCU_IsResetRequest @@ -88,7 +134,7 @@ static inline BOOL MCU_GoDsMode( void ) } /*---------------------------------------------------------------------------* - Name: MCU_IsWifi + Name: MCU_GetWifiLedStatus Description: get wifi LED status @@ -96,18 +142,18 @@ static inline BOOL MCU_GoDsMode( void ) Returns: TRUE is on *---------------------------------------------------------------------------*/ -static inline BOOL MCU_IsWifi( void ) +static inline BOOL MCU_GetWifiLedStatus( void ) { u8 data; - if ( MCU_ReadRegisters( MCU_REG_WIFI_ADDR, &data, 1 ) ) + if ( MCU_ReadRegisters( MCU_REG_WIFILED_ADDR, &data, 1 ) ) { - return ( data & MCU_REG_WIFI_MASK ) >> MCU_REG_WIFI_SHIFT; + return ( data & MCU_REG_WIFILED_MASK ) >> MCU_REG_WIFILED_SHIFT; } return FALSE; // error } /*---------------------------------------------------------------------------* - Name: MCU_SetWifiLed + Name: MCU_SetWifiLedStatus Description: set wifi LED status @@ -115,13 +161,13 @@ static inline BOOL MCU_IsWifi( void ) Returns: TRUE if success *---------------------------------------------------------------------------*/ -static inline BOOL MCU_SetWifi( BOOL enabled ) +static inline BOOL MCU_SetWifiLedStatus( BOOL enabled ) { - return MCU_SetParams( MCU_REG_WIFI_ADDR, (u8)( enabled ? MCU_REG_WIFI_MASK : 0 ), MCU_REG_WIFI_MASK ); + return MCU_SetParams( MCU_REG_WIFILED_ADDR, (u8)( enabled ? MCU_REG_WIFILED_MASK : 0 ), MCU_REG_WIFILED_MASK ); } /*---------------------------------------------------------------------------* - Name: MCU_GetCameraPattern + Name: MCU_GetCameraLedPattern Description: get camera LED status. @@ -129,18 +175,18 @@ static inline BOOL MCU_SetWifi( BOOL enabled ) Returns: camera LED pattern *---------------------------------------------------------------------------*/ -static inline MCUCameraPattern MCU_GetCameraPattern( void ) +static inline MCUCameraLedPattern MCU_GetCameraLedPattern( void ) { u8 data; - if ( MCU_ReadRegisters( MCU_REG_CAMERA_ADDR, &data, 1 ) ) + if ( MCU_ReadRegisters( MCU_REG_CAMLED_ADDR, &data, 1 ) ) { - return (MCUCameraPattern)( ( data & MCU_REG_CAMERA_PATTERN_MASK ) >> MCU_REG_CAMERA_PATTERN_SHIFT ); + return (MCUCameraLedPattern)( ( data & MCU_REG_CAMLED_PATTERN_MASK ) >> MCU_REG_CAMLED_PATTERN_SHIFT ); } - return MCU_CAMERA_PATTERN_NONE; // error + return MCU_CAMLED_PATTERN_NONE; // error } /*---------------------------------------------------------------------------* - Name: MCU_SetCameraPattern + Name: MCU_SetCameraLedPattern Description: set camera LED status. @@ -148,9 +194,49 @@ static inline MCUCameraPattern MCU_GetCameraPattern( void ) Returns: TRUE if sucess *---------------------------------------------------------------------------*/ -static inline BOOL MCU_SetCameraPattern( MCUCameraPattern pattern ) +static inline BOOL MCU_SetCameraLedPattern( MCUCameraLedPattern pattern ) { - return MCU_SetParams( MCU_REG_CAMERA_ADDR, (u8)( pattern << MCU_REG_CAMERA_PATTERN_SHIFT ), MCU_REG_CAMERA_PATTERN_MASK ); + return MCU_SetParams( MCU_REG_CAMLED_ADDR, (u8)( pattern << MCU_REG_CAMLED_PATTERN_SHIFT ), MCU_REG_CAMLED_PATTERN_MASK ); +} + +/*---------------------------------------------------------------------------* + Name: MCU_GetCardLedStatus + + Description: get card LED status. + NOTE: slot 1/2 does not correspond to MC_IF[A]/[B] + + Arguments: slot physical slot number (1 or 2) + + Returns: card LED status + *---------------------------------------------------------------------------*/ +static inline MCUCardLedStatus MCU_GetCardLedStatus( int slot ) +{ + u8 data; + u8 addr = (u8)(slot == 1 ? MCU_REG_CARDLED_1_ADDR : MCU_REG_CARDLED_2_ADDR); + SDK_ASSERT(slot == 1 || slot == 2); + if ( MCU_ReadRegisters( addr, &data, 1 ) ) + { + return (MCUCardLedStatus)( ( data & MCU_REG_CARDLED_MASK ) >> MCU_REG_CARDLED_SHIFT ); + } + return MCU_CARDLED_STATUS_ERROR; // error +} + +/*---------------------------------------------------------------------------* + Name: MCU_SetCardLedStatus + + Description: set card LED status. + NOTE: slot 1/2 does not correspond to MC_IF[A]/[B] + + Arguments: slot physical slot number (1 or 2) + status one of card LED status + + Returns: TRUE if sucess + *---------------------------------------------------------------------------*/ +static inline BOOL MCU_SetCardLedStatus( int slot, MCUCardLedStatus status ) +{ + u8 addr = (u8)(slot == 1 ? MCU_REG_CARDLED_1_ADDR : MCU_REG_CARDLED_2_ADDR); + SDK_ASSERT(slot == 1 || slot == 2); + return MCU_SetParams( addr, (u8)( status << MCU_REG_CARDLED_SHIFT ), MCU_REG_CARDLED_MASK ); } /*---------------------------------------------------------------------------* @@ -190,44 +276,6 @@ static inline BOOL MCU_SetVolume( u8 volume ) return FALSE; // invalid parameters } -/*---------------------------------------------------------------------------* - Name: MCU_GetVersion - - Description: get version. - - Arguments: None - - Returns: 0xFF if error, otherwise version (0-3) - *---------------------------------------------------------------------------*/ -static inline u8 MCU_GetVersion( void ) -{ - u8 data; - if ( MCU_ReadRegisters( MCU_REG_INFO_ADDR, &data, 1 ) ) - { - return (u8)( ( data & MCU_REG_INFO_VERSION_MASK ) >> MCU_REG_INFO_VERSION_SHIFT ); - } - return 0xFF; // error -} - -/*---------------------------------------------------------------------------* - Name: MCU_GetRevision - - Description: get revision. - - Arguments: None - - Returns: 0xFF if error, otherwise revision (0-3) - *---------------------------------------------------------------------------*/ -static inline u8 MCU_GetRevision( void ) -{ - u8 data; - if ( MCU_ReadRegisters( MCU_REG_INFO_ADDR, &data, 1 ) ) - { - return (u8)( ( data & MCU_REG_INFO_REVISION_MASK ) >> MCU_REG_INFO_REVISION_SHIFT ); - } - return 0xFF; // error -} - /*---------------------------------------------------------------------------* Name: MCU_GetFreeRegisters @@ -272,5 +320,4 @@ static inline BOOL MCU_SetFreeRegisters( u8 offset, const u8 *bufp, u32 nums ) } /* extern "C" */ #endif -/* TWL_MCU_ARM7_MCU_H_ */ -#endif +#endif /* TWL_MCU_CONTROL_H_ */ diff --git a/include/twl/mcu/ARM7/mcu_reg.h b/include/twl/mcu/ARM7/mcu_reg.h index adc5979..1430b9c 100644 --- a/include/twl/mcu/ARM7/mcu_reg.h +++ b/include/twl/mcu/ARM7/mcu_reg.h @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - libraries - mcu + Project: TwlSDK - mcu - include File: mcu_reg.h Copyright 2007 Nintendo. All rights reserved. @@ -10,21 +10,36 @@ 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: $ + $Date:: $ + $Rev$ + $Author$ *---------------------------------------------------------------------------*/ -#ifndef TWL_MCU_ARM7_MCU_REG_H_ -#define TWL_MCU_ARM7_MCU_REG_H_ +#ifndef TWL_MCU_MCU_REG_H_ +#define TWL_MCU_MCU_REG_H_ -#define MCU_REG_IRQ_ADDR 0x00 -#define MCU_REG_MODE_ADDR 0x01 -#define MCU_REG_WIFI_ADDR 0x02 -#define MCU_REG_CAMERA_ADDR 0x03 -#define MCU_REG_VOLUME_ADDR 0x04 -#define MCU_REG_INFO_ADDR 0x05 +#define MCU_REG_INFO_ADDR 0x00 +#define MCU_REG_IRQ_ADDR 0x01 +#define MCU_REG_MODE_ADDR 0x02 -#define MCU_REG_TEMP_ADDR 0x06 -#define MCU_REG_TEMP_LAST_ADDR 0x25 +#define MCU_REG_WIFILED_ADDR 0x10 +#define MCU_REG_CAMLED_ADDR 0x11 +#define MCU_REG_CARDLED_1_ADDR 0x12 +#define MCU_REG_CARDLED_2_ADDR 0x13 + +#define MCU_REG_VOLUME_ADDR 0x20 + +#define MCU_REG_TEMP_ADDR 0x21 +#define MCU_REG_TEMP_LAST_ADDR 0x30 + +/* MCU_REG_INFO */ + +#define MCU_REG_INFO_VERSION_SHIFT 4 +#define MCU_REG_INFO_VERSION_SIZE 4 +#define MCU_REG_INFO_VERSION_MASK 0xf0 + +#define MCU_REG_INFO_REVISION_SHIFT 0 +#define MCU_REG_INFO_REVISION_SIZE 4 +#define MCU_REG_INFO_REVISION_MASK 0x0f /* MCU_REG_IRQ */ @@ -38,21 +53,35 @@ #define MCU_REG_MODE_SYSTEM_SIZE 2 #define MCU_REG_MODE_SYSTEM_MASK 0x03 -/* MCU_REG_WIFI */ +/* MCU_REG_WIFILED */ -#define MCU_REG_WIFI_SHIFT 0 -#define MCU_REG_WIFI_SIZE 1 -#define MCU_REG_WIFI_MASK 0x01 +#define MCU_REG_WIFILED_SHIFT 0 +#define MCU_REG_WIFILED_SIZE 1 +#define MCU_REG_WIFILED_MASK 0x01 -/* MCU_REG_CAMERA */ +/* MCU_REG_CAMLED */ -#define MCU_REG_CAMERA_PATTERN_SHIFT 4 -#define MCU_REG_CAMERA_PATTERN_SIZE 4 -#define MCU_REG_CAMERA_PATTERN_MASK 0xf0 +#define MCU_REG_CAMLED_PATTERN_SHIFT 4 +#define MCU_REG_CAMLED_PATTERN_SIZE 4 +#define MCU_REG_CAMLED_PATTERN_MASK 0xf0 -#define MCU_REG_CAMERA_PARAM_SHIFT 0 -#define MCU_REG_CAMERA_PARAM_SIZE 4 -#define MCU_REG_CAMERA_PARAM_MASK 0x0f +#define MCU_REG_CAMLED_PARAM_SHIFT 0 +#define MCU_REG_CAMLED_PARAM_SIZE 4 +#define MCU_REG_CAMLED_PARAM_MASK 0x0f + +/* MCU_REG_CARDLED_1, MCU_REG_CARDLED_2 */ + +#define MCU_REG_CARDLED_SHIFT 0 +#define MCU_REG_CARDLED_SIZE 2 +#define MCU_REG_CARDLED_MASK 0x03 + +#define MCU_REG_CARDLED_1_SHIFT MCU_REG_CARDLED_SHIFT +#define MCU_REG_CARDLED_1_SIZE MCU_REG_CARDLED_SIZE +#define MCU_REG_CARDLED_1_MASK MCU_REG_CARDLED_MASK + +#define MCU_REG_CARDLED_2_SHIFT MCU_REG_CARDLED_SHIFT +#define MCU_REG_CARDLED_2_SIZE MCU_REG_CARDLED_SIZE +#define MCU_REG_CARDLED_2_MASK MCU_REG_CARDLED_MASK /* MCU_REG_VOL */ @@ -60,14 +89,4 @@ #define MCU_REG_VOLUME_SIZE 5 #define MCU_REG_VOLUME_MASK 0x1f -/* MCU_REG_INFO */ - -#define MCU_REG_INFO_VERSION_SHIFT 4 -#define MCU_REG_INFO_VERSION_SIZE 4 -#define MCU_REG_INFO_VERSION_MASK 0xf0 - -#define MCU_REG_INFO_REVISION_SHIFT 0 -#define MCU_REG_INFO_REVISION_SIZE 4 -#define MCU_REG_INFO_REVISION_MASK 0x0f - -#endif /* TWL_MCU_ARM7_MCU_REG_H_ */ +#endif /* TWL_MCU_MCU_REG_H_ */