From c8ed4d66e33e929b19966080701816ed6e693f9d Mon Sep 17 00:00:00 2001 From: n2232 Date: Fri, 21 Jan 2011 01:39:21 +0000 Subject: [PATCH] =?UTF-8?q?=E6=AD=A9=E6=95=B0=E8=A8=88=E4=BB=95=E6=A7=98?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=EF=BC=9A=EF=BC=92=EF=BC=94=EF=BC=8A=EF=BC=97?= =?UTF-8?q?=E6=99=82=E9=96=93=E3=81=A7=E5=91=88=E3=81=97=20=E6=8B=A1?= =?UTF-8?q?=E5=BC=B5=E6=83=85=E5=A0=B1=E3=83=AC=E3=82=B8=E3=82=B9=E3=82=BF?= =?UTF-8?q?=EF=BC=880x7F=EF=BC=89=E3=81=AE=E3=83=AA=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=928=E3=83=90=E3=82=A4=E3=83=88=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?=E3=81=A7=E4=B8=AD=E6=96=AD=E3=81=99=E3=82=8B=E3=81=A8=E3=80=81?= =?UTF-8?q?=E3=81=9D=E3=81=AE=E6=AC=A1=E3=81=AE=E9=80=9A=E4=BF=A1=E3=81=AE?= =?UTF-8?q?=E5=85=88=E9=A0=AD8-n=E3=83=90=E3=82=A4=E3=83=88=E3=81=8F?= =?UTF-8?q?=E3=82=89=E3=81=84=E3=81=8C=E4=B8=8D=E6=AD=A3=E3=81=AA=E3=81=AE?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20=E5=90=8C=E3=83=AC=E3=82=B8?= =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=81=AE=E6=9B=B4=E6=96=B0=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E3=80=81=E3=81=9D=E3=81=AE=E5=BD=B1?= =?UTF-8?q?=E9=9F=BF=E3=81=A7=E3=82=BF=E3=82=B9=E3=82=AF=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=EF=BC=88=E5=89=8A=E9=99=A4=EF=BC=89=20=E3=82=A8?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=B3=E3=82=B0=E3=81=AFOK=E3=80=82?= =?UTF-8?q?=E6=AD=A9=E6=95=B0=E8=A8=88=E3=81=AF=E3=81=BE=E3=81=A0=E5=8D=81?= =?UTF-8?q?=E5=88=86=E3=81=AA=E6=A4=9C=E8=A8=BC=E3=81=8C=E6=B8=88=E3=82=93?= =?UTF-8?q?=E3=81=A7=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@304 013db118-44a6-b54f-8bf7-843cb86687b1 --- trunk/i2c_ctr.c | 9 +--- trunk/pedo_alg_thre_det2.c | 85 +++++++++++++++--------------- trunk/pm.c | 11 +++- trunk/pm.h | 2 + trunk/renge/renge_task_immediate.h | 3 +- trunk/task_misc.c | 74 ++++++-------------------- trunk/vreg_ctr.c | 12 +---- 7 files changed, 74 insertions(+), 122 deletions(-) diff --git a/trunk/i2c_ctr.c b/trunk/i2c_ctr.c index 13acf25..b90d3ef 100644 --- a/trunk/i2c_ctr.c +++ b/trunk/i2c_ctr.c @@ -148,14 +148,7 @@ __interrupt void int_iic_ctr( ) reg_adrs = IICA; adrs_access_from = reg_adrs; tx_buf = vreg_ctr_read( reg_adrs ); // データの準備をしておく - if( reg_adrs != VREG_CX_INFO ) // 特殊なバーストリードを行うため、割り込み駆動から外す - { - state = IIC_TX_OR_RX; - } - else - { - state = IIC_IDLE; - } + state = IIC_TX_OR_RX; WREL = 1; break; diff --git a/trunk/pedo_alg_thre_det2.c b/trunk/pedo_alg_thre_det2.c index 1e33183..3568894 100644 --- a/trunk/pedo_alg_thre_det2.c +++ b/trunk/pedo_alg_thre_det2.c @@ -183,6 +183,8 @@ void pedometer()  歩数+1   累積をインクリメント  履歴を更新 + *2011/01/20 + 仕様変更 ログがいっぱいになったらそこで止める ========================================================*/ u8 p_record; u8 last_hour = 0x23; // 履歴の最新は何時? @@ -199,9 +201,14 @@ u8 log_year; static void hosu_increment() { - static u16 last_hour_fny; + static u16 last_hour_fny; // from new year - // 累積の更新 // + if( p_record >= PEDOMETER_LOG_SIZE ) + { + return; + } + + // 累積の更新 // // いろいろ失敗した... if( ++vreg_ctr[ VREG_C_ACC_HOSU_L ] == 0 ) { @@ -241,11 +248,12 @@ static void hosu_increment() // 元旦零時台で昨日扱いになった場合の帳尻合わせ if( now_longhour == 65535 ) { - now_longhour = ( ( 365 + (( now_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) -1; + now_longhour = ( ( 365 + (( now_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) -1; // 閏年を考慮 now_year -= 1; } - // 歩数計が止まっていた時間を考慮して必要なら進める // + // 書き込みポインタの更新 + // 歩数計が止まっていた時間を考慮して必要なら進める if( last_year == now_year ) { if( now_longhour > last_hour_fny ) @@ -272,17 +280,13 @@ static void hosu_increment() last_hour_fny = now_longhour; // 実際にインクリメント + if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA ) //※ 読みにくい… { - u16* p_pedo_data = &pool.vreg_c_ext.pedo_log[ p_record ]; - - if( *p_pedo_data == HOSU_NODATA ) - { - *p_pedo_data = 1; - } - else if( *p_pedo_data != HOSU_MAX ) - { - *p_pedo_data += 1; - } + pool.vreg_c_ext.pedo_log[ p_record ] = 1; + } + else if( pool.vreg_c_ext.pedo_log[ p_record ] != HOSU_MAX ) + { + pool.vreg_c_ext.pedo_log[ p_record ] += 1; } } } @@ -355,45 +359,39 @@ void hosu_read_end( ) ======================================================== */ u8 hosu_read( ) { - u8 dat; - u16 temp; + u8 rv; static u8 p_record_buffer; + static u8 dat_temp[6]; // 一応、アトミック処理に - switch( iic_burst_state ){ - case( 0 ): + if( iic_burst_state == 0 ) + { p_record_buffer = p_record; - iic_burst_state += 1; - return( last_hour ); + dat_temp[0] = last_hour; + dat_temp[1] = last_day; + dat_temp[2] = last_month; + dat_temp[3] = btobcd( log_year ); + dat_temp[4] = now_min; + dat_temp[5] = now_sec; + } - case( 1 ): + if( iic_burst_state <= 5 ) + { + rv = dat_temp[ iic_burst_state ]; iic_burst_state += 1; - return( last_day ); - - case( 2 ): - iic_burst_state += 1; - return( last_month ); - - case( 3 ): - iic_burst_state += 1; - return( btobcd( log_year ) ); - - case( 4 ): - iic_burst_state += 1; - return( now_min ); // reserved dummy - - case( 5 ): - iic_burst_state += 1; - return( now_sec ); // reserved. dummy - - default: + return( rv ); + } + else + { + u16 temp; + // 16ビットで記録してあるのでばらして送る todo: もっと楽する方法があるんじゃ temp = pool.vreg_c_ext.pedo_log[ p_record_buffer ]; if( record_read_msb_lsb == 0 ) { - dat = (u8)( temp & 0x00FF ); + rv = (u8)( temp & 0x00FF ); } else { - dat = (u8)(( temp >> 8 ) & 0x00FF ); + rv = (u8)(( temp >> 8 ) & 0x00FF ); if( p_record_buffer == 0 ) { p_record_buffer = PEDOMETER_LOG_SIZE-1; @@ -404,8 +402,9 @@ u8 hosu_read( ) } } record_read_msb_lsb ^= 1; - return( dat ); + return( rv ); } + } diff --git a/trunk/pm.c b/trunk/pm.c index 3211b9d..7725f4d 100644 --- a/trunk/pm.c +++ b/trunk/pm.c @@ -33,6 +33,10 @@ bit ntr_pm_bt_low_old; bit BT_CHG_STAT_Change; +u8 pmic_version; +u8 mgic_version[2]; + + // ======================================================== static void BT_model_detect(); static void BT_mgic_quick_start(); @@ -974,11 +978,16 @@ err PM_sys_pow_on( ) return ( ERR_ERR ); // reset1はほっといて良い } + // 電源周りIC情報 + pmic_version = iic_mcu_read_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VER ); + iic_mcu_read( IIC_SLA_BT_GAUGE, BT_GAUGE_REG_VERSION, 2, mgic_version ); + + // リセット解除など。システム起動! PM_reset_neg(); FCRAM_RST_neg; RESET2_neg; - codec_reg_init(); // CODEC 不定レジスタ初期化 + codec_reg_init(); // CODEC 不定レジスタ初期化(reset2の後でないといけないので) reg_shadow = 0; //  〃 こんなところで... return ( ERR_SUCCESS ); diff --git a/trunk/pm.h b/trunk/pm.h index 6ebdf32..fd751e6 100644 --- a/trunk/pm.h +++ b/trunk/pm.h @@ -131,6 +131,8 @@ extern u8 raw_adc_temperature; extern BT_VENDER battery_manufacturer; extern bit bt_force_update; +extern u8 pmic_version; +extern u8 mgic_version[]; //========================================================= diff --git a/trunk/renge/renge_task_immediate.h b/trunk/renge/renge_task_immediate.h index 374960b..7c5016d 100644 --- a/trunk/renge/renge_task_immediate.h +++ b/trunk/renge/renge_task_immediate.h @@ -4,14 +4,13 @@ #include "renge_defs.h" // ************************************* -#define TASK_IMMED_RUN_LIST_MAX 16 +#define TASK_IMMED_RUN_LIST_MAX 10 extern task_status_immed tski_do_command0( ); extern task_status_immed tski_ntr_pmic_comm(); extern task_status_immed tski_acc_read(); extern task_status_immed tski_acc_write(); -extern task_status_immed tski_mcu_info_read(); //extern task_status_immed tski_acc_hosu_set(); // accero.h extern task_status_immed tski_mcu_reset(); extern task_status_immed tski_vol_update(); diff --git a/trunk/task_misc.c b/trunk/task_misc.c index 21d3d92..568fc3a 100644 --- a/trunk/task_misc.c +++ b/trunk/task_misc.c @@ -231,7 +231,6 @@ task_status_immed tski_do_command0( ) return ( ERR_CONTINUE ); } */ -// SVA1 = IIC_C_SLAVEADDRESS; todo return ( ERR_FINISED ); } @@ -264,71 +263,29 @@ extern bit bt_chg_ready; 8) ( !temp_zone_charge_disable | ( bt_chg_ready << 1 ) ) 9) ======================================================== */ -task_status_immed tski_mcu_info_read() +u8 extinfo_read() { - static u8 infos[10]; // staticにしたんだし、電源投入時にでもキャッシュしとけばいいのに + u8 infos[10]; - if( SPD ) // stop - { - goto end; - } - - if( STD ) // restart - { - WDT_Restart( ); - } - - if( IICAIF == 0 ) // I2Cのステートが進むのを待つ - { - return( ERR_CONTINUE ); - } - - IICAIF = 0; - - WDT_Restart( ); if( iic_burst_state > 8 ) { - goto end; - } - else if( iic_burst_state == 0 ) - { - if( !system_status.captureBox ) - { - IICA = (u8)system_status.model; - } - else - { - IICA = MODEL_CAPTURE_BOX; - } - // これで勝手に転送が始まるから今のうちにデータの準備をしておく - infos[0] = iic_mcu_read_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VER ); - infos[1] = battery_manufacturer; - iic_mcu_read( IIC_SLA_BT_GAUGE, BT_GAUGE_REG_VERSION, 2, &infos[2] ); - infos[4] = (u8)( _dbg_rcomp & 0xFF ); - infos[5] = raw_adc_temperature; - infos[6] = ( !temp_zone_charge_disable | ( bt_chg_ready << 1 ) ); - infos[7] = system_status.info_fullcolor; - } - else - { - IICA = infos[ iic_burst_state -1 ]; + return( 0xAA ); } - if( !ACKD ) // 途中で打ち切り - { - goto end; - } + // static でとるほどのものでないので毎回スタックからとってくる + // switchとかにするとromが困る... なんだかなぁ。 + infos[0] = system_status.captureBox? MODEL_CAPTURE_BOX: (u8)system_status.model; + infos[1] = pmic_version; + infos[2] = battery_manufacturer; + infos[3] = mgic_version[0]; + infos[4] = mgic_version[1]; + infos[5] = (u8)( _dbg_rcomp & 0xFF ); + infos[6] = raw_adc_temperature; + infos[7] = ( !temp_zone_charge_disable | ( bt_chg_ready << 1 ) ); + infos[8] = system_status.info_fullcolor; iic_burst_state++; - return( ERR_CONTINUE ); - -end: - SPIE = 0; - IICAIF = 0; - IICAMK = 0; - LREL = 1; - iic_burst_state = 0; - return( ERR_FINISED ); + return( infos[ iic_burst_state -1 ] ); } #ifdef i2c_timeout_test @@ -343,3 +300,4 @@ void i2c_mcu_error_monitor() LED_CAM = 1; } #endif + diff --git a/trunk/vreg_ctr.c b/trunk/vreg_ctr.c index 9121791..d6e56a9 100644 --- a/trunk/vreg_ctr.c +++ b/trunk/vreg_ctr.c @@ -15,9 +15,7 @@ CTR MCU I2C #include "fsl_user.h" - -extern u8 mcu_info_read(); // task_misc.c - +extern u8 extinfo_read(); // task_misc.c extern u8 iic_burst_state; // 特殊バーストアクセスする時のカウンタ extern bit info_led_pattern_updated; // お知らせLEDのパターンを先頭に戻す @@ -38,7 +36,6 @@ bit irq_readed; // AAA // ******************************************************** extern task_status_immed tski_firm_update(); -extern task_status_immed tski_mcu_info_read(); extern task_status_immed tski_mcu_reset(); @@ -438,12 +435,7 @@ u8 vreg_ctr_read( u8 adrs ) } else if( adrs == VREG_CX_INFO ) { - // I2C_mを使うので、ここからでは割り込みが使えなくて困る - // なのでタスク登録する。 - // 強制的にI2C_2割り込みをマスクする - renge_task_immed_add( tski_mcu_info_read ); - IICAMK = 1; - return( 0x4A ); + return( extinfo_read() ); } #if 0