mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-10-31 13:51:10 -04:00
浮動小数点を使っていたところを固定小数点に変更
お知らせLED用のドライバほぼ完成 sqrt()を差し替えてみる...(未デバッグ) 無駄な関数をマクロに git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@129 013db118-44a6-b54f-8bf7-843cb86687b1
This commit is contained in:
parent
e8aebb8b95
commit
eebc9f8aa6
@ -3,12 +3,3 @@
|
||||
|
||||
#include "incs_loader.h"
|
||||
|
||||
|
||||
|
||||
//=========================================================
|
||||
// ウォッチドッグタイマのリスタート
|
||||
// 0xACはマジック
|
||||
void WDT_Restart( void )
|
||||
{
|
||||
WDTE = WDT_RESTART_MAGIC;
|
||||
}
|
||||
|
||||
@ -9,10 +9,12 @@
|
||||
|
||||
|
||||
//=========================================================
|
||||
void WDT_Restart( void );
|
||||
// ウォッチドッグタイマのリスタート
|
||||
// void WDT_Restart( void );
|
||||
#define WDT_Restart() WDTE = WDT_RESTART_MAGIC
|
||||
|
||||
// 規定値以外を書くと例外でリセットがかかる
|
||||
#define mcu_reset WDTE = 0x5A
|
||||
#define mcu_reset WDTE = 0xFF
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
/* ========================================================
|
||||
各社バッテリーパラメータ
|
||||
======================================================== */
|
||||
static const u8 BT_PARAM[][64] = {
|
||||
const u8 BT_PARAM[][64] = {
|
||||
// ID = 0 GND マクセル
|
||||
{
|
||||
0xAD, 0x30, 0xAE, 0x70, 0xB0, 0x00, 0xB3, 0x00,
|
||||
@ -66,8 +66,11 @@ static const u8 BT_PARAM[][64] = {
|
||||
/// パラメータ無し
|
||||
};
|
||||
|
||||
static const unsigned char BT_PANA_RCOMP = 135;
|
||||
static const float BT_PANA_TEMPCOUP = 0.3;
|
||||
static const float BT_PANA_TEMPCODN = 0.5;
|
||||
const unsigned char BT_PANA_RCOMP = 135;
|
||||
// static const float BT_PANA_TEMPCOUP = 0.3;
|
||||
// static const float BT_PANA_TEMPCODN = 0.5;
|
||||
// 256倍してある
|
||||
const unsigned char BT_PANA_TEMPCOUP = 77;
|
||||
const unsigned char BT_PANA_TEMPCODN = 128;
|
||||
|
||||
#endif
|
||||
|
||||
@ -9,30 +9,26 @@ MEMORY ROM : (02000H, 03000H )
|
||||
|
||||
;;; セグメントの割当先設定
|
||||
; ブートブロック0に割り当てる
|
||||
MERGE LDR_CODE: =BCL0
|
||||
MERGE LDR_CODL: =BCL0
|
||||
;MERGE @@LCODE : AT( 0E00H ) =BCL0 ; スタートアップルーチン
|
||||
MERGE @@LCODE : =BCL0 ; スタートアップルーチン
|
||||
MERGE LDR_CODE : =BCL0
|
||||
MERGE LDR_CODL : =BCL0
|
||||
MERGE @@LCODE : =BCL0 ; スタートアップルーチン
|
||||
MERGE FSL_CODE : =BCL0 ; =FSL ; 謹製フラッシュライブラリ
|
||||
;MERGE @@LCODEL : =BCL0
|
||||
|
||||
;MERGE LDR_RINT:=BCL0
|
||||
;MERGE LDR_CNST:=BCL0
|
||||
MERGE LDR_CNSL:=BCL0
|
||||
|
||||
|
||||
; 通常領域にあてる物達
|
||||
|
||||
; 通常領域に置く
|
||||
MERGE ROM_CODE:=ROM
|
||||
;MERGE ROM_CNST:=ROM
|
||||
|
||||
|
||||
; ちょっと、困るんですが、こうしないと初期値がセットされない
|
||||
MERGE @@CNST: =ROM
|
||||
MERGE @@R_INIT: =ROM
|
||||
MERGE @@R_INIT: =ROM ; ROM以外に置きたいならスタートアップルーチンを要修正
|
||||
|
||||
|
||||
|
||||
|
||||
; 謹製フラッシュライブラリ
|
||||
; MERGE FSL_CODE:=FSL
|
||||
MERGE FSL_CODE:=BCL0
|
||||
|
||||
|
||||
; マジックナンバー
|
||||
|
||||
@ -189,15 +189,19 @@ __interrupt void int_iic_ctr( )
|
||||
vreg_ctr_after_read( reg_adrs ); // 読んだらクリアなどの処理
|
||||
}
|
||||
else
|
||||
{ // 受信
|
||||
{ // 受信
|
||||
rx_buf = IICA;
|
||||
vreg_ctr_write( reg_adrs, rx_buf );
|
||||
WREL = 1;
|
||||
}
|
||||
//
|
||||
|
||||
// レジスタアドレスのインクリメント
|
||||
/// アクセスポインタを進めない特殊なレジスタ
|
||||
if( ( reg_adrs != VREG_C_ACC_HOSU_HIST )
|
||||
&& ( reg_adrs != VREG_C_INFO ) )
|
||||
{ // この二つのレジスタは特殊なアクセス方法をする。アクセスポインタを進めない。
|
||||
&& ( reg_adrs != VREG_C_INFO )
|
||||
&& ( reg_adrs != VREG_C_FREE_ADDRESS )
|
||||
)
|
||||
{
|
||||
reg_adrs += 1;
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
/*
|
||||
|
||||
acceroへ
|
||||
#ifdef _MCU_BSR_
|
||||
#pragma interrupt INTP23 intp23_ACC_ready RB3 // 加速度センサ、データ準備完了
|
||||
|
||||
@ -2,9 +2,12 @@
|
||||
#define __jhl_defs_h__
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef signed char s8;
|
||||
typedef signed char s8;
|
||||
typedef unsigned short u16;
|
||||
typedef signed short s16;
|
||||
typedef signed short s16;
|
||||
|
||||
typedef unsigned short ux16;
|
||||
typedef signed short sx16;
|
||||
|
||||
typedef unsigned char err;
|
||||
|
||||
|
||||
157
trunk/led.c
157
trunk/led.c
@ -31,29 +31,68 @@ static void led_pow_hotaru( );
|
||||
|
||||
|
||||
// ========================================================
|
||||
// お知らせLEDのパターンを流し込んでもらう
|
||||
// お知らせLEDのパターンデータ
|
||||
uni_info_LED info_LED = {
|
||||
32,
|
||||
32,
|
||||
0,
|
||||
{
|
||||
{255, 0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
|
||||
{0,255,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
|
||||
{0,0,255},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
|
||||
{255,255,255},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
}
|
||||
};
|
||||
|
||||
//調光可能LEDのワークというか
|
||||
/*
|
||||
typedef struct{
|
||||
u8 red;
|
||||
u8 grn;
|
||||
u8 blu;
|
||||
}st_info_LED_ptn;
|
||||
|
||||
typedef struct{
|
||||
st_info_LED_ptn ptn[32];
|
||||
u8 option1;
|
||||
u8 option2;
|
||||
u8 option3;
|
||||
u8 option4;
|
||||
}st_info_LED;
|
||||
|
||||
st_info_LED info_LED;
|
||||
u8 to;
|
||||
sx16 delta;
|
||||
ux16 now;
|
||||
}st_LED_dim_status;
|
||||
*/
|
||||
st_LED_dim_status LED_dim_status_pow_B;
|
||||
st_LED_dim_status LED_dim_status_3D;
|
||||
st_LED_dim_status LED_dim_status_WiFi;
|
||||
|
||||
|
||||
|
||||
// ========================================================
|
||||
#define led_fade_to( now, goal ) now = fade_to( now, goal )
|
||||
|
||||
|
||||
|
||||
/* ========================================================
|
||||
reg_ledをgoalになるまでグラデーションする
|
||||
とりあえず、ステップ固定
|
||||
@ -77,6 +116,29 @@ u8 fade_to( u8 now, u8 goal )
|
||||
|
||||
|
||||
|
||||
// ========================================================
|
||||
#define led_fade_to2( led, status ) \
|
||||
led = fade_to2( status )
|
||||
|
||||
|
||||
u8 fade_to2( st_LED_dim_status* status )
|
||||
{
|
||||
if( status->now != status->to )
|
||||
{
|
||||
if( abs(( status->to - status->now )) > abs(status->delta) )
|
||||
{
|
||||
status->now += status->delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
status->now = status->to;
|
||||
}
|
||||
}
|
||||
return( status->now / 128 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ========================================================
|
||||
|
||||
@ -418,38 +480,45 @@ void tsk_led_wifi( )
|
||||
void tsk_led_notify( )
|
||||
{
|
||||
// static u8 task_interval;
|
||||
static u16 time_to_next;
|
||||
static u8 pos;
|
||||
st_info_LED_ptn temp;
|
||||
static u8 time_to_next_frame;
|
||||
static u8 frame;
|
||||
static st_LED_dim_status LED_dim_status_info_R, LED_dim_status_info_G, LED_dim_status_info_B;
|
||||
|
||||
temp = info_LED.ptn[ pos ];
|
||||
/*
|
||||
led_fade_to( LED_duty_notify_red, (u8)temp.red );
|
||||
led_fade_to( LED_duty_notify_grn, (u8)temp.grn );
|
||||
led_fade_to( LED_duty_notify_blu, (u8)temp.blu );
|
||||
/*/
|
||||
LED_duty_notify_red = (u8)temp.red;
|
||||
LED_duty_notify_grn = (u8)temp.grn;
|
||||
LED_duty_notify_blu = (u8)temp.blu;
|
||||
//*/
|
||||
/*
|
||||
if( task_interval != 0 )
|
||||
|
||||
// 次のフレームに進める?
|
||||
if( time_to_next_frame == 0 )
|
||||
{
|
||||
task_interval -= 1;
|
||||
return;
|
||||
st_info_LED_ptn temp;
|
||||
|
||||
time_to_next_frame = info_LED.info_LED.term;
|
||||
|
||||
frame += 1;
|
||||
// 最後のフレームリピート
|
||||
if( frame > NOTIFY_LED_TERM + 1 + info_LED.info_LED.last_loop )
|
||||
{
|
||||
frame = 0;
|
||||
}
|
||||
|
||||
if( frame <= NOTIFY_LED_TERM )
|
||||
{
|
||||
temp = info_LED.info_LED.ptn[ frame ];
|
||||
|
||||
LED_dim_status_info_R.to = temp.red * 128;
|
||||
LED_dim_status_info_G.to = temp.grn * 128;
|
||||
LED_dim_status_info_B.to = temp.blu * 128;
|
||||
|
||||
// グラデーションのデルタを計算
|
||||
LED_dim_status_info_R.delta = (( LED_dim_status_info_R.to - LED_dim_status_info_R.now ) ) / info_LED.info_LED.fade_time;
|
||||
LED_dim_status_info_G.delta = (( LED_dim_status_info_G.to - LED_dim_status_info_G.now ) ) / info_LED.info_LED.fade_time;
|
||||
LED_dim_status_info_B.delta = (( LED_dim_status_info_B.to - LED_dim_status_info_B.now ) ) / info_LED.info_LED.fade_time;
|
||||
}
|
||||
|
||||
}
|
||||
task_interval -= 1;
|
||||
*/
|
||||
|
||||
if( time_to_next-- != 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
time_to_next = 32;
|
||||
pos += 1;
|
||||
pos &= 0x1F;
|
||||
time_to_next_frame -= 1;
|
||||
|
||||
led_fade_to2( LED_duty_notify_red, &LED_dim_status_info_R );
|
||||
led_fade_to2( LED_duty_notify_grn, &LED_dim_status_info_G );
|
||||
led_fade_to2( LED_duty_notify_blu, &LED_dim_status_info_B );
|
||||
}
|
||||
|
||||
|
||||
|
||||
32
trunk/led.h
32
trunk/led.h
@ -23,6 +23,7 @@
|
||||
|
||||
#define LED_BRIGHT_MAX 0x00FF
|
||||
|
||||
#define NOTIFY_LED_TERM 32 - 1
|
||||
|
||||
// ====================================
|
||||
#ifdef _MCU_BSR_ // 電波送信パルス
|
||||
@ -88,6 +89,37 @@ enum
|
||||
|
||||
|
||||
|
||||
// お知らせLED調光関係 //
|
||||
typedef struct{
|
||||
u8 red;
|
||||
u8 grn;
|
||||
u8 blu;
|
||||
}st_info_LED_ptn;
|
||||
|
||||
typedef struct{
|
||||
u8 term; // 1フレーム何チック?
|
||||
u8 fade_time; // 何チックで次のフレームの色に達するか
|
||||
u8 last_loop; // 最終フレームをn回繰り返す(0=1回)
|
||||
st_info_LED_ptn ptn[32];
|
||||
}st_info_LED;
|
||||
|
||||
typedef union{
|
||||
st_info_LED info_LED;
|
||||
u8 bindata[ sizeof( st_info_LED ) ];
|
||||
}uni_info_LED;
|
||||
|
||||
extern uni_info_LED info_LED;
|
||||
|
||||
|
||||
/*
|
||||
お知らせLED
|
||||
*/
|
||||
typedef struct{
|
||||
sx16 to;
|
||||
sx16 delta;
|
||||
sx16 now; // 小数点以下を覚えておかなくてはならないため
|
||||
}st_LED_dim_status;
|
||||
|
||||
// ====================================
|
||||
void LED_init( );
|
||||
void LED_stop( );
|
||||
|
||||
@ -55,11 +55,11 @@ __far static const unsigned char MGC_LOAD[] =
|
||||
|
||||
// V0.4ˆÈ<EFBFBD>~
|
||||
#pragma section @@CNSTL MGC_LOAD AT 0x0FF6
|
||||
__far static const unsigned char MGC_LOAD[] = __TIME__;
|
||||
__far const unsigned char MGC_LOAD[] = __TIME__;
|
||||
|
||||
#pragma section @@CNST MGC_MIMI AT 0x2100
|
||||
static const unsigned char MGC_HEAD[] = __TIME__;
|
||||
const unsigned char MGC_HEAD[] = __TIME__;
|
||||
|
||||
#pragma section @@CNST MGC_TAIL AT 0x47F6
|
||||
static const unsigned char MGC_TAIL[] = __TIME__;
|
||||
const unsigned char MGC_TAIL[] = __TIME__;
|
||||
*/
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
/* ********************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
歩数計
|
||||
3軸加速度のリアルタイムデータから、ベクトルのノルムを出し、
|
||||
閾値を超える時間、間隔、ノルムの大きさで閾値を切り替えるなど
|
||||
********************************************************* */
|
||||
#pragma mul
|
||||
#pragma div
|
||||
@ -28,6 +27,14 @@ extern uni_pool pool;
|
||||
|
||||
|
||||
|
||||
// ========================================================
|
||||
#define _use_my_sqrt_
|
||||
#ifdef _use_my_sqrt_
|
||||
unsigned long my_sqrt();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*=========================================================
|
||||
歩数計
|
||||
========================================================*/
|
||||
@ -50,19 +57,23 @@ void pedometer()
|
||||
|
||||
u8 i;
|
||||
|
||||
signed long temp1,temp2,temp3;
|
||||
signed long temp4,temp5,temp6;
|
||||
|
||||
u16 sx16 = abs( (u16)vreg_ctr[VREG_C_ACC_XH] * 256 + vreg_ctr[VREG_C_ACC_XL] );
|
||||
u16 sy16 = abs( (u16)vreg_ctr[VREG_C_ACC_YH] * 256 + vreg_ctr[VREG_C_ACC_YL] );
|
||||
u16 sz16 = abs( (u16)vreg_ctr[VREG_C_ACC_ZH] * 256 + vreg_ctr[VREG_C_ACC_ZL] );
|
||||
|
||||
// ベクトルのノルム
|
||||
#ifdef _mcu_
|
||||
# ifndef _use_my_sqrt_
|
||||
norm_hist[ hist_indx & TAP-1 ] = sqrt( (long)sx16 * ( sx16 / 2 ) +
|
||||
(long)sy16 * ( sy16 / 2 ) +
|
||||
(long)sz16 * ( sz16 / 2 )
|
||||
);
|
||||
# else
|
||||
norm_hist[ hist_indx & TAP-1 ] = my_sqrt( (long)sx16 * ( sx16 / 2 ) +
|
||||
(long)sy16 * ( sy16 / 2 ) +
|
||||
(long)sz16 * ( sz16 / 2 )
|
||||
);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _pc_
|
||||
@ -420,3 +431,102 @@ u16 get_long_hour()
|
||||
return( long_hour );
|
||||
}
|
||||
|
||||
|
||||
# ifdef _use_my_sqrt_
|
||||
// ========================================================
|
||||
// 高速?平方根アルゴリズム
|
||||
// ========================================================
|
||||
#if 0
|
||||
// 拝借もと
|
||||
// ttp://www.finetune.co.jp/~lyuka/technote/fract/sqrt_hypot.html
|
||||
/* NAME
|
||||
* sqrtl - square root function
|
||||
* SYNOPSYS
|
||||
* long
|
||||
* sqrtl(long x)
|
||||
* DISCRIPTIONS
|
||||
* The sqrtl() function compute the non-negative square root of x.
|
||||
* ERROR
|
||||
* Below 1/2 LSB.
|
||||
* SEE ALSO
|
||||
* sqrt(3), http://www.finetune.co.jp/~lyuka/fract/sqrt_hypot.html
|
||||
* COPYRIGHT
|
||||
* Copyright 2002, Takayuki HOSODA. All rights reserved.
|
||||
*/
|
||||
unsigned long my_sqrt( unsigned long a )
|
||||
{
|
||||
unsigned long x;
|
||||
unsigned long t;
|
||||
unsigned long s;
|
||||
unsigned char scale;
|
||||
|
||||
x = a;
|
||||
if (x > 0) {
|
||||
scale = 0;
|
||||
if (x < 0x8000) {
|
||||
x <<= 16;
|
||||
scale = 8;
|
||||
a = x;
|
||||
}
|
||||
x >>= 8;
|
||||
s = 8;
|
||||
for (t = 0x400000L; x < t; t >>= 2)
|
||||
s--;
|
||||
t = 88;
|
||||
t <<= s;
|
||||
x *= 22;
|
||||
s += 5;
|
||||
x >>= s; // -3.1e-2 < err < +2.9e-2
|
||||
/* 打ち切り
|
||||
s = a;
|
||||
t += x;
|
||||
x = s;
|
||||
s /= t;
|
||||
s += t;
|
||||
s >>= 1; // -4.8e-4 < err <= 0
|
||||
t = x;
|
||||
x /= s;
|
||||
x += s;
|
||||
x >>= 1; // -1.2e-7 < err <= 0
|
||||
s = x;
|
||||
s++;
|
||||
s *= x;
|
||||
if (t > s) // adjust LSB
|
||||
x++;
|
||||
*/
|
||||
if (scale) {
|
||||
x += 127;
|
||||
x >>= 8;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
// 拝借もと
|
||||
// ttp://www001.upp.so-net.ne.jp/y_yutaka/labo/math_algo/math_algo.html
|
||||
unsigned long my_sqrt(unsigned long x)
|
||||
{
|
||||
unsigned long s, t;
|
||||
|
||||
if (x <= 0) return 0;
|
||||
|
||||
s = 1;
|
||||
t = x;
|
||||
while (s < t)
|
||||
{
|
||||
s <<= 1;
|
||||
t >>= 1;
|
||||
}
|
||||
do
|
||||
{
|
||||
t = s;
|
||||
s = (x / s + s) >> 1;
|
||||
} while (s < t);
|
||||
|
||||
return t;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
91
trunk/pm.c
91
trunk/pm.c
@ -25,8 +25,11 @@
|
||||
// ========================================================
|
||||
u8 raw_adc_temperature;
|
||||
u8 rcomp;
|
||||
float temp_co_up;
|
||||
float temp_co_dn;
|
||||
// float temp_co_up;
|
||||
// float temp_co_dn;
|
||||
// 256倍してある
|
||||
unsigned char temp_co_up;
|
||||
unsigned char temp_co_dn;
|
||||
BT_VENDER battery_manufacturer = BT_VENDER_NOT_CHECKED;
|
||||
|
||||
|
||||
@ -85,6 +88,8 @@ err PM_LCD_on( )
|
||||
// BSR //
|
||||
void PM_LCD_off()
|
||||
{
|
||||
u8 temp;
|
||||
|
||||
SND_DEPOP_SND_MUTE;
|
||||
|
||||
// BLついてたら消す
|
||||
@ -115,12 +120,14 @@ void PM_LCD_off()
|
||||
blset = 0;
|
||||
#endif
|
||||
|
||||
PM_TCOM_VCS_off( );
|
||||
wait_ms( DELAY_PM_LCD_OFF );
|
||||
|
||||
PM_VDDLCD_off( ); // 残ってたの全部止めます。
|
||||
vreg_ctr[VREG_C_STATUS] &= ~REG_BIT_LCD_POW;
|
||||
if( iic_mcu_read_a_byte( IIC_SLA_PMIC, PM_REG_VDD_LCD ) != 0 )
|
||||
{
|
||||
PM_TCOM_VCS_off( );
|
||||
wait_ms( DELAY_PM_LCD_OFF );
|
||||
|
||||
PM_VDDLCD_off( ); // 残ってたの全部止めます。
|
||||
vreg_ctr[VREG_C_STATUS] &= ~REG_BIT_LCD_POW;
|
||||
}
|
||||
|
||||
set_irq( VREG_C_IRQ3, REG_BIT_LCD_OFF );
|
||||
}
|
||||
@ -703,34 +710,7 @@ void tsk_batt( )
|
||||
// 電池残量 //
|
||||
if( system_status.pwr_state == ON )
|
||||
{
|
||||
static u8 bt_left_state; // バッテリ残量で割り込みのため
|
||||
|
||||
BT_get_left();
|
||||
switch( bt_left_state )
|
||||
{
|
||||
case( 0 ): // 前回、バッテリーは十分にあった
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] <= BATT_TH_LO )
|
||||
{
|
||||
bt_left_state = 1; // 突然バッテリ残量が減っても、Lo割り込みを入れる
|
||||
set_irq( VREG_C_IRQ1, REG_BIT_BT_REMAIN );
|
||||
}
|
||||
break;
|
||||
|
||||
case( 1 ):
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] <= BATT_TH_EMPTY )
|
||||
{
|
||||
bt_left_state = 2;
|
||||
set_irq( VREG_C_IRQ1, REG_BIT_BT_REMAIN );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] > BATT_TH_LO )
|
||||
{
|
||||
bt_left_state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@ -933,7 +913,8 @@ task_status_immed BT_temp_update( )
|
||||
static u8 count = 0; // たまにしか書きに行かない
|
||||
|
||||
static u8 rawdat_old;
|
||||
static s16 temperature; // todo
|
||||
// static s16 temperature; // todo
|
||||
static unsigned long temperature; // todo
|
||||
u16 newrcomp;
|
||||
|
||||
/*
|
||||
@ -944,8 +925,10 @@ task_status_immed BT_temp_update( )
|
||||
*/
|
||||
if( rawdat_old != raw_adc_temperature ){
|
||||
DBG_P_n = 1;
|
||||
temperature = 81.45 - 111.9 * raw_adc_temperature/256.0;
|
||||
vreg_ctr[VREG_C_BT_TEMP] = (u8)temperature;
|
||||
// temperature = 81.45 - 111.9 * raw_adc_temperature/256.0;
|
||||
// それぞれ256倍してある
|
||||
temperature = 20851 - 28646 * raw_adc_temperature;
|
||||
vreg_ctr[VREG_C_BT_TEMP] = (u8)temperature / 256;
|
||||
DBG_P_n = 0;
|
||||
}
|
||||
|
||||
@ -955,11 +938,11 @@ task_status_immed BT_temp_update( )
|
||||
DBG_P_n = 1;
|
||||
if( vreg_ctr[VREG_C_BT_TEMP] > 20 )
|
||||
{
|
||||
newrcomp = -( ( temperature - 20 ) * temp_co_up );
|
||||
newrcomp = -( ( temperature - 20 ) * temp_co_up )/256;
|
||||
}
|
||||
else
|
||||
{
|
||||
newrcomp = -( ( temperature - 20 ) * temp_co_dn );
|
||||
newrcomp = -( ( temperature - 20 ) * temp_co_dn )/256;
|
||||
}
|
||||
newrcomp += rcomp;
|
||||
|
||||
@ -990,13 +973,41 @@ void BT_get_left(){
|
||||
{
|
||||
// 電池残量の取得
|
||||
{
|
||||
static u8 bt_left_state; // バッテリ残量で割り込みのため
|
||||
u8 temp[2];
|
||||
|
||||
iic_mcu_read( IIC_SLA_BT_GAUGE, BT_GAUGE_REG_SOC, 2, temp );
|
||||
|
||||
vreg_ctr[ VREG_C_BT_REMAIN ] = temp[0];
|
||||
vreg_ctr[ VREG_C_BT_REMAIN_FINE ] = temp[1];
|
||||
// todo 閾値を超えたら割り込み
|
||||
|
||||
// 残量で割り込み
|
||||
switch( bt_left_state )
|
||||
{
|
||||
case( 0 ): // 前回、バッテリーは十分にあった
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] <= BATT_TH_LO )
|
||||
{
|
||||
bt_left_state = 1; // 突然バッテリ残量が減っても、Lo割り込みを入れる
|
||||
set_irq( VREG_C_IRQ1, REG_BIT_BT_REMAIN );
|
||||
}
|
||||
break;
|
||||
|
||||
case( 1 ):
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] <= BATT_TH_EMPTY )
|
||||
{
|
||||
bt_left_state = 2;
|
||||
set_irq( VREG_C_IRQ1, REG_BIT_BT_REMAIN );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if( vreg_ctr[ VREG_C_BT_REMAIN ] > BATT_TH_LO )
|
||||
{
|
||||
bt_left_state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
vreg_ctr[ VREG_C_BT_VOLTAGE ] = iic_mcu_read_a_byte( IIC_SLA_BT_GAUGE, BT_GAUGE_REG_VCELL );
|
||||
}
|
||||
|
||||
@ -4,10 +4,12 @@
|
||||
|
||||
#include "pedometer.h"
|
||||
|
||||
#define VREG_C_FREE_SIZE 24
|
||||
|
||||
// 空いてるメモリ
|
||||
typedef struct {
|
||||
unsigned short pedo_log[ PEDOMETER_LOG_SIZE ];
|
||||
unsigned char vreg_c_free[ 24 ];
|
||||
unsigned char vreg_c_free[ VREG_C_FREE_SIZE ];
|
||||
}st_vreg_c_ext;
|
||||
|
||||
typedef union{
|
||||
@ -18,5 +20,4 @@ typedef union{
|
||||
extern uni_pool pool;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -9,12 +9,14 @@ CTR MCU I2C
|
||||
#include "led.h"
|
||||
#include "accero.h"
|
||||
#include "pm.h"
|
||||
#include "pool.h"
|
||||
|
||||
#include <fsl.h>
|
||||
#include "fsl_user.h"
|
||||
|
||||
extern u8 mcu_info_read(); // task_misc.c
|
||||
|
||||
extern u8 mcu_info_read(); // task_misc.c
|
||||
extern u8 iic_burst_state;
|
||||
|
||||
|
||||
// ********************************************************
|
||||
@ -153,24 +155,20 @@ void vreg_ctr_write( u8 adrs, u8 data )
|
||||
vreg_ctr[adrs] = data;
|
||||
break;
|
||||
|
||||
case ( VREG_C_FREE_0 ):
|
||||
case ( VREG_C_FREE_1 ):
|
||||
case ( VREG_C_FREE_2 ):
|
||||
case ( VREG_C_FREE_3 ):
|
||||
case ( VREG_C_FREE_4 ):
|
||||
case ( VREG_C_FREE_5 ):
|
||||
case ( VREG_C_FREE_6 ):
|
||||
case ( VREG_C_FREE_7 ):
|
||||
case ( VREG_C_FREE_8 ):
|
||||
case ( VREG_C_FREE_9 ):
|
||||
case ( VREG_C_FREE_A ):
|
||||
case ( VREG_C_FREE_B ):
|
||||
case ( VREG_C_FREE_C ):
|
||||
case ( VREG_C_FREE_D ):
|
||||
case ( VREG_C_FREE_E ):
|
||||
case ( VREG_C_FREE_F ):
|
||||
vreg_ctr[adrs] = data;
|
||||
break;
|
||||
case ( VREG_C_FREE_ADDRESS ):
|
||||
if( iic_burst_state == 0 )
|
||||
{
|
||||
iic_burst_state = 1;
|
||||
vreg_ctr[adrs] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( vreg_ctr[ VREG_C_FREE_ADDRESS ] >= VREG_C_FREE_SIZE )
|
||||
{
|
||||
vreg_ctr[ VREG_C_FREE_ADDRESS ] = 0;
|
||||
}
|
||||
pool.vreg_c_ext.vreg_c_free[ vreg_ctr[ VREG_C_FREE_ADDRESS ]++ ] = data;
|
||||
}
|
||||
|
||||
case ( VREG_C_LED_BRIGHT ):
|
||||
vreg_ctr[adrs] = data;
|
||||
@ -180,10 +178,29 @@ void vreg_ctr_write( u8 adrs, u8 data )
|
||||
case ( VREG_C_LED_WIFI ):
|
||||
case ( VREG_C_LED_CAM ):
|
||||
case ( VREG_C_LED_TUNE ):
|
||||
case ( VREG_C_LED_NOTIFY ):
|
||||
vreg_ctr[adrs] = data & 0x0F;
|
||||
break;
|
||||
|
||||
case ( VREG_C_LED_NOTIFY_DATA ):
|
||||
if( iic_burst_state == 0 )
|
||||
{
|
||||
iic_burst_state += 1;
|
||||
vreg_ctr[adrs] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( iic_burst_state > sizeof( uni_info_LED ) )
|
||||
{
|
||||
iic_burst_state = 1;
|
||||
}
|
||||
info_LED.bindata[ iic_burst_state -1 ] = data;
|
||||
iic_burst_state += 1;
|
||||
}
|
||||
|
||||
case ( VREG_C_LED_NOTIFY_OPTION ):
|
||||
vreg_ctr[adrs] = data;
|
||||
break;
|
||||
|
||||
/// 非同期で動いているためここでは書かない。
|
||||
// 予約するだけでstopで書く
|
||||
case ( VREG_C_RTC_SEC ):
|
||||
@ -314,6 +331,10 @@ u8 vreg_ctr_read( u8 adrs )
|
||||
{
|
||||
return( hosu_read() );
|
||||
}
|
||||
else if( adrs == VREG_C_FREE_ADDRESS )
|
||||
{
|
||||
return( pool.vreg_c_ext.vreg_c_free[ vreg_ctr[VREG_C_FREE_ADDRESS]++ ] );
|
||||
}
|
||||
else if( adrs == VREG_C_RTC_SEC_FINE_L )
|
||||
{
|
||||
rsub_temp = RSUBC;
|
||||
@ -325,6 +346,9 @@ u8 vreg_ctr_read( u8 adrs )
|
||||
}
|
||||
else if( adrs == VREG_C_INFO )
|
||||
{
|
||||
// I2C_mを使うので、ここからでは割り込みが使えなくて困る
|
||||
// なのでタスク登録する。
|
||||
// 強制的にI2C_2割り込みをマスクする
|
||||
renge_task_immed_add( tski_mcu_info_read );
|
||||
IICAMK = 1;
|
||||
return( 0x4A );
|
||||
|
||||
@ -193,7 +193,9 @@ enum VREG_C
|
||||
VREG_C_LED_WIFI,
|
||||
VREG_C_LED_CAM,
|
||||
VREG_C_LED_TUNE,
|
||||
VREG_C_LED_NOTIFY,
|
||||
VREG_C_LED_NOTIFY_DATA,
|
||||
VREG_C_LED_NOTIFY_OPTION,
|
||||
VREG_C_LED_NOTIFY_FLAG,
|
||||
|
||||
VREG_C_RTC_SEC = 0x30,
|
||||
VREG_C_RTC_MIN,
|
||||
@ -233,25 +235,9 @@ enum VREG_C
|
||||
VREG_C_ACC_HOSU_SETTING,
|
||||
VREG_C_ACC_HOSU_HIST = 0x4F,
|
||||
|
||||
// VREG_C_AMBIENT_BRIGHTNESS = 0x60,
|
||||
// VREG_C_AMBIENT_BRIGHTNESS = 0xXX,
|
||||
|
||||
// 歩数計の評価のため...
|
||||
VREG_C_FREE_0 = 0x50,
|
||||
VREG_C_FREE_1,
|
||||
VREG_C_FREE_2,
|
||||
VREG_C_FREE_3,
|
||||
VREG_C_FREE_4,
|
||||
VREG_C_FREE_5,
|
||||
VREG_C_FREE_6,
|
||||
VREG_C_FREE_7,
|
||||
VREG_C_FREE_8,
|
||||
VREG_C_FREE_9,
|
||||
VREG_C_FREE_A,
|
||||
VREG_C_FREE_B,
|
||||
VREG_C_FREE_C,
|
||||
VREG_C_FREE_D,
|
||||
VREG_C_FREE_E,
|
||||
VREG_C_FREE_F,
|
||||
VREG_C_FREE_ADDRESS = 0x50,
|
||||
|
||||
VREG_C_ENDMARK_
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user