ctr_mcu/trunk/tasks.c
fujita_ryohei 604432135f V0.25的な物。 自己アップデータの確認で一時的に巻き戻したいため。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@6 013db118-44a6-b54f-8bf7-843cb86687b1
2009-09-02 10:35:20 +00:00

224 lines
5.7 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.

#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#include "incs.h"
/* ========================================================
WiFi 関係
・WL_TX,RX
・LED_wifi
・32kHz
======================================================== */
task_interval tsk_wifi(){
return 10;
}
/* ========================================================
ステータスレジスタ関係
他のところでケアされていない部分
======================================================== */
task_interval tsk_misc_stat(){
static u8 state_old; // ステータス変化検出→割り込み の為
SHELL_CLOSE_P = 1;
set_bit( EXT_OPT_DET, vreg_ctr[ VREG_C_STATUS ], REG_BIT_EXT_OPT_LOCK );
set_bit( SHELL_CLOSE, vreg_ctr[ VREG_C_STATUS ], REG_BIT_SHELL_CLOSE );
SHELL_CLOSE_P = 0;
if(( vreg_ctr[ VREG_C_STATUS ] ^ state_old ) != 0 ){
vreg_ctr[ VREG_C_IRQ1 ] |= REG_BIT_STAT_CHANGE;
switch( system_status.pwr_state ){
case ON_TRIG:
case ON:
IRQ0_ast;
break;
case SLEEP_TRIG:
case SLEEP:
if( (( state_old & REG_BIT_SHELL_CLOSE ) != 0 )
&& ( !SHELL_CLOSE ) ){
// 蓋が開いた
IRQ0_ast;
}else{
return( 250 );
}
break;
case OFF_TRIG:
case OFF:
default:
break;
}
}
state_old = vreg_ctr[ VREG_C_STATUS ];
return( 100 );
}
/* ========================================================
======================================================== */
task_interval tsk_debug(){
u8 temp;
static u8 count = 0;
if( count == 0 ){
// LED_WIFI_2 ^= 1;
}
/*
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 0;
*/
return 255;
}
task_interval tsk_debug2(){
if(( system_status.pwr_state != OFF )
&& ( system_status.pwr_state != ON_TRIG )){
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 3, vreg_ctr[ VREG_C_IRQ0 ] );
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, vreg_ctr[ VREG_C_SND_VOL ] );
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, vreg_ctr[ VREG_C_3D_DEPTH ] );
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_ZH ] );
}
return( 50/2 );
}
#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( 次の起動までのシステムtick数 ); // 毎 tic 呼ばれることになります
}
// ポインタで何かもらうのは危険な気がしてきた
/* このように使う
renge_task_immed_add( タスク関数へのポインタ );
*/
task_status_immed tsk_imm_hina( u8* arg ){
return( ERR_FINISED );
// ERR_FINISED タスクを削除
// ERR_CONTINUE 次になんか割り込みなり、ユーザー操作なり、システムチックが
// 来たときに再度実行
}
#endif
/* ========================================================
加速度センサ割り込みピンがオリジナルマイコンには無いので
ポーリングする
======================================================== */
task_interval tsk_soft_int(){
#ifdef _MCU_KE3_
static u8 pin;
// Hエッジ検出
// pin = ( pin << 1 ) + ( ACC_VALID? 1: 0 );
// if( ( pin & 0x03 ) == 0x01 ){
if( ACC_VALID ){
renge_task_immed_add( tsk_cbk_accero );
}
return( 0 );
#else
// 本物のマイコンなら、割り込みでタスクを登録します
return( 248 );
#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 ){
RESETs_ast;
FCRAM_RST_ast;
}
if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_RESET2_REQ ){
RESET2_ast;
}
if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_FCRAM_RESET_REQ ){
FCRAM_RST_ast;
}
wait_ms( 5 );
RESETs_ngt;
FCRAM_RST_ngt;
}
vreg_ctr[ VREG_C_COMMAND0 ] = 0;
return( ERR_FINISED );
}
/* ========================================================
 互換向け、TWLアプリへの割り込み
  0なら呼ばれません。ケア不要
======================================================== */
task_status_immed do_command1(){
vreg_twl[ REG_TWL_ADRS_IRQ ] = (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x01 ) != 0 )? 0x80: 0x00; //pwsw_det
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x02 ) != 0 )? 0x01: 0x00; //reset_det
vreg_twl[ REG_TWL_ADRS_IRQ ] = (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x01 ) != 0 )? 0x80: 0x00; //pwsw_det
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x02 ) != 0 )? 0x01: 0x00; //reset_det
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x04 ) != 0 )? 0x02: 0x00; //off_det
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x08 ) != 0 )? 0x20: 0x00; //batt_low
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & 0x10 ) != 0 )? 0x10: 0x00; //batt_empty
return( ERR_FINISED );
}
/* ========================================================
CPUからのスリープ要求
======================================================== */
__interrupt void intp0_slp(){ // SLP
}