mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-06-19 00:55:37 -04:00
zeroNUP が流れ、1NUPに入れるべく作業中
・TWLに音量変化割り込みを入れまくらない。 ACKとしてのREADを期待せず、変化した分だけ入れる ・歩数計ログをクリア後、1歩目をカウントしたところからログいっぱいで止める &一応リファクタリング 年またぎなど一通りチェックはしたが… ぼちぼちブランチを切る git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@308 013db118-44a6-b54f-8bf7-843cb86687b1
This commit is contained in:
parent
2afd580bdd
commit
c1f70d8d17
@ -27,6 +27,7 @@ u8 adc_raw_dep;
|
|||||||
|
|
||||||
u8 vol_polling;
|
u8 vol_polling;
|
||||||
|
|
||||||
|
u8 vol_level_twl;
|
||||||
|
|
||||||
|
|
||||||
typedef struct filter_work
|
typedef struct filter_work
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
extern u8 vol_polling;
|
extern u8 vol_polling;
|
||||||
|
extern u8 vol_level_twl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define MCU_VER_MAJOR 0x01
|
#define MCU_VER_MAJOR 0x01
|
||||||
#define MCU_VER_MINOR 0x15
|
#define MCU_VER_MINOR 0x20
|
||||||
|
|
||||||
|
|
||||||
#define _firm_format_v3_
|
#define _firm_format_v3_
|
||||||
|
BIN
trunk/hoge.bin
BIN
trunk/hoge.bin
Binary file not shown.
@ -28,8 +28,9 @@ typedef signed short sx16;
|
|||||||
|
|
||||||
|
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
|
// VCの赤線をどうにかする
|
||||||
|
|
||||||
typedef bool bit;
|
#define bit bool
|
||||||
|
|
||||||
void EI(){};
|
void EI(){};
|
||||||
void DI(){};
|
void DI(){};
|
||||||
@ -83,6 +84,21 @@ unsigned char WDTE;
|
|||||||
void EI(){;}
|
void EI(){;}
|
||||||
void DI(){;}
|
void DI(){;}
|
||||||
|
|
||||||
|
unsigned char RWAIT;
|
||||||
|
unsigned char RWST;
|
||||||
|
|
||||||
|
unsigned char bcdtob( unsigned char );
|
||||||
|
|
||||||
|
unsigned char HOUR;
|
||||||
|
unsigned char DAY;
|
||||||
|
unsigned char MONTH;
|
||||||
|
unsigned char YEAR;
|
||||||
|
unsigned char MIN;
|
||||||
|
unsigned char SEC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,16 +17,39 @@
|
|||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
|
|
||||||
// ========================================================
|
// ========================================================
|
||||||
static void hosu_increment();
|
// 履歴の最終記録時刻
|
||||||
|
// この順番はログ読み出しの順番でもあるのでいじらないでね
|
||||||
|
// 順番にアドレスの若いのから確保されるのを期待してます...
|
||||||
|
typedef struct{
|
||||||
|
u8 hour_bcd;
|
||||||
|
u8 day_bcd;
|
||||||
|
u8 month_bcd;
|
||||||
|
u8 year_bcd;
|
||||||
|
u8 min_bcd;
|
||||||
|
u8 sec_bcd;
|
||||||
|
}st_calender;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ========================================================
|
// ========================================================
|
||||||
u16 get_long_hour();
|
static void hosu_increment_if_necessary();
|
||||||
|
static u16 get_long_hour();
|
||||||
|
static u16 calc_hours_spend( u8 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ========================================================
|
||||||
|
bit pedolog_overflow; // 192時間記録済みフラグ(i2cで読める)
|
||||||
|
extern uni_pool pool; // 歩数ログはこの構造体の中
|
||||||
|
static u8 p_record; // ログの書き込み位置
|
||||||
|
static st_calender cal_log_latest; // 最後に歩数を更新した時刻
|
||||||
|
static u16 last_hour_fny; // fny:from new year
|
||||||
|
static st_calender cal_temp;
|
||||||
|
static u16 now_longhour;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern uni_pool pool;
|
|
||||||
bit pedolog_overflow;
|
|
||||||
|
|
||||||
|
|
||||||
// ========================================================
|
// ========================================================
|
||||||
@ -35,6 +58,11 @@ bit pedolog_overflow;
|
|||||||
unsigned long my_sqrt();
|
unsigned long my_sqrt();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 今年は閏年?
|
||||||
|
#define is_leapyear( y ) (( y & 0x03 ) == 0 )
|
||||||
|
// 「去年」は閏年?
|
||||||
|
#define is_firstyear( y ) (( y & 0x03 ) == 1 )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*=========================================================
|
/*=========================================================
|
||||||
@ -82,7 +110,7 @@ void pedometer()
|
|||||||
|
|
||||||
hist_indx += 1;
|
hist_indx += 1;
|
||||||
|
|
||||||
// ヒストリにフィルタを掛けて、今回の値を求める
|
// ヒストリにフィルタ(fir)を掛けて、今回の値を求める //
|
||||||
filterd = 0;
|
filterd = 0;
|
||||||
// for( i = 8; i != 55; i++ ) // 係数が0ばかりのため
|
// for( i = 8; i != 55; i++ ) // 係数が0ばかりのため
|
||||||
for( i = 0; i != 46; i++ ) // 係数テーブルをいじりました。パラメータ調整時注意
|
for( i = 0; i != 46; i++ ) // 係数テーブルをいじりました。パラメータ調整時注意
|
||||||
@ -90,7 +118,7 @@ void pedometer()
|
|||||||
filterd += (signed long)norm_hist[ ( hist_indx + i ) & TAP-1 ] * lpf_coeff[ i ];
|
filterd += (signed long)norm_hist[ ( hist_indx + i ) & TAP-1 ] * lpf_coeff[ i ];
|
||||||
}
|
}
|
||||||
|
|
||||||
filterd += (4096)*512;
|
filterd += (4096)*512; // DC分加算...だったと思う
|
||||||
acc_norm_temp = (s16)( filterd /1024 & 0xFFFF ); // ←FIL_COEFF_QUANTから正規化
|
acc_norm_temp = (s16)( filterd /1024 & 0xFFFF ); // ←FIL_COEFF_QUANTから正規化
|
||||||
/*
|
/*
|
||||||
if( acc_norm[0] < acc_norm_temp )
|
if( acc_norm[0] < acc_norm_temp )
|
||||||
@ -123,11 +151,12 @@ void pedometer()
|
|||||||
{
|
{
|
||||||
if( acc_norm[0] - peak_l > 4200 ){
|
if( acc_norm[0] - peak_l > 4200 ){
|
||||||
// ■一歩増えました
|
// ■一歩増えました
|
||||||
hosu_increment();
|
hosu_increment_if_necessary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interval_hh = 0;
|
interval_hh = 0;
|
||||||
}
|
}
|
||||||
|
// なんちゃって閾値の動的変更
|
||||||
if( acc_norm[0] > 18000 )
|
if( acc_norm[0] > 18000 )
|
||||||
{
|
{
|
||||||
th_L = acc_norm[0] - 10000;
|
th_L = acc_norm[0] - 10000;
|
||||||
@ -154,29 +183,6 @@ void pedometer()
|
|||||||
{
|
{
|
||||||
time_l += ( time_l != 255 ) ? 1: 0;
|
time_l += ( time_l != 255 ) ? 1: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DBG_PEDO_AUTO_ENABLE_
|
|
||||||
{
|
|
||||||
static u8 i = 0;
|
|
||||||
|
|
||||||
vreg_ctr[ 0x50 ] = i++;
|
|
||||||
|
|
||||||
vreg_ctr[ 0x51 ] = (u8)( acc_norm[0] / 256 & 0x00FF );
|
|
||||||
vreg_ctr[ 0x52 ] = (u8)( acc_norm[0] & 0x00FF );
|
|
||||||
|
|
||||||
vreg_ctr[ 0x53 ] = (u8)( norm_hist[ hist_indx -1 & TAP-1 ] / 256 & 0xFF );
|
|
||||||
vreg_ctr[ 0x54 ] = (u8)( norm_hist[ hist_indx -1 & TAP-1 ] & 0xFF );
|
|
||||||
|
|
||||||
vreg_ctr[ 0x55 ] = interval_hh;
|
|
||||||
vreg_ctr[ 0x56 ] = time_l;
|
|
||||||
|
|
||||||
vreg_ctr[ 0x57 ] = vreg_ctr[ VREG_C_ACC_HOSU_L ];
|
|
||||||
vreg_ctr[ 0x58 ] = (u8)( peak_l / 256 & 0x00FF );
|
|
||||||
vreg_ctr[ 0x59 ] = (u8)( peak_l & 0x00FF );
|
|
||||||
// vreg_ctr[ 0x5A ] = (u8)( norm_avg[0] / 256 & 0x00FF );
|
|
||||||
// vreg_ctr[ 0x5B ] = (u8)( norm_avg[0] & 0x00FF );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -188,134 +194,83 @@ void pedometer()
|
|||||||
*2011/01/20
|
*2011/01/20
|
||||||
仕様変更 ログがいっぱいになったらそこで止める
|
仕様変更 ログがいっぱいになったらそこで止める
|
||||||
========================================================*/
|
========================================================*/
|
||||||
u8 p_record;
|
|
||||||
u8 log_year;
|
|
||||||
|
|
||||||
u8 pedo_log_latest[ 6 ];
|
|
||||||
enum {
|
|
||||||
LEDO_LOG_LATEST_HOUR,
|
|
||||||
LEDO_LOG_LATEST_DAY,
|
|
||||||
LEDO_LOG_LATEST_MONTH,
|
|
||||||
LEDO_LOG_LATEST_YEAR,
|
|
||||||
LEDO_LOG_LATEST_MIN,
|
|
||||||
LEDO_LOG_LATEST_SEC
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
u8 last_hour; // 履歴の最新は何時?
|
|
||||||
u8 last_day;
|
|
||||||
u8 last_month;
|
|
||||||
u8 pedo_log_latest[ LEDO_LOG_LATEST_YEAR ];
|
|
||||||
u8 last_min;
|
|
||||||
u8 last_sec;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define HOSU_NODATA 0xFFFF
|
#define HOSU_NODATA 0xFFFF
|
||||||
#define HOSU_MAX 0xFFFE
|
#define HOSU_MAX 0xFFFE
|
||||||
|
|
||||||
static void hosu_increment()
|
static void hosu_increment_if_necessary()
|
||||||
{
|
{
|
||||||
static u16 last_hour_fny; // from new year
|
u8 year_compd; // hour境界補正済み現在年。comp(ensation)
|
||||||
|
|
||||||
// 空白の時間を考慮する。1時間以上放置されたなど。
|
// 現在時刻取得
|
||||||
u16 now_longhour;
|
|
||||||
u8 now_year;
|
|
||||||
|
|
||||||
u8 temp_year, temp_hour, temp_day, temp_month, temp_min, temp_sec, log_year_temp;
|
|
||||||
|
|
||||||
// 時計を止める必要が有るので↓は一気に行って下さい
|
|
||||||
DI();
|
DI();
|
||||||
RWAIT = 1;
|
RWAIT = 1;
|
||||||
while( !RWST ){;}
|
while( !RWST ){;}
|
||||||
log_year_temp = temp_year = bcdtob( YEAR );
|
|
||||||
|
|
||||||
// 履歴読み出し時に使用。BCDのままでよい
|
cal_temp.hour_bcd = HOUR;
|
||||||
temp_hour = HOUR;
|
cal_temp.day_bcd = DAY;
|
||||||
temp_day = DAY;
|
cal_temp.month_bcd = MONTH;
|
||||||
temp_month = MONTH;
|
cal_temp.year_bcd = YEAR;
|
||||||
temp_min = MIN;
|
cal_temp.min_bcd = MIN;
|
||||||
temp_sec = SEC;
|
cal_temp.sec_bcd = SEC;
|
||||||
|
|
||||||
|
RWAIT = 0;
|
||||||
|
EI();
|
||||||
|
|
||||||
|
year_compd = bcdtob( cal_temp.year_bcd );
|
||||||
|
|
||||||
now_longhour = get_long_hour();
|
now_longhour = get_long_hour();
|
||||||
|
|
||||||
// RWAIT = 0; ↑で行っています
|
|
||||||
// EI(); 〃
|
|
||||||
|
|
||||||
// 元旦零時台で昨日扱いになった場合の帳尻合わせ
|
|
||||||
if( now_longhour == 65535 )
|
|
||||||
{
|
|
||||||
now_longhour = ( ( 365 + (( temp_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) -1; // 閏年を考慮
|
|
||||||
temp_year -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 書き込みポインタの更新
|
// 書き込みポインタの更新
|
||||||
if(( vreg_ctr[ VREG_C_ACC_HOSU_L ] | vreg_ctr[ VREG_C_ACC_HOSU_M ] | vreg_ctr[ VREG_C_ACC_HOSU_H ] ) != 0 )
|
if( ! ( vreg_ctr[ VREG_C_ACC_HOSU_L ] == 0 && // 歩数計on後、最初の一歩までは前回からの経過時間を計算しない
|
||||||
|
vreg_ctr[ VREG_C_ACC_HOSU_M ] == 0 &&
|
||||||
|
vreg_ctr[ VREG_C_ACC_HOSU_H ] == 0 )) //. 全ビットorでゼロ判定するのはデジタル回路屋の方言みたい
|
||||||
{
|
{
|
||||||
// 歩数計が止まっていた時間を考慮して必要なら進める
|
// 歩数計が止まっていた時間を考慮して必要なら進める
|
||||||
if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] == temp_year )
|
// 補正計算 元旦零時台で昨日扱いになった場合、大晦日の23時台に上書き
|
||||||
|
if( now_longhour == (u16)-1 ) // マジックナンバーとかではなくて実際に計算結果が-1
|
||||||
{
|
{
|
||||||
if( now_longhour > last_hour_fny )
|
now_longhour = ( ( 365 + ( is_firstyear(year_compd) ? 1: 0 )) * 24 ) -1;
|
||||||
{
|
year_compd -= 1;
|
||||||
fill_hosu_hist_hours( now_longhour - last_hour_fny );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] == ( temp_year -1 ) )
|
|
||||||
{
|
|
||||||
// 年をまたいでいるとき
|
|
||||||
fill_hosu_hist_hours( ( ( 365 + (( temp_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) - last_hour_fny + now_longhour );
|
|
||||||
}
|
|
||||||
else if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] < temp_year )
|
|
||||||
{
|
|
||||||
// 数年放置
|
|
||||||
fill_hosu_hist_hours( 0 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// カレンダーが巻き戻るなど
|
|
||||||
// ノーケアでよい
|
|
||||||
}
|
}
|
||||||
|
fill_hosu_hist_hours( calc_hours_spend( year_compd ) ); // ■書き込みポインタの更新も行う
|
||||||
|
|
||||||
// ログあふれで記録停止?
|
// ログあふれで記録停止?
|
||||||
if( pedolog_overflow )
|
if( pedolog_overflow )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
// おしまい。ログの更新もなし。
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// インクリメントして良い
|
// インクリメントして良い
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_HOUR ] = temp_hour;
|
cal_log_latest = cal_temp; // ■ログ時刻更新
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_DAY ] = temp_day;
|
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_MONTH ] = temp_month;
|
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] = temp_year;
|
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_MIN ] = temp_min;
|
|
||||||
pedo_log_latest[ LEDO_LOG_LATEST_SEC ] = temp_sec;
|
|
||||||
|
|
||||||
last_hour_fny = now_longhour;
|
last_hour_fny = now_longhour;
|
||||||
log_year = log_year_temp;
|
|
||||||
|
// 毎時ログ インクリメント
|
||||||
|
if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA ) // その時間帯最初のカウントの時
|
||||||
|
{ // これしないと1歩足りない
|
||||||
|
pool.vreg_c_ext.pedo_log[ p_record ] = 1;
|
||||||
|
}
|
||||||
|
else if( pool.vreg_c_ext.pedo_log[ p_record ] != HOSU_MAX )
|
||||||
|
{
|
||||||
|
// 通常パス
|
||||||
|
pool.vreg_c_ext.pedo_log[ p_record ] += 1;
|
||||||
|
|
||||||
// 累積の更新 //
|
// 累積の更新 //
|
||||||
// いろいろ失敗した...
|
if( ++vreg_ctr[ VREG_C_ACC_HOSU_L ] == 0 ) //. いろいろ失敗した...
|
||||||
if( ++vreg_ctr[ VREG_C_ACC_HOSU_L ] == 0 )
|
|
||||||
{
|
{
|
||||||
if( ++vreg_ctr[ VREG_C_ACC_HOSU_M ] == 0 )
|
if( ++vreg_ctr[ VREG_C_ACC_HOSU_M ] == 0 )
|
||||||
{
|
{
|
||||||
if( ++vreg_ctr[ VREG_C_ACC_HOSU_H ] == 0 ){
|
if( ++vreg_ctr[ VREG_C_ACC_HOSU_H ] == 0 ){
|
||||||
vreg_ctr[ VREG_C_ACC_HOSU_L ] = 255; // カンスト orz
|
vreg_ctr[ VREG_C_ACC_HOSU_L ] = 255; //. カンスト orz
|
||||||
vreg_ctr[ VREG_C_ACC_HOSU_M ] = 255;
|
vreg_ctr[ VREG_C_ACC_HOSU_M ] = 255;
|
||||||
vreg_ctr[ VREG_C_ACC_HOSU_H ] = 255;
|
vreg_ctr[ VREG_C_ACC_HOSU_H ] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 毎時ログインクリメント
|
|
||||||
if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA )
|
|
||||||
{
|
|
||||||
pool.vreg_c_ext.pedo_log[ p_record ] = 1;
|
|
||||||
}
|
}
|
||||||
else if( pool.vreg_c_ext.pedo_log[ p_record ] != HOSU_MAX )
|
|
||||||
{
|
|
||||||
pool.vreg_c_ext.pedo_log[ p_record ] += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -324,43 +279,34 @@ static void hosu_increment()
|
|||||||
空白の時間を適切に0にして、
|
空白の時間を適切に0にして、
|
||||||
今を含む1時間のデータを書く位置にポインタ?を進める
|
今を含む1時間のデータを書く位置にポインタ?を進める
|
||||||
======================================================== */
|
======================================================== */
|
||||||
void fill_hosu_hist_hours( u16 hours )
|
static void fill_hosu_hist_hours( u16 hours )
|
||||||
{
|
{
|
||||||
// ログ最大容量以上放置された?
|
// ログあふれ?
|
||||||
if( hours > PEDOMETER_LOG_SIZE )
|
if( (u16)p_record + hours >= PEDOMETER_LOG_SIZE )
|
||||||
{
|
|
||||||
hours = PEDOMETER_LOG_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( p_record >= PEDOMETER_LOG_SIZE )
|
|
||||||
{
|
{
|
||||||
pedolog_overflow = true;
|
pedolog_overflow = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( p_record + hours >= PEDOMETER_LOG_SIZE )
|
|
||||||
{
|
|
||||||
pedolog_overflow = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 空白の数時間の設定
|
// 空白の数時間の設定
|
||||||
do
|
while( hours != 0 )
|
||||||
{
|
{
|
||||||
// 新仕様 いっぱいで停止
|
// 新仕様 いっぱいで停止
|
||||||
p_record += 1;
|
p_record += 1;
|
||||||
|
#if 1 // debug
|
||||||
if( p_record >= PEDOMETER_LOG_SIZE )
|
if( p_record >= PEDOMETER_LOG_SIZE )
|
||||||
{
|
{
|
||||||
pedolog_overflow = true;
|
pedolog_overflow = true;
|
||||||
NOP(); // ここに来るようだとバグ
|
// NOP(); // ここに来るようだとバグ
|
||||||
break;
|
break;
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
pool.vreg_c_ext.pedo_log[ p_record ] = 0;
|
pool.vreg_c_ext.pedo_log[ p_record ] = 0;
|
||||||
}
|
}
|
||||||
hours -= 1;
|
hours -= 1;
|
||||||
}
|
}
|
||||||
while( hours != 0 );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -389,16 +335,18 @@ void clear_hosu_hist()
|
|||||||
|
|
||||||
|
|
||||||
extern u8 iic_burst_state;
|
extern u8 iic_burst_state;
|
||||||
bit record_read_msb_lsb;
|
bit pedolog_read_msb;
|
||||||
|
|
||||||
/* ========================================================
|
/* ========================================================
|
||||||
歩数計ヒストリ読み出しの後処理(初期化)
|
歩数計ヒストリ読み出しの後処理(初期化)
|
||||||
読み出しポインタのクリア
|
読み出しポインタのクリア
|
||||||
======================================================== */
|
======================================================== */
|
||||||
|
/* マクロにしました
|
||||||
void hosu_read_end( )
|
void hosu_read_end( )
|
||||||
{
|
{
|
||||||
record_read_msb_lsb = 0;
|
pedolog_read_msb = 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ========================================================
|
/* ========================================================
|
||||||
@ -409,20 +357,19 @@ u8 hosu_read( )
|
|||||||
{
|
{
|
||||||
u8 rv;
|
u8 rv;
|
||||||
static u8 p_record_buffer;
|
static u8 p_record_buffer;
|
||||||
static u8 dat_temp[6]; // 一応、アトミック処理に
|
static st_calender cal_buff; // 一応、アトミック処理に
|
||||||
|
|
||||||
if( iic_burst_state == 0 )
|
if( iic_burst_state == 0 )
|
||||||
{
|
{
|
||||||
p_record_buffer = p_record;
|
p_record_buffer = p_record;
|
||||||
|
DI();
|
||||||
|
cal_buff = cal_log_latest;
|
||||||
|
EI();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( iic_burst_state <= 5 )
|
if( iic_burst_state <= 5 )
|
||||||
{
|
{
|
||||||
rv = pedo_log_latest[ iic_burst_state ];
|
rv = *( (u8*)&cal_buff + iic_burst_state ); // あうあう
|
||||||
if( iic_burst_state == LEDO_LOG_LATEST_YEAR ) // BCDに直さなきゃという失態
|
|
||||||
{
|
|
||||||
rv = btobcd( rv );
|
|
||||||
}
|
|
||||||
iic_burst_state += 1;
|
iic_burst_state += 1;
|
||||||
return( rv );
|
return( rv );
|
||||||
}
|
}
|
||||||
@ -431,7 +378,7 @@ u8 hosu_read( )
|
|||||||
u16 temp;
|
u16 temp;
|
||||||
// 16ビットで記録してあるのでばらして送る todo: もっと楽する方法があるんじゃ
|
// 16ビットで記録してあるのでばらして送る todo: もっと楽する方法があるんじゃ
|
||||||
temp = pool.vreg_c_ext.pedo_log[ p_record_buffer ];
|
temp = pool.vreg_c_ext.pedo_log[ p_record_buffer ];
|
||||||
if( record_read_msb_lsb == 0 )
|
if( !pedolog_read_msb )
|
||||||
{
|
{
|
||||||
rv = (u8)( temp & 0x00FF );
|
rv = (u8)( temp & 0x00FF );
|
||||||
}
|
}
|
||||||
@ -447,7 +394,7 @@ u8 hosu_read( )
|
|||||||
p_record_buffer -= 1;
|
p_record_buffer -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
record_read_msb_lsb ^= 1;
|
pedolog_read_msb ^= 1;
|
||||||
return( rv );
|
return( rv );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,64 +409,62 @@ u8 hosu_read( )
|
|||||||
======================================================== */
|
======================================================== */
|
||||||
const u16 DAYS_FROM_HNY[] = {
|
const u16 DAYS_FROM_HNY[] = {
|
||||||
0,
|
0,
|
||||||
0, 31, 31+28, 59+31, 90+30,
|
31,
|
||||||
120+31, 151+30, 181+31, 212+31, 243+30,
|
31+28, // =59。 …3月0日は1月59日
|
||||||
273+31, 304+30 };
|
31+28+31,
|
||||||
|
31+28+31+30,
|
||||||
|
31+28+31+30+31,
|
||||||
|
31+28+31+30+31+30,
|
||||||
|
31+28+31+30+31+30+31,
|
||||||
|
31+28+31+30+31+30+31+31,
|
||||||
|
31+28+31+30+31+30+31+31+30,
|
||||||
|
31+28+31+30+31+30+31+31+30+31,
|
||||||
|
31+28+31+30+31+30+31+31+30+31+30
|
||||||
|
};
|
||||||
|
|
||||||
u16 get_long_hour()
|
static u16 get_long_hour()
|
||||||
{
|
{
|
||||||
|
u8 year = bcdtob( cal_temp.year_bcd );
|
||||||
|
u8 month = bcdtob( cal_temp.month_bcd );
|
||||||
|
u8 day = bcdtob( cal_temp.day_bcd );
|
||||||
|
u8 hour = bcdtob( cal_temp.hour_bcd );
|
||||||
|
u8 min_bcd = cal_temp.min_bcd; // 大小比較しかしないのでbcdのままでよい
|
||||||
|
u8 sec_bcd = cal_temp.sec_bcd;
|
||||||
u16 long_hour;
|
u16 long_hour;
|
||||||
u8 year_hex;
|
|
||||||
u8 month_hex;
|
|
||||||
u8 day_hex;
|
|
||||||
u8 hour_hex;
|
|
||||||
|
|
||||||
u8 min;
|
|
||||||
u8 sec;
|
|
||||||
|
|
||||||
// RWAIT = 1 を確認してから↓に進んで下さい
|
|
||||||
year_hex = YEAR;
|
|
||||||
month_hex = MONTH;
|
|
||||||
day_hex = DAY;
|
|
||||||
hour_hex = HOUR;
|
|
||||||
min = MIN;
|
|
||||||
sec = SEC;
|
|
||||||
|
|
||||||
RWAIT = 0;
|
|
||||||
EI();
|
|
||||||
|
|
||||||
year_hex = bcdtob( year_hex );
|
|
||||||
month_hex = bcdtob( month_hex );
|
|
||||||
day_hex = bcdtob( day_hex );
|
|
||||||
hour_hex = bcdtob( hour_hex );
|
|
||||||
|
|
||||||
// まず日数の部分
|
// まず日数の部分
|
||||||
long_hour = DAYS_FROM_HNY[ month_hex ];
|
long_hour = DAYS_FROM_HNY[ month -1 ]; // -1はインデックス合わせ
|
||||||
if(( ( year_hex & 0x03 ) == 0 ) && ( ( 3 <= month_hex )))
|
if( is_leapyear(year) && ( 3 <= month ))
|
||||||
{
|
{
|
||||||
// 閏年で、閏日より後
|
// 閏年で、閏日より後
|
||||||
long_hour += 1;
|
long_hour += 1;
|
||||||
}
|
}
|
||||||
long_hour += day_hex - 1;
|
long_hour += day - 1;
|
||||||
long_hour *= 24; // 日数→時間
|
long_hour *= 24; // 日数→時間
|
||||||
|
|
||||||
long_hour += hour_hex;
|
long_hour += hour;
|
||||||
|
|
||||||
if( ( min > vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
|
// 時・分境界の前?後?
|
||||||
|| ( ( min >= vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
|
if( ( min_bcd > vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
|
||||||
&& ( sec > vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY_SEC ] ))
|
|| ( ( min_bcd >= vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
|
||||||
|
&& ( sec_bcd > vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY_SEC ] ))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return( long_hour );
|
return( long_hour );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return( long_hour -1 ); // 1時間前に含める 注意:元旦の0時
|
return( long_hour -1 ); // 1時間前に含める 注意:元旦で昨年扱いにするとき。-1 になる
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long my_sqrt(unsigned long x)
|
|
||||||
|
/* ========================================================
|
||||||
|
軽量平方根。
|
||||||
|
必要十分な精度で打ち切る
|
||||||
|
======================================================== */
|
||||||
|
static unsigned long my_sqrt(unsigned long x)
|
||||||
{
|
{
|
||||||
unsigned long s, t;
|
unsigned long s, t;
|
||||||
|
|
||||||
@ -540,3 +485,41 @@ unsigned long my_sqrt(unsigned long x)
|
|||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ========================================================
|
||||||
|
二つの 前回呼ばれた時刻と、現在時刻の差分を求める。返るのはfill_hosu_hist_hours にそのまま渡せる
|
||||||
|
======================================================== */
|
||||||
|
static u16 calc_hours_spend( u8 year )
|
||||||
|
{
|
||||||
|
// 同じ年の内
|
||||||
|
if( cal_log_latest.year_bcd == year )
|
||||||
|
{
|
||||||
|
if( now_longhour > last_hour_fny )
|
||||||
|
{
|
||||||
|
return( now_longhour - last_hour_fny );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return( 0 ); // 同じ時間帯(と、巻き戻り。 どうなっても知らない)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( cal_log_latest.year_bcd == ( year -1 ) )
|
||||||
|
{
|
||||||
|
// 年をまたいでいるとき
|
||||||
|
return( ( ( 365 + ( is_firstyear(year) ? 1: 0 )) * 24 ) - last_hour_fny + now_longhour );
|
||||||
|
}
|
||||||
|
else if( cal_log_latest.year_bcd < year )
|
||||||
|
{
|
||||||
|
// 数年放置
|
||||||
|
return( PEDOMETER_LOG_SIZE +1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// カレンダーが巻き戻るなど
|
||||||
|
// ノーケアでよい…が、不定値というわけにもいかない
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,8 +2,17 @@
|
|||||||
#define _pedo_
|
#define _pedo_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =========================================================
|
// =========================================================
|
||||||
void hosu_read_end( );
|
extern bit pedolog_read_msb;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================
|
||||||
|
//void hosu_read_end( ); マクロ化
|
||||||
|
#define hosu_read_end() pedolog_read_msb = 0
|
||||||
|
|
||||||
u8 hosu_read( );
|
u8 hosu_read( );
|
||||||
void fill_hosu_hist_hours( u16 );
|
void fill_hosu_hist_hours( u16 );
|
||||||
void clear_hosu_hist();
|
void clear_hosu_hist();
|
||||||
|
@ -81,7 +81,8 @@ void tsk_misc( )
|
|||||||
PM互換レジスタへの書き込み
|
PM互換レジスタへの書き込み
|
||||||
ポーリングしかしてない。割り込み?
|
ポーリングしかしてない。割り込み?
|
||||||
======================================================== */
|
======================================================== */
|
||||||
if( !PM_IRQ_n ){
|
if( !PM_IRQ_n )
|
||||||
|
{
|
||||||
renge_task_immed_add( tski_ntr_pmic_comm );
|
renge_task_immed_add( tski_ntr_pmic_comm );
|
||||||
// NOP();
|
// NOP();
|
||||||
}
|
}
|
||||||
@ -110,24 +111,28 @@ void tsk_misc( )
|
|||||||
======================================================== */
|
======================================================== */
|
||||||
void check_twl_vol_irq()
|
void check_twl_vol_irq()
|
||||||
{
|
{
|
||||||
|
static u8 vol_level_twl_sent;
|
||||||
static u8 mabiki;
|
static u8 mabiki;
|
||||||
|
|
||||||
|
if( !is_TWL )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
// おしまい
|
||||||
|
}
|
||||||
|
|
||||||
if( mabiki != 0 )
|
if( mabiki != 0 )
|
||||||
{
|
{
|
||||||
mabiki--;
|
mabiki--;
|
||||||
|
return;
|
||||||
|
// おしまい
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
mabiki = 6;
|
|
||||||
|
|
||||||
if( is_TWL )
|
mabiki = 9; // 1フレームは開ける
|
||||||
{
|
if( vol_level_twl != vol_level_twl_sent )
|
||||||
if( vol_level_twl != vol_level_twl_readed )
|
|
||||||
{
|
{
|
||||||
|
vol_level_twl_sent = vol_level_twl;
|
||||||
set_irq( VREG_C_IRQ2, REG_BIT_SLIDE_VOL_ACROSS_TWL_BOUNDARY );
|
set_irq( VREG_C_IRQ2, REG_BIT_SLIDE_VOL_ACROSS_TWL_BOUNDARY );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ extern bit twl_ver_read;
|
|||||||
extern bit cam_led_update;
|
extern bit cam_led_update;
|
||||||
|
|
||||||
extern bit vol_changed_by_twl;
|
extern bit vol_changed_by_twl;
|
||||||
u8 vol_level_twl,vol_level_twl_readed; // SoC が最後に読んだVol値
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ========================================================
|
/* ========================================================
|
||||||
@ -116,10 +114,6 @@ u8 vreg_twl_read( u8 phy_adrs )
|
|||||||
vreg_twl[ REG_TWL_INT_ADRS_IRQ ]= 0;
|
vreg_twl[ REG_TWL_INT_ADRS_IRQ ]= 0;
|
||||||
return( temp );
|
return( temp );
|
||||||
|
|
||||||
case( REG_TWL_INT_ADRS_VOL ):
|
|
||||||
vol_level_twl_readed = vol_level_twl; // TWLとスライダと不整合が起きないように
|
|
||||||
return( vreg_twl[ REG_TWL_INT_ADRS_VOL ] );
|
|
||||||
|
|
||||||
case( REG_TWL_INT_ADRS_VER_INFO ):
|
case( REG_TWL_INT_ADRS_VER_INFO ):
|
||||||
// set_irq( VREG_C_IRQ2, REG_BIT_TWL_VER_READ ); // 速度的に無理なので
|
// set_irq( VREG_C_IRQ2, REG_BIT_TWL_VER_READ ); // 速度的に無理なので
|
||||||
twl_ver_read = true;
|
twl_ver_read = true;
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
#define __vreg_twl__
|
#define __vreg_twl__
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
extern u8 vreg_twl[];
|
extern u8 vreg_twl[];
|
||||||
extern u8 vol_level_twl,vol_level_twl_readed; // SoC が最後に読んだVol値
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,9 +22,9 @@ SubClock=None
|
|||||||
[Mapping]
|
[Mapping]
|
||||||
Count=0
|
Count=0
|
||||||
[Main]
|
[Main]
|
||||||
Geometry=52, 213, 1200, 858
|
Geometry=110, 110, 1200, 858
|
||||||
Window=Normal
|
Window=Max
|
||||||
MDI_MAX=ON
|
MDI_MAX=OFF
|
||||||
Button=ON
|
Button=ON
|
||||||
Mode=Auto
|
Mode=Auto
|
||||||
Trace=Uncond ON
|
Trace=Uncond ON
|
||||||
@ -78,9 +78,9 @@ Symbol Type=OFF
|
|||||||
Language=C
|
Language=C
|
||||||
Kanji=SJIS
|
Kanji=SJIS
|
||||||
[Source]
|
[Source]
|
||||||
Geometry=410, 186, 600, 400
|
Geometry=212, 6, 902, 1043
|
||||||
Window=Max
|
Window=Normal
|
||||||
DispStart=30
|
DispStart=11
|
||||||
CaretPos=81,0
|
CaretPos=81,0
|
||||||
Mode=Normal
|
Mode=Normal
|
||||||
DispFile=
|
DispFile=
|
||||||
@ -140,18 +140,18 @@ SaveStart=
|
|||||||
SaveEnd=
|
SaveEnd=
|
||||||
Accumulative=ON
|
Accumulative=ON
|
||||||
[Source1]
|
[Source1]
|
||||||
Geometry=25, 25, 600, 400
|
Geometry=32, 50, 771, 1011
|
||||||
Window=Normal
|
Window=Normal
|
||||||
DispStart=393
|
DispStart=453
|
||||||
CaretPos=442,5
|
CaretPos=506,17
|
||||||
Mode=Normal
|
Mode=Normal
|
||||||
DispFile=\\tsclient\C\78k_data\yav-mcu-basara\trunk\vreg_ctr.c
|
DispFile=\\tsclient\C\78k_data\yav-mcu-basara\trunk\pedo_alg_thre_det2.c
|
||||||
Accumulative=ON
|
Accumulative=ON
|
||||||
[Assemble]
|
[Assemble]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=574, 49, 600, 400
|
||||||
Window=Hide
|
Window=Normal
|
||||||
DispStart=847434752
|
DispStart=802
|
||||||
CaretPos=0,0
|
CaretPos=802,27
|
||||||
Address1=
|
Address1=
|
||||||
Address2=
|
Address2=
|
||||||
Address3=
|
Address3=
|
||||||
@ -259,9 +259,9 @@ Destination=0
|
|||||||
[I/O Port]
|
[I/O Port]
|
||||||
Line=0
|
Line=0
|
||||||
[Stack]
|
[Stack]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=1141, 319, 400, 300
|
||||||
Window=Hide
|
Window=Normal
|
||||||
Boundary=0
|
Boundary=13762687
|
||||||
Mode=Proper
|
Mode=Proper
|
||||||
[Sfr]
|
[Sfr]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=0, 0, 0, 0
|
||||||
@ -822,9 +822,9 @@ L529=IICWL1
|
|||||||
L530=IICWH1
|
L530=IICWH1
|
||||||
L531=SVA1
|
L531=SVA1
|
||||||
[Local Variable]
|
[Local Variable]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=1150, 803, 400, 300
|
||||||
Window=Hide
|
Window=Normal
|
||||||
Boundary=0
|
Boundary=13041851
|
||||||
Mode=Proper
|
Mode=Proper
|
||||||
[Trace View]
|
[Trace View]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=0, 0, 0, 0
|
||||||
@ -965,17 +965,20 @@ Detail=OFF
|
|||||||
Last Name=
|
Last Name=
|
||||||
Count=0
|
Count=0
|
||||||
[Variable]
|
[Variable]
|
||||||
Geometry=0, 0, 0, 0
|
Geometry=1110, 10, 440, 300
|
||||||
Window=Hide
|
Window=Normal
|
||||||
Boundary=0
|
Boundary=13762700
|
||||||
Line=0
|
0=+cal_log_latest,.,N,A,-,1
|
||||||
|
1=.last_hour_fny,D,N,A,+,1
|
||||||
|
2=.now_longhour,D,N,A,+,1
|
||||||
|
Line=3
|
||||||
[Quick Watch]
|
[Quick Watch]
|
||||||
0=
|
0=cal_buff,P,A,1
|
||||||
1=
|
1=rv,P,A,1
|
||||||
2=
|
2=iic_burst_state,P,A,1
|
||||||
3=
|
3=now_longhour,P,A,1
|
||||||
4=
|
4=last_hour_fny,P,A,1
|
||||||
5=
|
5=cal_log_latest,P,A,1
|
||||||
6=
|
6=
|
||||||
7=
|
7=
|
||||||
8=
|
8=
|
||||||
@ -990,11 +993,19 @@ Line=0
|
|||||||
Geometry=0, 0, 0, 0
|
Geometry=0, 0, 0, 0
|
||||||
Window=Hide
|
Window=Hide
|
||||||
Width=150 30 200 100
|
Width=150 30 200 100
|
||||||
Name0=Swb00001
|
Name0=Swb00003
|
||||||
Address0=vreg_ctr.c#_vreg_ctr_read+0x74
|
Address0=pedo_alg_thre_det2.c#_get_long_hour+0x7b
|
||||||
Window0=ASM
|
Window0=ASM
|
||||||
Status0=ON
|
Status0=ON
|
||||||
Count=1
|
Name1=Swb00001
|
||||||
|
Address1=pedo_alg_thre_det2.c#_hosu_increment_if_necessary+0x55
|
||||||
|
Window1=ASM
|
||||||
|
Status1=ON
|
||||||
|
Name2=Swb00002
|
||||||
|
Address2=pedo_alg_thre_det2.c#_calc_hours_spend+0x28
|
||||||
|
Window2=ASM
|
||||||
|
Status2=ON
|
||||||
|
Count=3
|
||||||
[Reset]
|
[Reset]
|
||||||
Debugger=ON
|
Debugger=ON
|
||||||
Symbol=OFF
|
Symbol=OFF
|
||||||
|
Loading…
Reference in New Issue
Block a user