mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-06-18 16:45:33 -04:00
101 lines
2.3 KiB
C
101 lines
2.3 KiB
C
/* ========================================================
|
|
MCU CTR BSR
|
|
2008- nintendo
|
|
開発技術部 藤田
|
|
$Id: asdf$
|
|
======================================================== */
|
|
|
|
|
|
// ========================================================
|
|
//#include "incs_loader.h"
|
|
#include "incs.h"
|
|
|
|
//#include "WDT.h"
|
|
#include "rtc.h"
|
|
#include "pm.h"
|
|
#include "accero.h"
|
|
#include "led.h"
|
|
#include "adc.h"
|
|
#include "i2c_mcu.h"
|
|
#include "pool.h"
|
|
|
|
|
|
// ========================================================
|
|
system_status_ system_status;
|
|
uni_pool pool;
|
|
bit force_off;
|
|
|
|
#ifdef i2c_timeout_test
|
|
bit i2c_mcu_time_out_error; // I2Cが何らかで詰まった。結露など含む。
|
|
extern void i2c_mcu_error_monitor();
|
|
#endif
|
|
|
|
extern bit pm_extdc_old;
|
|
|
|
/********************************************//**
|
|
メインループです。
|
|
|
|
本当のエントリ関数は loader.c にあります
|
|
|
|
- ペリフェラル・I2Cレジスタの初期化、
|
|
- リブート判定
|
|
|
|
を行い、タスクシステムを回します。
|
|
***********************************************/
|
|
void main_loop( void )
|
|
{
|
|
renge_init();
|
|
|
|
#ifdef i2c_timeout_test
|
|
i2c_mcu_time_out_error = false;
|
|
#endif
|
|
iic_mcu_start();
|
|
|
|
EI();
|
|
|
|
BT_chk();
|
|
|
|
system_status.pwr_state = OFF_TRIG;
|
|
|
|
// リブート判定
|
|
if( system_status.reboot )
|
|
{
|
|
// 本体電源onなら、onを継続させる…MCU WDTリセット、自己アップデートなど
|
|
if( PM_chk_LDSW() )
|
|
{
|
|
system_status.pwr_state = ON_TRIG;
|
|
}
|
|
vreg_ctr[VREG_C_BT_REMAIN] = 100;
|
|
pm_extdc_old = PM_EXTDC_n_RAW; // リブート時、充電LEDが前回の状態を続けるように
|
|
}
|
|
else
|
|
{
|
|
pm_extdc_old = ~PM_EXTDC_n_RAW; // アダプタでPOR時に点けるため。
|
|
}
|
|
|
|
vreg_ctr_init();
|
|
|
|
clear_hosu_hist(); // 歩数計履歴クリア
|
|
|
|
renge_task_interval_run_force = true;
|
|
|
|
RTCIMK = 0; /* 割り込み(アラーム&インターバル)許可 */
|
|
|
|
// メインループ //
|
|
while( 1 )
|
|
{ // システムtick、または割り込みで廻ります。
|
|
renge_task_interval_run(); // 内部で、システムtickまたは強制起動します
|
|
renge_task_immed_run();
|
|
#ifdef i2c_timeout_test
|
|
if( i2c_mcu_time_out_error )
|
|
{
|
|
i2c_mcu_error_monitor();
|
|
}
|
|
#endif
|
|
HALT();
|
|
}
|
|
}
|
|
|
|
|
|
|