mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-10-31 13:51:10 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@4 013db118-44a6-b54f-8bf7-843cb86687b1
218 lines
4.9 KiB
C
218 lines
4.9 KiB
C
#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;
|
|
}
|
|
|
|
|
|
task_interval tsk_debug2(){
|
|
volatile static u8 i;
|
|
|
|
i ++;
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, i );
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, i + 0x08 );
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 2, i + 0x20 );
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 3, i + 0x80 );
|
|
/*
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_0ZH ] );
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 1, vreg_ctr[ VREG_C_VOL ] );
|
|
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 2, vreg_ctr[ VREG_C_3D_DEPTH ] );
|
|
*/
|
|
return 255;
|
|
}
|
|
|
|
|
|
#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レジスタへの書き込み
|
|
======================================================== */
|
|
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 );
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================
|
|
TEG2では無し。後で実装
|
|
======================================================== */
|
|
task_status_immed do_command1(){
|
|
static u8 state = 0;
|
|
return( ERR_FINISED );
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================
|
|
CPUからのスリープ要求
|
|
======================================================== */
|
|
__interrupt void intp0_slp(){ // SLP
|
|
|
|
}
|
|
|
|
|