diff --git a/trunk/VCProj/bsr_trunk.sdf b/trunk/VCProj/bsr_trunk.sdf index d18c6a1..4a7b6da 100644 Binary files a/trunk/VCProj/bsr_trunk.sdf and b/trunk/VCProj/bsr_trunk.sdf differ diff --git a/trunk/VCProj/bsr_trunk.suo b/trunk/VCProj/bsr_trunk.suo index 9613782..e8275ca 100644 Binary files a/trunk/VCProj/bsr_trunk.suo and b/trunk/VCProj/bsr_trunk.suo differ diff --git a/trunk/batt_params.c b/trunk/batt_params.c index a863711..b427620 100644 --- a/trunk/batt_params.c +++ b/trunk/batt_params.c @@ -102,22 +102,22 @@ const bt_param_ bt_param[ /*_BT_PARAM_NUM_*/ ] = // { 0xF5, 0xF3 } // compare max, min }, - // bt_PARAM_SNAKE_PANA + // bt_PARAM_SNAKE_PANA '13 0422 再調整版 { { - 0x9D, 0xA0, 0xA8, 0xF0, 0xAD, 0x90, 0xAF, 0x00, - 0xB3, 0x00, 0xB3, 0xE0, 0xB4, 0xA0, 0xB5, 0x40, - 0xB6, 0x30, 0xB7, 0xE0, 0xB8, 0xC0, 0xBE, 0x70, - 0xC1, 0x40, 0xC4, 0x20, 0xC9, 0xA0, 0xD0, 0x30, - 0x01, 0x10, 0x06, 0x00, 0x2C, 0x20, 0x0D, 0xA0, - 0x37, 0x00, 0x37, 0x30, 0x47, 0xF0, 0x28, 0xF0, - 0x25, 0xF0, 0x37, 0x30, 0x10, 0xF0, 0x14, 0xF0, - 0x0F, 0x70, 0x0D, 0x00, 0x0D, 0x00, 0x0D, 0x00, + 0x9D, 0x80, 0xA3, 0x60, 0xA9, 0x50, 0xAD, 0x90, + 0xAF, 0x60, 0xB1, 0x60, 0xB3, 0x70, 0xB4, 0xE0, + 0xB6, 0x20, 0xB7, 0xF0, 0xB9, 0xA0, 0xBC, 0xB0, + 0xBF, 0xB0, 0xC5, 0xB0, 0xCB, 0x90, 0xD1, 0x50, + 0x00, 0xC0, 0x03, 0x40, 0x06, 0x80, 0x18, 0x20, + 0x16, 0xA0, 0x16, 0x20, 0x30, 0x00, 0x34, 0xA0, + 0x27, 0xC0, 0x23, 0x40, 0x11, 0xC0, 0x0F, 0xE0, + 0x0F, 0xE0, 0x0E, 0xE0, 0x0C, 0x20, 0x0C, 0x20 }, 2, - { 106, (-256* 0.925), (-256* 2.3) }, - 0xDA30, // = 55856 - { 0xE9, 0xE7 }, + { 89, (-256* 0.9), (-256* 2.5) }, + 56144, // 0xDB50 + { 232, 230 }, } diff --git a/trunk/bsr_system.h b/trunk/bsr_system.h index 4cd0707..ddf0f6c 100644 --- a/trunk/bsr_system.h +++ b/trunk/bsr_system.h @@ -15,6 +15,7 @@ enum pwr_state_ SLEEP, // WAKE, OFF, + DIRECT_BOOT_CHECK, }; enum poweron_reason_ diff --git a/trunk/config.h b/trunk/config.h index c8e1c8a..7c0cfa6 100644 --- a/trunk/config.h +++ b/trunk/config.h @@ -7,11 +7,14 @@ */ #define MCU_VER_MAJOR 0x02 -#define MCU_VER_MINOR 0x2E +#define MCU_VER_MINOR 0x40 +/* +内部管理バージョン 2.40 +*/ // ビルドスイッチ -#define _MCU_ARR // snake 系 +//#define _MCU_ARR // snake 系 // デバッグ向けスイッチ diff --git a/trunk/hal.c b/trunk/hal.c index e2e72ec..9cfa47a 100644 --- a/trunk/hal.c +++ b/trunk/hal.c @@ -21,6 +21,7 @@ bit SW_POW_n; bit SW_HOME_n; bit SW_WIFI_n; bit SHELL_OPEN; +//bit SW_SEL_n; // とりあえず、レジスタ操作未対応 /* #define REG_BIT_HAL0_PM_EXTDC_n ( 1 << 7 ) @@ -161,6 +162,10 @@ void hal_update() SHELL_OPEN = SHELL_OPEN_RAW; } + // sel キー + /// とりあえず、レジスタからの操作しない(ビット足りない、要レジスタ追加なので) + + // 無線電波発射 if( temp_conf & REG_BIT_HAL0_WL_TX ) { diff --git a/trunk/led.c b/trunk/led.c index 1bacaf3..bf62e07 100644 --- a/trunk/led.c +++ b/trunk/led.c @@ -93,6 +93,7 @@ u8 fade_to2( st_LED_dim_status* status ) } else { + // delta が小さいときは to の値にぶつけてしまう status->now = status->to; } } @@ -292,6 +293,11 @@ static void calc_info_led_fade_out( st_LED_dim_status* tgt_led ) { tgt_led -> to = 0; tgt_led -> delta = ( 0 - tgt_led -> now ) / 64; + // フェードアウト限定(ゼロに向かっていく。符号の向きを想定してしまう。) + if(( tgt_led -> now != 0 ) && ( tgt_led -> delta == 0 )) + { + tgt_led -> delta = (sx16)-1; + } } diff --git a/trunk/loader.c b/trunk/loader.c index f965104..19059cb 100644 --- a/trunk/loader.c +++ b/trunk/loader.c @@ -202,7 +202,7 @@ void chk_platform_type() #ifdef _DBG_FORCE_FLOWER // 強制的に機種設定をしてデバッグしたいとき -// system_status.family = FAMILY_FLOWER; + system_status.family = FAMILY_FLOWER; #endif #ifdef _MCU_ARR diff --git a/trunk/pm.h b/trunk/pm.h index b6cb8bc..4b377d0 100644 --- a/trunk/pm.h +++ b/trunk/pm.h @@ -148,6 +148,7 @@ extern u8 pmreg_v_core; // SoC err PM_sys_pow_on( ); void PM_sys_pow_off( ); //err PM_bt_auth( ); +void reset_release( ); void PM_LCD_vcom_set( ); err PM_LCD_on( ); @@ -162,8 +163,6 @@ void codec_reg_init(); void set_vdd_voltages( enum family_ family ); -void reset_release(); - task_status_immed tski_BT_temp_update( ); task_status_immed tski_vcom_set( ); task_status_immed tski_PM_LCD_on(); diff --git a/trunk/sw.c b/trunk/sw.c index be26b65..ab9c5a8 100644 --- a/trunk/sw.c +++ b/trunk/sw.c @@ -50,6 +50,11 @@ u16 off_timeout_timer; static u16 sw_pwsw_mukan_time; +//========================================================= +static void chk_pow_sw(); +static void chk_wifi_sw(); + + /********************************************//** 押した時間を数える。押しっぱなしでも0に戻らない @@ -98,7 +103,7 @@ static u16 sw_pwsw_mukan_time; /********************************************//** スイッチの監視 -  チャタリングをはねたり、長押しや、押したトリガなどの検出を行う + チャタリングをはねたり、長押しや、押したトリガなどの検出を行う ***********************************************/ void tsk_sw( ) { @@ -124,17 +129,47 @@ void tsk_sw( ) } // 8ms 毎にきます - switch ( system_status.pwr_state ) + switch( system_status.pwr_state ) { - case ( ON ): - case ( SLEEP ): - case ( OFF ): - case ( ON_CHECK ): + case( ON ): + case( SLEEP ): + chk_wifi_sw(); + if( !SHELL_OPEN ) + { + break; + } + // else 節の時は fall through (蓋閉じならpwswチェックをスキップ)。 + // 実装が良くない気もするが... + + // HOME sw // + chk_clicked( SW_HOME_n, SW_home_count, REG_BIT_SW_HOME_CLICK ); + chk_clicked( !SW_HOME_n, SW_home_count_rel, REG_BIT_SW_HOME_RELEASE ); + /* fall through */ + + case( OFF ): + case( ON_CHECK ): + chk_pow_sw(); + + break; + + default: + break; + } +} + + + +/********************************************//** + 電源スイッチの監視 + 試遊台、ホームメニューには入れないようにしたくて、自動起動にしてあるそうだが + mmen の不具合でホームメニューにいけてしまう事がある(市場クレーム有り) + なのでマイコンでその操作をマスクする。 + ***********************************************/ +static void chk_pow_sw() +{ // 実機の場合 if( ! system_status.taikendai ) { - - // 電源スイッチの監視 // if( SW_pow_count == ( TIME_PWSW_CLICK ) ) // クリック時間に到達 { if( is_wifi_calib_resets_ast ) // wifi キャリブレーション時なら、SoCに通知せずにoffに遷移 @@ -163,7 +198,6 @@ void tsk_sw( ) }else{ // スタンドアロン試遊台 - // 電源スイッチの監視 // if( SW_pow_count == ( TIME_PWSW_CLICK ) ) { if( sw_pwsw_mukan_time == 0 ) @@ -183,16 +217,19 @@ void tsk_sw( ) sw_pwsw_mukan_time--; } } + count_sw_n( SW_POW_n, SW_pow_count, SW_pow_mask ); // ボタン押し時間のカウント +} - // 実機・体験台共通 - count_sw_n( SW_POW_n, SW_pow_count, SW_pow_mask ); // ボタン押し時間のカウント - // HOME sw // - chk_clicked( SW_HOME_n, SW_home_count, REG_BIT_SW_HOME_CLICK ); - chk_clicked( !SW_HOME_n, SW_home_count_rel, REG_BIT_SW_HOME_RELEASE ); +/********************************************//** + wifi スイッチの監視 + 最悪な実装なのはわかっているが、市場に出てしまった不良スイッチを救うため + …そもそも他のスイッチも全部こうするのがいいんだろうけど + ***********************************************/ +static void chk_wifi_sw() +{ // wifi sw // - /// 最悪な実装なのはわかっているが、市場に出てしまった不良スイッチを救うため if( sw_wifi_mukan_time != 0 ) { sw_wifi_mukan_time--; @@ -205,9 +242,5 @@ void tsk_sw( ) sw_wifi_mukan_time = TIME_MUKAN; } } - break; - default: - break; - }// switch() } diff --git a/trunk/task_misc.c b/trunk/task_misc.c index 1b5e925..4776366 100644 --- a/trunk/task_misc.c +++ b/trunk/task_misc.c @@ -395,15 +395,6 @@ u8 extinfo_read(void) infos_bits[1] = (u8)LED_CAM; ret = *infos_table[iic_burst_state]; - -#if 0 -// debug // - /// システムに機種識別で嘘をつく - if( iic_burst_state == 9 ) - { - ret = (u8)FAMILY_FLOWER; - } -#endif iic_burst_state ++; } diff --git a/trunk/task_sys.c b/trunk/task_sys.c index 457ab56..b3621ad 100644 --- a/trunk/task_sys.c +++ b/trunk/task_sys.c @@ -36,9 +36,18 @@ extern void nop8(); -static void chk_emergencyExit(); +static err chk_emergencyExit(); static void force_off_check(); static void send_getup_to_soc(); +static void chk_sleep(); +static void chk_awake(); +static err direct_boot_sleep_check(); +static err chk_pwsw_timeout(); +static void go_stop(); +static void ports_finalize(); +static void irqs_finalize(); +static void restore_status_regs(); +static err leds_closed(); #ifdef _DBG_CHK_OFF_LEAK_ static void leak_check(); #endif @@ -62,6 +71,7 @@ extern bit i2c_mcu_time_out_error; #define PWSW_POWON_TIME (u8)( 20 / SYS_INTERVAL_TICK ) // [ms] // INTERVAL_TSK_SW で割らない。値が元から小さいので #define PWSW_ON_CHECK_TIMEOUT 100 // 適当 電源onの為に電源スイッチが操作されたとき、この時間経過したらmcuを省電力に戻す +#define SELSW_DIRECT_BOOT_DELAY (u16)( 1000 / SYS_INTERVAL_TICK ) /********************************************//** @@ -69,7 +79,6 @@ extern bit i2c_mcu_time_out_error; ***********************************************/ void tsk_sys( ) { - static u8 pwsw_timeout = 0; // 電源ボタンチャタリング回避。 タイムアウトするまでに電源投入確定しないとoffに戻る hal_update(); @@ -87,26 +96,15 @@ void tsk_sys( ) if( PM_EXTDC_n ) { // アダプタなし - if( SW_pow_count != 0 ) + if( chk_pwsw_timeout() == ERR_ERR ) { - pwsw_timeout = 0; - } - else - { - pwsw_timeout ++; - } - - if( pwsw_timeout > PWSW_ON_CHECK_TIMEOUT ) - { - SW_pow_count = 0; - system_status.pwr_state = OFF_TRIG; // スイッチはノイズだった。寝る。 - renge_task_interval_run_force = true; + // タイムアウト。スリープに入れる return; } } else { - BT_chk(); + BT_chk(); // バッテリ外されたら充電停止などするため } @@ -165,11 +163,42 @@ void tsk_sys( ) } // ここまで来ると、電源投入確定 // - // プルアップon + // プルアップon // PU_BT_IN_CHG_n = 1; PU7 = bits8(0,0,0,1, 1,1,0,1); // 4:SW_WIFI 3:SW_PWSW 2:PM_IRQ 0:PM_EXTDC_n PU_SW_HOME_n_JIKKI = 1; // SW_HOME + wait_ms( 50 ); // プルアップ後電圧がちゃんと上がるのをまってhal_update() しないと期待したのが取れない + /// 50ms は暫定値 + // 蓋閉じなら、HOMEも押されてないと電源を入れない。しかも一秒押し続ける + // (reset解除せずに電源断してしまう。ユーザーには気づくまい。) + system_status.pwr_state = DIRECT_BOOT_CHECK; + +// system_status.pwr_state = ON_TRIG; + break; + + case DIRECT_BOOT_CHECK: //------------------------------------------------------- + switch( direct_boot_sleep_check() ) + { + case ERR_ERR: // スリープが入っていて、必要なキーが足りないので起動させない + system_status.pwr_state = OFF_TRIG; + return; + break; + + default: + dbg_nop(); + /* fall through */ + + case ERR_RET1: // 1秒間 sel を押し続けなくてはならない。カウントの途中... + return; + break; + + case ERR_SUCCESS: // 起動させる。ダイレクトブートするはず。 + system_status.pwr_state = ON_TRIG; + break; + } + + case ON_TRIG: //------------------------------------------------------- reset_release(); if( system_status.poweron_reason == RSN_PWSW || @@ -188,31 +217,19 @@ void tsk_sys( ) PM_LCD_vcom_set( ); // LCDの対向電圧値など書き込み - break; - - case ON_TRIG: //------------------------------------------------------- -#ifdef i2c_timeout_test - LED_duty_pow_blu = 0; // debug - LED_duty_3d = 0; - LED_duty_notify_red = 0; - LED_duty_notify_grn = 0; - LED_duty_notify_blu = 0; - LED_pow_red = 0; - LED_CAM = 0; - i2c_mcu_time_out_error = false; -#endif IIC_ctr_Init( ); IIC_twl_Init( ); vreg_twl_init( ); vreg_ctr_reset( ); - KRM = bits8(0,0,0,0, 0,0,0,0); - PIF0 = 0; - system_status.poweron_reason = NONE; renge_task_interval_run_force = true; + // 割り込み関係 + KRM = bits8(0,0,0,0, 0,0,0,0); + PIF0 = 0; + MK0 = INT_MSK0_RSV; MK1 = INT_MSK1_RSV; @@ -225,13 +242,7 @@ void tsk_sys( ) // リブート時、ステータスを何となく更新 if( system_status.reboot ) { - u8 bl_status_temp; - - bl_status_temp = read_pmic( PM_REG_ADRS_BL ); - vreg_ctr[ VREG_C_STATUS ] |= (( bl_status_temp & 0x03 ) << 5 ); - set_bit( ( read_pmic( PM_REG_ADRS_VDD_LCD ) != 0 ), - vreg_ctr[ VREG_C_STATUS ], REG_BIT_LCD_POW ); - BT_chk(); + restore_status_regs(); } LED_init( ); // reboot時の↑BT_Chk,BT_chk後に行いたい @@ -249,30 +260,17 @@ void tsk_sys( ) break; case ON: //--------------------------------------------- - // PMICによる強制電源断チェック - // デバッガがreset1をアサートすることもある。そのときは全部リセット - chk_emergencyExit(); - - // SLP監視 - if( going_to_sleep ) // 絶対に SLP_REQ の前に予告が来る + if( chk_emergencyExit() == ERR_ERR ) { - timeout_sleep ++; - if( timeout_sleep == 0 || // オーバーフローを期待。sleepするって言ったけど一瞬で起きて気がつかなかった - ( PIF0 && !SLP_REQ )) // slp割り込みが入った気がしたが、もう起きてしまった - { - PIF0 = 0; - send_getup_to_soc(); - } - if( PIF0 && SLP_REQ ){ - PIF0 = 0; - PM_VDD_ecoMode(); - system_status.pwr_state = SLEEP; - renge_task_interval_run_force = true; - } + // PMICによる強制電源断チェック + // デバッガがreset1をアサートすることもある。そのときは全部リセット + system_status.pwr_state = OFF_TRIG; + renge_task_interval_run_force = true; } - // 強制offカウント - force_off_check(); + chk_sleep(); // SLP監視。system_status.pwr_state いじります。行儀悪い + + force_off_check(); // 強制offカウント #ifndef _TAIKENDAI_SEISAN_SPECIAL_ if( system_status.taikendai ) // アダプタが抜けたら自動で電源off @@ -287,14 +285,13 @@ void tsk_sys( ) break; case SLEEP: //------------------------------------------ - chk_emergencyExit(); - // スリープから復帰 - if( !SLP_REQ ){ - PM_VDD_normMode(); - wait_ms( 5 ); // tdly_sw - send_getup_to_soc(); - system_status.pwr_state = ON; + if( chk_emergencyExit() == ERR_ERR ) + { + system_status.pwr_state = OFF_TRIG; + renge_task_interval_run_force = true; } + + chk_awake(); // スリープから復帰 force_off_check(); // leak_check(); @@ -319,11 +316,7 @@ void tsk_sys( ) case OFF_TRIG: //--------------------------------------- // LED消灯を待つ - vreg_ctr[ VREG_C_LED_POW ] = LED_POW_ILM_OFF; - vreg_ctr[ VREG_C_LED_WIFI ] = WIFI_LED_OFF; - vreg_ctr[ VREG_C_LED_3D ] = LED_3D_ILM_OFF; - info_led_off = true; - if( LED_duty_pow_blu != 0 ) + if( leds_closed() != ERR_SUCCESS ) { return; } @@ -334,7 +327,7 @@ void tsk_sys( ) // 加速度センサ停止 vreg_ctr[ VREG_C_ACC_CONFIG ] = 0x00; tski_acc_setup(); - EI(); // DI状態でかえって来るので、I2C_mcu 完了させるのに必要を + EI(); // DI状態でかえって来るので、I2C_mcu 完了させるのに必要 // その他ペリフェラル停止 LED_stop( ); @@ -351,47 +344,12 @@ void tsk_sys( ) while( iic_mcu_busy ) {;} - // irqマスク設定 - KRM = ( KR_SW_POW ); // Mask ではなく、Modeなのだそうだ。紛らわしい - MK0 = ~( INT_MSK0_EXTDC | INT_MSK0_WDTI ); - MK1 = ~( INT_MSK1_KR | INT_MSK1_RTCINTVAL ); // INT_MSK1_RTCALARM | RTCアラーム封印中 - MK2L = 0xFF; - - // irqフラグクリア - vreg_ctr[VREG_C_IRQ0] = 0; - vreg_ctr[VREG_C_IRQ1] = 0; - vreg_ctr[VREG_C_IRQ2] = 0; - vreg_ctr[VREG_C_IRQ3] = 0; - - // PU5 そのまま - PU7 = bits8(0,0,0,0, 1,0,0,1); // PWSWI,PM_EXTTDC,( IRQ0_deactive(), PM_IRQ_deactive ) - PU_SW_HOME_n_JIKKI = 0; // SW_HOME 停止 - - IF0 = 0; - IF1 = 0; - IF2 = 0; - - IRQ0_disable; + irqs_finalize(); + IRQ0_disable; // 対 SoC のピン PM_sys_pow_off( ); // 電源カットオフ - // ポート類を停止モードに。こういう回路でも、L出力にしなきゃだめだそうな。 - SW_WIFI_n_RAW = 0; - PM_SW_WIFI_n = 0; - - SW_HOME_n_JIKKI_RAW = 0; - PM_SW_HOME_n_JIKKI = 0; - - WL_TX = 0; - PM_WL_TX = 0; - - SW_SEL_n = 0; - PM_SW_SEL_n = 0; - - ACCEL_INT1 = 0; - PM_ACCEL_INT1 = 0; - ACC_VALID = 0; - PM_ACC_VALID = 0; + ports_finalize(); system_status.pwr_state = OFF; SW_pow_mask = true; @@ -405,7 +363,6 @@ void tsk_sys( ) // 注:現状では電源ボタンしか電源投入はありません。 system_status.poweron_reason = NONE; - pwsw_timeout = 0; if( !PM_EXTDC_n || chg_led_override != 0 ) // これがゼロになるまで待つ @@ -436,8 +393,125 @@ void tsk_sys( ) pm_chk_adapter(); PM_Chg_Stop(); + + go_stop(); // 割り込み待ちで stop モードへ。 + + hal_update(); + renge_flg_interval = 0; bt_force_update = true; + // 起きた理由は? + if( !PM_EXTDC_n ){ + system_status.pwr_state = OFF; // 一回回ってきて、ON_CHECKに行く + } +/* 封印中 + // RTCアラーム。 + else if( vreg_ctr[ VREG_C_IRQ1 ] & REG_BIT_RTC_ALARM ) + { + system_status.poweron_reason = RSN_RTC_ALARM; + system_status.pwr_state = ON_CHECK; + } + // else if( 他の割り込みで電源on ){ + // 現状他の要因では起きない + // } +*/ + else // if( !SW_POW_n ) // (それ以外なら)電源ボタンで起きた + { + SW_pow_mask = false; + system_status.poweron_reason = RSN_PWSW; + system_status.pwr_state = ON_CHECK; + } + + RTCIMK = 0; // sys tick タイマー有効 + +#ifndef _TAIKENDAI_SEISAN_SPECIAL_ + if( system_status.taikendai ) + { + system_status.pwr_state = OFF_TRIG; + } +#endif + } + } +} + + + +/********************************************//** + 電源ボタンチャタリング回避。 + タイムアウトするまでに電源投入確定しないとoffに戻る + ***********************************************/ +static err chk_pwsw_timeout() +{ + static u8 pwsw_timeout = 0; + + if( SW_pow_count != 0 ) + { + pwsw_timeout = 0; + } + else + { + pwsw_timeout ++; + } + + if( pwsw_timeout > PWSW_ON_CHECK_TIMEOUT ) + { + SW_pow_count = 0; + system_status.pwr_state = OFF_TRIG; // スイッチはノイズだった。寝る。 + renge_task_interval_run_force = true; + return ERR_ERR; + } + + return ERR_SUCCESS; +} + + + +/********************************************//** + スリープに入れるか? + SoC から通知がある + ***********************************************/ +static void chk_sleep() +{ + if( going_to_sleep ) // 絶対に SLP_REQ の前に予告が来る + { + timeout_sleep ++; + if( timeout_sleep == 0 || // オーバーフローを期待。sleepするって言ったけど一瞬で起きて気がつかなかった + ( PIF0 && !SLP_REQ )) // slp割り込みが入った気がしたが、もう起きてしまった + { + PIF0 = 0; + send_getup_to_soc(); + } + if( PIF0 && SLP_REQ ){ + PIF0 = 0; + PM_VDD_ecoMode(); + system_status.pwr_state = SLEEP; + renge_task_interval_run_force = true; + } + } +} + + +/********************************************//** + 起床させるか? + ***********************************************/ +static void chk_awake() +{ + if( !SLP_REQ ){ + PM_VDD_normMode(); + wait_ms( 5 ); // tdly_sw + send_getup_to_soc(); + system_status.pwr_state = ON; + } +} + + + +/********************************************//** + STOP モードへ移行 + 諸々のレジスタ設定があります + ***********************************************/ +static void go_stop() +{ while( RWST ) {;} @@ -462,57 +536,133 @@ void tsk_sys( ) // クロック復帰 OSMC = bits8(0,0,0,0, 0,0,0,1); // 8MHz動作準備 - renge_flg_interval = 0; - hal_update(); - + nop8(); CKC = bits8(0,0,0,0, 1,0,0,0); // OSMC.FSEL = 1 後3clk以上開ける +} - // 起きた理由は? - if( !PM_EXTDC_n ){ - system_status.pwr_state = OFF; // 一回回ってきて、ON_CHECKに行く +/********************************************//** + FLOWER direct boot チェック + sleep がスライドスイッチになった都合でチェックを強化(なってるのかなぁ) + MCU 側でやること。 + ・sleep になってたら起動しない + ・ただし、home が押されてたら起動させる + ***********************************************/ +static err direct_boot_sleep_check() +{ + static u16 sel_sw_count; + + // 蓋空き? + if( SHELL_OPEN ) + { + // 通常起動 + sel_sw_count = 0; + return ERR_SUCCESS; } -/* // RTCアラーム。封印中 - else if( vreg_ctr[ VREG_C_IRQ1 ] & REG_BIT_RTC_ALARM ) + + // else 蓋閉じ/スリープスイッチon + /// ダイレクトブートチェック + if( SW_SEL_n || SW_POW_n ) { - system_status.poweron_reason = RSN_RTC_ALARM; - system_status.pwr_state = ON_CHECK; + // sel が押されてない + sel_sw_count = 0; + return ERR_ERR; } - // else if( 他の割り込みで電源on ){ - // 現状他の要因では起きない - // } -*/ - else // if( !SW_POW_n ) // (それ以外なら)電源ボタンで起きた + + // else sel が押されてる。時間測定する。 + sel_sw_count++; + if( sel_sw_count < SELSW_DIRECT_BOOT_DELAY ) { - SW_pow_mask = false; - system_status.poweron_reason = RSN_PWSW; - system_status.pwr_state = ON_CHECK; + return ERR_RET1; // 押しているがまだ足りない } - RTCIMK = 0; // sys tick タイマー有効 - -#ifndef _TAIKENDAI_SEISAN_SPECIAL_ - if( system_status.taikendai ) - { - system_status.pwr_state = OFF_TRIG; - } -#endif - } - } + // else ダイレクトブート条件満たした + sel_sw_count = 0; + return ERR_SUCCESS; } + +/********************************************//** + ポート類を停止モードに。 + こういう回路でも、L出力にしなきゃだめだそうな。 + ***********************************************/ +static void ports_finalize() +{ + SW_WIFI_n_RAW = 0; + PM_SW_WIFI_n = 0; + + SW_HOME_n_JIKKI_RAW = 0; + PM_SW_HOME_n_JIKKI = 0; + + WL_TX = 0; + PM_WL_TX = 0; + + SW_SEL_n = 0; + PM_SW_SEL_n = 0; + + ACCEL_INT1 = 0; + PM_ACCEL_INT1 = 0; + ACC_VALID = 0; + PM_ACC_VALID = 0; + + // PU5 そのまま + PU7 = bits8(0,0,0,0, 1,0,0,1); // PWSWI,PM_EXTTDC,( IRQ0_deactive(), PM_IRQ_deactive ) + PU_SW_HOME_n_JIKKI = 0; // SW_HOME 停止 +} + +/********************************************//** + MCU 内部 IRQ の停止 + ***********************************************/ +static void irqs_finalize() +{ + // irqマスク設定 + KRM = ( KR_SW_POW ); // Mask ではなく、Modeなのだそうだ。紛らわしい + MK0 = ~( INT_MSK0_EXTDC | INT_MSK0_WDTI ); + MK1 = ~( INT_MSK1_KR | INT_MSK1_RTCINTVAL ); // INT_MSK1_RTCALARM | RTCアラーム封印中 + MK2L = 0xFF; + + // irqフラグクリア + vreg_ctr[VREG_C_IRQ0] = 0; + vreg_ctr[VREG_C_IRQ1] = 0; + vreg_ctr[VREG_C_IRQ2] = 0; + vreg_ctr[VREG_C_IRQ3] = 0; + + IF0 = 0; + IF1 = 0; + IF2 = 0; +} + + +static err leds_closed() +{ + vreg_ctr[ VREG_C_LED_POW ] = LED_POW_ILM_OFF; + vreg_ctr[ VREG_C_LED_WIFI ] = WIFI_LED_OFF; + vreg_ctr[ VREG_C_LED_3D ] = LED_3D_ILM_OFF; + info_led_off = true; + + if( LED_duty_pow_blu != 0 || + LED_duty_WiFi != 0 || + LED_duty_3d != 0 || + LED_duty_notify_red != 0 || + LED_duty_notify_grn != 0 || + LED_duty_notify_blu != 0 ) + { + return ERR_ERR; + } + return ERR_SUCCESS; +} /********************************************//** PMICが電源異常で止めたか確認 ***********************************************/ -static void chk_emergencyExit(){ +static err chk_emergencyExit(){ static u8 shirobako_power_control_count; // wifi モジュールキャリブレーションモードでreset1を自分から下げてるときはチェックをパス if( is_wifi_calib_resets_ast ) { - return; + return ERR_SUCCESS; } if( shirobako_power_control_count == 0 ) @@ -523,8 +673,7 @@ static void chk_emergencyExit(){ { // リセットが下がってる /// PMICが異常終了判断をした - system_status.pwr_state = OFF_TRIG; - renge_task_interval_run_force = true; + return ERR_ERR; } else { @@ -552,9 +701,8 @@ static void chk_emergencyExit(){ { #ifndef _RVD_ // 白箱は電源を切りたいらしい - system_status.pwr_state = OFF_TRIG; - renge_task_interval_run_force = true; shirobako_power_control_count = WAIT_SHIROBAKO_POW_CONTROL; + return ERR_ERR; #endif } else @@ -575,10 +723,23 @@ static void chk_emergencyExit(){ } } } + return ERR_SUCCESS; } +/********************************************//** +リブート時、ステータスを何となく更新 + ***********************************************/ +static void restore_status_regs() +{ + u8 bl_status_temp; + bl_status_temp = read_pmic( PM_REG_ADRS_BL ); + vreg_ctr[ VREG_C_STATUS ] |= (( bl_status_temp & 0x03 ) << 5 ); + set_bit( ( read_pmic( PM_REG_ADRS_VDD_LCD ) != 0 ), + vreg_ctr[ VREG_C_STATUS ], REG_BIT_LCD_POW ); + BT_chk(); +} /********************************************//** - 電源ボタン長押し - 電池切れ @@ -637,7 +798,8 @@ static void leak_check() volatile u8 ports_i[12]; volatile u8 ports_o[12]; - ports_i[0] = ( PM0 & PU0 & ~P0 ); // プルアップ切り忘れ? + // プルアップ切り忘れ? + ports_i[0] = ( PM0 & PU0 & ~P0 ); ports_i[1] = ( PM1 & PU1 & ~P1 ); ports_i[2] = 0; ports_i[3] = ( PM3 & PU3 & ~P3 ); @@ -650,7 +812,8 @@ static void leak_check() ports_i[10] = 0; ports_i[11] = ( PM20 & PU20 & ~P20 ); - ports_o[0] = ( ~PM0 & P0 ); // H 出力しちゃってるかも + // H 出力しちゃってるかも + ports_o[0] = ( ~PM0 & P0 ); ports_o[1] = ( ~PM1 & P1 ); ports_o[2] = ( ~PM2 & P2 ); ports_o[3] = ( ~PM3 & P3 & ~POM3 ); diff --git a/trunk/vreg_ctr.c b/trunk/vreg_ctr.c index 064f1ac..7cffd4a 100644 --- a/trunk/vreg_ctr.c +++ b/trunk/vreg_ctr.c @@ -177,6 +177,10 @@ void vreg_ctr_write( u8 adrs, u8 data ) pool.vreg_c_ext.vreg_c_free[ vreg_free_adrs ] = data; vreg_free_adrs ++; } + else + { + dbg_NOP(); + } break; case VREG_CX_FREE_ADRS: @@ -510,8 +514,15 @@ u8 vreg_ctr_read( u8 adrs ) } else if( adrs == VREG_CX_FREE_DATA ) { - temp = pool.vreg_c_ext.vreg_c_free[ vreg_free_adrs ]; - // vreg_free_adrs ++; // ここで加算してしまうとインデックスがずれる + if( vreg_free_adrs >= VREG_C_FREE_SIZE ) + { + temp = 0x00; + } + else + { + temp = pool.vreg_c_ext.vreg_c_free[ vreg_free_adrs ]; + // vreg_free_adrs ++; // ここで加算してしまうとインデックスがずれる + } return( temp ); } else if( adrs == VREG_CX_INFO ) diff --git a/trunk/vreg_ctr.h b/trunk/vreg_ctr.h index 00c2140..b0629e2 100644 --- a/trunk/vreg_ctr.h +++ b/trunk/vreg_ctr.h @@ -133,11 +133,6 @@ // VREG_C_LED_NOTIFY_FLAG #define REG_BIT_IN_LOOP ( 1 << 0 ) -// RBR control (0x57) -#define REG_BIT_FLIGHT ( 1 << 1 ) -#define REG_BIT_RESET_n ( 1 << 0 ) - - // HAL bitfields 0 #define REG_BIT_HAL0_PM_EXTDC_n ( 1 << 7 ) #define REG_BIT_HAL0_BT_IN_CHG_n ( 1 << 6 )