mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-06-19 09:05:48 -04:00

I2C_mを使用前にしっかり初期化するように変更(電池残量ICの動作不良解消か?) CODECのPMIC互換レジスタ対応修正。要求仕様と実際の仕様が異なっていた git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@19 013db118-44a6-b54f-8bf7-843cb86687b1
351 lines
9.4 KiB
C
351 lines
9.4 KiB
C
#pragma SFR
|
||
#pragma NOP
|
||
#pragma HALT
|
||
#pragma STOP
|
||
|
||
#include "incs.h"
|
||
#include "renge.h"
|
||
#include "pm.h"
|
||
|
||
#include "accero.h"
|
||
|
||
extern u8 boot_ura;
|
||
|
||
#define INTERVAL_TSK_MISC_STAT 4
|
||
|
||
|
||
|
||
/* ========================================================
|
||
ステータスレジスタなど
|
||
======================================================== */
|
||
void tsk_misc_stat( )
|
||
{
|
||
static u8 interval_task_misc_stat = 0;
|
||
static u8 state_old; // ステータス変化検出→割り込み の為
|
||
u8 diff;
|
||
|
||
if( interval_task_misc_stat != 0 )
|
||
{
|
||
interval_task_misc_stat -= 1;
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
interval_task_misc_stat = ( INTERVAL_TSK_MISC_STAT / SYS_INTERVAL_TICK );
|
||
}
|
||
|
||
set_bit( SHELL_CLOSE, vreg_ctr[VREG_C_STATUS], REG_BIT_ST_SHELL_CLOSED );
|
||
|
||
|
||
// ステータスレジスタ関係 → 割り込み //
|
||
if( ( system_status.pwr_state == ON ) || ( system_status.pwr_state == SLEEP ) )
|
||
{
|
||
diff = vreg_ctr[VREG_C_STATUS] ^ state_old;
|
||
if( diff != 0 )
|
||
{
|
||
state_old = vreg_ctr[VREG_C_STATUS];
|
||
|
||
if( diff & REG_BIT_LCD_POW )
|
||
{
|
||
// 液晶電源セット完了
|
||
if( vreg_ctr[VREG_C_STATUS] & REG_BIT_LCD_POW )
|
||
{
|
||
// on
|
||
set_irq( VREG_C_IRQ3, REG_BIT_LCD_ON );
|
||
}
|
||
else
|
||
{
|
||
// off
|
||
set_irq( VREG_C_IRQ3, REG_BIT_LCD_OFF );
|
||
}
|
||
}
|
||
|
||
if( diff & REG_BIT_BL )
|
||
{
|
||
// バックライトに変化有り
|
||
if( vreg_ctr[VREG_C_STATUS] & REG_BIT_BL )
|
||
{
|
||
// ついた
|
||
set_irq( VREG_C_IRQ3, REG_BIT_BL_ON );
|
||
}
|
||
else
|
||
{
|
||
// 消えた
|
||
set_irq( VREG_C_IRQ3, REG_BIT_BL_OFF );
|
||
}
|
||
}
|
||
|
||
if( diff & REG_BIT_BATT_CHARGE )
|
||
{
|
||
// 充電状態に以下略
|
||
if( vreg_ctr[VREG_C_STATUS] & REG_BIT_BATT_CHARGE )
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_BT_CHG_START );
|
||
}
|
||
else
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_BT_CHG_STOP );
|
||
}
|
||
}
|
||
|
||
if( diff & REG_BIT_POW_SUPPLY )
|
||
{
|
||
// 電源供給
|
||
if( vreg_ctr[VREG_C_STATUS] & REG_BIT_POW_SUPPLY )
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_BT_DC_CONNECT );
|
||
}
|
||
else
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_BT_DC_DISC );
|
||
}
|
||
}
|
||
|
||
if( diff & REG_BIT_ST_SHELL_CLOSED )
|
||
{
|
||
// 蓋の開け閉め
|
||
if( vreg_ctr[VREG_C_STATUS] & REG_BIT_ST_SHELL_CLOSED )
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_SHELL_OPEN );
|
||
}
|
||
else
|
||
{
|
||
set_irq( VREG_C_IRQ2, REG_BIT_SHELL_CLOSE );
|
||
}
|
||
}
|
||
}
|
||
|
||
//#ifdef _MCU_KE3_
|
||
/* ========================================================
|
||
加速度センサ割り込みピンがオリジナルマイコンには無いので
|
||
ポーリングする。
|
||
歩数計用
|
||
BSRマイコンはaccero.cで割り込みルーチンからタスク登録します。
|
||
======================================================== */
|
||
if( ( vreg_ctr[VREG_C_ACC_CONFIG] & 0x03 ) != 0x00 )
|
||
{
|
||
if( ACC_VALID )
|
||
{
|
||
// renge_task_immed_add( tsk_cbk_accero );
|
||
}
|
||
}
|
||
//#endif
|
||
|
||
// 割り込みの取りこぼし?
|
||
if( !PM_IRQ_n ){
|
||
// renge_task_immed_add( ntr_pmic_comm );
|
||
NOP();
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
|
||
/* ========================================================
|
||
======================================================== */
|
||
void tsk_debug( )
|
||
{
|
||
u8 temp;
|
||
static u8 count = 0;
|
||
static u8 task_interval;
|
||
|
||
if( system_status.pwr_state == ON_TRIG ){
|
||
if( !SW_SEL_n ){
|
||
renge_task_immed_add( tski_PM_LCD_on );
|
||
wait_ms( 50 );
|
||
renge_task_immed_add( tski_PM_BL_on );
|
||
}
|
||
|
||
// vreg_ctr[ VREG_C_ACC_CONFIG ] = 0x03;
|
||
// renge_task_immed_add( acc_hosu_set );
|
||
}
|
||
|
||
|
||
/*
|
||
temp = iic_mcu_read_a_byte( IIC_SLA_8LEDS, IIC_8LEDS_REG_DO );
|
||
count += 1;
|
||
iic_mcu_write_a_byte( IIC_SLA_8LEDS, IIC_8LEDS_REG_DO, count );
|
||
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 3, count );
|
||
*/
|
||
return;
|
||
}
|
||
|
||
u8 temp_debug_3;
|
||
|
||
void tsk_debug2( )
|
||
{
|
||
u8 str[4];
|
||
|
||
if( ( system_status.pwr_state == ON ) || ( system_status.pwr_state == SLEEP ) )
|
||
{
|
||
/*
|
||
str[3] = vreg_ctr[ VREG_C_FREE0 ];
|
||
str[2] = vreg_ctr[ VREG_C_FREE1 ];
|
||
str[1] = vreg_ctr[ VREG_C_STATUS ];
|
||
str[0] = vreg_ctr[ VREG_C_RTC_SEC ];
|
||
*/
|
||
str[3] = vreg_ctr[ VREG_C_IRQ1 ];
|
||
str[2] = vreg_ctr[ VREG_C_IRQ2 ];
|
||
str[1] = vreg_ctr[ VREG_C_IRQ3 ];
|
||
// str[0] = vreg_ctr[ VREG_C_STATUS ];
|
||
str[0] = temp_debug_3;
|
||
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 2, vreg_ctr[ VREG_C_IRQ1 ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, boot_ura );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, vreg_ctr[ VREG_C_SND_VOL ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, vreg_ctr[ VREG_TUNE ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_ZH ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 3, vreg_ctr[ VREG_C_TUNE ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 2, vreg_ctr[ VREG_C_SND_VOL ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, vreg_ctr[ VREG_C_STATUS ] );
|
||
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_ZH ] );
|
||
|
||
iic_mcu_write( IIC_SLA_DBG_MONITOR, 0, 4, &str[0] );
|
||
}
|
||
return;
|
||
}
|
||
|
||
|
||
#if 0
|
||
/* ========================================================
|
||
タスクひな形
|
||
======================================================== */
|
||
task_interval tsk_hina( )
|
||
{
|
||
switch ( system_status.pwr_state )
|
||
{
|
||
case OFF:
|
||
case ON_TRIG:
|
||
case ON:
|
||
case SLEEP_TRIG:
|
||
case SLEEP:
|
||
case OFF_TRIG:
|
||
default:
|
||
}
|
||
|
||
return ( 次の起 ・ョまでのシ ・X ・e ・ tick ・・); // 毎 tic 呼ばれることになります
|
||
}
|
||
|
||
|
||
// ポインタで何かもらうのは危険な気がしてきた
|
||
/* このように使う
|
||
renge_task_immed_add( タスク関数へのポインタ );
|
||
*/
|
||
task_status_immed tsk_imm_hina( u8 * arg )
|
||
{
|
||
return ( ERR_FINISED );
|
||
// ERR_FINISED タスクを削除
|
||
// ERR_CONTINUE 次になんか割り込みなり、ユーザー操作なり、システムチックが
|
||
// 来たときに再度実行
|
||
}
|
||
|
||
|
||
#endif
|
||
|
||
|
||
|
||
|
||
/* ========================================================
|
||
逐一起動タスク
|
||
======================================================== */
|
||
|
||
/* ========================================================
|
||
COMMANDレジスタへの書き込み
|
||
0なら呼ばれません。ケア不要
|
||
======================================================== */
|
||
task_status_immed do_command0( )
|
||
{
|
||
|
||
// 本体電源など
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_OFF_REQ )
|
||
{
|
||
system_status.pwr_state = OFF_TRIG;
|
||
}
|
||
else
|
||
{
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_RESET1_REQ )
|
||
{
|
||
#ifdef _PMIC_TWL_
|
||
RESETs_ast;
|
||
#else
|
||
PM_reset_ast( );
|
||
RESET2_ast;
|
||
#endif
|
||
FCRAM_RST_ast;
|
||
wait_ms( 5 );
|
||
}
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_RESET2_REQ )
|
||
{
|
||
RESET2_ast;
|
||
wait_ms( 5 );
|
||
}
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_FCRAM_RESET_REQ )
|
||
{
|
||
FCRAM_RST_ast;
|
||
wait_ms( 5 );
|
||
}
|
||
#ifdef _PMIC_TWL_
|
||
RESETs_neg;
|
||
#else
|
||
PM_reset_neg( );
|
||
RESET2_neg;
|
||
#endif
|
||
FCRAM_RST_neg;
|
||
}
|
||
|
||
// 液晶電源など
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_CMD_BL_ON )
|
||
{
|
||
renge_task_immed_add( tski_PM_BL_on );
|
||
}
|
||
else if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_CMD_BL_OFF )
|
||
{
|
||
renge_task_immed_add( tski_PM_BL_off );
|
||
}
|
||
|
||
if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_CMD_LCD_ON )
|
||
{
|
||
renge_task_immed_add( tski_PM_LCD_on );
|
||
}
|
||
else if( vreg_ctr[VREG_C_COMMAND0] & REG_BIT_CMD_LCD_OFF )
|
||
{
|
||
renge_task_immed_add( tski_PM_LCD_off );
|
||
}
|
||
|
||
vreg_ctr[VREG_C_COMMAND0] = 0;
|
||
return ( ERR_FINISED );
|
||
}
|
||
|
||
|
||
|
||
/* ========================================================
|
||
互換向け、TWLアプリへの割り込み
|
||
仮想レジスタの書き込み時に行います。
|
||
======================================================== */
|
||
// task_status_immed do_command1( )
|
||
|
||
|
||
|
||
/* ========================================================
|
||
CPUからのスリープ要求
|
||
ポーリングにしました。
|
||
======================================================== */
|
||
/*
|
||
__interrupt void intp0_slp( )
|
||
{ // SLP
|
||
if( SLP_REQ ){
|
||
system_status.pwr_state = SLEEP_TRIG;
|
||
}else{
|
||
system_status.pwr_state = ON_TRIG;
|
||
if( PM_BL_on() == 0 ){
|
||
renge_task_interval_run_force = 1;
|
||
iic_mcu_stop();
|
||
system_status.pwr_state = OFF_TRIG;
|
||
}
|
||
}
|
||
renge_task_interval_run_force = 1;
|
||
}
|
||
*/
|