ctr_mcu/branches/lager_eval_sdk3.0/task_misc.c
n2232 641c4002f3 LAGER 評価のため、専用ファーム作成
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@421 013db118-44a6-b54f-8bf7-843cb86687b1
2011-10-04 00:56:38 +00:00

400 lines
10 KiB
C
Raw Permalink 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.

#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs.h"
#include "renge\renge.h"
#include "pm.h"
#include "accero.h"
#include "adc.h"
#include "i2c_mcu.h"
#include "led.h"
#include "vreg_twl.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
// ========================================================
extern void f();
// ========================================================
bit twl_ver_read; // twl home menuがverを読んだら互換カーネルに割り込みを入れるため
bit going_to_sleep; // SoCから、sleepに入る通知をもらう。slp_i のH期間が0になると
// スリープから復帰できなくなるのを防ぐため
// 自動テスト用
bit reserve_pedo_increnent;
// ========================================================
static void update_LED_3D();
static void check_twl_vol_irq();
extern void DI_wt_chk();
/* ========================================================
ステータスレジスタなど
======================================================== */
void tsk_misc( )
{
/* ========================================================
加速度センサ割り込みピンがオリジナルマイコンには無いので
ポーリングする。
歩数計用
BSRマイコンはaccero.cで割り込みルーチンからタスク登録します。
======================================================== */
// 割り込みの取りこぼし?
if( ACC_VALID )
{
if( renge_task_immed_add( tski_cbk_accero ) == ERR_SUCCESS ){
// dbg_nop();
}
}
if( system_status.pwr_state == ON )
{
/* ========================================================
PM互換レジスタへの書き込み
ポーリングしかしてない。割り込み?
======================================================== */
if( !PM_IRQ_n )
{
renge_task_immed_add( tski_ntr_pmic_comm );
// dbg_nop();
}
/* ========================================================
TWLランチャーが起動したことをCTRが知りたいらしい
======================================================== */
if( twl_ver_read )
{
twl_ver_read = false;
set_irq( VREG_C_IRQ2, REG_BIT_TWL_VER_READ );
}
// TWL の音量変化割り込みチェック //
check_twl_vol_irq();
}
// 3D ランプ更新 //
update_LED_3D();
if( reserve_pedo_increnent )
{
reserve_pedo_increnent = 0;
hosu_increment_if_necessary();
}
#ifdef _ENABLE_PRESS_SEL_TO_WDT_
if( system_status.pwr_state == ON )
{
static u16 timer;
if( !SW_SEL_n )
{
timer += 1;
if( timer == 2000 )
{
DI();
timer = 0;
while(1)
{
NOP(); // そのうちWDTが発生する
}
}
}
}
#endif
//. スタックテスト
// f();
}
/* ========================================================
TWLがVolを書くのと、スライダの操作がバッティングすると
不整合が起こる事があり、それを防ぐ
TWLでは8通常時、押しボタンは8段階だった。それに合わせて割り込みを入れたい
======================================================== */
void check_twl_vol_irq()
{
static u8 vol_level_twl_sent;
static u8 mabiki;
if( !is_TWL )
{
return;
// おしまい
}
if( mabiki != 0 )
{
mabiki--;
return;
// おしまい
}
mabiki = 9; // 1フレームは開ける
if( vol_level_twl != vol_level_twl_sent )
{
vol_level_twl_sent = vol_level_twl;
set_irq( VREG_C_IRQ2, REG_BIT_SLIDE_VOL_ACROSS_TWL_BOUNDARY );
}
}
// 3D_LED /////////////////////////////////////
void update_LED_3D()
{
if( system_status.pwr_state != ON )
{
LED_duty_3d = 0;
return;
// おしまい //
}
if( vreg_ctr[VREG_C_LED_3D] == LED_3D_ILM_OFF )
{
if( LED_duty_3d != 0 )
{
LED_duty_3d --;
}
}
else
{
if( LED_duty_3d != vreg_ctr[VREG_C_LED_BRIGHT] )
{
if( LED_duty_3d < vreg_ctr[VREG_C_LED_BRIGHT] )
{
LED_duty_3d ++;
}
else
{
LED_duty_3d --;
}
}
}
}
/* ========================================================
逐一起動タスク
======================================================== */
/* ========================================================
COMMANDレジスタへの書き込み
  0なら呼ばれません。ケア不要
======================================================== */
task_status_immed tski_do_command0( )
{
u8 temp_command;
// command0 本体電源など
DI_wt_chk();
temp_command = vreg_ctr[VREG_C_COMMAND0];
vreg_ctr[VREG_C_COMMAND0] = 0;
EI();
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_RESET2_REQ )
{
RESET2_ast;
if( vreg_twl[ REG_TWL_INT_ADRS_MODE ] == 0 )
{
FCRAM_RST_ast; // twlはntrモードで動作してる
}
// TWLモードからDSモードへの切り替え中にリセットすると
// IRQが読まれない場合があるのでTWLレジスタを初期化する
vreg_twl_init();
}
if( temp_command & REG_BIT_FCRAM_RESET_REQ )
{
FCRAM_RST_ast;
}
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 );
}
*/
return ( ERR_FINISED );
}
/* デバッグ・自動テスト用 ============================== */
u16 _dbg_rcomp;
extern u8 raw_adc_temperature;
extern u8 iic_burst_state;
extern bit temp_zone_charge_disable;
extern bit bt_authorized;
/* ========================================================
 デバッグ用にいろいろ読んできます。
 返値はデータそのもの
出てくる順場は、
1) プラットフォーム
2) PMIC バージョン
3) 電池メーカー
4) ガスゲージバージョン
5) 〃
6) ( rcomp & 0xFF )
7) raw_adc_temperature
8) ( !temp_zone_charge_disable | ( bt_authorized << 1 ) )
9) お知らせLEDはフルカラー
10) system_status.family
======================================================== */
#define KOUMOKU 19
static u8 infos_bits[2];
static u8 infos_temp[5];
static const u8 *infos_table[] = {
&infos_temp[0], /* 0 */
&pmic_version,
(u8*)&battery_manufacturer,
&mgic_version[0],
&mgic_version[1],
&infos_temp[1], /* 5 */
&raw_adc_temperature,
&infos_temp[2],
&infos_temp[3],
(u8*)&system_status.family,
// LED_pow_red, /* 10 */
&infos_bits[0],
(u8*)&LED_duty_pow_blu,
(u8*)&LED_duty_3d,
(u8*)&LED_duty_notify_red,
(u8*)&LED_duty_notify_grn,
(u8*)&LED_duty_notify_blu, /* 15 */
&infos_bits[1],
// &LED_CAM,
(u8*)&LED_duty_WiFi,
&infos_temp[4] /* 18 */
/* 項目足すときは KOUMOKU に注意 */
};
u8 extinfo_read(void)
{
u8 ret = 0xFF;
/*
* tempは計算処理が必要なデータ。メモリに余裕がないので計算が必要な
* 変数は、要/不要に関わらず計算するポリシー
*/
if( iic_burst_state < KOUMOKU )
{
infos_temp[0] = system_status.captureBox? MODEL_CAPTURE_BOX
: ( system_status.is_dev? MODEL_ISBAKO: (u8)system_status.model );
infos_temp[1] = (u8)( _dbg_rcomp & 0xFF );
infos_temp[2] = ( !temp_zone_charge_disable | ( bt_authorized << 1 ) );
infos_temp[3] = 1; /* 仕様変更により1固定になった */
infos_temp[4] = 0
// | ( PM_EXTDC_n ? REG_BIT_HAL0_PM_EXTDC_n : 0 ) // status0にある
| ( RBR_RESET_n ? REG_BIT_HAL0_PM_EXTDC_n : 0 ) // ↑空きを使わせてもらう
| ( BT_IN_CHG_n ? REG_BIT_HAL0_BT_IN_CHG_n : 0 )
| ( BT_CHG_Ena_n ? REG_BIT_HAL0_RSV_5 : 0 ) // 空きビット使用,out pin
| 0 // WL_TX 使えない
// | ( SHELL_OPEN ? REG_BIT_HAL0_SHELL_OPEN : 0 ) // status0にある
| ( RBR_FLIGHT ? REG_BIT_HAL0_SHELL_OPEN : 0 ) // ↑空きを使わせてもらう
| ( SW_WIFI_n ? REG_BIT_HAL0_SW_WIFI_n : 0 )
| ( SW_HOME_n ? REG_BIT_HAL0_SW_HOME_n : 0 )
| ( SW_POW_n ? REG_BIT_HAL0_SW_POW_n : 0 );
infos_bits[0] = (u8)LED_pow_red;
infos_bits[1] = (u8)LED_CAM;
ret = *infos_table[iic_burst_state];
iic_burst_state ++;
}
return ret;
}
#ifdef i2c_timeout_test
void i2c_mcu_error_monitor()
{
LED_duty_pow_blu = 0xff;
LED_duty_3d = 0xff;
LED_duty_notify_red = 0xff;
LED_duty_notify_grn = 0xff;
LED_duty_notify_blu = 0xff;
LED_pow_red = 1;
LED_CAM = 1;
}
#endif