ctr_mcu/trunk/tasks.c
fujita_ryohei 218026b2e2 V0.3
rengeの即時実行の方のタスク登録やらがおかしかったので修正。
  タスクの管理?に不整合が出てしまう。タスク登録処理中に、割り込みからも登録しようとすると不整合が出る。 タスクを登録するが、呼ばなくなってしまう。
  登録中に割り込み禁止にすると、I2Cのステートがおかしくなってしまう。
  ↑解消のため、I2C_CTRをすべて割り込みドリブンにした。
 RTCアラーム実装
 IRQマスク実装

未:TWL側とのやりとり
  歩数計 今回のタスク管理の修正で評価に入れる状態になったと思われ


git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@9 013db118-44a6-b54f-8bf7-843cb86687b1
2009-09-15 01:16:25 +00:00

289 lines
7.8 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"
#include "renge.h"
#include "pm.h"
extern u8 boot_ura;
/* ========================================================
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_STATUS0 ], REG_BIT_EXT_OPT_LOCK );
set_bit( SHELL_CLOSE, vreg_ctr[ VREG_C_STATUS0 ], REG_BIT_SHELL_CLOSE );
SHELL_CLOSE_P = 0;
// ステータスレジスタ関係 → 割り込み //
if(( vreg_ctr[ VREG_C_STATUS0 ] ^ state_old ) != 0 ){
vreg_ctr[ VREG_C_IRQ1 ] |= REG_BIT_STAT_CHANGE;
switch( system_status.pwr_state ){
case ON_TRIG:
break;
case ON:
if( ( vreg_ctr[ VREG_C_IRQ_MASK1 ] & REG_BIT_STAT_CHANGE ) == 0 ){
IRQ0_ast;
}
break;
case SLEEP_TRIG:
case SLEEP:
if( (( state_old & REG_BIT_SHELL_CLOSE ) != 0 )
&& ( !SHELL_CLOSE ) ){
// 蓋開けた のみ通知
if( ( vreg_ctr[ VREG_C_IRQ_MASK1 ] & REG_BIT_STAT_CHANGE ) == 0 ){
IRQ0_ast;
}
}
break;
case OFF_TRIG:
case OFF:
default:
break;
}
}
state_old = vreg_ctr[ VREG_C_STATUS0 ];
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(){
u8 str[4];
if(( system_status.pwr_state == ON )
|| ( system_status.pwr_state == SLEEP )){
str[3] = vreg_ctr[ VREG_C_IRQ0 ];
str[2] = vreg_ctr[ VREG_C_IRQ1 ];
str[1] = vreg_ctr[ VREG_C_STATUS0 ];
str[0] = vreg_ctr[ VREG_C_ACC_YH ];
iic_mcu_write( IIC_SLA_DBG_MONITOR, 0, 4, str );
// 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_STATUS0 ] );
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_ZH ] );
}
return( 3 );
}
#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_
if( (( vreg_ctr[ VREG_C_ACC_CONFIG_HOSU ] & 0x01 ) != 0 )
|| (( vreg_ctr[ VREG_C_ACC_CONFIG ] & 0x03 ) == 0x01 ) ){
if( system_status.pwr_state == ON ){
// 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
// 本物のマイコンなら、割り込みでタスクを登録します
#endif
return( 248 );
}
/* ========================================================
逐一起動タスク
======================================================== */
/* ========================================================
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;
}
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 );
#ifdef _PMIC_TWL_
RESETs_neg;
#else
PM_reset_neg();
RESET2_neg;
#endif
FCRAM_RST_neg;
}
// 液晶電源など
if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_BL_ON ){
renge_task_immed_add( tski_PM_BL_on );
}else if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_BL_OFF ){
renge_task_immed_add( tski_PM_BL_off );
}
if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_LCD_ON ){
renge_task_immed_add( tski_PM_LCD_on );
}else if( vreg_ctr[ VREG_C_COMMAND0 ] & REG_BIT_LCD_OFF ){
renge_task_immed_add( tski_PM_LCD_off );
}
vreg_ctr[ VREG_C_COMMAND0 ] = 0;
return( ERR_FINISED );
}
/* ========================================================
 互換向け、TWLアプリへの割り込み
  0なら呼ばれません。ケア不要
======================================================== */
task_status_immed do_command1(){
// 呼ばれません
while(1){
NOP(); // 誤り検出
}
vreg_twl[ REG_TWL_ADRS_IRQ ] = (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_PWSW_DET ) != 0 )? REG_BIT_TWL_IRQ_PWSW_DET: 0x00; //pwsw_det
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_RESET ) != 0 )? REG_BIT_TWL_IRQ_RESET: 0x00; //reset_req
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_OFF ) != 0 )? REG_BIT_TWL_IRQ_OFF: 0x00; //off_req
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_BT_LOW ) != 0 )? REG_BIT_TWL_IRQ_BT_LOW: 0x00; //batt_low
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_BT_EMPTY ) != 0 )? REG_BIT_TWL_IRQ_BT_EMPTY: 0x00; //batt_empty
vreg_twl[ REG_TWL_ADRS_IRQ ] |= (( vreg_ctr[ VREG_C_COMMAND1 ] & REG_BIT_TWL_CMD_VOL_CHANGE ) != 0 )? REG_BIT_TWL_IRQ_VOL_CHANGE: 0x00; //vol_changed
return( ERR_FINISED );
}
/* ========================================================
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;
*/
}