ctr_mcu/trunk/task_misc.c
n2232 4a96cf6746 vol書き込みポーリングを行うように変更
ROM不足に対応するため、メモリマップをちょっと変更。 従来品とのアップデート/ダウンデートもとりあえず大丈夫(自ファームのチェック部分)
RAMも心配になってきたのでboolとして使ってるu8をbit型に、気がついたところから
型違いのwarningを減らすためにキャストをちゃんとする。気がついたところから
tsk_debugを外した…がサイズ変わらず
if~else~else~でつないでいたところをテーブル&ループに変更 項目数が増えると(>4)78k0/rはこっちの方が早くて小さいのか
TWLがVolを書くのと、スライダの操作がバッティングすると不整合が起こる事があり、それを防ぐ




git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@241 013db118-44a6-b54f-8bf7-843cb86687b1
2010-10-13 01:41:23 +00:00

326 lines
8.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#include "incs.h"
#include "renge\renge.h"
#include "pm.h"
#include "accero.h"
#include "adc.h"
#include "i2c_mcu.h"
#include "led.h"
#ifdef _MCU_BSR_
#define ACKD ACKD1
#define ACKE ACKE1
#define COI COI1
#define IICAEN IICA1EN
#define IICRSV IICRSV1
#define IICA IICA1
#define IICAIF IICAIF1
#define IICAMK IICAMK1
#define IICAPR0 IICAPR11
#define IICAPR1 IICAPR01
#define IICCTL0 IICCTL10
#define IICE IICE1
#define IICF IICF1
#define IICS IICS1
#define IICWH IICWH1
#define IICWL IICWL1
#define LREL LREL1
#define SPD SPD1
#define SPIE SPIE1
#define STCEN STCEN1
#define STD STD1
#define SVA SVA1
#define WREL WREL1
#define WTIM WTIM1
#define TRC TRC1
#define SMC SMC1
#define DFC DFC1
#endif
// ========================================================
bit twl_ver_read;
bit going_to_sleep;
u8 vol_soc_readed; // 最後にSoCが読んだVol。TWLとの不整合防止
// twl の8段階volのリニア値からの境界 ×2 (分解能が倍になっているので)
const u8 TWL_VOL_BOUNDARY[] = {
// 0, 4, 12, 22, 32, 42, 52, 62 // mute付近で気に入らない感じになるかも...
0, 1, 12, 22, 32, 42, 52, 62
};
/* ========================================================
ステータスレジスタなど
======================================================== */
void tsk_misc( )
{
/* ========================================================
加速度センサ割り込みピンがオリジナルマイコンには無いので
ポーリングする。
歩数計用
BSRマイコンはaccero.cで割り込みルーチンからタスク登録します。
======================================================== */
// 割り込みの取りこぼし?
if( ACC_VALID )
{
if( renge_task_immed_add( tski_cbk_accero ) == ERR_SUCCESS ){
// NOP();
}
}
if( system_status.pwr_state == ON )
{
/* ========================================================
PM互換レジスタへの書き込み
ポーリングしかしてない。割り込み?
======================================================== */
if( !PM_IRQ_n ){
renge_task_immed_add( tski_ntr_pmic_comm );
// NOP();
}
/* ========================================================
TWLランチャーが起動したことをCTRが知りたいらしい
======================================================== */
if( twl_ver_read )
{
twl_ver_read = false;
set_irq( VREG_C_IRQ2, REG_BIT_TWL_VER_READ );
}
/* ========================================================
TWLがVolを書くのと、スライダの操作がバッティングすると
不整合が起こる事があり、それを防ぐ
======================================================== */
{
static u8 vol_soc_readed_old;
static u8 vol_soc_readed_twl_level;
if( vol_soc_readed != vol_soc_readed_old )
{
u8 new_level;
u8 i;
vol_soc_readed_old = vol_soc_readed;
for( i=0; i<=7; i++ )
{
if( vol_soc_readed <= TWL_VOL_BOUNDARY[ i ] )
{
new_level = i;
break;
}
}
if( vol_soc_readed_twl_level != new_level )
{
set_irq( VREG_C_IRQ2, REG_BIT_SLIDE_VOL_ACROSS_TWL_BOUNDARY );
}
}
}
}
// TUNE_LED ///////////////////////////////////
{
if( system_status.pwr_state != ON )
{
LED_duty_3d = 0;
}
else
{
if( vreg_ctr[VREG_C_LED_TUNE] == LED_TUNE_ILM_OFF )
{
if( LED_duty_3d != 0 )
{
LED_duty_3d -= 1;
}
}
else
{
if( LED_duty_3d != vreg_ctr[VREG_C_LED_BRIGHT] )
{
if( LED_duty_3d < vreg_ctr[VREG_C_LED_BRIGHT] )
{
LED_duty_3d += 1;
}
else
{
LED_duty_3d -= 1;
}
}
}
}
}
}
/* ========================================================
逐一起動タスク
======================================================== */
/* ========================================================
COMMANDレジスタへの書き込み
  0なら呼ばれません。ケア不要
======================================================== */
task_status_immed tski_do_command0( )
{
// command0 本体電源など
u8 temp_command = vreg_ctr[VREG_C_COMMAND0];
vreg_ctr[VREG_C_COMMAND0] = 0;
if( temp_command & REG_BIT_GOING_TO_SLEEP )
{
going_to_sleep = true;
}
if( ( temp_command & ( REG_BIT_OFF_REQ | REG_BIT_RESET1_REQ | REG_BIT_FCRAM_RESET_REQ | REG_BIT_RESET2_REQ )) != 0x00 )
{
if( temp_command & REG_BIT_OFF_REQ )
{
system_status.pwr_state = OFF_TRIG;
}
else
{
if( temp_command & REG_BIT_RESET1_REQ )
{
PM_reset_ast( );
RESET2_ast;
FCRAM_RST_ast;
}
if( temp_command & REG_BIT_FCRAM_RESET_REQ )
{
FCRAM_RST_ast;
}
else if( temp_command & REG_BIT_RESET2_REQ )
{
RESET2_ast;
if( vreg_twl[ REG_TWL_INT_ADRS_MODE ] == 0 )
{
FCRAM_RST_ast; // twlはntrモードで動作してる
}
vreg_twl[ REG_TWL_INT_ADRS_MODE ] = 0;
}
wait_ms( 5 );
FCRAM_RST_neg;
PM_reset_neg();
RESET2_neg;
// CODEC 不定レジスタ初期化
codec_reg_init();
}
}
/*
スリープ要求直後に電源OFF・リセットコマンドは来まい
if( vreg_ctr[VREG_C_COMMAND0] != 0 )
{
return ( ERR_CONTINUE );
}
*/
// SVA1 = IIC_C_SLAVEADDRESS; todo
return ( ERR_FINISED );
}
/* ========================================================
 互換向け、TWLアプリへの割り込み
仮想レジスタの書き込み時に行います。
======================================================== */
u16 _dbg_rcomp;
extern u8 raw_adc_temperature;
extern u8 iic_burst_state;
extern bit temp_zone_charge_disable;
extern bit bt_chg_ready;
/* ========================================================
 デバッグ用にいろいろ読んできます。
 返値はデータそのもの
出てくる順場は、
1) プラットフォーム
2) PMIC バージョン
3) 電池メーカー
4) ガスゲージバージョン
5) 〃
6) ( rcomp & 0xFF )
7) raw_adc_temperature
8) ( !temp_zone_charge_disable | ( bt_chg_ready << 1 ) )
9)
======================================================== */
task_status_immed tski_mcu_info_read()
{
static u8 infos[10];
if( SPD ) // stop
{
goto end;
}
if( STD ) // restart
{
SPIE = 1;
WDT_Restart( );
}
if( IICAIF == 0 ) // I2Cのステートが進むのを待つ
{
return( ERR_CONTINUE );
}
else
{
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 ];
}
iic_burst_state++;
return( ERR_CONTINUE );
end:
LREL = 1;
SPIE = 0;
IICAMK = 0;
iic_burst_state = 0;
return( ERR_FINISED );
}