■3.41 jane プリライト

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@624 013db118-44a6-b54f-8bf7-843cb86687b1
This commit is contained in:
N2232 2016-12-02 00:48:50 +00:00
parent bdd7c46617
commit 59cb0f91a4
110 changed files with 19904 additions and 0 deletions

View File

@ -0,0 +1,159 @@
############################################################
# 環境設定
############################################################
# マイコン開発環境のインストール先を環境変数で指定する
NECEL_ROOT =
if $(defined-env NECEL_ROOT)
value $(absname $"$(getenv NECEL_ROOT)")
else
value "C:\Program Files (x86)\NEC Electronics Tools"
# cygwinのインストール先を環境変数で指定する
CYGWIN_ROOT =
if $(defined-env CYGWIN_ROOT)
value $(absname $"$(getenv CYGWIN_ROOT)")
else
value "C:\cygwin"
# GCCバージョンを環境変数で指定する
CYGWIN_GCC =
if $(defined-env CYGWIN_GCC)
value $(CYGWIN_ROOT)/bin/$"$(getenv CYGWIN_GCC)"
else
value $(CYGWIN_ROOT)/bin/gcc-4
#デバイスファイルは NECEL_ROOT/dev に置くこと
#自己アップデート用ライブラリは CC_LIBS_ROOT/以下に置くこと
SUBDIR_INTER_ASM = $(dir inter_asm)
CC_ROOT = $(NECEL_ROOT)/CC78K0R
CC_VER = W2.13
CC = $(CC_ROOT)/$(CC_VER)/bin/cc78k0r.exe
RA = $(NECEL_ROOT)/RA78K0R/W1.33/bin/ra78k0r.exe
LK = $(NECEL_ROOT)/RA78K0R/W1.33/bin/lk78k0r.exe
OC = $(NECEL_ROOT)/RA78K0R/W1.33/bin/oc78k0r.exe
LCNV = $(NECEL_ROOT)/RA78K0R/W1.33/bin/lc78k0r.exe
DEVFILE_ROOT = $(NECEL_ROOT)/dev
CC_LIBS_ROOT = $(CC_ROOT)/$(CC_VER)/lib78k0r
CC_INCLUDES_ROOT = $(CC_ROOT)/$(CC_VER)/inc78k0r
S0RM = s0rm.rel
# セキュリティID
GIVALUE = 1B339499E033F240BFAAh
# ユーザオプションバイト
GBValue = 7EFBFFh
DEVICE_NAME = 9F0104
FSL_LIB = fsl.lib
TARGET_NAME = bsr
TARGET_LMF = $(TARGET_NAME).lmf
TARGET_HEX = $(TARGET_NAME).hex
# ここまで
############################################################
############################################################
# ソースを追加したら編集する箇所
############################################################
SRC_FILES[] =
loader
pm
i2c_ctr
main
magic
WDT
i2c_mcu
i2c_twl
led
rtc
vreg_ctr
vreg_twl
adc
renge\renge
accero
self_flash
sw
task_debug
task_misc
task_sys
pedo_alg_thre_det2
ini_VECT
task_status
led_cam
led_pow
hal
batt_params
voltable
pedo_lpf_coeff
INCLUDES[] =
./
renge
# ここまで
############################################################
.PHONY: clean BeforeBuild
AddRel(files) =
file_names = $(addsuffix .rel, $(files))
return $(file_names)
# *.cからinter_asm/*.asmを作るための関数
AsmProgram(files) =
foreach(filename, $(files))
asm_name = $(addprefix $(SUBDIR_INTER_ASM)/, $(addsuffix .asm, $(basename $(filename))))
c_name = $(addsuffix .c, $(filename))
.SCANNER: $(asm_name): $(c_name)
$(CYGWIN_GCC) -MM -w -I$(CC_INCLUDES_ROOT) $(c_name) | sed 's/$(filename)\.o/$(SUBDIR_INTER_ASM)\/$(filename)\.asm/g'
$(asm_name): $(c_name)
$(CC) -c$(DEVICE_NAME) -y$(DEVFILE_ROOT) -_msgoff -irenge -i$(CC_INCLUDES_ROOT) -ms -qvjl2w -sa$(SUBDIR_INTER_ASM) -zpb -no $(c_name)
return $(addsuffix .c, $(files))
# inter_asm/*.asm から *.relを作るための関数
RelProgram(files) =
foreach(filename, $(files))
rel_name = $(addsuffix .rel, $(basename $(filename)))
asm_name = $(addprefix $(SUBDIR_INTER_ASM)/, $(addsuffix .asm, $(basename $(filename))))
asm_win_name = $(addprefix $(SUBDIR_INTER_ASM)\\, $(addsuffix .asm, $(basename $(filename))))
c_name = $(addsuffix .c, $(filename))
.SCANNER: $(rel_name): $(asm_win_name)
$(CYGWIN_GCC) -MM -w -I$(CC_INCLUDES_ROOT) $(c_name) | sed 's/\.o/\.rel/g'
$(rel_name): $(asm_name)
$(RA) -c$(DEVICE_NAME) -y$(DEVFILE_ROOT) -_msgoff $(asm_win_name)
return $(addsuffix .rel, $(basename $(files)))
$(TARGET_LMF): $(RelProgram $(SRC_FILES)) $(AsmProgram $(SRC_FILES))
$(LK) -y$(DEVFILE_ROOT) -_msgoff -o$(TARGET_LMF) $(CC_LIBS_ROOT)/$(S0RM) -gi$(GIVALUE) -pbsr_k0r.map -nkd -gb$(GBValue) -b$(CC_LIBS_ROOT)/$(FSL_LIB) -bcl0rdm.lib -bcl0rm.lib -bcl0rmf.lib -i$(CC_LIBS_ROOT) -dbsr_mcu.dr -s -w0 $(AddRel $(basename $(SRC_FILES)))
$(TARGET_HEX) : $(TARGET_LMF)
$(OC) -y$(DEVFILE_ROOT) -_msgoff -o.\\$(TARGET_HEX) -nu -ki $(TARGET_LMF)
BeforeBuild:
# ビルド前に必ず実行したい処理
# OMakeがタイムスタンプではなくMD5でファイルの状態を管理しているので
# 残念ながら cleanしてからビルドしなおす必要がある
C:\Windows\system32\cmd.exe /c $(CYGWIN_ROOT)\bin\touch magic.c
if $(not $(file-exists $(SUBDIR_INTER_ASM)))
mkdir $(SUBDIR_INTER_ASM)
hoge.bin: BeforeBuild $(TARGET_HEX)
C:\Windows\system32\cmd.exe /c ruby nec_s_2_bsrbin2.rb $(TARGET_HEX)
clean:
rm -rf *.prn *.rel $(SUBDIR_INTER_ASM)/*.asm *.omc .omakedb .omakedb.lock
.DEFAULT: hoge.bin

View File

@ -0,0 +1,4 @@
#
# Include the OMakefile in this directory.
#
.SUBDIRS: .

Binary file not shown.

View File

@ -0,0 +1,2 @@
#v4.0:v100
Debug|Win32|C:\78k_data\yav-mcu-basara\trunk\VCProj\|

View File

@ -0,0 +1,105 @@
2016/09/06 9:50:08 にビルドを開始しました。
1>ノード 2 上のプロジェクト "C:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\VCProj\bsr_trunk.vcxproj" (build ターゲット)。
1>InitializeBuildStatus:
"AlwaysCreate" が指定されたため "Debug\arr_trunk.unsuccessfulbuild" を作成しています。
ClCompile:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /Zi /nologo /W1 /WX- /O2 /Oy- /D _MBCS /D _MBCS /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TC /analyze- /errorReport:prompt ..\accero.c ..\adc.c ..\batt_params.c ..\hal.c ..\i2c_ctr.c "..\i2c_mcu-sub.c" ..\i2c_mcu.c ..\i2c_twl.c ..\ini_VECT.c ..\kanaria_c.c ..\led.c ..\led_cam.c ..\led_pow.c ..\loader.c ..\magic.c ..\main.c ..\my_led.c ..\pedo_alg_thre_det2.c ..\pedo_lpf_coeff.c ..\pm.c ..\reboot.c ..\renge\renge.c ..\rtc.c ..\self_flash.c ..\sim\simFixture.c ..\sim\sim_interrupt_decrare.c ..\sw.c ..\task_debug.c ..\task_misc.c ..\task_status.c ..\task_sys.c ..\util_funcs.c ..\voltable.c ..\vreg_ctr.c ..\vreg_twl.c ..\WDT.c
accero.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
adc.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
batt_params.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\batt_params.h(30): error C2059: 構文エラー : '定数'
hal.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
i2c_ctr.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
i2c_mcu-sub.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
i2c_mcu.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
i2c_twl.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
ini_VECT.c
1>..\ini_VECT.c(344): fatal error C1083: include ファイルを開けません。'sim/sim_interrupt_decrare.c': No such file or directory
kanaria_c.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
led.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
led_cam.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
led_pow.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
loader.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
magic.c
main.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
my_led.c
1>c1 : fatal error C1083: ソース ファイルを開けません。'..\my_led.c': No such file or directory
pedo_alg_thre_det2.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
pedo_lpf_coeff.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
pm.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
コードを生成中...
コンパイル中...
reboot.c
1>..\reboot.c(8): warning C4068: 不明なプラグマがありました。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
renge.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(16): error C2054: '__callt' の後に '(' が必要です。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(16): error C2085: 'renge_task_immed_run' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(17): error C2061: 構文エラー : 識別子 '__callt'
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(22): error C2054: '__callt' の後に '(' が必要です。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(22): error C2085: 'renge_task_interval_run' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(23): error C2085: 'renge_flg_interval' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge.h(24): error C2085: 'renge_task_interval_run_force' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(13): error C2085: 'tsk_sw' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(14): error C2085: 'tsk_adc' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(15): error C2085: 'tsk_batt' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(16): error C2085: 'tsk_led_pow' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(17): error C2085: 'tsk_led_wifi' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(18): error C2085: 'tsk_led_notify' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(19): error C2085: 'tsk_led_cam' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(20): error C2085: 'tsk_misc' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(21): error C2085: 'tsk_status' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(22): error C2085: 'tsk_sys' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(24): error C2085: 'tasks' : 仮パラメーター リスト内にありません。
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\renge\renge_task_intval.h(24): error C2143: 構文エラー : ';' が '=' の前にありません。
1>..\renge\renge.c(33): fatal error C1083: include ファイルを開けません。'../sim/simOnWin.h': No such file or directory
rtc.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
self_flash.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
simFixture.c
1>c1 : fatal error C1083: ソース ファイルを開けません。'..\sim\simFixture.c': No such file or directory
sim_interrupt_decrare.c
1>c1 : fatal error C1083: ソース ファイルを開けません。'..\sim\sim_interrupt_decrare.c': No such file or directory
sw.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
task_debug.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
task_misc.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
task_status.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
task_sys.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
util_funcs.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
voltable.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
vreg_ctr.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
vreg_twl.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs.h(17): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
WDT.c
1>c:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\incs_loader.h(28): fatal error C1083: include ファイルを開けません。'sim/simOnWin.h': No such file or directory
コードを生成中...
1>プロジェクト "C:\78k_data\yav-mcu-basara\snake_branches\3.40_jane\VCProj\bsr_trunk.vcxproj" (build ターゲット) のビルドが終了しました -- 失敗。
ビルドに失敗しました。
経過時間 00:00:04.73

View File

@ -0,0 +1,207 @@
BODY
{
BACKGROUND-COLOR: white;
FONT-FAMILY: "Verdana", sans-serif;
FONT-SIZE: 100%;
MARGIN-LEFT: 0px;
MARGIN-TOP: 0px
}
P
{
FONT-FAMILY: "Verdana", sans-serif;
FONT-SIZE: 70%;
LINE-HEIGHT: 12pt;
MARGIN-BOTTOM: 0px;
MARGIN-LEFT: 10px;
MARGIN-TOP: 10px
}
.note
{
BACKGROUND-COLOR: #ffffff;
COLOR: #336699;
FONT-FAMILY: "Verdana", sans-serif;
FONT-SIZE: 100%;
MARGIN-BOTTOM: 0px;
MARGIN-LEFT: 0px;
MARGIN-TOP: 0px;
PADDING-RIGHT: 10px
}
.infotable
{
BACKGROUND-COLOR: #f0f0e0;
BORDER-BOTTOM: #ffffff 0px solid;
BORDER-COLLAPSE: collapse;
BORDER-LEFT: #ffffff 0px solid;
BORDER-RIGHT: #ffffff 0px solid;
BORDER-TOP: #ffffff 0px solid;
FONT-SIZE: 70%;
MARGIN-LEFT: 10px
}
.issuetable
{
BACKGROUND-COLOR: #ffffe8;
BORDER-COLLAPSE: collapse;
COLOR: #000000;
FONT-SIZE: 100%;
MARGIN-BOTTOM: 10px;
MARGIN-LEFT: 13px;
MARGIN-TOP: 0px
}
.issuetitle
{
BACKGROUND-COLOR: #ffffff;
BORDER-BOTTOM: #dcdcdc 1px solid;
BORDER-TOP: #dcdcdc 1px;
COLOR: #003366;
FONT-WEIGHT: normal
}
.header
{
BACKGROUND-COLOR: #cecf9c;
BORDER-BOTTOM: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid;
BORDER-RIGHT: #ffffff 1px solid;
BORDER-TOP: #ffffff 1px solid;
COLOR: #000000;
FONT-WEIGHT: bold
}
.issuehdr
{
BACKGROUND-COLOR: #E0EBF5;
BORDER-BOTTOM: #dcdcdc 1px solid;
BORDER-TOP: #dcdcdc 1px solid;
COLOR: #000000;
FONT-WEIGHT: normal
}
.issuenone
{
BACKGROUND-COLOR: #ffffff;
BORDER-BOTTOM: 0px;
BORDER-LEFT: 0px;
BORDER-RIGHT: 0px;
BORDER-TOP: 0px;
COLOR: #000000;
FONT-WEIGHT: normal
}
.content
{
BACKGROUND-COLOR: #e7e7ce;
BORDER-BOTTOM: #ffffff 1px solid;
BORDER-LEFT: #ffffff 1px solid;
BORDER-RIGHT: #ffffff 1px solid;
BORDER-TOP: #ffffff 1px solid;
PADDING-LEFT: 3px
}
.issuecontent
{
BACKGROUND-COLOR: #ffffff;
BORDER-BOTTOM: #dcdcdc 1px solid;
BORDER-TOP: #dcdcdc 1px solid;
PADDING-LEFT: 3px
}
A:link
{
COLOR: #cc6633;
TEXT-DECORATION: underline
}
A:visited
{
COLOR: #cc6633;
}
A:active
{
COLOR: #cc6633;
}
A:hover
{
COLOR: #cc3300;
TEXT-DECORATION: underline
}
H1
{
BACKGROUND-COLOR: #003366;
BORDER-BOTTOM: #336699 6px solid;
COLOR: #ffffff;
FONT-SIZE: 130%;
FONT-WEIGHT: normal;
MARGIN: 0em 0em 0em -20px;
PADDING-BOTTOM: 8px;
PADDING-LEFT: 30px;
PADDING-TOP: 16px
}
H2
{
COLOR: #000000;
FONT-SIZE: 80%;
FONT-WEIGHT: bold;
MARGIN-BOTTOM: 3px;
MARGIN-LEFT: 10px;
MARGIN-TOP: 20px;
PADDING-LEFT: 0px
}
H3
{
COLOR: #000000;
FONT-SIZE: 80%;
FONT-WEIGHT: bold;
MARGIN-BOTTOM: -5px;
MARGIN-LEFT: 10px;
MARGIN-TOP: 20px
}
H4
{
COLOR: #000000;
FONT-SIZE: 70%;
FONT-WEIGHT: bold;
MARGIN-BOTTOM: 0px;
MARGIN-TOP: 15px;
PADDING-BOTTOM: 0px
}
UL
{
COLOR: #000000;
FONT-SIZE: 70%;
LIST-STYLE: square;
MARGIN-BOTTOM: 0pt;
MARGIN-TOP: 0pt
}
OL
{
COLOR: #000000;
FONT-SIZE: 70%;
LIST-STYLE: square;
MARGIN-BOTTOM: 0pt;
MARGIN-TOP: 0pt
}
LI
{
LIST-STYLE: square;
MARGIN-LEFT: 0px
}
.expandable
{
CURSOR: hand
}
.expanded
{
color: black
}
.collapsed
{
DISPLAY: none
}
.foot
{
BACKGROUND-COLOR: #ffffff;
BORDER-BOTTOM: #cecf9c 1px solid;
BORDER-TOP: #cecf9c 2px solid
}
.settings
{
MARGIN-LEFT: 25PX;
}
.help
{
TEXT-ALIGN: right;
margin-right: 10px;
}

View File

@ -0,0 +1,232 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:key name="ProjectKey" match="Event" use="@Project"/>
<xsl:template match="Events" mode="createProjects">
<projects>
<xsl:for-each select="Event">
<!--xsl:sort select="@Project" order="descending"/-->
<xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Project != @Project)">
<xsl:variable name="ProjectName" select="@Project"/>
<project>
<xsl:attribute name="name">
<xsl:value-of select="@Project"/>
</xsl:attribute>
<xsl:if test="@Project=''">
<xsl:attribute name="solution">
<xsl:value-of select="@Solution"/>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="key('ProjectKey', $ProjectName)">
<!--xsl:sort select="@Source" /-->
<xsl:if test="(1=position()) or (preceding-sibling::*[1]/@Source != @Source)">
<source>
<xsl:attribute name="name">
<xsl:value-of select="@Source"/>
</xsl:attribute>
<xsl:variable name="Source">
<xsl:value-of select="@Source"/>
</xsl:variable>
<xsl:for-each select="key('ProjectKey', $ProjectName)[ @Source = $Source ]">
<event>
<xsl:attribute name="error-level">
<xsl:value-of select="@ErrorLevel"/>
</xsl:attribute>
<xsl:attribute name="description">
<xsl:value-of select="@Description"/>
</xsl:attribute>
</event>
</xsl:for-each>
</source>
</xsl:if>
</xsl:for-each>
</project>
</xsl:if>
</xsl:for-each>
</projects>
</xsl:template>
<xsl:template match="projects">
<xsl:for-each select="project">
<xsl:sort select="@Name" order="ascending"/>
<h2>
<xsl:if test="@solution"><a _locID="Solution">ソリューション</a>: <xsl:value-of select="@solution"/></xsl:if>
<xsl:if test="not(@solution)"><a _locID="Project">プロジェクト</a>: <xsl:value-of select="@name"/>
<xsl:for-each select="source">
<xsl:variable name="Hyperlink" select="@name"/>
<xsl:for-each select="event[@error-level='4']">
<A class="note"><xsl:attribute name="HREF"><xsl:value-of select="$Hyperlink"/></xsl:attribute><xsl:value-of select="@description"/></A>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</h2>
<table cellpadding="2" cellspacing="0" width="98%" border="1" bordercolor="white" class="infotable">
<tr>
<td nowrap="1" class="header" _locID="Filename">ファイル名</td>
<td nowrap="1" class="header" _locID="Status">状態</td>
<td nowrap="1" class="header" _locID="Errors">エラー</td>
<td nowrap="1" class="header" _locID="Warnings">警告</td>
</tr>
<xsl:for-each select="source">
<xsl:sort select="@name" order="ascending"/>
<xsl:variable name="source-id" select="generate-id(.)"/>
<xsl:if test="count(event)!=count(event[@error-level='4'])">
<tr class="row">
<td class="content">
<A HREF="javascript:"><xsl:attribute name="onClick">javascript:document.images['<xsl:value-of select="$source-id"/>'].click()</xsl:attribute><IMG border="0" _locID="IMG.alt" _locAttrData="alt" alt="セクションの展開/折りたたみ" class="expandable" height="11" onclick="changepic()" src="_UpgradeReport_Files/UpgradeReport_Plus.gif" width="9"><xsl:attribute name="name"><xsl:value-of select="$source-id"/></xsl:attribute><xsl:attribute name="child">src<xsl:value-of select="$source-id"/></xsl:attribute></IMG></A> <xsl:value-of select="@name"/>
</td>
<td class="content">
<xsl:if test="count(event[@error-level='3'])=1">
<xsl:for-each select="event[@error-level='3']">
<xsl:if test="@description='Converted'"><a _locID="Converted1">変換済み</a></xsl:if>
<xsl:if test="@description!='Converted'"><xsl:value-of select="@description"/></xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:if test="count(event[@error-level='3'])!=1 and count(event[@error-level='3' and @description='Converted'])!=0"><a _locID="Converted2">変換済み</a>
</xsl:if>
</td>
<td class="content"><xsl:value-of select="count(event[@error-level='2'])"/></td>
<td class="content"><xsl:value-of select="count(event[@error-level='1'])"/></td>
</tr>
<tr class="collapsed" bgcolor="#ffffff">
<xsl:attribute name="id">src<xsl:value-of select="$source-id"/></xsl:attribute>
<td colspan="7">
<table width="97%" border="1" bordercolor="#dcdcdc" rules="cols" class="issuetable">
<tr>
<td colspan="7" class="issuetitle" _locID="ConversionIssues">変換レポート - <xsl:value-of select="@name"/>:</td>
</tr>
<xsl:for-each select="event[@error-level!='3']">
<xsl:if test="@error-level!='4'">
<tr>
<td class="issuenone" style="border-bottom:solid 1 lightgray">
<xsl:value-of select="@description"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</xsl:if>
</xsl:for-each>
<tr valign="top">
<td class="foot">
<xsl:if test="count(source)!=1">
<xsl:value-of select="count(source)"/><a _locID="file1"> ファイル</a>
</xsl:if>
<xsl:if test="count(source)=1">
<a _locID="file2">1 ファイル</a>
</xsl:if>
</td>
<td class="foot">
<a _locID="Converted3">変換済み</a>: <xsl:value-of select="count(source/event[@error-level='3' and @description='Converted'])"/><BR/>
<a _locID="NotConverted">変換されませんでした。</a>: <xsl:value-of select="count(source) - count(source/event[@error-level='3' and @description='Converted'])"/>
</td>
<td class="foot"><xsl:value-of select="count(source/event[@error-level='2'])"/></td>
<td class="foot"><xsl:value-of select="count(source/event[@error-level='1'])"/></td>
</tr>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="Property">
<xsl:if test="@Name!='Date' and @Name!='Time' and @Name!='LogNumber' and @Name!='Solution'">
<tr><td nowrap="1"><b><xsl:value-of select="@Name"/>: </b><xsl:value-of select="@Value"/></td></tr>
</xsl:if>
</xsl:template>
<xsl:template match="UpgradeLog">
<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="_UpgradeReport_Files\UpgradeReport.css"/>
<title _locID="ConversionReport0">変換レポート
<xsl:if test="Properties/Property[@Name='LogNumber']">
<xsl:value-of select="Properties/Property[@Name='LogNumber']/@Value"/>
</xsl:if>
</title>
<script language="javascript">
function outliner () {
oMe = window.event.srcElement
//get child element
var child = document.all[event.srcElement.getAttribute("child",false)];
//if child element exists, expand or collapse it.
if (null != child)
child.className = child.className == "collapsed" ? "expanded" : "collapsed";
}
function changepic() {
uMe = window.event.srcElement;
var check = uMe.src.toLowerCase();
if (check.lastIndexOf("upgradereport_plus.gif") != -1)
{
uMe.src = "_UpgradeReport_Files/UpgradeReport_Minus.gif"
}
else
{
uMe.src = "_UpgradeReport_Files/UpgradeReport_Plus.gif"
}
}
</script>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" onclick="outliner();">
<h1 _locID="ConversionReport">変換レポート - <xsl:value-of select="Properties/Property[@Name='Solution']/@Value"/></h1>
<p><span class="note">
<b _locID="TimeOfConversion">変換時間:</b> <xsl:value-of select="Properties/Property[@Name='Date']/@Value"/> <xsl:value-of select="Properties/Property[@Name='Time']/@Value"/><br/>
</span></p>
<xsl:variable name="SortedEvents">
<Events>
<xsl:for-each select="Event">
<xsl:sort select="@Project" order="ascending"/>
<xsl:sort select="@Source" order="ascending"/>
<xsl:sort select="@ErrorLevel" order="ascending"/>
<Event>
<xsl:attribute name="Project"><xsl:value-of select="@Project"/> </xsl:attribute>
<xsl:attribute name="Solution"><xsl:value-of select="/UpgradeLog/Properties/Property[@Name='Solution']/@Value"/> </xsl:attribute>
<xsl:attribute name="Source"><xsl:value-of select="@Source"/> </xsl:attribute>
<xsl:attribute name="ErrorLevel"><xsl:value-of select="@ErrorLevel"/> </xsl:attribute>
<xsl:attribute name="Description"><xsl:value-of select="@Description"/> </xsl:attribute>
</Event>
</xsl:for-each>
</Events>
</xsl:variable>
<xsl:variable name="Projects">
<xsl:apply-templates select="msxsl:node-set($SortedEvents)/*" mode="createProjects"/>
</xsl:variable>
<xsl:apply-templates select="msxsl:node-set($Projects)/*"/>
<p></p><p>
<table class="note">
<tr>
<td nowrap="1">
<b _locID="ConversionSettings">変換の設定</b>
</td>
</tr>
<xsl:apply-templates select="Properties"/>
</table></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bsr_trunk", "bsr_trunk.vcxproj", "{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Debug|Win32.ActiveCfg = Debug|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Debug|Win32.Build.0 = Debug|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Release|Win32.ActiveCfg = Release|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bsr_trunk", "bsr_trunk.vcproj", "{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Debug|Win32.ActiveCfg = Debug|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Debug|Win32.Build.0 = Debug|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Release|Win32.ActiveCfg = Release|Win32
{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,594 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="bsr_trunk"
ProjectGUID="{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}"
RootNamespace="bsr_trunk"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="0"
CharacterSet="2"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="nmake -f yav_mcu_bsr.mak"
ReBuildCommandLine=""
CleanCommandLine=""
Output=""
PreprocessorDefinitions=""
IncludeSearchPath=""
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="ソース ファイル"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\accero.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\adc.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_ctr.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_mcu.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_twl.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\ini_VECT.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\led.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\loader.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\magic.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\main.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pedo_alg_thre_det2.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pm.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\reboot.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\rtc.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\self_flash.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\sw.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\task_debug.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\task_misc.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\task_status.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\task_sys.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\vreg_ctr.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\vreg_twl.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\WDT.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="ヘッダー ファイル"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\accero.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\adc.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\batt_params.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\bsr_system.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\config.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\fsl.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\fsl_user.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_ctr.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_mcu.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_twl.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\i2c_twl_defs.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\incs.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\incs_loader.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\jhl_defs.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\led.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\loader.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pedo_lpf_coeff.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pedometer.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pm.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\pool.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\reboot.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\rtc.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\self_flash.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\sw.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\user_define.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\vreg_ctr.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\vreg_twl.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\WDT.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="リソース ファイル"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="renge"
>
<File
RelativePath="..\renge\renge.c"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\renge\renge.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\renge\renge_defs.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\renge\renge_task_immediate.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
<File
RelativePath="..\renge\renge_task_intval.h"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
</Filter>
<File
RelativePath="..\bsr_mcu.dr"
>
<FileConfiguration
Name="Debug|Win32"
>
</FileConfiguration>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory="C:\78k_data\yav-mcu-basara\trunk"
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="REDPC2232"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="REDPC2232"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@ -0,0 +1,162 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9DF31AC3-BD19-4158-BD6F-9CFE64AEE5D2}</ProjectGuid>
<RootNamespace>bsr_trunk</RootNamespace>
<ProjectName>arr_trunk</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">nmake -f yav_mcu_bsr.mak</NMakeBuildCommandLine>
<NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath>
<NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeForcedIncludes)</NMakeForcedIncludes>
<NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath>
<NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\Program Files (x86)\NEC Electronics Tools\CC78K0R\W2.13\inc78k0r;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\bsr_mcu.dr" />
<None Include="..\renge\renge_tasks.txt" />
<None Include="..\renge\renge_task_config.rb" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\accero.c" />
<ClCompile Include="..\adc.c" />
<ClCompile Include="..\batt_params.c" />
<ClCompile Include="..\hal.c" />
<ClCompile Include="..\i2c_ctr.c" />
<ClCompile Include="..\i2c_mcu-sub.c" />
<ClCompile Include="..\i2c_mcu.c" />
<ClCompile Include="..\i2c_twl.c" />
<ClCompile Include="..\ini_VECT.c" />
<ClCompile Include="..\kanaria_c.c" />
<ClCompile Include="..\led.c" />
<ClCompile Include="..\led_cam.c" />
<ClCompile Include="..\led_pow.c" />
<ClCompile Include="..\loader.c" />
<ClCompile Include="..\magic.c" />
<ClCompile Include="..\main.c" />
<ClCompile Include="..\my_led.c" />
<ClCompile Include="..\pedo_alg_thre_det2.c" />
<ClCompile Include="..\pedo_lpf_coeff.c" />
<ClCompile Include="..\pm.c" />
<ClCompile Include="..\reboot.c" />
<ClCompile Include="..\renge\renge.c" />
<ClCompile Include="..\rtc.c" />
<ClCompile Include="..\self_flash.c" />
<ClCompile Include="..\sim\simFixture.c" />
<ClCompile Include="..\sim\sim_interrupt_decrare.c" />
<ClCompile Include="..\sw.c" />
<ClCompile Include="..\task_debug.c" />
<ClCompile Include="..\task_misc.c" />
<ClCompile Include="..\task_status.c" />
<ClCompile Include="..\task_sys.c" />
<ClCompile Include="..\util_funcs.c" />
<ClCompile Include="..\voltable.c" />
<ClCompile Include="..\vreg_ctr.c" />
<ClCompile Include="..\vreg_twl.c" />
<ClCompile Include="..\WDT.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\accero.h" />
<ClInclude Include="..\adc.h" />
<ClInclude Include="..\batt_params.h" />
<ClInclude Include="..\bsr_system.h" />
<ClInclude Include="..\config.h" />
<ClInclude Include="..\fsl.h" />
<ClInclude Include="..\fsl_user.h" />
<ClInclude Include="..\hal.h" />
<ClInclude Include="..\i2c_ctr.h" />
<ClInclude Include="..\i2c_mcu.h" />
<ClInclude Include="..\i2c_twl.h" />
<ClInclude Include="..\i2c_twl_defs.h" />
<ClInclude Include="..\incs.h" />
<ClInclude Include="..\incs_loader.h" />
<ClInclude Include="..\jhl_defs.h" />
<ClInclude Include="..\led.h" />
<ClInclude Include="..\loader.h" />
<ClInclude Include="..\magic.h" />
<ClInclude Include="..\pedometer.h" />
<ClInclude Include="..\pedo_lpf_coeff.h" />
<ClInclude Include="..\pm.h" />
<ClInclude Include="..\pool.h" />
<ClInclude Include="..\reboot.h" />
<ClInclude Include="..\renge\renge.h" />
<ClInclude Include="..\renge\renge_defs.h" />
<ClInclude Include="..\renge\renge_task_immediate.h" />
<ClInclude Include="..\renge\renge_task_intval.h" />
<ClInclude Include="..\rtc.h" />
<ClInclude Include="..\self_flash.h" />
<ClInclude Include="..\sim\sfrAlias.h" />
<ClInclude Include="..\sim\simOnWin.h" />
<ClInclude Include="..\sw.h" />
<ClInclude Include="..\user_define.h" />
<ClInclude Include="..\util_funcs.h" />
<ClInclude Include="..\voltable.h" />
<ClInclude Include="..\vreg_ctr.h" />
<ClInclude Include="..\vreg_twl.h" />
<ClInclude Include="..\WDT.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,258 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ソース ファイル">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="ヘッダー ファイル">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="リソース ファイル">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="ソース ファイル\renge">
<UniqueIdentifier>{4e2142a2-478d-4e47-ab3f-7ae7d1e531bd}</UniqueIdentifier>
</Filter>
<Filter Include="ヘッダー ファイル\sim">
<UniqueIdentifier>{3bd01c87-17d0-4cf4-93a8-fb6bde3060a4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="..\bsr_mcu.dr" />
<None Include="..\renge\renge_task_config.rb">
<Filter>ソース ファイル\renge</Filter>
</None>
<None Include="..\renge\renge_tasks.txt">
<Filter>ソース ファイル\renge</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\util_funcs.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\voltable.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\vreg_ctr.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\vreg_twl.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\WDT.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\accero.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\adc.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\batt_params.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\hal.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\i2c_ctr.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\i2c_mcu.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\i2c_twl.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\ini_VECT.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\kanaria_c.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\led.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\led_cam.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\led_pow.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\loader.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\magic.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\main.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\my_led.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\pedo_alg_thre_det2.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\pedo_lpf_coeff.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\pm.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\reboot.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\rtc.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\self_flash.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\sw.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\task_debug.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\task_misc.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\task_status.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\task_sys.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="..\renge\renge.c">
<Filter>ソース ファイル\renge</Filter>
</ClCompile>
<ClCompile Include="..\sim\sim_interrupt_decrare.c">
<Filter>ヘッダー ファイル\sim</Filter>
</ClCompile>
<ClCompile Include="..\sim\simFixture.c">
<Filter>ヘッダー ファイル\sim</Filter>
</ClCompile>
<ClCompile Include="..\i2c_mcu-sub.c">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\bsr_system.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\config.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\fsl.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\fsl_user.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\hal.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\i2c_ctr.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\i2c_mcu.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\i2c_twl.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\i2c_twl_defs.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\incs.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\incs_loader.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\jhl_defs.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\led.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\loader.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\magic.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\pedo_lpf_coeff.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\pedometer.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\pm.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\pool.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\reboot.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\rtc.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\self_flash.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\sw.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\user_define.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\util_funcs.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\voltable.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\vreg_ctr.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\vreg_twl.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\WDT.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\accero.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\adc.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\batt_params.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="..\renge\renge.h">
<Filter>ソース ファイル\renge</Filter>
</ClInclude>
<ClInclude Include="..\renge\renge_defs.h">
<Filter>ソース ファイル\renge</Filter>
</ClInclude>
<ClInclude Include="..\renge\renge_task_immediate.h">
<Filter>ソース ファイル\renge</Filter>
</ClInclude>
<ClInclude Include="..\renge\renge_task_intval.h">
<Filter>ソース ファイル\renge</Filter>
</ClInclude>
<ClInclude Include="..\sim\sfrAlias.h">
<Filter>ヘッダー ファイル\sim</Filter>
</ClInclude>
<ClInclude Include="..\sim\simOnWin.h">
<Filter>ヘッダー ファイル\sim</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@ -0,0 +1,12 @@
/* ========================================================
wdt
$Id$
======================================================== */
#include "incs_loader.h"
/*
*/

View File

@ -0,0 +1,20 @@
#ifndef _WDT_
#define _WDT_
//=========================================================
#define WDT_RESTART_MAGIC 0xAC
//=========================================================
// ウォッチドッグタイマのリスタート
// void WDT_Restart( void );
#define WDT_Restart() WDTE = WDT_RESTART_MAGIC
// 規定値以外を書くと例外でリセットがかかる
#define mcu_wdt_reset WDTE = 0x0
#endif

View File

@ -0,0 +1,274 @@
/* ========================================================
 
CPUに割り込み
I2Cの競合回避などがあるので
$Id: accero.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#pragma ROT
// rorb, rolb, rorw, rolw
#pragma MUL
#pragma BCD
#endif
#ifndef _WIN32
#pragma interrupt INTP23 intp23_ACC_ready RB3 // 加速度センサ、データ準備完了
#endif
#include "incs.h"
#include "accero.h"
#include "i2c_mcu.h"
#ifndef _WIN32
#include <math.h>
#endif
// ========================================================
// レジスタ名
#define ACC_REG_WHOAMI 0x0F
#define ACC_REG_CTRL1 0x20
#define ACC_REG_CTRL5 0x24
#define ACC_REG_X 0x28
#define ACC_REG_FLG_BURST_ACCESS 0x80
// ビット位置
#define ACC_bP_PM0 5
#define ACC_bP_DR0 3
// ビット設定値
#define ACC_BITS_PM_PDN 0
#define ACC_BITS_PM_NORM 1
#define ACC_BITS_PM_LP0R5 2
#define ACC_BITS_PM_LP1 3
#define ACC_BITS_PM_LP2 4
#define ACC_BITS_PM_LP5 5
#define ACC_BITS_PM_LP10 6
#define ACC_BITS_DR_50Hz 0
#define ACC_BITS_DR_100Hz 1
#define ACC_BITS_DR_400Hz 2
#define ACC_BITS_DR_1000Hz 3
#define ACC_BITS_ALL_AXIS_ON 7
#define VREG_BITMASK_ACC_CONF_ACQ ( 1 << 0 )
#define VREG_BITMASK_ACC_CONF_HOSU ( 1 << 1 )
// ========================================================
#define ACC_RAW_DATA_SIZE 6
// ========================================================
static u8 acc_retry_count; // 加速度センサ読み出し時、エラーだったときリトライする。回数数える
// ========================================================
task_status tsk_soft_int( );
/********************************************//**
 
I2Cが使用中だったら
***********************************************/
task_status_immed tski_cbk_accero( )
{ // 疑似isrから登録されます
u8 acc_dat_buff[ ACC_RAW_DATA_SIZE ];
// 加速度センサデータレジスタへの反映
if( iic_mcu_read( IIC_SLA_ACCEL, ( ACC_REG_X | ACC_REG_FLG_BURST_ACCESS ), ACC_RAW_DATA_SIZE, acc_dat_buff )
!= ERR_SUCCESS )
{
// SLA NAK //
if( acc_retry_count < 4 )
{
acc_retry_count ++;
// リトライ
return( TSKI_CONTINUE );
}
else
{
// 加速度センサが異常になったので止める
vreg_stop_acc;
tski_acc_setup();
vreg_set_acc_error;
return ( TSKI_FINISHED ); // タスクの削除は必要
}
}
else
{
// 正常時パス //
DI_wt_chk();
memcpy( &vreg_ctr[VREG_C_ACC_XL], acc_dat_buff, ACC_RAW_DATA_SIZE );
EI();
acc_retry_count = 0;
// 加速度更新&割り込み
if( is_acc_on && ( system_status.pwr_state == ON ))
{
set_irq( VREG_C_IRQ1, REG_BIT_ACC_DAT_RDY );
// ゴミデータのカラ読み
if( ACC_VALID )
{
u8 temp[ACC_RAW_DATA_SIZE];
iic_mcu_read( IIC_SLA_ACCEL, ( ACC_REG_X | ACC_REG_FLG_BURST_ACCESS ), ACC_RAW_DATA_SIZE, temp );
}
}
if( (( system_status.pwr_state == ON )||( system_status.pwr_state == SLEEP ))
&&( is_pedo_on )
)
{
pedometer(); // 歩数計
}
}
return ( TSKI_FINISHED );
}
/********************************************//**
  
***********************************************/
task_status_immed tski_acc_read( )
{
vreg_ctr[VREG_C_ACC_W_BUF] = iic_mcu_read_a_byte( IIC_SLA_ACCEL, vreg_ctr[VREG_C_ACC_R_ADRS] );
set_irq( VREG_C_IRQ1, REG_BIT_ACC_ACK );
return ( TSKI_FINISHED );
}
/********************************************//**
  
***********************************************/
task_status_immed tski_acc_write( )
{
iic_mcu_write_a_byte( IIC_SLA_ACCEL, vreg_ctr[VREG_C_ACC_W_ADRS], vreg_ctr[VREG_C_ACC_W_BUF] );
set_irq( VREG_C_IRQ1, REG_BIT_ACC_ACK );
return ( TSKI_FINISHED );
}
/********************************************//**
 
***********************************************/
task_status_immed tski_acc_setup( )
{
// 加速度 on/off設定する
u8 str_send_buf[4];
str_send_buf[1] = 0x00; // ctrl2 HPF:normal, filterd, HPF for IRQ : dis/dis, HPF coeff:norm
// ピン不足のため、TSとそれ以外回路違いを区別して設定
if( system_status.model == MODEL_TS_BOARD )
{
str_send_buf[2] = bits8(0,0,0,0, 0,0,1,0);
}
else
{
str_send_buf[2] = bits8(0,0,0,1, 0,0,0,0);
}
str_send_buf[3] = 0x80; // ctrl3 block update:enable, MSB first, scale: +-2G(default), selftest: dis
{
u8 acc_setting_sent = ( vreg_ctr[VREG_C_ACC_CONFIG] & ( VREG_BITMASK_ACC_CONF_HOSU | VREG_BITMASK_ACC_CONF_ACQ ));
if( acc_setting_sent == 0 )
{
// 完全停止
PMK23 = 1;
str_send_buf[0] =
( ACC_BITS_PM_PDN << ACC_bP_PM0 | 0 << ACC_bP_DR0 | ACC_BITS_ALL_AXIS_ON );
}
else
{
// on 100Hz 自動取り込み
PMK23 = 0;
str_send_buf[0] =
( ACC_BITS_PM_NORM << ACC_bP_PM0
| ACC_BITS_DR_100Hz << ACC_bP_DR0
| ACC_BITS_ALL_AXIS_ON );
}
// 実書き込み兼、通信できたかフラグ更新
if( iic_mcu_write( IIC_SLA_ACCEL, ( ACC_REG_CTRL1 | ACC_REG_FLG_BURST_ACCESS ), 4, str_send_buf ) == I2C_ERR_NOSLAVE )
{
// センサ反応無し。タスクは削除しなくてはならない。
vreg_set_acc_error;
return ( TSKI_FINISHED );
// おしまい
}
// else
// センサ設定成功 正常パス
vreg_ctr[ VREG_C_STATUS_1 ] &= ~REG_BIT_ACCERO_ERR;
acc_retry_count = 0;
// 前回のゴミが有ればカラ読み
if( ACC_VALID )
{
if( system_status.pwr_state == ON )
{
u8 temp[ACC_RAW_DATA_SIZE];
iic_mcu_read( IIC_SLA_ACCEL, ( ACC_REG_X | ACC_REG_FLG_BURST_ACCESS ), 6, temp );
}
}
// センサに書きにいっている最中にSoCがまた書き換えてしまうかもしれない
DI_wt_chk();
if( acc_setting_sent != ( vreg_ctr[VREG_C_ACC_CONFIG] & ( VREG_BITMASK_ACC_CONF_HOSU | VREG_BITMASK_ACC_CONF_ACQ )))
{
// DI状態のまま帰る
return ( TSKI_CONTINUE ); // ちょっと間をおいて再度書きにくる // もっとよい実装?
}
}
// DI状態のまま帰る
return ( TSKI_FINISHED );
}
/********************************************//**
I2Cが使用中かもしれないので
***********************************************/
__interrupt void intp23_ACC_ready( )
{
EI();
if( ( vreg_ctr[VREG_C_ACC_CONFIG] & ( VREG_BITMASK_ACC_CONF_HOSU | VREG_BITMASK_ACC_CONF_ACQ ) ) != 0x00 )
{
// 加速度センサ on
if( ( system_status.pwr_state == ON ) || ( system_status.pwr_state == SLEEP ) )
{
// if( ACC_VALID ) // 確認不要
{
renge_task_immed_add( tski_cbk_accero );
}
}
}
}

View File

@ -0,0 +1,14 @@
#ifndef _accero_
#define _accero_
#include "jhl_defs.h"
#include "pedometer.h"
///////////////////////////////////////////////////////////
task_status_immed tski_cbk_accero( );
task_status_immed tski_acc_setup( );
#endif

475
snake_tags/3.40_jane/adc.c Normal file
View File

@ -0,0 +1,475 @@
/* ========================================================
adc.c
nintendo
'09 Apr
$Id$
======================================================== */
#include "incs.h"
#include "adc.h"
#include "pm.h"
#include "led.h"
#include "vreg_twl.h"
#include "i2c_mcu.h"
// ===================================================== //
static bit adc_updated;
static bit vol_changed_by_ctr;
bit vol_changed_by_twl;
static u8 vol_old;
static u8 adc_raw_vol;
static u8 adc_raw_dep;
u8 vol_polling;
u8 vol_level_twl;
extern const u8 slider_to_codec[];
// ===================================================== //
typedef struct filter_work
{
u8* value_used;
s8 diffs; // KIKAN中の偏り具合
s8 kikan;
u8 large_diff_count;
}filter_work;
static filter_work work_vr_3d = {
&vreg_ctr[ VREG_C_3D ]
// のこりは不定値でよし。constにしちゃダメ
};
static u8 vol_data_ctr;
static u8 vol_data_ctr_tmp;
static filter_work work_vr_vol = {
&vol_data_ctr_tmp
// のこりは不定値でよし。constにしちゃダメ
};
// twl の8段階volのリニア値からの境界
/*
twl内の32 -> 8
01,4,8,13,18,23,28,31
*/
static const u8 TWL_VOL_BOUNDARY[] = {
1, 4, 8, 13, 18, 23, 28, 31
};
// ===================================================== //
extern void nop8();
static void adc_filter( u8 new_val, filter_work* work );
static u8 adc_scaling( u8 );
static void update_twl_vol( u8 sent_index );
// ===================================================== //
#define INTERVAL_TSK_ADC 15
/********************************************//**
ADC設定と
- BT_TEMP,_P
- ADIN1
- VOL
***********************************************/
void tsk_adc( )
{
if( adc_updated )
{
adc_updated = false;
// 3D /////////////////////////////////////////
vreg_ctr[ VREG_C_3D ] = adc_raw_dep; // 生値
// Volume /////////////////////////////////////
{
vreg_ctr[ VREG_C_VOL_ADC_RAW ] = adc_raw_vol;
adc_filter( adc_scaling( adc_raw_vol ), &work_vr_vol ); // 結果は*work_vr_volから指されるvol_data_ctr 読みにくい...
vol_data_ctr = vol_data_ctr_tmp / 4;
if( vol_old != vol_data_ctr )
{
vol_changed_by_ctr = true;
vol_old = vol_data_ctr;
vol_polling = 3;
// renge_task_immed_add( tski_vol_update ); ↓で登録
}
}
// バッテリ識別 ///////////////////////////
/* 呼ばれません */
}
// 書き忘れがあるといやなのでポーリング orz
if( vol_polling < 5 )
{
renge_task_immed_add( tski_vol_update );
vol_polling = (u8)(200 / SYS_INTERVAL_TICK) + 5; // 5回/sec
}
vol_polling --;
ADCEN = 1;
ADM = bits8(0,0,0,0, 1,0,1,1); // セレクトモード、昇圧、fCLK/6 // ここから ↓
ADPC = 0x06; // ADCポートのセレクト
ADS = ADC_SEL_3D;
nop8();
ADCS = 1; // AD開始。 // ここまで  までに1us=8clk以上開ける
ADIF = 0;
ADMK = 0;
}
/********************************************//**
volを現在のスライダの位置に強制更新
***********************************************/
void vol_reset()
{
vol_old = vol_data_ctr;
vreg_ctr[ VREG_C_SND_VOL ] = vol_data_ctr; // 64段
}
/********************************************//**
 Volを更新します
 
- Volスライダを動かした
- Horizonに強制更新を指示された codecリセット時
- TWLアプリがVolをいじった
***********************************************/
task_status_immed tski_vol_update()
{
static u8 sent_index, sent_index_twl;
static bit last_modifyer_is_twl; // false = ctr
if( !( system_status.pwr_state == ON ) ||
( system_status.pwr_state == SLEEP )){
return( TSKI_FINISHED );
}
// どの音量にするの? //
if( vol_changed_by_ctr )
{
// スライダ
vol_changed_by_ctr = false;
last_modifyer_is_twl = false;
sent_index = vol_data_ctr;
}
else if( vol_changed_by_twl )
{
// TWLアプリ
vol_changed_by_twl = false;
last_modifyer_is_twl = true;
if( vreg_twl[ REG_TWL_INT_ADRS_VOL ] == 0 )
{
sent_index_twl = 0;
}
else
{
sent_index_twl = vreg_twl[ REG_TWL_INT_ADRS_VOL ] *2 +1;
}
sent_index = sent_index_twl;
}
else
{
// force_sliderを0にしたとき & 書きまくるとき
// スライダかTWLの最後にセットした方をセット
if( last_modifyer_is_twl )
{
sent_index = sent_index_twl;
}
else
{
sent_index = vol_data_ctr;
}
}
// レジスタの更新 //
vreg_ctr[ VREG_C_SND_VOL ] = sent_index;
// twl側更新
update_twl_vol( sent_index );
// codecに伝える
/// 同値でも書く
iic_mcu_write_a_byte_codec( CODEC_REG_VOL, slider_to_codec[ sent_index ] );
// set_irq( VREG_C_IRQ0, REG_BIT_VR_SNDVOL_CHANGE ); // 割り込み廃止
return( TSKI_FINISHED );
}
/********************************************//**
TWL
***********************************************/
static void update_twl_vol( u8 sent_index )
{
// スケーリング
if( sent_index == 0 )
{
vreg_twl[ REG_TWL_INT_ADRS_VOL ] = 0;
}
else if( sent_index <= 4 )
{
vreg_twl[ REG_TWL_INT_ADRS_VOL ] = 2; // 1はミッシングで正解
}
else
{
vreg_twl[ REG_TWL_INT_ADRS_VOL ] = sent_index/2 ;
}
// 8段階のレベル化。 割り込みを入れるのに必要
{
static u8 vol_twl_old;
if( vol_twl_old != vreg_twl[ REG_TWL_INT_ADRS_VOL ] )
{
// 8段レベルに変換
u8 new_level = 31;
u8 i;
vol_twl_old = vreg_twl[ REG_TWL_INT_ADRS_VOL ];
for( i=0; i<=7; i++ )
{
if( vreg_twl[ REG_TWL_INT_ADRS_VOL ] <= TWL_VOL_BOUNDARY[ i ] )
{
new_level = i;
break;
}
}
vol_level_twl = new_level;
}
}
}
/********************************************//**
 ADC isr
 
 
  
***********************************************/
__interrupt void int_adc( )
{
volatile u8 adc_data = ADCRH;
switch ( ADS )
{
/*
case ( ADC_SEL_AMB_BRIT ):
// 環境明るさ //
vreg_ctr[ VREG_C_AMBIENT_BRIGHTNESS ] = adc_data;
break;
*/
case ( ADC_SEL_3D ):
// 3Dボリューム //
EI();
adc_raw_dep = adc_data;
break;
case ( ADC_SEL_VOL ):
// 音量スライダ //
EI();
if( system_status.model == MODEL_TS_BOARD )
{
adc_raw_vol = adc_data;
}
else
{
adc_raw_vol = 255 - adc_data;
}
break;
case ( ADC_SEL_BATT_TEMP ):
// バッテリ温度 //
EI();
#ifdef _ENABLE_HAL_
if( vreg_ctr[ VREG_C_HAL_OVW_TEMPERATURE ] == 0xFF ) // HAL無効
#else
if( 1 )
#endif
{
raw_adc_temperature = adc_data;
}
else
{
raw_adc_temperature = vreg_ctr[ VREG_C_HAL_OVW_TEMPERATURE ];
}
if(// (( vreg_ctr[ VREG_C_STATUS_1 ] & REG_BIT_MGIC_ERR ) == 0 ) &&
(( system_status.pwr_state == ON ) ||
( system_status.pwr_state == SLEEP )
)
)
{
renge_task_immed_add( tski_BT_temp_update );
}
break;
/* 呼ばれません
case ( ADC_SEL_BATT_DET ):
// バッテリメーカー識別 //
break;
*/
}
// もっとまともな書き方がありそうだ
if( ADS < ADC_SEL_BATT_DET )
{
ADS += 1; // 次のチャンネル
}
else
{
ADCEN = 0; // 止めてしまう
adc_updated = true;
}
ADIF = 0; // ←これをしないと、いっこ前のチャンネルのデータの完了で直後に割り込む可能性がある
}
/********************************************//**
adcレジスタから読み出し
tsk_adcと競合することを考慮していません
***********************************************/
u8 get_adc( u8 ch )
{
u8 temp;
ADMK = 1;
ADIF = 0;
ADCEN = 1;
ADM = bits8(0,0,0,0, 1,0,1,1); // セレクトモード、昇圧、fCLK/6 ///ここから↓
ADPC = 0x06; // ADCポートのセレクト
ADS = ch;
nop8();
ADCS = 1; // AD開始。 /// ここまで↑ に、1us以上開ける
ADIF = 0;
while( ADIF == 0 ){;}
temp = ADCRH;
ADCEN = 0;
ADMK = 0;
return ( temp );
}
/********************************************//**
VRの可動範囲を考えてスケーリング
Vol専用 使
***********************************************/
static u8 adc_scaling( u8 orig_val )
{
u16 temp;
if( orig_val <= vreg_ctr[ VREG_C_VOL_CAL_MIN ] )
{
return( 0 );
}
if( orig_val >= vreg_ctr[ VREG_C_VOL_CAL_MAX ] )
{
return( 255 );
}
temp = (u16)(( orig_val - vreg_ctr[ VREG_C_VOL_CAL_MIN ] ) * 256 ) / ( vreg_ctr[ VREG_C_VOL_CAL_MAX ] - vreg_ctr[ VREG_C_VOL_CAL_MIN ] );
if( temp > 255 )
{
temp = 255;
}
return( (u8)( temp & 0xFF ) );
}
/********************************************//**
V2
***********************************************/
#define KIKAN 16
static void adc_filter( u8 new_val, filter_work *work )
{
if( abs( new_val - *( work -> value_used )) > 2 )
{
// 大きく離れた
work -> large_diff_count ++;
if( work -> large_diff_count > 16 )
{
*( work -> value_used ) = new_val;
work -> diffs = 0;
work -> kikan = KIKAN;
}
}
else
{
work -> large_diff_count = 0;
// 近所の値でも、ある期間でいっぱい偏っていたらそっちに寄せる
if( *( work -> value_used ) < new_val )
{
work -> diffs ++;
}
else if( *( work -> value_used ) > new_val )
{
work -> diffs --;
}
if( --( work -> kikan ) == 0 )
{
if( ( work -> diffs ) == KIKAN )
// if( ( work -> diffs ) > (s8)( KIKAN * 0.8 ) )
{
*( work -> value_used ) = *( work -> value_used ) + 1;
}
else if( ( work -> diffs ) == ( -1 * KIKAN ) )
// else if( ( work -> diffs ) < (s8)( -1 * KIKAN * 0.8 ) )
{
*( work -> value_used ) = *( work -> value_used ) - 1;
}
work -> diffs = 0;
work -> kikan = KIKAN;
}
}
}

View File

@ -0,0 +1,48 @@
#ifndef __adc__
#define __adc__
#include "jhl_defs.h"
///////////////////////////////////////
// ANI2 P22
#define ADC_SEL_AMB_BRIT 0x02
/*
// ANI3 P23
#define ADC_SEL_GYRO_YAW 0x03
// ANI4 P24
#define ADC_SEL_GYRO_PITCH 0x04
// ANI5 P25
#define ADC_SEL_GYRO_ROLL 0x05
*/
// ANI6 P26
#define ADC_SEL_3D 0x06
// ANI7 P27
#define ADC_SEL_VOL 0x07
// ANI8 P150
#define ADC_SEL_BATT_TEMP 0x08
// ANI9 P151
#define ADC_SEL_BATT_DET 0x09
///////////////////////////////////////
#define CODEC_REG_VOL 0x13
///////////////////////////////////////
extern u8 vol_polling;
extern u8 vol_level_twl;
///////////////////////////////////////
u8 get_adc( u8 ch );
void vol_reset();
#endif

View File

@ -0,0 +1,130 @@
/* ========================================================
$Id: asdf$
======================================================== */
#include "jhl_defs.h"
#include "batt_params.h"
const bt_param_ bt_param[ /*_BT_PARAM_NUM_*/ ] = // 同じ電池を使い回すので モデル×電池≠パラメータ数
{
// ctr ////////////////////////////////////////////////
// BT_PARAM_CTR_MAXELL
{
{
0xAE, 0xF0, 0xB4, 0x30, 0xB7, 0x40, 0xBA, 0x30,
0xBB, 0x50, 0xBB, 0xB0, 0xBC, 0x50, 0xBD, 0x10,
0xBD, 0x60, 0xBD, 0xB0, 0xBF, 0xE0, 0xC2, 0xB0,
0xC4, 0x20, 0xC7, 0xB0, 0xCA, 0xE0, 0xCE, 0x10,
0x01, 0xF0, 0x14, 0x10, 0x14, 0x20, 0x06, 0x30,
0x63, 0x90, 0x49, 0x00, 0x6E, 0x00, 0x77, 0x70,
0x7B, 0x00, 0x19, 0x00, 0x19, 0x00, 0x17, 0xF0,
0x1C, 0x60, 0x12, 0x00, 0x12, 0x00, 0x12, 0x00
},
2, // 2 = 19 bit mode
{ 92, (u8)(-256* 0.79), (u8)(-256* 4.35) }, //  (u8)誤キャストの誤パラメータのままの方が
0xD800, // システムとしては良好な動作
{ 0xEA, 0xE8 }
},
// BT_PARAM_CTR_PANA
{
{
0x8C, 0x30, 0x9C, 0x10, 0xA5, 0xE0, 0xB0, 0x40,
0xB1, 0xC0, 0xB2, 0x00, 0xB2, 0x50, 0xB3, 0x10,
0xB4, 0x90, 0xB6, 0x20, 0xB8, 0x60, 0xBA, 0x50,
0xBF, 0xA0, 0xC6, 0xB0, 0xCE, 0x90, 0xD0, 0x20,
0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
0x7B, 0x30, 0x68, 0x60, 0x20, 0x00, 0x17, 0x00,
0x17, 0x30, 0x12, 0xF0, 0x0D, 0xE0, 0x07, 0xF0,
0x07, 0x00, 0x09, 0x30, 0x01, 0xC0, 0x01, 0xC0
},
1,
{ 171, (u8)(-256* 1.00), (u8)(-256* 2.60) }, //  (u8)誤キャストの誤パラメータのままの方が
0xDA20, // システムとしては良好な動作
{ 0x69, 0x67 },
},
// SPFL ///////////////////////////////////////////////
// BT_PARAM_SPFL_MAXELL
{
{
0xA1, 0x20, 0xB7, 0x50, 0xB9, 0xD0, 0xBB, 0x00,
0xBC, 0x30, 0xBC, 0x60, 0xBC, 0xA0, 0xBD, 0x10,
0xBD, 0xC0, 0xBE, 0x70, 0xBF, 0xD0, 0xC2, 0xA0,
0xC4, 0x00, 0xC8, 0x50, 0xCC, 0x80, 0xD0, 0xB0,
0x01, 0xA0, 0x25, 0x10, 0x18, 0xB0, 0x17, 0xC0,
0x95, 0x20, 0x6F, 0xE0, 0x7C, 0x60, 0x35, 0x10,
0x35, 0x00, 0x37, 0xF0, 0x16, 0xF0, 0x1C, 0xA0,
0x17, 0x30, 0x11, 0xD0, 0x11, 0xF0, 0x11, 0xF0
},
2,
{ 94, (-256* 0.35), (-256* 3.85) },
0xDAB0,
{ 0xF5, 0xF3 }
},
// BT_PARAM_SPFL_PANA
{
{
0x9C, 0xF0, 0xAD, 0x50, 0xAF, 0xB0, 0xB3, 0x00,
0xB3, 0xE0, 0XB5, 0x60, 0XB6, 0x70, 0xB7, 0xA0,
0xBA, 0x00, 0xBC, 0x00, 0xBE, 0x90, 0xC1, 0x60,
0xC4, 0x00, 0xC7, 0x00, 0xCC, 0xA0, 0xD0, 0xA0,
0x02, 0x00, 0x19, 0x10, 0x12, 0x00, 0x48, 0x10,
0x25, 0x10, 0x41, 0xF0, 0x2F, 0xA0, 0x13, 0xF0,
0x1C, 0xD0, 0x10, 0xD0, 0x0F, 0xA0, 0x11, 0x00,
0x10, 0xE0, 0x0C, 0x10, 0x0C, 0x00, 0x0C, 0x00
},
2,
{ 113, (-256* 0.30), (-256* 2.25) },
0xDAA0,
{ 0xE7, 0xE5 },
},
// SNAKE /////////////////////////////////////////////
// BT_PARAM_SNAKE_MAXELL
{
{
0x9D, 0x80, 0xB7, 0xB0, 0xB8, 0xA0, 0xB9, 0xA0,
0xBB, 0x40, 0xBC, 0x50, 0xBC, 0xA0, 0xBD, 0x00,
0xBD, 0x90, 0xBF, 0x30, 0xC0, 0xE0, 0xC3, 0x30,
0xC5, 0x40, 0xC7, 0x50, 0xCD, 0x40, 0xD0, 0xA0,
0x01, 0x90, 0x35, 0x10, 0x2F, 0x30, 0x11, 0x00,
0x29, 0x40, 0x88, 0x50, 0x71, 0xA0, 0x5F, 0xE0,
0x32, 0xD0, 0x1C, 0xF0, 0x14, 0xF0, 0x1A, 0x80,
0x1A, 0x80, 0x11, 0x10, 0x12, 0x00, 0x12, 0x00
},
2,
{ 86, (-256* 0.6), (-256* 3.675) }, // rcomp, r-hot, r-cold
0xDAA0, // ocv
{ 0xF5, 0xF3 } // compare max, min
},
// bt_PARAM_SNAKE_PANA 3版130909更新
{
{
0x9D, 0xD0, 0xA6, 0x20, 0xAC, 0xE0, 0xAE, 0x20,
0xB0, 0x40, 0xB2, 0x10, 0xB3, 0xC0, 0xB5, 0x00,
0xB6, 0x70, 0xB7, 0xD0, 0xB9, 0x20, 0xBC, 0x00,
0xBE, 0xD0, 0xC4, 0x70, 0xCA, 0x40, 0xD0, 0xA0,
0x02, 0x00, 0x02, 0x00, 0x24, 0x00, 0x14, 0x00,
0x16, 0x00, 0x1A, 0x00, 0x38, 0xC0, 0x2D, 0xE0,
0x29, 0xC0, 0x27, 0xE0, 0x0F, 0xE0, 0x11, 0xE0,
0x0F, 0xE0, 0x0F, 0x40, 0x0C, 0x00, 0x0C, 0x00
},
2, // 2:19bit 1:18bit
{ 95, (-256* 0.85), (-256* 1.9) },
55968,
{ 230, 228 },
}
// FLOWER /////////////////////////////////////////////
// 無し。CTRのバッテリーを使う。
// CLOSER /////////////////////////////////////////////
// 無し。SPFLのバッテリーを使う。
};

View File

@ -0,0 +1,64 @@
#ifndef _bt_params_h_
#define _bt_params_h_
/*
$Id: asdf$
*/
#include "jhl_defs.h"
/*
d¯Ê CTR | SPFL | YBS
0 ID = 0 maxell <EFBFBD>©
120 1
360 2
750 <EFBFBD>@ 3
1.3k<EFBFBD>@ 4
2.7k 5 pana <EFBFBD>©
8.2k<EFBFBD>@ 6
*/
#define BATT_PARAM_SIZE 64
#define BT_PARAM_OFFSET_MAXELL 0
#define BT_PARAM_OFFSET_PANA 1
typedef enum
{
BT_PARAM_CTR_MAXELL = 0,
BT_PARAM_CTR_PANA,
BT_PARAM_SPFL_MAXELL,
BT_PARAM_SPFL_PANA,
BT_PARAM_SNAKE_MAXELL,
BT_PARAM_SNAKE_PANA,
BT_PARAM_FLOWER_MAXELL,
BT_PARAM_FLOWER_PANA,
BT_PARAM_CLOSER_MAXELL,
BT_PARAM_CLOSER_PANA,
_BT_PARAM_NUM_
} BT_TYPE;
typedef struct
{
u8 rcomp;
s16 up,down;
} rcomp_;
typedef struct
{
u8 hi;
u8 low;
} verify_;
typedef struct
{
u8 mg_param[BATT_PARAM_SIZE];
u8 v_scale;
rcomp_ rcomp;
u16 ocv;
verify_ verify;
} bt_param_;
#endif

1023
snake_tags/3.40_jane/bsr.hex Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,897 @@
78K0R Linker W1.33 Date:25 Nov 2016 Page: 1
Command: -yC:\Program Files (x86)\NEC Electronics Tools\DEV -_msgoff -
obsr.lmf ..\..\..\..\Program Files (x86)\NEC Electronics Tool
s\CC78K0R\W2.13\lib78k0r\s0rm.rel -gi1B339499E033F240BFAAh -p
bsr_k0r.map -nkd -gb7EFBFFh -bC:\Program Files (x86)\NEC Elec
tronics Tools\CC78K0R\W2.13\lib78k0r\fsl.lib -bcl0rdm.lib -bc
l0rm.lib -bcl0rmf.lib -iC:\Program Files (x86)\NEC Electronic
s Tools\CC78K0R\W2.13\lib78k0r -dbsr_mcu.dr -s -w2 loader.rel
pm.rel i2c_ctr.rel main.rel magic.rel WDT.rel i2c_mcu.rel i2
c_twl.rel led.rel rtc.rel vreg_ctr.rel vreg_twl.rel adc.rel r
enge.rel accero.rel self_flash.rel sw.rel task_debug.rel task
_misc.rel task_sys.rel pedo_alg_thre_det2.rel ini_VECT.rel ta
sk_status.rel led_cam.rel led_pow.rel hal.rel batt_params.rel
voltable.rel pedo_lpf_coeff.rel kanaria.rel kanaria_c.rel ge
t_ei.rel util_funcs.rel i2c_mcu-sub.rel
Para-file:
Out-file: bsr.lmf
Map-file: bsr_k0r.map
Direc-file:bsr_mcu.dr
*** Link information ***
73 output segment(s)
3EBEH byte(s) real data
6429 symbol(s) defined
*** Memory map ***
SPACE=REGULAR
MEMORY=BCL0
BASE ADDRESS=00000H SIZE=01000H
OUTPUT INPUT INPUT BASE SIZE
SEGMENT SEGMENT MODULE ADDRESS
@@VECT00 00000H 00002H CSEG AT
@@VECT00 @cstart 00000H 00002H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL loader 00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL WDT 00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL i2c_mcu 00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL i2c_twl 00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL self_flash
00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL task_debug
00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL task_status
00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL hal 00002H 00000H
LDR_CNSL 00002H 00000H CSEG PAGE64KP
LDR_CNSL util_funcs
00002H 00000H
* gap * 00002H 0000EH
@@VECT10 00010H 00004H CSEG AT
@@VECT10 ini_VECT 00010H 00004H
* gap * 00014H 00008H
@@VECT1C 0001CH 00002H CSEG AT
@@VECT1C ini_VECT 0001CH 00002H
* gap * 0001EH 00006H
@@VECT24 00024H 00002H CSEG AT
@@VECT24 ini_VECT 00024H 00002H
* gap * 00026H 00004H
@@VECT2A 0002AH 00002H CSEG AT
@@VECT2A i2c_twl 0002AH 00002H
* gap * 0002CH 00008H
@@VECT34 00034H 00008H CSEG AT
@@VECT34 ini_VECT 00034H 00008H
* gap * 0003CH 0000EH
@@VECT4A 0004AH 00002H CSEG AT
@@VECT4A ini_VECT 0004AH 00002H
* gap * 0004CH 0000EH
@@VECT5A 0005AH 00002H CSEG AT
@@VECT5A i2c_ctr 0005AH 00002H
* gap * 0005CH 00006H
@@VECT62 00062H 00002H CSEG AT
@@VECT62 accero 00062H 00002H
* gap * 00064H 0001CH
@@CALT 00080H 00006H CSEG CALLT0
@@CALT @cstart 00080H 00000H
@@CALT loader 00080H 00000H
@@CALT pm 00080H 00000H
@@CALT i2c_ctr 00080H 00000H
@@CALT main 00080H 00000H
@@CALT magic 00080H 00000H
@@CALT WDT 00080H 00000H
@@CALT i2c_mcu 00080H 00000H
@@CALT i2c_twl 00080H 00000H
@@CALT led 00080H 00000H
@@CALT rtc 00080H 00000H
@@CALT vreg_ctr 00080H 00000H
@@CALT vreg_twl 00080H 00000H
@@CALT adc 00080H 00000H
@@CALT renge 00080H 00006H
@@CALT accero 00086H 00000H
@@CALT self_flash
00086H 00000H
@@CALT sw 00086H 00000H
@@CALT task_debug
00086H 00000H
@@CALT task_misc
00086H 00000H
@@CALT task_sys 00086H 00000H
@@CALT pedo_alg_thre_det2
00086H 00000H
@@CALT ini_VECT 00086H 00000H
@@CALT task_status
00086H 00000H
@@CALT led_cam 00086H 00000H
@@CALT led_pow 00086H 00000H
@@CALT hal 00086H 00000H
@@CALT batt_params
00086H 00000H
@@CALT voltable 00086H 00000H
@@CALT pedo_lpf_coeff
00086H 00000H
@@CALT kanaria_c
00086H 00000H
@@CALT util_funcs
00086H 00000H
@@CALT i2c_mcu-sub
00086H 00000H
* gap * 00086H 0003AH
?CSEGOB0 000C0H 00004H CSEG OPT_BYTE
@@CODE 000C4H 00000H CSEG BASE
@@CODE magic 000C4H 00000H
@@CODE ini_VECT 000C4H 00000H
@@CODE batt_params
000C4H 00000H
LDR_CODL 000C4H 00000H CSEG
LDR_CODL loader 000C4H 00000H
LDR_CODL WDT 000C4H 00000H
LDR_CODL i2c_mcu 000C4H 00000H
LDR_CODL i2c_twl 000C4H 00000H
LDR_CODL self_flash
000C4H 00000H
LDR_CODL task_debug
000C4H 00000H
LDR_CODL task_status
000C4H 00000H
LDR_CODL hal 000C4H 00000H
LDR_CODL util_funcs
000C4H 00000H
?CSEGSI 000C4H 0000AH CSEG
LDR_CODE 000CEH 00982H CSEG
LDR_CODE loader 000CEH 001A0H
LDR_CODE WDT 0026EH 00000H
LDR_CODE i2c_mcu 0026EH 002A2H
LDR_CODE i2c_twl 00510H 0005BH
LDR_CODE self_flash
0056BH 00370H
LDR_CODE task_debug
008DBH 00000H
LDR_CODE task_status
008DBH 00075H
LDR_CODE hal 00950H 000DCH
LDR_CODE util_funcs
00A2CH 00024H
FSL_CODE 00A50H 00322H CSEG
FSL_CODE fsl_block_cmd
00A50H 0002BH
FSL_CODE fsl_block_check
00A7BH 00013H
FSL_CODE fsl_common
00A8EH 0014FH
FSL_CODE fsl_reset
00BDDH 00001H
FSL_CODE fsl_si_ibf
00BDEH 00064H
FSL_CODE fsl_phySwap
00C42H 0004DH
FSL_CODE fsl_si_common
00C8FH 00061H
FSL_CODE fsl_swap 00CF0H 00030H
FSL_CODE fsl_write
00D20H 00052H
@@LCODE 00D72H 00277H CSEG
@@LCODE @cstart 00D72H 0006DH
@@LCODE @imul 00DDFH 00011H
@@LCODE @lumul 00DF0H 0002BH
@@LCODE @isdiv 00E1BH 00022H
@@LCODE @iudiv 00E3DH 0002DH
@@LCODE @isrem 00E6AH 00021H
@@LCODE @iurem 00E8BH 0002FH
@@LCODE @lsdiv 00EBAH 00039H
@@LCODE @ludiv 00EF3H 0003FH
@@LCODE @divuw 00F32H 00034H
@@LCODE @ladd 00F66H 0000FH
@@LCODE @llsh 00F75H 0001BH
@@LCODE @lursh 00F90H 0001FH
@@LCODE @iscmp 00FAFH 0000CH
@@LCODE @lband 00FBBH 00014H
@@LCODE @bcdtob 00FCFH 0001AH
* gap * 00FE9H 0000DH
MGC_LOAD 00FF6H 0000AH CSEG AT
MGC_LOAD magic 00FF6H 0000AH
MEMORY=ROM
BASE ADDRESS=02000H SIZE=03000H
OUTPUT INPUT INPUT BASE SIZE
SEGMENT SEGMENT MODULE ADDRESS
MGC_MIMI 02000H 0000AH CSEG AT
MGC_MIMI magic 02000H 0000AH
@@CNST 0200AH 00282H CSEG
@@CNST @cstart 0200AH 00000H
@@CNST loader 0200AH 00000H
@@CNST pm 0200AH 00008H
@@CNST i2c_ctr 02012H 00000H
@@CNST main 02012H 00000H
@@CNST magic 02012H 00000H
@@CNST WDT 02012H 00000H
@@CNST i2c_mcu 02012H 00000H
@@CNST i2c_twl 02012H 00000H
@@CNST led 02012H 00000H
@@CNST rtc 02012H 00000H
@@CNST vreg_ctr 02012H 00000H
@@CNST vreg_twl 02012H 00000H
@@CNST adc 02012H 00008H
@@CNST renge 0201AH 00000H
@@CNST accero 0201AH 00000H
@@CNST self_flash
0201AH 00002H
@@CNST sw 0201CH 00000H
@@CNST task_debug
0201CH 00000H
@@CNST task_misc
0201CH 00000H
@@CNST task_sys 0201CH 00000H
@@CNST pedo_alg_thre_det2
0201CH 00018H
@@CNST ini_VECT 02034H 00000H
@@CNST task_status
02034H 00000H
@@CNST led_cam 02034H 00000H
@@CNST led_pow 02034H 00020H
@@CNST hal 02054H 00000H
@@CNST batt_params
02054H 001C8H
@@CNST voltable 0221CH 00040H
@@CNST pedo_lpf_coeff
0225CH 00030H
@@CNST kanaria_c
0228CH 00000H
@@CNST util_funcs
0228CH 00000H
@@CNST i2c_mcu-sub
0228CH 00000H
ROM_CODE 0228CH 02639H CSEG
ROM_CODE pm 0228CH 00A6DH
ROM_CODE i2c_ctr 02CF9H 0005CH
ROM_CODE main 02D55H 00055H
ROM_CODE led 02DAAH 00284H
ROM_CODE rtc 0302EH 000E0H
ROM_CODE vreg_ctr 0310EH 0049EH
ROM_CODE vreg_twl 035ACH 000F9H
ROM_CODE adc 036A5H 00261H
ROM_CODE renge 03906H 00018H
ROM_CODE accero 0391EH 00155H
ROM_CODE sw 03A73H 00135H
ROM_CODE task_misc
03BA8H 001C4H
ROM_CODE task_sys 03D6CH 0038AH
ROM_CODE pedo_alg_thre_det2
040F6H 004D4H
ROM_CODE led_cam 045CAH 000C4H
ROM_CODE led_pow 0468EH 0016FH
ROM_CODE voltable 047FDH 00000H
ROM_CODE pedo_lpf_coeff
047FDH 00000H
ROM_CODE kanaria_c
047FDH 00006H
ROM_CODE get_ei 04803H 0000DH
ROM_CODE i2c_mcu-sub
04810H 000B5H
@@BASE 048C5H 00614H CSEG BASE
@@BASE loader 048C5H 00000H
@@BASE pm 048C5H 0003EH
@@BASE i2c_ctr 04903H 00170H
@@BASE main 04A73H 00000H
@@BASE magic 04A73H 00000H
@@BASE WDT 04A73H 00000H
@@BASE i2c_mcu 04A73H 000F2H
@@BASE i2c_twl 04B65H 000D0H
@@BASE led 04C35H 00000H
@@BASE rtc 04C35H 0005DH
@@BASE vreg_ctr 04C92H 00000H
@@BASE vreg_twl 04C92H 00000H
@@BASE adc 04C92H 00094H
@@BASE renge 04D26H 0016BH
@@BASE accero 04E91H 00042H
@@BASE self_flash
04ED3H 00000H
@@BASE sw 04ED3H 00000H
@@BASE task_debug
04ED3H 00000H
@@BASE task_misc
04ED3H 00000H
@@BASE task_sys 04ED3H 00000H
@@BASE pedo_alg_thre_det2
04ED3H 00000H
@@BASE ini_VECT 04ED3H 00006H
@@BASE task_status
04ED9H 00000H
@@BASE led_cam 04ED9H 00000H
@@BASE led_pow 04ED9H 00000H
@@BASE hal 04ED9H 00000H
@@BASE batt_params
04ED9H 00000H
@@BASE voltable 04ED9H 00000H
@@BASE pedo_lpf_coeff
04ED9H 00000H
@@BASE kanaria_c
04ED9H 00000H
@@BASE util_funcs
04ED9H 00000H
@@BASE i2c_mcu-sub
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL @cstart 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL pm 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL i2c_ctr 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL main 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL led 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL rtc 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL vreg_ctr 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL vreg_twl 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL adc 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL renge 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL accero 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL sw 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL task_misc
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL task_sys 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL pedo_alg_thre_det2
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL ini_VECT 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL led_cam 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL led_pow 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL batt_params
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL voltable 04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL pedo_lpf_coeff
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL kanaria_c
04ED9H 00000H
@@CNSTL 04ED9H 00000H CSEG PAGE64KP
@@CNSTL i2c_mcu-sub
04ED9H 00000H
@@RLINIT 04ED9H 00000H CSEG UNIT64KP
@@RLINIT loader 04ED9H 00000H
@@RLINIT pm 04ED9H 00000H
@@RLINIT i2c_ctr 04ED9H 00000H
@@RLINIT main 04ED9H 00000H
@@RLINIT magic 04ED9H 00000H
@@RLINIT WDT 04ED9H 00000H
@@RLINIT i2c_mcu 04ED9H 00000H
@@RLINIT i2c_twl 04ED9H 00000H
@@RLINIT led 04ED9H 00000H
@@RLINIT rtc 04ED9H 00000H
@@RLINIT vreg_ctr 04ED9H 00000H
@@RLINIT vreg_twl 04ED9H 00000H
@@RLINIT adc 04ED9H 00000H
@@RLINIT renge 04ED9H 00000H
@@RLINIT accero 04ED9H 00000H
@@RLINIT self_flash
04ED9H 00000H
@@RLINIT sw 04ED9H 00000H
@@RLINIT task_debug
04ED9H 00000H
@@RLINIT task_misc
04ED9H 00000H
@@RLINIT task_sys 04ED9H 00000H
@@RLINIT pedo_alg_thre_det2
04ED9H 00000H
@@RLINIT ini_VECT 04ED9H 00000H
@@RLINIT task_status
04ED9H 00000H
@@RLINIT led_cam 04ED9H 00000H
@@RLINIT led_pow 04ED9H 00000H
@@RLINIT hal 04ED9H 00000H
@@RLINIT batt_params
04ED9H 00000H
@@RLINIT voltable 04ED9H 00000H
@@RLINIT pedo_lpf_coeff
04ED9H 00000H
@@RLINIT kanaria_c
04ED9H 00000H
@@RLINIT util_funcs
04ED9H 00000H
@@RLINIT i2c_mcu-sub
04ED9H 00000H
@@RLINIT @rom 04ED9H 00000H
@@CODEL 04ED9H 00000H CSEG
@@CODEL pm 04ED9H 00000H
@@CODEL i2c_ctr 04ED9H 00000H
@@CODEL main 04ED9H 00000H
@@CODEL magic 04ED9H 00000H
@@CODEL led 04ED9H 00000H
@@CODEL rtc 04ED9H 00000H
@@CODEL vreg_ctr 04ED9H 00000H
@@CODEL vreg_twl 04ED9H 00000H
@@CODEL adc 04ED9H 00000H
@@CODEL renge 04ED9H 00000H
@@CODEL accero 04ED9H 00000H
@@CODEL sw 04ED9H 00000H
@@CODEL task_misc
04ED9H 00000H
@@CODEL task_sys 04ED9H 00000H
@@CODEL pedo_alg_thre_det2
04ED9H 00000H
@@CODEL ini_VECT 04ED9H 00000H
@@CODEL led_cam 04ED9H 00000H
@@CODEL led_pow 04ED9H 00000H
@@CODEL batt_params
04ED9H 00000H
@@CODEL voltable 04ED9H 00000H
@@CODEL pedo_lpf_coeff
04ED9H 00000H
@@CODEL kanaria_c
04ED9H 00000H
@@CODEL i2c_mcu-sub
04ED9H 00000H
* gap * 04ED9H 00001H
@@CNSTL 04EDAH 0000AH CSEG PAGE64KP
@@CNSTL @bcdtob 04EDAH 0000AH
@@R_INIT 04EE4H 0004AH CSEG UNIT64KP
@@R_INIT @cstart 04EE4H 00000H
@@R_INIT loader 04EE4H 00000H
@@R_INIT pm 04EE4H 00000H
@@R_INIT i2c_ctr 04EE4H 00000H
@@R_INIT main 04EE4H 00000H
@@R_INIT magic 04EE4H 00000H
@@R_INIT WDT 04EE4H 00000H
@@R_INIT i2c_mcu 04EE4H 00000H
@@R_INIT i2c_twl 04EE4H 00000H
@@R_INIT led 04EE4H 00000H
@@R_INIT rtc 04EE4H 00000H
@@R_INIT vreg_ctr 04EE4H 00000H
@@R_INIT vreg_twl 04EE4H 00000H
@@R_INIT adc 04EE4H 0000CH
@@R_INIT renge 04EF0H 00014H
@@R_INIT accero 04F04H 00000H
@@R_INIT self_flash
04F04H 00000H
@@R_INIT sw 04F04H 00000H
@@R_INIT task_debug
04F04H 00000H
@@R_INIT task_misc
04F04H 00026H
@@R_INIT task_sys 04F2AH 00000H
@@R_INIT pedo_alg_thre_det2
04F2AH 00000H
@@R_INIT ini_VECT 04F2AH 00000H
@@R_INIT task_status
04F2AH 00000H
@@R_INIT led_cam 04F2AH 00000H
@@R_INIT led_pow 04F2AH 00004H
@@R_INIT hal 04F2EH 00000H
@@R_INIT batt_params
04F2EH 00000H
@@R_INIT voltable 04F2EH 00000H
@@R_INIT pedo_lpf_coeff
04F2EH 00000H
@@R_INIT kanaria_c
04F2EH 00000H
@@R_INIT util_funcs
04F2EH 00000H
@@R_INIT i2c_mcu-sub
04F2EH 00000H
@@R_INIT @rom 04F2EH 00000H
@@R_INIS 04F2EH 00010H CSEG UNIT64KP
@@R_INIS @cstart 04F2EH 00000H
@@R_INIS loader 04F2EH 00000H
@@R_INIS pm 04F2EH 00002H
@@R_INIS i2c_ctr 04F30H 00002H
@@R_INIS main 04F32H 00000H
@@R_INIS magic 04F32H 00000H
@@R_INIS WDT 04F32H 00000H
@@R_INIS i2c_mcu 04F32H 00000H
@@R_INIS i2c_twl 04F32H 00000H
@@R_INIS led 04F32H 00000H
@@R_INIS rtc 04F32H 00000H
@@R_INIS vreg_ctr 04F32H 00000H
@@R_INIS vreg_twl 04F32H 00000H
@@R_INIS adc 04F32H 00000H
@@R_INIS renge 04F32H 00000H
@@R_INIS accero 04F32H 00000H
@@R_INIS self_flash
04F32H 00000H
@@R_INIS sw 04F32H 00000H
@@R_INIS task_debug
04F32H 00000H
@@R_INIS task_misc
04F32H 00000H
@@R_INIS task_sys 04F32H 00002H
@@R_INIS pedo_alg_thre_det2
04F34H 00006H
@@R_INIS ini_VECT 04F3AH 00000H
@@R_INIS task_status
04F3AH 00000H
@@R_INIS led_cam 04F3AH 00002H
@@R_INIS led_pow 04F3CH 00002H
@@R_INIS hal 04F3EH 00000H
@@R_INIS batt_params
04F3EH 00000H
@@R_INIS voltable 04F3EH 00000H
@@R_INIS pedo_lpf_coeff
04F3EH 00000H
@@R_INIS kanaria_c
04F3EH 00000H
@@R_INIS util_funcs
04F3EH 00000H
@@R_INIS i2c_mcu-sub
04F3EH 00000H
@@R_INIS @rom 04F3EH 00000H
@@LCODEL 04F3EH 00022H CSEG
@@LCODEL abs 04F3EH 00008H
@@LCODEL memcpy_n 04F46H 0001AH
* gap * 04F60H 00094H
MGC_VER 04FF4H 00002H CSEG AT
MGC_VER magic 04FF4H 00002H
MGC_TAIL 04FF6H 0000AH CSEG AT
MGC_TAIL magic 04FF6H 0000AH
MEMORY=RAM
BASE ADDRESS=FF900H SIZE=00500H
OUTPUT INPUT INPUT BASE SIZE
SEGMENT SEGMENT MODULE ADDRESS
@@DATA FF900H 003CCH DSEG BASEP
@@DATA @cstart FF900H 00002H
@@DATA loader FF902H 00000H
@@DATA pm FF902H 00002H
@@DATA i2c_ctr FF904H 00000H
@@DATA main FF904H 0021EH
@@DATA magic FFB22H 00000H
@@DATA WDT FFB22H 00000H
@@DATA i2c_mcu FFB22H 00004H
@@DATA i2c_twl FFB26H 00000H
@@DATA led FFB26H 00076H
@@DATA rtc FFB9CH 00008H
@@DATA vreg_ctr FFBA4H 0005CH
@@DATA vreg_twl FFC00H 00010H
@@DATA adc FFC10H 00000H
@@DATA renge FFC10H 00014H
@@DATA accero FFC24H 00000H
@@DATA self_flash
FFC24H 00002H
@@DATA sw FFC26H 00000H
@@DATA task_debug
FFC26H 00000H
@@DATA task_misc
FFC26H 00008H
@@DATA task_sys FFC2EH 00000H
@@DATA pedo_alg_thre_det2
FFC2EH 00098H
@@DATA ini_VECT FFCC6H 00000H
@@DATA task_status
FFCC6H 00000H
@@DATA led_cam FFCC6H 00000H
@@DATA led_pow FFCC6H 00006H
@@DATA hal FFCCCH 00000H
@@DATA batt_params
FFCCCH 00000H
@@DATA voltable FFCCCH 00000H
@@DATA pedo_lpf_coeff
FFCCCH 00000H
@@DATA kanaria FFCCCH 00000H
@@DATA kanaria_c
FFCCCH 00000H
@@DATA util_funcs
FFCCCH 00000H
@@DATA i2c_mcu-sub
FFCCCH 00000H
@@DATA @rom FFCCCH 00000H
@@INIT FFCCCH 0004AH DSEG BASEP
@@INIT @cstart FFCCCH 00000H
@@INIT loader FFCCCH 00000H
@@INIT pm FFCCCH 00000H
@@INIT i2c_ctr FFCCCH 00000H
@@INIT main FFCCCH 00000H
@@INIT magic FFCCCH 00000H
@@INIT WDT FFCCCH 00000H
@@INIT i2c_mcu FFCCCH 00000H
@@INIT i2c_twl FFCCCH 00000H
@@INIT led FFCCCH 00000H
@@INIT rtc FFCCCH 00000H
@@INIT vreg_ctr FFCCCH 00000H
@@INIT vreg_twl FFCCCH 00000H
@@INIT adc FFCCCH 0000CH
@@INIT renge FFCD8H 00014H
@@INIT accero FFCECH 00000H
@@INIT self_flash
FFCECH 00000H
@@INIT sw FFCECH 00000H
@@INIT task_debug
FFCECH 00000H
@@INIT task_misc
FFCECH 00026H
@@INIT task_sys FFD12H 00000H
@@INIT pedo_alg_thre_det2
FFD12H 00000H
@@INIT ini_VECT FFD12H 00000H
@@INIT task_status
FFD12H 00000H
@@INIT led_cam FFD12H 00000H
@@INIT led_pow FFD12H 00004H
@@INIT hal FFD16H 00000H
@@INIT batt_params
FFD16H 00000H
@@INIT voltable FFD16H 00000H
@@INIT pedo_lpf_coeff
FFD16H 00000H
@@INIT kanaria FFD16H 00000H
@@INIT kanaria_c
FFD16H 00000H
@@INIT util_funcs
FFD16H 00000H
@@INIT i2c_mcu-sub
FFD16H 00000H
@@INIT @rom FFD16H 00000H
FSL_DATA FFD16H 00010H DSEG UNITP
FSL_DATA fsl_common
FFD16H 00010H
@@INITL FFD26H 00000H DSEG UNIT64KP
@@INITL loader FFD26H 00000H
@@INITL pm FFD26H 00000H
@@INITL i2c_ctr FFD26H 00000H
@@INITL main FFD26H 00000H
@@INITL magic FFD26H 00000H
@@INITL WDT FFD26H 00000H
@@INITL i2c_mcu FFD26H 00000H
@@INITL i2c_twl FFD26H 00000H
@@INITL led FFD26H 00000H
@@INITL rtc FFD26H 00000H
@@INITL vreg_ctr FFD26H 00000H
@@INITL vreg_twl FFD26H 00000H
@@INITL adc FFD26H 00000H
@@INITL renge FFD26H 00000H
@@INITL accero FFD26H 00000H
@@INITL self_flash
FFD26H 00000H
@@INITL sw FFD26H 00000H
@@INITL task_debug
FFD26H 00000H
@@INITL task_misc
FFD26H 00000H
@@INITL task_sys FFD26H 00000H
@@INITL pedo_alg_thre_det2
FFD26H 00000H
@@INITL ini_VECT FFD26H 00000H
@@INITL task_status
FFD26H 00000H
@@INITL led_cam FFD26H 00000H
@@INITL led_pow FFD26H 00000H
@@INITL hal FFD26H 00000H
@@INITL batt_params
FFD26H 00000H
@@INITL voltable FFD26H 00000H
@@INITL pedo_lpf_coeff
FFD26H 00000H
@@INITL kanaria FFD26H 00000H
@@INITL kanaria_c
FFD26H 00000H
@@INITL util_funcs
FFD26H 00000H
@@INITL i2c_mcu-sub
FFD26H 00000H
@@INITL @rom FFD26H 00000H
@@DATAL FFD26H 00000H DSEG UNIT64KP
@@DATAL loader FFD26H 00000H
@@DATAL pm FFD26H 00000H
@@DATAL i2c_ctr FFD26H 00000H
@@DATAL main FFD26H 00000H
@@DATAL magic FFD26H 00000H
@@DATAL WDT FFD26H 00000H
@@DATAL i2c_mcu FFD26H 00000H
@@DATAL i2c_twl FFD26H 00000H
@@DATAL led FFD26H 00000H
@@DATAL rtc FFD26H 00000H
@@DATAL vreg_ctr FFD26H 00000H
@@DATAL vreg_twl FFD26H 00000H
@@DATAL adc FFD26H 00000H
@@DATAL renge FFD26H 00000H
@@DATAL accero FFD26H 00000H
@@DATAL self_flash
FFD26H 00000H
@@DATAL sw FFD26H 00000H
@@DATAL task_debug
FFD26H 00000H
@@DATAL task_misc
FFD26H 00000H
@@DATAL task_sys FFD26H 00000H
@@DATAL pedo_alg_thre_det2
FFD26H 00000H
@@DATAL ini_VECT FFD26H 00000H
@@DATAL task_status
FFD26H 00000H
@@DATAL led_cam FFD26H 00000H
@@DATAL led_pow FFD26H 00000H
@@DATAL hal FFD26H 00000H
@@DATAL batt_params
FFD26H 00000H
@@DATAL voltable FFD26H 00000H
@@DATAL pedo_lpf_coeff
FFD26H 00000H
@@DATAL kanaria FFD26H 00000H
@@DATAL kanaria_c
FFD26H 00000H
@@DATAL util_funcs
FFD26H 00000H
@@DATAL i2c_mcu-sub
FFD26H 00000H
@@DATAL @rom FFD26H 00000H
* gap * FFD26H 000DAH
MEMORY=RAM2
BASE ADDRESS=FFE20H SIZE=000C0H
OUTPUT INPUT INPUT BASE SIZE
SEGMENT SEGMENT MODULE ADDRESS
@@INIS FFE20H 00010H DSEG SADDRP
@@INIS @cstart FFE20H 00000H
@@INIS loader FFE20H 00000H
@@INIS pm FFE20H 00002H
@@INIS i2c_ctr FFE22H 00002H
@@INIS main FFE24H 00000H
@@INIS magic FFE24H 00000H
@@INIS WDT FFE24H 00000H
@@INIS i2c_mcu FFE24H 00000H
@@INIS i2c_twl FFE24H 00000H
@@INIS led FFE24H 00000H
@@INIS rtc FFE24H 00000H
@@INIS vreg_ctr FFE24H 00000H
@@INIS vreg_twl FFE24H 00000H
@@INIS adc FFE24H 00000H
@@INIS renge FFE24H 00000H
@@INIS accero FFE24H 00000H
@@INIS self_flash
FFE24H 00000H
@@INIS sw FFE24H 00000H
@@INIS task_debug
FFE24H 00000H
@@INIS task_misc
FFE24H 00000H
@@INIS task_sys FFE24H 00002H
@@INIS pedo_alg_thre_det2
FFE26H 00006H
@@INIS ini_VECT FFE2CH 00000H
@@INIS task_status
FFE2CH 00000H
@@INIS led_cam FFE2CH 00002H
@@INIS led_pow FFE2EH 00002H
@@INIS hal FFE30H 00000H
@@INIS batt_params
FFE30H 00000H
@@INIS voltable FFE30H 00000H
@@INIS pedo_lpf_coeff
FFE30H 00000H
@@INIS kanaria_c
FFE30H 00000H
@@INIS util_funcs
FFE30H 00000H
@@INIS i2c_mcu-sub
FFE30H 00000H
@@INIS @rom FFE30H 00000H
@@DATS FFE30H 00066H DSEG SADDRP
@@DATS @cstart FFE30H 00000H
@@DATS loader FFE30H 00000H
@@DATS pm FFE30H 0001AH
@@DATS i2c_ctr FFE4AH 00004H
@@DATS main FFE4EH 00000H
@@DATS magic FFE4EH 00000H
@@DATS WDT FFE4EH 00000H
@@DATS i2c_mcu FFE4EH 00008H
@@DATS i2c_twl FFE56H 00000H
@@DATS led FFE56H 00006H
@@DATS rtc FFE5CH 00000H
@@DATS vreg_ctr FFE5CH 00004H
@@DATS vreg_twl FFE60H 00000H
@@DATS adc FFE60H 0000AH
@@DATS renge FFE6AH 00002H
@@DATS accero FFE6CH 00002H
@@DATS self_flash
FFE6EH 00000H
@@DATS sw FFE6EH 0000CH
@@DATS task_debug
FFE7AH 00000H
@@DATS task_misc
FFE7AH 00004H
@@DATS task_sys FFE7EH 00002H
@@DATS pedo_alg_thre_det2
FFE80H 0000EH
@@DATS ini_VECT FFE8EH 00000H
@@DATS task_status
FFE8EH 00002H
@@DATS led_cam FFE90H 00002H
@@DATS led_pow FFE92H 00004H
@@DATS hal FFE96H 00000H
@@DATS batt_params
FFE96H 00000H
@@DATS voltable FFE96H 00000H
@@DATS pedo_lpf_coeff
FFE96H 00000H
@@DATS kanaria_c
FFE96H 00000H
@@DATS util_funcs
FFE96H 00000H
@@DATS i2c_mcu-sub
FFE96H 00000H
@@DATS @rom FFE96H 00000H
@@BITS FFE96H 00006H BSEG
@@BITS @cstart FFE96H.0 00000H.0
@@BITS loader FFE96H.0 00000H.0
@@BITS pm FFE96H.0 00001H.1
@@BITS i2c_ctr FFE97H.1 00000H.0
@@BITS main FFE97H.1 00000H.1
@@BITS magic FFE97H.2 00000H.0
@@BITS WDT FFE97H.2 00000H.0
@@BITS i2c_mcu FFE97H.2 00000H.4
@@BITS i2c_twl FFE97H.6 00000H.0
@@BITS led FFE97H.6 00000H.4
@@BITS rtc FFE98H.2 00000H.3
@@BITS vreg_ctr FFE98H.5 00000H.1
@@BITS vreg_twl FFE98H.6 00000H.0
@@BITS adc FFE98H.6 00000H.4
@@BITS renge FFE99H.2 00000H.2
@@BITS accero FFE99H.4 00000H.0
@@BITS self_flash
FFE99H.4 00000H.0
@@BITS sw FFE99H.4 00000H.1
@@BITS task_debug
FFE99H.5 00000H.0
@@BITS task_misc
FFE99H.5 00000H.3
@@BITS task_sys FFE9AH.0 00000H.0
@@BITS pedo_alg_thre_det2
FFE9AH.0 00000H.2
@@BITS ini_VECT FFE9AH.2 00000H.0
@@BITS task_status
FFE9AH.2 00000H.0
@@BITS led_cam FFE9AH.2 00000H.1
@@BITS led_pow FFE9AH.3 00000H.0
@@BITS hal FFE9AH.3 00000H.6
@@BITS batt_params
FFE9BH.1 00000H.0
@@BITS voltable FFE9BH.1 00000H.0
@@BITS pedo_lpf_coeff
FFE9BH.1 00000H.0
@@BITS kanaria_c
FFE9BH.1 00000H.0
@@BITS util_funcs
FFE9BH.1 00000H.0
@@BITS i2c_mcu-sub
FFE9BH.1 00000H.0
* gap * FFE9CH 00038H
@@SEGREG FFED4H 00004H DSEG AT
@@SEGREG @SEGREG FFED4H 00004H
@@RTARG0 FFED8H 00008H DSEG AT
@@RTARG0 @RTARG0 FFED8H 00008H
Target chip : uPD79F0104
Device file : E1.00b


View File

@ -0,0 +1,46 @@
;;; 領域の定義
;32kB = 0x7FFF
MEMORY BCL0: (00000H, 01000H )
;MEMORY BCL1: (01000H, 01000H ) ; バックアップ領域
MEMORY ROM : (02000H, 03000H )
;MEMORY ROM_BKUP:(05000H, 03000H ) ; バックアップ領域
;MEMORY OCD :(0FC00H, 00400H ) ; OCDが使っているらしい
;;; セグメントの割当先設定
; ブートブロック0に割り当てる
MERGE LDR_CODE : =BCL0
MERGE LDR_CODL : =BCL0
MERGE FSL_CODE : =BCL0 ; =FSL ; 謹製フラッシュライブラリ
MERGE @@LCODE : =BCL0 ; スタートアップルーチン
;MERGE @@LCODEL : =BCL0
;MERGE LDR_RINT:=BCL0
;MERGE LDR_CNST:=BCL0
MERGE LDR_CNSL:=BCL0
; 通常領域に置く
MERGE ROM_CODE:=ROM
MERGE @@CNST: =ROM
MERGE @@R_INIT: =ROM ; ROM以外に置きたいならスタートアップルーチンを要修正
; マジックナンバー
;; magic.cの中で指定
;--- RAM領域 -------------------------------------------------------
;
; RAM1,RAM2領域はユーザープログラムで使用しても良いですが、セルフプログラム時は
; セルフプログラムのライブラリが使用するため、値は破壊されます。
;
memory RAM : (0FF900H, 0500H) ; ユーザーRAM領域
;memory SLF_RAM : (0FF900H, 0020H) ; Slef Program予約領域[使用禁止]
memory RAM2 : (0FFE20H, 00C0H) ; セルフプログラム時、使用禁止領域
;memory SLF_RAM : (0FFE00H, 0020H) ; Slef Program予約領域[使用禁止]

View File

@ -0,0 +1,73 @@
#ifndef __bsr_system__
#define __bsr_system__
// $Id$
// イベントループのステート
enum pwr_state_
{
OFF_TRIG = 0,
ON_CHECK,
ON_TRIG,
ON,
// SLEEP_TRIG,
SLEEP,
// WAKE,
OFF,
};
enum poweron_reason_
{
NONE = 0,
RSN_PWSW,
RSN_RTC_ALARM,
RSN_TRIAL, // 体験台
RSN_RSV4,
RSN_RSV5
};
enum model_
{
MODEL_JIKKI,
MODEL_TS_BOARD,
MODEL_KUC_DEBUGGER,
MODEL_JIKKI_NOBATT,
MODEL_KUC_CAPTURE,
MODEL_IS_DEBUGGER, // ただし、system_status.modelは MODEL_JIKKI にしておくので未使用
MODEL_IS_CAPTURE,
};
enum family_
{
FAMILY_CTR,
FAMILY_SPFL, // LL=XL
FAMILY_SNAKE, // LAGER=New3DS
FAMILY_FLOWER, // 2DS=RED
FAMILY_CLOSER,
FAMILY_JANE,
};
// タスクシステムの状態情報など
typedef struct _system_status_
{
enum pwr_state_ pwr_state;
enum poweron_reason_ poweron_reason;
unsigned char reboot:1;
unsigned char captureBox:1; // キャプチャ箱 SDK には実機と返す
unsigned char taikendai:1;
unsigned char taikendai_nbd:1;
unsigned char is_dev:1; // IS のデバッガ、ほぼ実機
enum model_ model;
enum family_ family;
unsigned char LCD_is_CGS:1;
}system_status_;
extern bit force_off;
extern system_status_ system_status;
#endif

View File

@ -0,0 +1,113 @@
#ifndef __config__
#define __config__
/*
$Id: config.h 418 2011-09-22 01:35:37Z n2232 $
*/
#define MCU_VER_MAJOR 0x03
#define MCU_VER_MINOR 0x41
/*
2014/02/13 2.36
*/
// ビルドスイッチ
#define _MCU_ARR // snake,closer
// デバッグ向けスイッチ
//#define _debug_led_ // LED print デバッグをしたいとき
//#define _ALLOW_NOBATT_ // 実機電池なし(=アダプタのみ)での起動を許可
//#define _DBG_LED_PRINT_ // LED print デバッグをしたいとき(自己アップデート用)
//#define _ENABLE_COMMAND3_ // mcuリセットやwdtコマンドを有効にする
//#define _FORCE_TAIKENDAI_
//#define _FORCE_TAIKENDAI_NBD_
//#define _DBG_CHK_OFF_LEAK_ // OFF時リーク電流のチェック(デバッガで確認)
//#define _DBG_NOP_ // ブレークを貼るためにNOP()を有効にしたいとき
//#define _ENABLE_HAL_ // デバッグ用にHALを有効にする。コメントアウトでスルーになる。
//#define _ENABLE_PRESS_SEL_TO_WDT_ // SEL 長押しでWDT発動
//#define _WDT_CHECK_ // WDTがかかったらしいので追跡したいときbreakおいて、コールスタック見る
// ↑ オプションバイトの1バイト目、bit7をセットする必要があります。
//#define _DI_WITH_CHECK_ // 割り込み禁止を二重に掛けないかチェック
//#define _DBG_BT_FULL_
//#define _DBG_FORCE_FLOWER
#ifdef _DBG_NOP_ // コード上必要なNOPと区別するため
# define dbg_nop() NOP()
#else
# define dbg_nop() ;
#endif
#define _I2C_ERR_ABORT_ // *標準でon* I2Cで誤書き込みらしきが発生したら以降無視 
//. ブレーク張っても全然引っかからなくなりましたが...
// 特殊仕様ファーム
//#define _TAIKENDAI_
// homeメニューに入れてしまうのを回避する特殊ファームをつくる。ROMが足りないので電池パラメータ周りをパスする
//#define _TAIKENDAI_SEISAN_SPECIAL_
// 生産中に体験台向け仕様が発症すると、アダプタがないと電源が入らずに検査に支障があるので一時ファーム
//#define _RVD_
// デバッガアタッチ時にターゲットリセットで電源が切れてしまうのを回避
// ↑改訂の時は↓気をつけないと体験台の生産できないからね!
#ifdef _TAIKENDAI_SEISAN_SPECIAL_
#define MCU_VER_MINOR 0x81
#endif
#ifdef _TAIKENDAI_
#define MCU_VER_MINOR 0x92
// 0x90 1.31 相当 HOMEに入れてしまうのをスイッチのマスクで対策
// ROM不足のため、電池パラメータ削除
#endif
#define _firm_format_v3_
//#define _MODEL_TEG2_
// ↑TEG2 CPU Type-T
//#define _MODEL_WM0_
//#define _MODEL_WM0_TEG2_CTRC_
//#define _MODEL_TS0_
// ↑TEG2 CPU Type-C
#define _MODEL_CTR_
// ↑TS board, WM1,1 TS-CTRC, 実機
// ---------------------------------- //
#ifdef _MODEL_TEG2_
unsupported!
#endif
#ifdef _MODEL_WM0_
unsupported!
#endif
#ifdef _MODEL_TS0_
unsupported!
#endif
#ifdef _MODEL_CTR_
#define _PMIC_CTR_
#define _MCU_BSR_
#endif
#endif

362
snake_tags/3.40_jane/fsl.h Normal file
View File

@ -0,0 +1,362 @@
/*==============================================================================================*/
/* Project = Selfprogramming library for 78K0R/Ix3/Kx3-L Single Voltage SST (MF2) Flash */
/* Module = fsl.h */
/* Version = V1.01 */
/* Date = 28.03.2008 11:45:42 */
/*==============================================================================================*/
/* COPYRIGHT */
/*==============================================================================================*/
/* Copyright (c) 2007 by NEC Electronics (Europe) GmbH, */
/* a company of the NEC Electronics Corporation */
/*==============================================================================================*/
/* Purpose: */
/* constant, type and function prototype definitions used by the FSL */
/* */
/*==============================================================================================*/
/* */
/* Warranty Disclaimer */
/* */
/* Because the Product(s) is licensed free of charge, there is no warranty of any kind */
/* whatsoever and expressly disclaimed and excluded by NEC, either expressed or implied, */
/* including but not limited to those for non-infringement of intellectual property, */
/* merchantability and/or fitness for the particular purpose. NEC shall not have any obligation */
/* to maintain, service or provide bug fixes for the supplied Product(s) and/or the Application.*/
/* */
/* Each User is solely responsible for determining the appropriateness of using the Product(s) */
/* and assumes all risks associated with its exercise of rights under this Agreement, */
/* including, but not limited to the risks and costs of program errors, compliance with */
/* applicable laws, damage to or loss of data, programs or equipment, and unavailability or */
/* interruption of operations. */
/* */
/* Limitation of Liability */
/* */
/* In no event shall NEC be liable to the User for any incidental, consequential, indirect, */
/* or punitive damage (including but not limited to lost profits) regardless of whether */
/* such liability is based on breach of contract, tort, strict liability, breach of warranties, */
/* failure of essential purpose or otherwise and even if advised of the possibility of */
/* such damages. NEC shall not be liable for any services or products provided by third party */
/* vendors, developers or consultants identified or referred to the User by NEC in connection */
/* with the Product(s) and/or the Application. */
/* */
/*==============================================================================================*/
/* Environment: PM plus (V6.30) */
/* RA78K0(V1.20) */
/* CC78K0(V2.00) */
/*==============================================================================================*/
#ifndef __FSL_H_INCLUDED
#define __FSL_H_INCLUDED
/*==============================================================================================*/
/* FSL type definitions */
/*==============================================================================================*/
typedef unsigned char fsl_u08;
typedef unsigned int fsl_u16;
typedef unsigned long int fsl_u32;
/*==============================================================================================*/
/* constant definitions */
/*==============================================================================================*/
/*status code definitions returned by the FSL functions */
#define FSL_OK 0x00
#define FSL_ERR_FLMD0 0x01
#define FSL_ERR_PARAMETER 0x05
#define FSL_ERR_PROTECTION 0x10
#define FSL_ERR_ERASE 0x1A
#define FSL_ERR_BLANKCHECK 0x1B
#define FSL_ERR_IVERIFY 0x1B
#define FSL_ERR_WRITE 0x1C
#define FSL_ERR_EEP_IVERIFY 0x1D
#define FSL_ERR_EEP_BLANKCHECK 0x1E
#define FSL_ERR_INTERRUPTION 0x1F
/*==============================================================================================*/
/* global function prototypes */
/*==============================================================================================*/
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: initialization of selfprogramming environment */
/* After initialization: */
/* - the pointer to the data-buffer is stored */
/* - all timing data are re-calculated according to the used system clock */
/* */
/* CAUTION: */
/* The FSL_Init(&data_buffer) function is interruptible. Please use the */
/* FSL_Init_cont(&data_buffer) to recall it as long return status is 0x1F. */
/* */
/* Input: data_buffer_pu08 - pointer to a data buffer of N...256 bytes */
/* (used for data exchange between firmware and application) */
/* Output: - */
/* Returned: u08, status_code */
/* = 0x00(FSL_OK), normal and means initialization OK */
/* = 0x1F(FSL_ERR_INTERRUPTION), initialization interrupted by user interrupt*/
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_Init( fsl_u08 * data_buffer_pu08 );
extern fsl_u08 FSL_Init_cont( fsl_u08 * data_buffer_pu08 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: checks the voltage level (high or low) at FLMD0 pin */
/* Input: - */
/* Output: - */
/* Returned: fsl_u08, status_code */
/* = 0x00(FSL_OK), normal and means FLMD0=HIGH */
/* = 0x01(FSL_ERR_FLMD0), error, FLMD0=LOW */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_ModeCheck( void );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: checks if specified block is blank */
/* Input: block_u16 - block number has to be checked */
/* Output: - */
/* Returned: fsl_u08, status_code */
/* = 0x00(FSL_OK), normal and means "block is blank" */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x1B(FSL_ERR_BLANKCHECK), blank-check error, means "block not blank" */
/* = 0x1F(FSL_ERR_INTERRUPTION), blank-check interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_BlankCheck( fsl_u16 block_u16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: erase specified block */
/* Input: block_u16 - block number has to be erase */
/* Output: - */
/* Returned: fsl_u08, status_code */
/* = 0x00(FSL_OK), normal and means "block erased successfully" */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), tried to erase protected area */
/* = 0x1A(FSL_ERR_ERASE), erase error, retry up to max. 255 times */
/* = 0x1F(FSL_ERR_INTERRUPTION), erasing interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_Erase( fsl_u16 block_u16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: performs internal verify on specified block */
/* Input: block_u16 - block number has to be verified */
/* Output: - */
/* Returned: fsl_u08, status_code */
/* = 0x00(FSL_OK), normal and means "block is verified" */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x1B(FSL_ERR_IVERIFY), internal verify error */
/* = 0x1F(FSL_ERR_INTERRUPTION), verify interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_IVerify( fsl_u16 block_u16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: writes N words from the data buffer into flash */
/* Input: s_address_u32 - starting flash address the data has to be written */
/* See Condition 2) please. */
/* my_wordcount_u08 - number of words (4 bytes) has to be written */
/* Output: - */
/* Condition: 1) (s_address_u32 MOD 4 == 0) */
/* 2) most significant byte (MSB) of s_address_u32 has to be 0x00. */
/* Means: 0x00abcdef 24 bit flash address allowed */
/* 3) (word_count_u08 <= sizeof(data buffer)) NOT CHECKED BY LIBRARY !!!!! */
/* Changed: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), protection error */
/* = 0x1C(FSL_ERR_WRITE), write error */
/* = 0x1F(FSL_ERR_INTERRUPTION), write interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_Write( fsl_u32 s_address_u32, fsl_u08 word_count_u08 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: writes N words from the data buffer into flash */
/* Before "writing" a N-word blankcheck is performed. */
/* After "writing" a N-Word internal verify is performed. */
/* Input: s_address_u32 - starting destination address has to be written */
/* my_wordcount_u08 - number of words (4 bytes) has to be written */
/* Output: - */
/* Condition: 1) (s_address_u32 MOD 4 == 0) */
/* 2) (word_count_u08 <= sizeof(data buffer)) NOT CHECKED BY FIRMWARE !!!!! */
/* Changed: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), protection error */
/* = 0x1C(FSL_ERR_WRITE), write error */
/* = 0x1D(FSL_ERR_EEP_IVERIFY), verify error */
/* = 0x1E(FSL_ERR_EEP_BLANKCHECK), blankcheck error */
/* = 0x1F(FSL_ERR_INTERRUPTION), write interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_EEPROMWrite( fsl_u32 s_address_u32,
fsl_u08 word_count_u08 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: reads the security information */
/* Input: destination_pu16 - destination address of the security info */
/* The format of the security info is: "unsigned short int" */
/* */
/* Format of the security info: */
/* bit_0 = 0 -> chip erase command disabled, otherwise enabled */
/* bit_1 = 0 -> block erase command disabled, otherwise enabled */
/* bit_2 = 0 -> write command disabled, otherwise enabled */
/* bit_4 = 0 -> boot-area re-programming disabled, otherwise enabled */
/* bit_8...bit_15 = 03H -> last block of the boot-area */
/* other bits = 1 */
/* Output: - */
/* Changed: content of the data_buffer */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_GetSecurityFlags( fsl_u16 * destination_pu16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: read the boot flag i */
/* Input: destination_pu08 - destination address of the bootflag info */
/* The format of the boot-flag info is: "unsigned char" */
/* The value of the boot info is 0x00 for cluster 0 and 0x01 for cluster 1. */
/* Output: - */
/* Changed: content of the data_buffer */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_GetActiveBootCluster( fsl_u08 * destination_pu08 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: puts the last address of the specified block into *destination_pu32 */
/* Input: *destination_pu32 - destination where the last-block-address */
/* should be stored */
/* block_u16 - block number of the last address is needed */
/* Changed: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_GetBlockEndAddr( fsl_u32 * destination_pu32,
fsl_u16 block_u16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: puts the information about the protected flash area into the function parameter */
/* Input: *start_block_pu16 - destination where the FSW start block should be stored */
/* *end_block_pu16 - destination where the FSW end block should be stored */
/* Changed: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_GetFlashShieldWindow( fsl_u16 * start_block_pu16,
fsl_u16 * end_block_pu16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: defines a new Flash-Shield-Window area inside the flash memory */
/* Input: start_block_u16 - starting block of the Flash-Shield-Window (FSW) */
/* end_block_u16 - ending block of the flash-Shield-Window (FSW) */
/* Changed: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), protection error */
/* = 0x1A(FSL_ERR_ERASE), erase error */
/* = 0x1B(FSL_ERR_IVERIFY), internal verify error */
/* = 0x1F(FSL_ERR_INTERRUPTION), write interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_SetFlashShieldWindow( fsl_u16 start_block_u16,
fsl_u16 end_block_u16 );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: Swapping of bootcluster 0 and 1 */
/* */
/* CAUTION !!!! */
/* After this function the boot cluster are immediately swapped */
/* Input: - */
/* Output: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), protection error */
/* = 0x1A(FSL_ERR_ERASE), erase error */
/* = 0x1B(FSL_ERR_IVERIFY), internal verify error */
/* = 0x1F(FSL_ERR_INTERRUPTION), write interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_SwapBootCluster( void );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL command function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: sets specified security flag by dedicated command-function. */
/* */
/* There are following security levels: */
/* a) chip-erase protection (cannot be reset by programmer !!!) */
/* b) block-erase protection (can be reset by chip-erase on programmer) */
/* c) write protection (can be reset by chip-erase on programmer) */
/* d) boot-cluster protection (cannot be reset by programmer !!!) */
/* */
/* CAUTION !!!! */
/* Each security flag can be written by the application only once */
/* */
/* Input: - */
/* Output: - */
/* Returned: fsl_u08, status code */
/* = 0x00(FSL_OK), normal */
/* = 0x05(FSL_ERR_PARAMETER), parameter error */
/* = 0x10(FSL_ERR_PROTECTION), protection error */
/* = 0x1A(FSL_ERR_ERASE), erase error */
/* = 0x1B(FSL_ERR_IVERIFY), internal verify error */
/* = 0x1F(FSL_ERR_INTERRUPTION), write interrupted by user interrupt */
/*----------------------------------------------------------------------------------------------*/
extern fsl_u08 FSL_SetChipEraseProtectFlag( void );
extern fsl_u08 FSL_SetBlockEraseProtectFlag( void );
extern fsl_u08 FSL_SetWriteProtectFlag( void );
extern fsl_u08 FSL_SetBootClusterProtectFlag( void );
/*----------------------------------------------------------------------------------------------*/
/* Block type: FSL function */
/*----------------------------------------------------------------------------------------------*/
/* Purpose: defines the firmware operation method after interrupt service (ISR) execution. */
/* Input: mode_u08 = 0x00, after RETI the firmware is continuing the interrupted command.*/
/* = other, after RETI the firmware is interrupted with status 0x1F. */
/* Changed: - */
/* Returned: - */
/*----------------------------------------------------------------------------------------------*/
extern void FSL_SetInterruptMode( fsl_u08 mode_u08 );
#endif

View File

@ -0,0 +1,113 @@
/*==============================================================================================*/
/* Project = Selfprogramming library for 78K0R/Ix3/Kx3-L Single Voltage SST (MF2) Flash */
/* Module = fsl_user.h */
/* Version = V1.01 */
/* Date = 28.03.2008 11:45:55 */
/*==============================================================================================*/
/* COPYRIGHT */
/*==============================================================================================*/
/* Copyright (c) 2007 by NEC Electronics (Europe) GmbH, */
/* a company of the NEC Electronics Corporation */
/*==============================================================================================*/
/* Purpose: */
/* user configurable constant/macros of the selfprogramming library */
/* */
/*==============================================================================================*/
/* */
/* Warranty Disclaimer */
/* */
/* Because the Product(s) is licensed free of charge, there is no warranty of any kind */
/* whatsoever and expressly disclaimed and excluded by NEC, either expressed or implied, */
/* including but not limited to those for non-infringement of intellectual property, */
/* merchantability and/or fitness for the particular purpose. NEC shall not have any obligation */
/* to maintain, service or provide bug fixes for the supplied Product(s) and/or the Application.*/
/* */
/* Each User is solely responsible for determining the appropriateness of using the Product(s) */
/* and assumes all risks associated with its exercise of rights under this Agreement, */
/* including, but not limited to the risks and costs of program errors, compliance with */
/* applicable laws, damage to or loss of data, programs or equipment, and unavailability or */
/* interruption of operations. */
/* */
/* Limitation of Liability */
/* */
/* In no event shall NEC be liable to the User for any incidental, consequential, indirect, */
/* or punitive damage (including but not limited to lost profits) regardless of whether */
/* such liability is based on breach of contract, tort, strict liability, breach of warranties, */
/* failure of essential purpose or otherwise and even if advised of the possibility of */
/* such damages. NEC shall not be liable for any services or products provided by third party */
/* vendors, developers or consultants identified or referred to the User by NEC in connection */
/* with the Product(s) and/or the Application. */
/* */
/*==============================================================================================*/
/* Environment: PM plus (V6.30) */
/* RA78K0(V1.20) */
/* CC78K0(V2.00) */
/*==============================================================================================*/
#ifndef __FSL_USER_H_INCLUDED
#define __FSL_USER_H_INCLUDED
/*==============================================================================================*/
/* constant definitions */
/*==============================================================================================*/
/* specify the CPU frequency in [Hz], only 2MHz....20MHz allowed */
#define FSL_SYSTEM_FREQUENCY 8000000
/* define whether low-voltage mode is used or not */
/* #define FSL_LOW_VOLTAGE_MODE */
/* size of the common data buffer expressed in [bytes] */
/* the data buffer is used for data-exchange between the firmware and the selflib. */
//#define FSL_DATA_BUFFER_SIZE 256
#define FSL_DATA_BUFFER_SIZE 0
/* customizable interrupt controller configuration during selfprogramming period */
/* Bit --7-------6-------5-------4-------3-------2-------1-------0---------------------- */
/* MK0L: PMK5 PMK4 PMK3 PMK2 PMK1 PMK0 LVIMK WDTIMK */
/* MK0H: SREMK0 SRMK0* STMK0* DMAMK1 DMAMK0 SREMK3 SRMK3 STMK3 */
/* MK1L: TMMK03 TMMK02 TMMK01 TMMK00 IICMK0 SREMK1 SRMK1 STMK1* */
/* MK1H: TMMK04 SREMK2 SRMK2 STMK2* KRMK RTCIMK RTCMK ADMK */
/* MK2L: PMK10 PMK9 PMK8 PMK7 PMK6 TMMK07 TMMK06 TMMK05 */
/* MK2H: 1 1 1 1 1 1 1 PMK11 */
/*------------------------------------------------------------------------------------------ */
/* */
/* Examples: */
/* ========= */
/*#define FSL_MK0L_MASK 0xF7 -> allow INTP1 interrupt during selfprogramming */
/*#define FSL_MK0H_MASK 0xEF -> allow DMA1 interrupt during selfprogramming */
/*#define FSL_MK1L_MASK 0xBF -> allow TM02 interrupt during selfprogramming */
/*#define FSL_MK1H_MASK 0xFF -> all interrupts disabled during selfprogramming */
/*#define FSL_MK2L_MASK 0xF7 -> allow INTP6 interrupt during selfprogramming */
/*#define FSL_MK2H_MASK 0xFF -> all interrupts disabled during selfprogramming */
/*------------------------------------------------------------------------------------------ */
#define FSL_MK0L_MASK 0xFF /* all interrupts disabled during selfprogramming */
#define FSL_MK0H_MASK 0xFF /* all interrupts disabled during selfprogramming */
#define FSL_MK1L_MASK 0xFF /* all interrupts disabled during selfprogramming */
#define FSL_MK1H_MASK 0xFF /* all interrupts disabled during selfprogramming */
#define FSL_MK2L_MASK 0xFF /* all interrupts disabled during selfprogramming */
#define FSL_MK2H_MASK 0xFF /* all interrupts disabled during selfprogramming */
/* FLMD0 control bit */
#ifndef _WIN32
#define FSL_FLMD0_HIGH {BECTL.7 = 1;}
#define FSL_FLMD0_LOW {BECTL.7 = 0;}
#else
#define FSL_FLMD0_HIGH {BECTL_7 = 1;}
#define FSL_FLMD0_LOW {BECTL_7 = 0;}
#endif
/*----------------------------------------------------------------------------------------------*/
/* switch interrupt backu functionality ON/OFF using #define/#undef */
/*----------------------------------------------------------------------------------------------*/
/* #define FSL_INT_BACKUP */
#undef FSL_INT_BACKUP
#endif

View File

@ -0,0 +1,26 @@
$PROCESSOR ( 9F0104 )
PUBLIC _get_ei
;
; PSWのEIを読み出します。
;
ROM_CODE CSEG BASE
_get_ei:
set1 CY
and1 CY,PSW.7 ; check IE bit. if 0, all interrupts are disabled.
bnc $ie_dis
mov C,#01h
ret
ie_dis:
mov C,#00h
ret
end

182
snake_tags/3.40_jane/hal.c Normal file
View File

@ -0,0 +1,182 @@
/* ========================================================
HALレイヤ
$Id: asdf$
======================================================== */
#ifndef _WIN32
#pragma SFR
#endif
#include "incs_loader.h"
#define WIFI_txLatch PIF21 // 電波送信パルス 本来 led.h で定義
// HALでかぶせるの ////////////////////////////////////////
// こんな事するなら正論理にすr...いや何でもない
bit PM_EXTDC_n;
bit BT_IN_CHG_n;
bit SW_POW_n;
bit SW_HOME_n;
bit SW_WIFI_n;
bit SHELL_OPEN;
/*
#define REG_BIT_HAL0_PM_EXTDC_n ( 1 << 7 )
#define REG_BIT_HAL0_BT_IN_CHG_n ( 1 << 6 )
//#define REG_BIT_HAL0_PM_IRQ_n ( 1 << 5 ) // 使わない
#define REG_BIT_HAL0_WL_TX ( 1 << 4 )
#define REG_BIT_HAL0_SHELL_OPEN ( 1 << 3 )
#define REG_BIT_HAL0_SW_WIFI_n ( 1 << 2 )
#define REG_BIT_HAL0_SW_HOME_n ( 1 << 1 )
#define REG_BIT_HAL0_SW_POW_n ( 1 << 0 )
#define REG_BIT_HAL1_DIPSW_1 ( 1 << 3 )
#define REG_BIT_HAL1_DIPSW_0 ( 1 << 2 )
#define REG_BIT_HAL1_HW_DET_1 ( 1 << 1 )
#define REG_BIT_HAL1_HW_DET_0 ( 1 << 0 )
*/
// 載せ替え
// チャタリング除去ならここでやったり(押し時間カウントは別)
void hal_update()
{
#ifdef _ENABLE_HAL_
u8 temp_conf = vreg_ctr[ VREG_C_HAL_OVW_CONT0 ];
u8 temp_dat = vreg_ctr[ VREG_C_HAL_OVW_DAT0 ];
#else
u8 temp_conf = 0x00;
u8 temp_dat = 0; // 何でも良い
#endif
// アダプタ有無
if( temp_conf & REG_BIT_HAL0_PM_EXTDC_n )
{
// 三項式はなんだか大きくなりがち
if(( temp_dat & REG_BIT_HAL0_PM_EXTDC_n ) == 0 )
{
PM_EXTDC_n = 0;
}
else
{
PM_EXTDC_n = 1;
}
}
else
{
PM_EXTDC_n = PM_EXTDC_n_RAW;
}
// 充電中?
if( temp_conf & REG_BIT_HAL0_BT_IN_CHG_n )
{
if(( temp_dat & REG_BIT_HAL0_BT_IN_CHG_n ) == 0 )
{
BT_IN_CHG_n = 0;
}
else
{
BT_IN_CHG_n = 1;
}
}
else
{
BT_IN_CHG_n = BT_IN_CHG_n_RAW;
}
// 電源釦
if( temp_conf & REG_BIT_HAL0_SW_POW_n )
{
if(( temp_dat & REG_BIT_HAL0_SW_POW_n ) == 0 )
{
SW_POW_n = 0 ;
}
else
{
SW_POW_n = 1;
}
}
else
{
SW_POW_n = SW_POW_n_RAW;
}
// 実家釦
if( temp_conf & REG_BIT_HAL0_SW_HOME_n )
{
if(( temp_dat & REG_BIT_HAL0_SW_HOME_n ) == 0 )
{
SW_HOME_n = 0;
}
else
{
SW_HOME_n = 1;
}
}
else
{
if( system_status.model == MODEL_TS_BOARD )// 接続先のポートが違うため
{
SW_HOME_n = SW_HOME_n_TSBOARD_RAW;
}
else
{
SW_HOME_n = SW_HOME_n_JIKKI_RAW;
}
}
// 無線開閉
if( temp_conf & REG_BIT_HAL0_SW_WIFI_n )
{
if(( temp_dat & REG_BIT_HAL0_SW_WIFI_n ) == 0 )
{
SW_WIFI_n = 0;
}
else
{
SW_WIFI_n = 1;
}
}
else
{
SW_WIFI_n = SW_WIFI_n_RAW;
}
// 蝶番
if( temp_conf & REG_BIT_HAL0_SHELL_OPEN )
{
if(( temp_dat & REG_BIT_HAL0_SHELL_OPEN ) == 0 )
{
SHELL_OPEN = 0;
}
else
{
SHELL_OPEN = 1;
}
}
else
{
SHELL_OPEN = SHELL_OPEN_RAW;
}
// 無線電波発射
if( temp_conf & REG_BIT_HAL0_WL_TX )
{
WIFI_txLatch = 1;
}
}
void hal_reset()
{
vreg_ctr[ VREG_C_HAL_OVW_CONT0 ] = 0;
vreg_ctr[ VREG_C_HAL_OVW_CONT1 ] = 0;
vreg_ctr[ VREG_C_HAL_OVW_TEMPERATURE ] = 0xFF;
vreg_ctr[ VREG_C_HAL_OVW_BT_FUEL ] = 0xFF;
vreg_ctr[ VREG_C_HAL_OVW_BT_VOLTAGE ] = 0xFF;
}

View File

@ -0,0 +1,16 @@
#ifndef _hal_h_
#define _hal_h_
extern bit PM_EXTDC_n;
extern bit BT_IN_CHG_n;
extern bit SW_POW_n;
extern bit SW_HOME_n;
extern bit SW_WIFI_n;
extern bit SHELL_OPEN;
// ========================================================
void hal_update();
void hal_reset();
#endif

Binary file not shown.

View File

@ -0,0 +1,312 @@
/* ========================================================
SoC I2C通信
.nintendo
'09 Apr
$Id: i2c_ctr.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma interrupt INTIICA1 int_iic_ctr RB1
#endif
#include "incs.h"
#include "rtc.h"
#include "pedometer.h"
#ifdef _MCU_BSR_
// #ifdef _MODEL_TS0_ || _MODEL_WM0_
// ワーキングモデルはI2Cが逆
// TEGは回路図でテレコ
#define ACKD ACKD1
#define ACKE ACKE1
#define COI COI1
#define IICAEN IICA1EN
#define IICRSV IICRSV1
#define IICA IICA1
#define IICAIF IICAIF1
#define IICAMK IICAMK1
#define IICAPR0 IICAPR11
#define IICAPR1 IICAPR01
#define IICCTL0 IICCTL10
#define IICE IICE1
#define IICF IICF1
#define IICS IICS1
#define IICWH IICWH1
#define IICWL IICWL1
#define LREL LREL1
#define SPD SPD1
#define SPIE SPIE1
#define STCEN STCEN1
#define STD STD1
#define SVA SVA1
#define WREL WREL1
#define WTIM WTIM1
#define TRC TRC1
#define SMC SMC1
#define DFC DFC1
#define PortMode PM20
#define Port P20
#endif
// ==============================================
enum en_IIC_STATE
{
IIC_IDLE = 0,
IIC_RCV_REG_ADRS,
IIC_TX_OR_RX,
IIC_TX,
IIC_RX
};
// ==============================================
extern bit irq_readed; // いずれかのIRQレジスタが読まれた
u8 iic_burst_state;
static enum en_IIC_STATE state = IIC_IDLE;
#define bit_iics_spd (i2c_stat & (1<<0))
#define bit_iics_std (i2c_stat & (1<<1))
#define bit_iics_ackd (i2c_stat & (1<<2))
#define bit_iics_trc (i2c_stat & (1<<3))
#define bit_iics_coi (i2c_stat & (1<<4))
/********************************************//**
isr
***********************************************/
__interrupt void int_iic_ctr( )
{
static u8 reg_adrs;
static u8 tx_buf;
u8 rx_buf;
static u8 adrs_access_from; // バーストアクセスの時に使う
u8 i2c_stat = IICS; // volatileのため
// 読み出し終了
if( !bit_iics_ackd // 割り込み要因はNAKデータ送信の最後
|| bit_iics_spd ) // ストップコンディション(!ACKD に来たときは割り込み来ない (SPIE = 0))
{
/*
I2Cの反応が遅くてこのフラグを処理する前にSTDがきてしまうことがある
*/
// レジスタリードで、割り込みピンをネゲート
// まだ読まれてない割り込みがあれば、再度アサート
if( irq_readed )
{
IRQ0_neg;
irq_readed = false;
if( !( (( vreg_ctr[VREG_C_IRQ0] & vreg_ctr[VREG_C_IRQ_MASK0 ] ) == 0 )
&& (( vreg_ctr[VREG_C_IRQ1] & vreg_ctr[VREG_C_IRQ_MASK1 ] ) == 0 )
&& (( vreg_ctr[VREG_C_IRQ2] & vreg_ctr[VREG_C_IRQ_MASK2 ] ) == 0 )
&& (( vreg_ctr[VREG_C_IRQ3] & vreg_ctr[VREG_C_IRQ_MASK3 ] ) == 0 ) ))
{
while( !IRQ0 ){;} // 時間稼ぎ不要かも
IRQ0_ast;
}
}
// I2C終了時に何かする物 //
hosu_read_end( ); // 歩数計読み出し終了
rtc_unlock( );
state = IIC_IDLE;
SPIE = 0;
LREL = 1;
EI();
return;
}
if( bit_iics_std ) // 割り込み要因:スタートコンディション
{
if( !( state == IIC_IDLE || state == IIC_TX_OR_RX ))
{
// sp/nack 取り損ねた
// dbg_nop(); // こないはず...
/*
// パケットの先頭のstと見なす。
// 普通に続行
state = IIC_IDLE;
/*/
// リトライしてもらう
state = IIC_IDLE;
SPIE = 0;
LREL = 1;
EI();
//*/
}
// 通常
}
EI();
switch ( state )
{
case ( IIC_IDLE ):
// 自局呼び出しに応答。
// 初期化など
iic_burst_state = 0;
SPIE = 1;
WREL = 1; // ウェイト解除
state = IIC_RCV_REG_ADRS;
return;
case ( IIC_RCV_REG_ADRS ): // 2バイト目(レジスタアドレス)受信後に来る
// レジスタアドレス受信
reg_adrs = IICA;
WREL = 1;
adrs_access_from = reg_adrs;
tx_buf = vreg_ctr_read( reg_adrs ); // データの準備をしておく
state = IIC_TX_OR_RX;
return;
case ( IIC_TX_OR_RX ): // ↑の次に来る割り込み。STなら送信準備、データが来たら書き込まれ
// if( TRC ) // 送信方向フラグ で区別するのは、割り込み遅延時に不具合が起こりえる
if( bit_iics_std )
{ // スタートコンディション検出フラグ
// リードされる
if( bit_iics_coi )
{ // アドレス一致フラグ
state = IIC_TX;
// no break, no return //
}
else
{
// リスタートで違うデバイスが呼ばれた!
SPIE = 0;
LREL = 1; // ウェイト解除?
state = IIC_IDLE; // 終了処理
return;
}
}
else
{
state = IIC_RX; // データ1バイト受信の割り込みだった
// no break, no return //
}
/* FALLTHROUGH */
default: // バースト R/W でここが何回も呼ばれることになる
if( state == IIC_TX )
{ // 送信
IICA = tx_buf;
vreg_ctr_after_read( reg_adrs, tx_buf ); // 読んだらクリアなどの処理
}
else
{ // 受信
rx_buf = IICA;
#ifdef _I2C_ERR_ABORT_
if( reg_adrs >= 0x80 || reg_adrs <= 1 )
{
LREL = 1; // なんかデータ化けたので通信終了 nakが返るのがなぁ…
return;
}
#endif
vreg_ctr_write( reg_adrs, rx_buf );
WREL = 1;
}
// レジスタアドレスのインクリメント
/// アクセスポインタを進めない特殊なレジスタ
switch( adrs_access_from )
{
case( VREG_C_ACC_HOSU_HIST ):
case( VREG_C_LED_NOTIFY_DATA ):
case( VREG_C_LED_POW ):
case( VREG_CX_INFO ):
case( VREG_CX_FREE_DATA ):
break;
case( VREG_CX_FREE_ADRS ):
if( reg_adrs == VREG_CX_FREE_ADRS )
{
reg_adrs = VREG_CX_FREE_DATA;
}
break;
default:
reg_adrs ++;
}
if( state == IIC_TX )
{ // さらにつぎに送るデータの準備だけシテオク。SPが来て使われないかもしれない
tx_buf = vreg_ctr_read( reg_adrs );
}
break;
}
}
/********************************************//**
 
 
 todo twl init ?
 
 
***********************************************/
void IIC_ctr_Init( void )
{
IICAEN = 1;
IICE = 0; /* IICA disable */
IICAMK = 1; /* INTIICA disable */
IICAIF = 0; /* clear INTIICA interrupt flag */
// IICAPR0 = 1; /* set INTIICA high priority */
// IICAPR1 = 0; /* set INTIICA high priority */ スタック不足
Port &= ~0x03;
SVA = IIC_C_SLAVEADDRESS;
IICF = 0x01;
STCEN = 1; // リスタートの許可
IICRSV = 1; // 通信予約をさせない:スレーブに徹する
SPIE = 0; // ストップコンディションでの割り込みを禁止
WTIM = 1; // 自動でACKを返した後clkをLに固定する
ACKE = 1;
IICWH = 9;
IICWL = 11; // L期間の長さ
SMC = 1; // 高速モード
DFC = 1; // デジタルフィルタon (@fast mode)
IICAMK = 0; // 割り込みを許可
IICE = 1;
PortMode &= ~0x03;
state = IIC_IDLE;
}
/********************************************//**
***********************************************/
void IIC_ctr_Stop( void )
{
IICE = 0; /* IICA disable */
IICAEN = 0;
}

View File

@ -0,0 +1,210 @@
#ifndef _MDSERIAL_A_
#define _MDSERIAL_A_
/* IIC operation enable (IICE0) */
#define IIC0_OPERATION 0x80
#define IIC0_OPERATION_DISABLE 0x00 /* stop operation */
#define IIC0_OPERATION_ENABLE 0x80 /* enable operation */
/* Exit from communications (LREL0) */
#define IIC0_COMMUNICATION 0x40
#define IIC0_COMMUNICATION_NORMAL 0x00 /* normal operation */
#define IIC0_COMMUNICATION_EXIT 0x40 /* exit from current communication */
/* Wait cancellation (WREL0) */
#define IIC0_WAITCANCEL 0x20
#define IIC0_WAIT_NOTCANCEL 0x00 /* do not cancel wait */
#define IIC0_WAIT_CANCEL 0x20 /* cancel wait */
/* Generation of interrupt when stop condition (SPIE0) */
#define IIC0_STOPINT 0x10
#define IIC0_STOPINT_DISABLE 0x00 /* disable */
#define IIC0_STOPINT_ENABLE 0x10 /* enable */
/* Wait and interrupt generation (WTIM0) */
#define IIC0_WAITINT 0x08
#define IIC0_WAITINT_CLK8FALLING 0x00 /* generate at the eighth clocks falling edge */
#define IIC0_WAITINT_CLK9FALLING 0x08 /* generated at the ninth clocks falling edge */
/* Acknowledgement control (ACKE0) */
#define IIC0_ACK 0x04
#define IIC0_ACK_DISABLE 0x00 /* enable acknowledgement */
#define IIC0_ACK_ENABLE 0x04 /* disable acknowledgement */
/* Start condition trigger (STT0) */
#define IIC0_STARTCONDITION 0x02
#define IIC0_START_NOTGENERATE 0x00 /* do not generate start condition */
#define IIC0_START_GENERATE 0x02 /* generate start condition */
/* Stop condition trigger (SPT0) */
#define IIC0_STOPCONDITION 0x01
#define IIC0_STOP_NOTGENERATE 0x00 /* do not generate stop condition */
#define IIC0_STOP_GENERATE 0x01 /* generate stop condition */
/*
IIC Status Register 0 (IICS0)
*/
/* Master device status (MSTS0) */
#define IIC0_MASTERSTATUS 0x80
#define IIC0_STATUS_NOTMASTER 0x00 /* slave device status or communication standby status */
#define IIC0_STATUS_MASTER 0x80 /* master device communication status */
/* Detection of arbitration loss (ALD0) */
#define IIC0_ARBITRATION 0x40
#define IIC0_ARBITRATION_NO 0x00 /* arbitration win or no arbitration */
#define IIC0_ARBITRATION_LOSS 0x40 /* arbitration loss */
/* Detection of extension code reception (EXC0) */
#define IIC0_EXTENSIONCODE 0x20
#define IIC0_EXTCODE_NOT 0x00 /* extension code not received */
#define IIC0_EXTCODE_RECEIVED 0x20 /* extension code received */
/* Detection of matching addresses (COI0) */
#define IIC0_ADDRESSMATCH 0x10
#define IIC0_ADDRESS_NOTMATCH 0x00 /* addresses do not match */
#define IIC0_ADDRESS_MATCH 0x10 /* addresses match */
/* Detection of transmit/receive status (TRC0) */
#define IIC0_STATUS 0x08
#define IIC0_STATUS_RECEIVE 0x00 /* receive status */
#define IIC0_STATUS_TRANSMIT 0x08 /* transmit status */
/* Detection of acknowledge signal (ACKD0) */
#define IIC0_ACKDETECTION 0x04
#define IIC0_ACK_NOTDETECTED 0x00 /* ACK signal was not detected */
#define IIC0_ACK_DETECTED 0x04 /* ACK signal was detected */
/* Detection of start condition (STD0) */
#define IIC0_STARTDETECTION 0x02
#define IIC0_START_NOTDETECTED 0x00 /* start condition not detected */
#define IIC0_START_DETECTED 0x02 /* start condition detected */
/* Detection of stop condition (SPD0) */
#define IIC0_STOPDETECTION 0x01
#define IIC0_STOP_NOTDETECTED 0x00 /* stop condition not detected */
#define IIC0_STOP_DETECTED 0x01 /* stop condition detected */
/*
IIC Flag Register 0 (IICF0)
*/
/* STT0 clear flag (STCF) */
#define IIC0_STARTFLAG 0x80
#define IIC0_STARTFLAG_GENERATE 0x00 /* generate start condition */
#define IIC0_STARTFLAG_UNSUCCESSFUL 0x80 /* start condition generation unsuccessful */
/* IIC bus status flag (IICBSY) */
#define IIC0_BUSSTATUS 0x40
#define IIC0_BUS_RELEASE 0x00 /* bus release status */
#define IIC0_BUS_COMMUNICATION 0x40 /* bus communication status */
/* Initial start enable trigger (STCEN) */
#define IIC0_STARTWITHSTOP 0x02
#define IIC0_START_WITHSTOP 0x00 /* generation of a start condition without detecting a stop condition */
#define IIC0_START_WITHOUTSTOP 0x02 /* generation of a start condition upon detection of a stop condition */
/* Communication reservation function disable bit (IICRSV) */
#define IIC0_RESERVATION 0x01
#define IIC0_RESERVATION_ENABLE 0x00 /* enable communication reservation */
#define IIC0_RESERVATION_DISABLE 0x01 /* disable communication reservation */
/*
IIC clock selection register 0 (IICCL0)
*/
#define IICCL0_INITIALVALUE 0x00
/* Detection of SCL0 pin level (CLD0) */
#define IIC0_SCLLEVEL 0x20
#define IIC0_SCL_LOW 0x00 /* clock line at low level */
#define IIC0_SCL_HIGH 0x20 /* clock line at high level */
/* Detection of SDA0 pin level (DAD0) */
#define IIC0_SDALEVEL 0x10
#define IIC0_SDA_LOW 0x00 /* data line at low level */
#define IIC0_SDA_HIGH 0x10 /* data line at high level */
/* Operation mode switching (SMC0) */
#define IIC0_OPERATIONMODE 0x08
#define IIC0_MODE_STANDARD 0x00 /* operates in standard mode */
#define IIC0_MODE_HIGHSPEED 0x08 /* operates in high-speed mode */
/* Digital filter operation control (DFC0) */
#define IIC0_DIGITALFILTER 0x04
#define IIC0_FILTER_OFF 0x00 /* digital filter off */
#define IIC0_FILTER_ON 0x04 /* digital filter on */
/* Operation mode switching (CL01, CL00) */
#define IIC0_CLOCKSELECTION 0x03
/* Combine of (SMC0, CL01, CL00)*/
#define IIC0_CLOCK0 0x00
#define IIC0_CLOCK1 0x01
#define IIC0_CLOCK2 0x02
#define IIC0_CLOCK3 0x03
#define IIC0_CLOCK4 0x08
#define IIC0_CLOCK5 0x09
#define IIC0_CLOCK6 0x0a
#define IIC0_CLOCK7 0x0b
/*
IIC function expansion register 0 (IICX0)
*/
/* IIC clock expension (CLX0) */
#define IIC0_CLOCKEXPENSION 0x01
#define IIC0_EXPENSION0 0x00
#define IIC0_EXPENSION1 0x01
/* Operation clock (CLX0, SMC0, CL01, CL00)
| IIC0_EXPENSION0 | IIC0_EXPENSION1 |
------------|-------------------|-------------------|----------------------
IIC0_CLOCK0 | fprs/2 | prohibited | selection clock(fw)
| fprs/88 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK1 | fprs/2 | prohibited | selection clock(fw)
| fprs/172 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK2 | fprs/2 | prohibited | selection clock(fw)
| fprs/344 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK3 |prohibited/fexscl0 | prohibited | selection clock(fw)
| fw/66 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK4 | fprs/2 | fprs/2 | selection clock(fw)
| fprs/48 | fprs/24 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK5 | fprs/2 | fprs/2 | selection clock(fw)
| fprs/48 | fprs/24 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK6 | fprs/4 | fprs/4 | selection clock(fw)
| fprs/96 | fprs/48 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK7 |prohibited/fexscl0 | prohibited | selection clock(fw)
| fw/18 | | transfer clock
| high speed | | mode
------------|-------------------|-------------------|----------------------
*/
#define ADDRESS_COMPLETE 0x80
#define IIC_MASTER_FLAG_CLEAR 0x00
/******************************************************************************
* Macro define
******************************************************************************/
/******************************************************************************
* Function define
******************************************************************************/
void IIC_ctr_Init( void );
void IIC_ctr_Stop( void );
#endif

View File

@ -0,0 +1,124 @@
/* ========================================================
I2C使
de JHL
'09 Feb -
$Id: $
======================================================== */
#ifndef _WIN32
#pragma sfr
#pragma di
#pragma ei
#pragma nop
#pragma inline // memcpy()をインライン展開する(の方が小さい!)
#endif
#include "incs.h"
#include "i2c_mcu.h"
#include "loader.h"
#include "util_funcs.h"
#include "i2c_mcu_sub.h"
#include "pm.h" /// やりたくなかった…CODECのレジスタ名をひくため
// ========================================================
// ワークアラウンド用
static void iic_mcu_simple_dummy_write();
static i2c_err iic_mcu_codec_write_low( u8 adrs, u8 dat );
// i2c_mcu.c にいる
extern void iic_mcu_send_re_st( );
extern void iic_mcu_send_sp( );
extern i2c_err iic_mcu_send_a_byte( u8 );
extern i2c_err iic_mcu_call_slave( u8 slave );
/*
yamaha codecから不用意に割り込みが入ることがあるが
*/
/********************************************//**
iic_mcu_write_a_byte CODEC不具合ワークアラウンド
***********************************************/
#define YAMAHA_CODEC_ERRATA_CHECK_MASK ( 0x7D )
i2c_err iic_mcu_write_a_byte_codec( u8 adrs, u8 dat )
{
u8 pm_reg_original;
i2c_err rv;
// ヤマハcodecワークアラウンド SPIとの共用レジスタの中身を取得
if(( rv = iic_mcu_read( IIC_SLA_CODEC, CODEC_REG_PM, 1, &pm_reg_original )) != I2C_ERR_OK )
{
return( rv );
}
// phase1 ここまで
// 書き込み!
if( ( rv = iic_mcu_codec_write_low( adrs, dat ) ) != I2C_ERR_OK )
{
return( rv );
}
// ヤマハcodecワークアラウンド
if( ( pm_reg_original & YAMAHA_CODEC_ERRATA_CHECK_MASK ) == 0 ) // はじめから共有レジスタが0だったらテストもしない
// (& リセット要求が立ってたらどうせリセットかかるので)
{
return( I2C_ERR_OK );
}
{
// 共有レジスタが 0x00 に書き換わっている(エラッタ発生!)ようなら書き戻す
u8 pm_reg_after;
if(( rv = iic_mcu_read( IIC_SLA_CODEC, CODEC_REG_PM, 1, &pm_reg_after )) != I2C_ERR_OK )
{
return( rv );
}
if( ( pm_reg_after & YAMAHA_CODEC_ERRATA_CHECK_MASK ) != 0x00 )
{
// コンフリクトはなかった or リセット要求など
return( I2C_ERR_OK );
}
// else {
rv = iic_mcu_codec_write_low( CODEC_REG_PM, pm_reg_original ); // 書き戻すが、再チェックはしない
return ( rv ); // エラーが返ることもあるかも
// リトライなどは無し
}
return( rv ); // no reach //
}
static i2c_err iic_mcu_codec_write_low( u8 adrs, u8 dat )
{
IICMK10 = 1; // DMA用のISRに飛ばさないためにマスク
if( iic_mcu_call_slave( IIC_SLA_CODEC ) != I2C_ERR_OK )
{
iic_mcu_busy = false;
return ( I2C_ERR_NOSLAVE );
}
iic_mcu_send_a_byte( adrs );
iic_mcu_send_a_byte( dat );
// TIワークアラウンド
codec_dummy_write();
iic_mcu_send_sp( );
iic_mcu_busy = false;
return( I2C_ERR_OK );
}
// re-stでダミーライト
void codec_dummy_write()
{
iic_mcu_send_re_st( );
iic_mcu_send_a_byte( IIC_SLA_CODEC ); // ダミーライト
iic_mcu_send_a_byte( 0x20 ); // ゴミを書いても問題ないアドレス
iic_mcu_send_a_byte( 0xAA ); // 何でもよい
}

View File

@ -0,0 +1,660 @@
/* ========================================================
I2C使
de JHL
'09 Feb -
$Id: $
======================================================== */
#ifndef _WIN32
#pragma sfr
#pragma di
#pragma ei
#pragma nop
#pragma inline // memcpy()をインライン展開する(の方が小さい!)
#endif
#include "incs_loader.h"
#include "i2c_mcu.h"
#include "loader.h"
#include "util_funcs.h"
#include "i2c_mcu_sub.h"
// ========================================================
// レジスタのビット名
// プリフィックスbだが、一部のビット名がレジスタ名にかぶるため...
// SMR0n
#define bCKS0 ( 1 << 15 )
#define bCCS0 ( 1 << 14 )
#define bSTS0 ( 1 << 8 )
#define bSIS0 ( 1 << 6 )
#define bMD0n2 ( 1 << 2 )
#define bMD0n1 ( 1 << 1 )
#define bMD0n0 ( 1 << 0 )
#define bSMR0n_FIXEDBIT ( 1 << 5 )
// SSR0n
#define bit_TSF0 6
#define PEF0 ( 1 << 1 )
// SIR0n
#define PECT0 ( 1 << 1 )
// SCR0n
#define TXE0 ( 1 << 15 )
#define RXE0 ( 1 << 14 )
#define SLC02 4
#define DLS02 0
#define TSF0 ( 1 << 6 )
// SOn
#define TAUS_MASK 0x0B0B;
// DMCn
#define DRS ( 1 << 6 )
// ========================================================
static void iic_mcu_send_st( );
// *subからしか呼ばない
void iic_mcu_send_re_st( );
void iic_mcu_send_sp( );
i2c_err iic_mcu_send_a_byte( u8 );
i2c_err iic_mcu_call_slave( u8 slave );
// ========================================================
bit iic_mcu_wo_dma;
volatile bit iic_mcu_busy;
static volatile bit iic_mcu_initialized;
static u8 iic_send_work[4];
static u8 *p_iic_send_wo_dma_dat;
static u8 iic_send_wo_dma_len;
// データエラーROHM製加速度センサ時リトライのため
/// とりあえず、DMA使用マルチバイトライト の時にしか機能しない
static u8 last_slave, last_reg_adrs, last_size;
i2c_err iic_mcu_result; // 一文字リードの時はデータを返す。
#ifdef i2c_timeout_test
extern bit i2c_mcu_time_out_error;
#endif
/********************************************//**
***********************************************/
void nop8()
{
// ここに来る call に3clk, return に 6clk
}
/********************************************//**
***********************************************/
static i2c_err iic_mcu_wait_free()
{
u16 tot = 0;
iic_mcu_start( );
while( 1 )
{
DI_wt_chk();
if( !iic_mcu_busy )
{
iic_mcu_busy = true;
EI();
break;
}
EI();
if( ++tot == 0 )
{
#ifdef i2c_timeout_test
i2c_mcu_time_out_error = true;
#endif
return( I2C_ERR_TIMEOUT );
}
}
return( I2C_ERR_OK );
}
/********************************************//**
1
iic_mcu_result
***********************************************/
u8 iic_mcu_read_a_byte( u8 SLA, u8 adrs )
{
u8 dat;
iic_mcu_result = iic_mcu_read( SLA, adrs, 1, &dat );
if( iic_mcu_result != I2C_ERR_OK )
{
dat = 0xff;
}
return ( dat );
}
/********************************************//**
***********************************************/
i2c_err iic_mcu_read( u8 slave, u8 adrs, u8 len, u8 * dest )
{
#if 1
if( iic_mcu_wait_free() != I2C_ERR_OK )
{
// (タイムアウト)
return( I2C_ERR_TIMEOUT );
}
#else
// 使用中なら帰る
#endif
// スタートコンディションとスレーブの呼び出し、レジスタアドレスの送信
if( iic_mcu_call_slave( slave ) != 0 )
{
iic_mcu_busy = false;
return ( I2C_ERR_NOSLAVE );
}
// レジスタアドレスの送信
iic_mcu_send_a_byte( adrs ); // 終わるまで帰ってこない
// 絶対にNAKが帰ってこない前提
// データ受信 //
iic_mcu_send_re_st( ); // リスタートコンディション
iic_mcu_send_a_byte( slave | 0x01 ); // 送信完了まで戻ってきません。
// データ受信
ST0 = 0x0004; // 受信モードに設定を変えるのでロジック停止
SCR02 = RXE0 | 1 << SLC02 | 7 << DLS02; // 受信設定
SS0 = 0x0004; // 通信待機
do
{
if( len == 1 )
{
SOE0 = 0x0000; // 最後のNAK
}
IICIF10 = 0;
SIO10 = 0xFF; // ダミーデータを書くと受信開始
while( IICIF10 == 0 )
{;} // 受信完了待ち
*dest = SIO10;
dest++;
len--;
}
while( len != 0 );
if( slave == IIC_SLA_CODEC )
{
codec_dummy_write();
}
iic_mcu_send_sp( );
IICIF10 = 0;
iic_mcu_busy = false;
return ( I2C_ERR_OK );
}
/********************************************//**
 iic_mcu_write 
***********************************************/
i2c_err iic_mcu_write_a_byte( u8 SLA, u8 adrs, u8 dat )
{
// 文字の時はDMAとか起動しないでさっさと終わらせる
if( iic_mcu_wait_free() != I2C_ERR_OK )
{
return( I2C_ERR_TIMEOUT );
}
// スタートコンディションとスレーブの呼び出し...
IICMK10 = 1;
if( iic_mcu_call_slave( SLA ) != I2C_ERR_OK )
{
iic_mcu_busy = false;
return( I2C_ERR_NOSLAVE );
}
iic_mcu_send_a_byte( adrs );
iic_mcu_send_a_byte( dat );
iic_mcu_send_sp( );
iic_mcu_busy = false;
return ( I2C_ERR_OK );
}
/********************************************//**
adrs
*strから
len文字書きます
1)
2) len < sizeof(iic_send_work) DMA 使RAM不足
DMA1を使用します
***********************************************/
i2c_err iic_mcu_write( u8 slave, u8 adrs, u8 len, void * src )
{
if( iic_mcu_wait_free() != I2C_ERR_OK )
{
return( I2C_ERR_TIMEOUT );
}
#if 0 // rengeが真のマルチタスクになった暁には
// 使用中なら帰る
#endif
// スタートコンディションとスレーブの呼び出し...
IICMK10 = 1;
IICIF10 = 0;
if( iic_mcu_call_slave( slave ) != I2C_ERR_OK )
{
iic_mcu_busy = false;
return ( I2C_ERR_NOSLAVE );
}
IICIF10 = 0;
if( ! iic_mcu_wo_dma /* || len <= iic_send_work */ )
{
// DMAを使用する通常//
// レジスタアドレスを送り、データの準備
memcpy( iic_send_work, src, 4 ); //バッファとして4バイトしか用意して無いため。
// リトライ時のため
last_slave = slave;
last_reg_adrs = adrs;
last_size = len;
// DMAセット
while( DST1 )
{;}
DEN1 = 1;
DSA1 = (u8)( &SIO10 );
DRA1 = (u16)( &iic_send_work[0] );
DBC1 = len;
DMC1 = DRS | 8; // RAM -> SFR, 8bit, IRQ, IIC10
DMAIF1 = 0;
DMAMK1 = 0;
DST1 = 1; // DEN1 = 1から2clk以上開け
SIO10 = adrs; // 書きっぱなし! 割り込みが発生してDMAスタート
// 残りは割り込みルーチン内で
}
else
{
// DMAを使用しない //
// レジスタアドレスの送信
IICMK10 = 0;
SIO10 = adrs;
iic_send_wo_dma_len = len;
p_iic_send_wo_dma_dat = (u8*)src;
// 残りは割り込みルーチン内で
}
return ( I2C_ERR_OK );
}
/********************************************//**
DMA転送終了割り込み
IIC_mcu
DMA転送が終わっただけでI2Cの転送は終わってません
  DMA1の処理が遅延した場合
IIC10の割り込みの準備ができずに
 DMA仕様の差異は
***********************************************/
__interrupt void int_dma1( )
{
static bit in_retry;
EI();
// 最後のバイトの送信完了待ち
while( ( SSR02L & TSF0 ) != 0 )
{
u16 i = 0;
if( ++i == 0 ) // タイムアウト?
{
break;
}
}
// ストップコンディション発行
// iic_mcu_send_sp(); // ISR中で外の関数を呼ぶのは都合が悪い汎用レジスタ待避が発生するので展開
{
ST0 = 0x0004;
SOE0 = 0; // 受信の時はもっと前に「も」設定してる。(NACK出力)
SO0 = 0x0000 | TAUS_MASK; // SCL
nop8(); //. もう何も怖くない。外の関数呼ぶ
/*
NOP(); NOP(); NOP(); NOP();
NOP(); NOP(); NOP(); NOP();
*/
SO0 = 0x0400 | TAUS_MASK; // SCL
nop8();
/*
NOP(); NOP(); NOP(); NOP();
NOP(); NOP(); NOP(); NOP();
*/
SO0 = 0x0404 | TAUS_MASK;
}
IICMK10 = 1;
// データの途中で NAK だったら、一度だけリトライする。
/// 手抜き実装
if( SIR02 != 0 )
{
SIR02 = SSR02;
if( !in_retry )
{
in_retry = true;
IICIF10 = 0;
iic_mcu_call_slave( last_slave ); // ここでNAKは今ンケア
while( DST1 ){;}
DRA1 = (u16)( &iic_send_work[0] ); // 自動インクリメントされてしまっているので再セット
DBC1 = last_size; // 自動デクリメントされてしまっているので再セット
// ほかの設定は前回のまま
DMAIF1 = 0;
DMAMK1 = 0;
DST1 = 1;
SIO10 = last_reg_adrs; // 書きっぱなし! 割り込みが発生してDMAスタート
return;
// おしまい
}
else
{
// エラー二度目。もう知らない
dbg_nop();
// そのまま終了処理へ
}
}
// 正常終了
in_retry = false;
DMAMK1 = 1;
DEN1 = 0;
iic_mcu_busy = false;
}
/********************************************//**
IIC MCUのバイト送出完了割り込み
DMA使用時は使用されません
 DMAの割り込みにすぐ飛ばない場合
 IIC割り込みのセットが間に合わず困ることがあります
***********************************************/
__interrupt void int_iic10( )
{
EI();
if( iic_send_wo_dma_len != 0 ) // まだ送信しきっていない?
{
SIO10 = *p_iic_send_wo_dma_dat;
p_iic_send_wo_dma_dat ++;
iic_send_wo_dma_len --;
return;
// おしまい //
}
// 最後のバイト送信完了、ストップコンディション発行
IICMK10 = 1;
// iic_mcu_send_sp(); // ISR中で外の関数を呼ぶのは都合が悪い汎用レジスタ待避が発生するので展開
{
ST0 = 0x0004;
SOE0 = 0; // 受信の時はもっと前に「も」設定してる。(NACK出力)
SO0 = 0x0000 | TAUS_MASK; // clear SCL
NOP(); NOP(); NOP(); NOP(); // NOP8等も呼んではだめ
NOP(); NOP(); NOP(); NOP();
SO0 = 0x0400 | TAUS_MASK; // set SCL
NOP(); NOP(); NOP(); NOP();
NOP(); NOP(); NOP(); NOP();
SO0 = 0x0404 | TAUS_MASK; // set CSL adn SDA
}
iic_mcu_wo_dma = false;
iic_mcu_busy = false;
}
/********************************************//**
 ACKの確認
ACK                  I2C_ERR_OK
 NACK   I2C_ERR_NOSLAVE
***********************************************/
i2c_err iic_mcu_call_slave( u8 slave )
{
iic_mcu_send_st( );
/*
// dbg
if( SSR02 != 0 )
{
P1.5 = P1.0 = P1.3 = 1;
}
*/
SIR02 = SSR02; // NAKエラーのフラグクリア
if( iic_mcu_send_a_byte( slave ) != I2C_ERR_OK )
{
iic_mcu_send_sp( );
return ( I2C_ERR_NOSLAVE ); // 指定のスレーブがいない
}
return ( I2C_ERR_OK );
}
/********************************************//**
***********************************************/
i2c_err iic_mcu_send_a_byte( u8 dat )
{
IICMK10 = 1;
IICIF10 = 0;
SIO10 = dat;
while( IICIF10 == 0 )
{
// NOP( );
} // 通信中
if( SSR02 != 0 ) // 何らかエラー発生?
{
SIR02 = SSR02; // エラークリア
return( I2C_ERR_NAK );
}
return( I2C_ERR_OK );
}
/********************************************//**
***********************************************/
static void iic_mcu_send_st( )
{
SO0 &= ~0x0004; // SDA
nop8();
SO0 &= ~0x0400; // SCL
SOE0 = 0x0004; // ハード制御へ
SCR02 = TXE0 | 1 << SLC02 | 7 << DLS02; // 送信許可、データは8ビット単位
SS0 = 0x0004; // 通信待機
}
/********************************************//**
***********************************************/
void iic_mcu_send_re_st( )
{
ST0 |= 0x0004;
SO0 |= 0x0400 | TAUS_MASK; // ( SDA = H ), SCL -> H
nop8();
SOE0 &= ~0x0004; // ( SCL = H ), SDA -> L
nop8();
iic_mcu_send_st( );
}
/********************************************//**
***********************************************/
void iic_mcu_send_sp( )
{
ST0 = 0x0004;
SOE0 = 0; // 受信の時はもっと前に「も」設定してる。(NACK出力)
SO0 = 0x0000 | TAUS_MASK; // SCL
nop8();
SO0 = 0x0400 | TAUS_MASK; // SCL
nop8();
SO0 = 0x0404 | TAUS_MASK;
}
/********************************************//**
***********************************************/
void iic_mcu_start( )
{
if( iic_mcu_initialized )
{
return;
}
iic_mcu_busy = true;
// DST1 = 0;
I2C_PU_on();
// DEN1 = 0; // DST1 = 0 から 2clkもしくは、DSTn==0をポーリングしてから
wait_ms( 1 ); // 立ち上がるのに50us位かかる
SAU0EN = 1;
nop8();
SPS0 = 0x0000; // シリアルユニットのクロック0。(8M/2)/1
SMR02 = bSMR0n_FIXEDBIT | bMD0n2; // 簡易I2Cに設定
SDR02 = 10 << 9; // ボーレート設定 8M/1/(x+1)/2
SO0 = 0x0404 | TAUS_MASK; // 最初はHH
iic_mcu_wo_dma = false;
// バスのリセット
{
IICIF10 = 0;
IICMK10 = 1;
iic_mcu_send_st();
SIO10 = 0xFF;
while( IICIF10 == 0 ){;} // 通信中
iic_mcu_send_sp();
SIR02 = SSR02;
}
iic_mcu_busy = false;
iic_mcu_initialized = true;
}
/********************************************//**
使
***********************************************/
void iic_mcu_stop( )
{
while( iic_mcu_busy )
{;} // DMA動作中はもう少し待つ
iic_mcu_send_re_st( ); // SCL,SDAをLLにする
I2C_PU_off();
SAU0EN = 0;
iic_mcu_initialized = false;
}

View File

@ -0,0 +1,40 @@
#ifndef __ic2_mcu__
#define __ic2_mcu__
// ========================================================
typedef enum{
I2C_ERR_OK = 0,
I2C_ERR_NAK,
I2C_ERR_NOSLAVE,
I2C_ERR_TIMEOUT,
I2C_ERR_UNDEF = 0xFF
}i2c_err;
// ========================================================
extern volatile bit iic_mcu_busy;
extern bit iic_mcu_wo_dma;
extern i2c_err iic_mcu_result;
// ========================================================
i2c_err iic_mcu_read( u8 SLA, u8 adrs, u8 len, u8 * dest );
u8 iic_mcu_read_a_byte( u8 SLA, u8 adrs );
i2c_err iic_mcu_write( u8 SLA, u8 adrs, u8 len, void * src );
i2c_err iic_mcu_write_a_byte( u8 SLA, u8 adrs, u8 dat );
i2c_err iic_mcu_write_a_byte_codec( u8 adrs, u8 dat ); // codecバグ回避機能付き
// ↓その通信が完了したら解除されます。
#define iic_mcu_set_wo_dma() { while( iic_mcu_busy ){;} iic_mcu_wo_dma = true; }
void iic_mcu_start( void );
void iic_mcu_stop( void );
#endif

View File

@ -0,0 +1,9 @@
#ifndef __ic2_mcu_sub__
#define __ic2_mcu_sub__
// $Id: asdf$
i2c_err iic_mcu_write_a_byte_codec( u8 adrs, u8 dat );
void codec_dummy_write( void );
#endif

View File

@ -0,0 +1,246 @@
/* ========================================================
TWL I2C
$Id: i2c_twl.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma sfr /* 特殊機能レジスタ使用 */
#endif
/*============================================================================*/
#ifndef _WIN32
# pragma interrupt INTIICA0 int_iic_twl RB2
#endif
#include "incs_loader.h"
#include "i2c_twl_defs.h"
#include "i2c_twl.h"
#include "vreg_twl.h"
#include "WDT.h"
#ifdef _MCU_BSR_
//#ifdef _MODEL_TS0_ || _MODEL_WM0_
// ワーキングモデルはI2Cが逆
#define ACKD ACKD0
#define ACKE ACKE0
#define COI COI0
#define IICAEN IICA0EN
#define IICRSV IICRSV0
#define IICA IICA0
#define IICAIF IICAIF0
#define IICAMK IICAMK0
#define IICAPR0 IICAPR00
#define IICAPR1 IICAPR10
#define IICCTL0 IICCTL00
#define IICE IICE0
#define IICF IICF0
#define IICS IICS0
#define IICWH IICWH0
#define IICWL IICWL0
#define LREL LREL0
#define SPD SPD0
#define SPIE SPIE0
#define STCEN STCEN0
#define STD STD0
#define SVA SVA0
#define WREL WREL0
#define WTIM WTIM0
#define SMC SMC0
#define TRC TRC0
#define DFC DFC0
#define PortMode PM6
#define Port P6
#endif // _MCU_BSR_
#ifndef _MCU_BSR_
// ke3の時はダミー関数
void IIC_twl_Stop( void )
{
}
void IIC_twl_Init( void )
{
}
#else // _MCU_BSR_
enum IIC_TWL_STATE{
WAIT_ADRS = 0,
WAIT_DATA,
DATA_READED
};
/*============================================================================*/
// 注 ↓はマクロなので、returnはメインループに戻ります。
#define wait_next { \
tot = 0; \
while( IICAIF != 1 ){ \
tot ++; \
if( tot == 0 ){ \
LREL = 1; \
return; \
} \
} \
}
/********************************************//**
isr
TWLはウェイトを理解してくれずR/W
***********************************************/
__interrupt void int_iic_twl( )
{
u8 vreg_adrs;
u8 state;
// ①
WREL = 1; // ウェイト解除して次のバイトを待つ
WDT_Restart();
state = WAIT_ADRS;
while( 1 )
{
u8 my_iics;
{
u16 tot;
wait_next; // 1バイト受信完了を待つ
}
my_iics = IICS;
IICAIF = 0;
if( my_iics & 0x02 ) // ( STD && !SPD )
{
// スタートコンディションがきた
if( ( my_iics & 0x08 ) == 0 ) // ( TRC ) 送信方向フラグ 0:マイコンが受信
{
// ①マイコンが応答できず、TWLがリトライしたときとか
// ここに来るのはスレーブ呼び出しの時 //
WREL = 1;
state = WAIT_ADRS;
/// レジスタアドレスが書かれるのを待つ
}
else
{
// ③R Rでのスレーブ呼び出し(リスタートコンディション) //
IICA = vreg_twl_read( vreg_adrs ); // データ送信
// ストップ待ち後、LREL = 1 にしないと、送信バッファが破壊されることがある
state = DATA_READED;
}
}
else if( ( my_iics & 0x03 ) == 0 ) // ( !STD && !SPD )
{
u8 rcvd;
// 何らか受信
rcvd = IICA;
WREL = 1;
if( state == WAIT_ADRS )
{
// ②
vreg_adrs = adrs_table_twl_ext2int( rcvd );
/// データが書かれるか、リスタートで読み出されるのを待つ
state = WAIT_DATA;
}
else if( state == DATA_READED )
{
// データ1バイト送信後発生する
LREL = 1;
return;
}
else
{
// ③W
// データ書き込まれ
SVA = 0x5A; // ダミー
LREL = 1; // スタートコンディション待ちへ(連続書き込み未対応のため)
vreg_twl_write( vreg_adrs, rcvd );
SVA = IIC_T_SLAVEADDRESS;
return; // 受信おしまい //
}
}
else if( my_iics & 0x01 ) // SPD
{
// 終了
LREL = 1;
return;
}
else
{
// NOP();
}
}
}
/********************************************//**
***********************************************/
void IIC_twl_Init( void )
{
IICAEN = 1;
IICE = 0; /* IICA disable */
IICAMK = 1; /* INTIICA disable */
IICAIF = 0; /* clear INTIICA interrupt flag */
IICAPR0 = 0; /* set INTIICA high priority */
IICAPR1 = 0; /* set INTIICA high priority */
Port &= ~0x03;
SVA = IIC_T_SLAVEADDRESS;
IICF = 0x01;
STCEN = 1; // リスタートの許可
IICRSV = 1; // 通信予約をさせない:スレーブに徹する
SPIE = 0; // ストップコンディションでの割り込みを禁止
WTIM = 1; // 自動でACKを返した後clkをLに固定する
ACKE = 1; // ダメCPUは無視して次の通信をはじめるかもしれないんで早くclkを開放しないといけない
IICWH = 9;
IICWL = 11; // L期間の長さ
SMC = 1;
DFC = 1; // デジタルフィルタon (@fast mode)
IICAMK = 0; // 割り込みを許可
IICE = 1;
PortMode &= ~0x03;
LREL = 1;
}
/********************************************//**
***********************************************/
void IIC_twl_Stop( void )
{
IICE = 0; /* IICA disable */
IICAEN = 0;
}
#endif

View File

@ -0,0 +1,7 @@
#ifndef _iic_twl_
#define _iic_twl_
void IIC_twl_Init( void );
void IIC_twl_Stop( void );
#endif

View File

@ -0,0 +1,196 @@
#ifndef _MDSERIAL_
#define _MDSERIAL_
/* IIC operation enable (IICE0) */
#define IIC0_OPERATION 0x80
#define IIC0_OPERATION_DISABLE 0x00 /* stop operation */
#define IIC0_OPERATION_ENABLE 0x80 /* enable operation */
/* Exit from communications (LREL0) */
#define IIC0_COMMUNICATION 0x40
#define IIC0_COMMUNICATION_NORMAL 0x00 /* normal operation */
#define IIC0_COMMUNICATION_EXIT 0x40 /* exit from current communication */
/* Wait cancellation (WREL0) */
#define IIC0_WAITCANCEL 0x20
#define IIC0_WAIT_NOTCANCEL 0x00 /* do not cancel wait */
#define IIC0_WAIT_CANCEL 0x20 /* cancel wait */
/* Generation of interrupt when stop condition (SPIE0) */
#define IIC0_STOPINT 0x10
#define IIC0_STOPINT_DISABLE 0x00 /* disable */
#define IIC0_STOPINT_ENABLE 0x10 /* enable */
/* Wait and interrupt generation (WTIM0) */
#define IIC0_WAITINT 0x08
#define IIC0_WAITINT_CLK8FALLING 0x00 /* generate at the eighth clocks falling edge */
#define IIC0_WAITINT_CLK9FALLING 0x08 /* generated at the ninth clocks falling edge */
/* Acknowledgement control (ACKE0) */
#define IIC0_ACK 0x04
#define IIC0_ACK_DISABLE 0x00 /* enable acknowledgement */
#define IIC0_ACK_ENABLE 0x04 /* disable acknowledgement */
/* Start condition trigger (STT0) */
#define IIC0_STARTCONDITION 0x02
#define IIC0_START_NOTGENERATE 0x00 /* do not generate start condition */
#define IIC0_START_GENERATE 0x02 /* generate start condition */
/* Stop condition trigger (SPT0) */
#define IIC0_STOPCONDITION 0x01
#define IIC0_STOP_NOTGENERATE 0x00 /* do not generate stop condition */
#define IIC0_STOP_GENERATE 0x01 /* generate stop condition */
/*
IIC Status Register 0 (IICS0)
*/
/* Master device status (MSTS0) */
#define IIC0_MASTERSTATUS 0x80
#define IIC0_STATUS_NOTMASTER 0x00 /* slave device status or communication standby status */
#define IIC0_STATUS_MASTER 0x80 /* master device communication status */
/* Detection of arbitration loss (ALD0) */
#define IIC0_ARBITRATION 0x40
#define IIC0_ARBITRATION_NO 0x00 /* arbitration win or no arbitration */
#define IIC0_ARBITRATION_LOSS 0x40 /* arbitration loss */
/* Detection of extension code reception (EXC0) */
#define IIC0_EXTENSIONCODE 0x20
#define IIC0_EXTCODE_NOT 0x00 /* extension code not received */
#define IIC0_EXTCODE_RECEIVED 0x20 /* extension code received */
/* Detection of matching addresses (COI0) */
#define IIC0_ADDRESSMATCH 0x10
#define IIC0_ADDRESS_NOTMATCH 0x00 /* addresses do not match */
#define IIC0_ADDRESS_MATCH 0x10 /* addresses match */
/* Detection of transmit/receive status (TRC0) */
#define IIC0_STATUS 0x08
#define IIC0_STATUS_RECEIVE 0x00 /* receive status */
#define IIC0_STATUS_TRANSMIT 0x08 /* transmit status */
/* Detection of acknowledge signal (ACKD0) */
#define IIC0_ACKDETECTION 0x04
#define IIC0_ACK_NOTDETECTED 0x00 /* ACK signal was not detected */
#define IIC0_ACK_DETECTED 0x04 /* ACK signal was detected */
/* Detection of start condition (STD0) */
#define IIC0_STARTDETECTION 0x02
#define IIC0_START_NOTDETECTED 0x00 /* start condition not detected */
#define IIC0_START_DETECTED 0x02 /* start condition detected */
/* Detection of stop condition (SPD0) */
#define IIC0_STOPDETECTION 0x01
#define IIC0_STOP_NOTDETECTED 0x00 /* stop condition not detected */
#define IIC0_STOP_DETECTED 0x01 /* stop condition detected */
/*
IIC Flag Register 0 (IICF0)
*/
/* STT0 clear flag (STCF) */
#define IIC0_STARTFLAG 0x80
#define IIC0_STARTFLAG_GENERATE 0x00 /* generate start condition */
#define IIC0_STARTFLAG_UNSUCCESSFUL 0x80 /* start condition generation unsuccessful */
/* IIC bus status flag (IICBSY) */
#define IIC0_BUSSTATUS 0x40
#define IIC0_BUS_RELEASE 0x00 /* bus release status */
#define IIC0_BUS_COMMUNICATION 0x40 /* bus communication status */
/* Initial start enable trigger (STCEN) */
#define IIC0_STARTWITHSTOP 0x02
#define IIC0_START_WITHSTOP 0x00 /* generation of a start condition without detecting a stop condition */
#define IIC0_START_WITHOUTSTOP 0x02 /* generation of a start condition upon detection of a stop condition */
/* Communication reservation function disable bit (IICRSV) */
#define IIC0_RESERVATION 0x01
#define IIC0_RESERVATION_ENABLE 0x00 /* enable communication reservation */
#define IIC0_RESERVATION_DISABLE 0x01 /* disable communication reservation */
/*
IIC clock selection register 0 (IICCL0)
*/
#define IICCL0_INITIALVALUE 0x00
/* Detection of SCL0 pin level (CLD0) */
#define IIC0_SCLLEVEL 0x20
#define IIC0_SCL_LOW 0x00 /* clock line at low level */
#define IIC0_SCL_HIGH 0x20 /* clock line at high level */
/* Detection of SDA0 pin level (DAD0) */
#define IIC0_SDALEVEL 0x10
#define IIC0_SDA_LOW 0x00 /* data line at low level */
#define IIC0_SDA_HIGH 0x10 /* data line at high level */
/* Operation mode switching (SMC0) */
#define IIC0_OPERATIONMODE 0x08
#define IIC0_MODE_STANDARD 0x00 /* operates in standard mode */
#define IIC0_MODE_HIGHSPEED 0x08 /* operates in high-speed mode */
/* Digital filter operation control (DFC0) */
#define IIC0_DIGITALFILTER 0x04
#define IIC0_FILTER_OFF 0x00 /* digital filter off */
#define IIC0_FILTER_ON 0x04 /* digital filter on */
/* Operation mode switching (CL01, CL00) */
#define IIC0_CLOCKSELECTION 0x03
/* Combine of (SMC0, CL01, CL00)*/
#define IIC0_CLOCK0 0x00
#define IIC0_CLOCK1 0x01
#define IIC0_CLOCK2 0x02
#define IIC0_CLOCK3 0x03
#define IIC0_CLOCK4 0x08
#define IIC0_CLOCK5 0x09
#define IIC0_CLOCK6 0x0a
#define IIC0_CLOCK7 0x0b
/*
IIC function expansion register 0 (IICX0)
*/
/* IIC clock expension (CLX0) */
#define IIC0_CLOCKEXPENSION 0x01
#define IIC0_EXPENSION0 0x00
#define IIC0_EXPENSION1 0x01
/* Operation clock (CLX0, SMC0, CL01, CL00)
| IIC0_EXPENSION0 | IIC0_EXPENSION1 |
------------|-------------------|-------------------|----------------------
IIC0_CLOCK0 | fprs/2 | prohibited | selection clock(fw)
| fprs/88 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK1 | fprs/2 | prohibited | selection clock(fw)
| fprs/172 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK2 | fprs/2 | prohibited | selection clock(fw)
| fprs/344 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK3 |prohibited/fexscl0 | prohibited | selection clock(fw)
| fw/66 | | transfer clock
| normal | | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK4 | fprs/2 | fprs/2 | selection clock(fw)
| fprs/48 | fprs/24 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK5 | fprs/2 | fprs/2 | selection clock(fw)
| fprs/48 | fprs/24 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK6 | fprs/4 | fprs/4 | selection clock(fw)
| fprs/96 | fprs/48 | transfer clock
| high speed | high speed | mode
------------|-------------------|-------------------|----------------------
IIC0_CLOCK7 |prohibited/fexscl0 | prohibited | selection clock(fw)
| fw/18 | | transfer clock
| high speed | | mode
------------|-------------------|-------------------|----------------------
*/
#define ADDRESS_COMPLETE 0x80
#define IIC_MASTER_FLAG_CLEAR 0x00
#endif

View File

@ -0,0 +1,44 @@
#ifndef _WIN32
#pragma SFR
#pragma di
#pragma ei
#pragma nop
#pragma stop
#pragma halt
#endif
#ifndef _WIN32
#pragma section @@CODE ROM_CODE
//#pragma section @@CNST ROM_CNST
#endif
#ifdef _WIN32
// VCの赤線をどうにかする
#include "sim/simOnWin.h"
# endif
//=========================================================
#ifndef _incs_h_
#define _incs_h_
// ↓ 歩数計で_pc_とで切り替えてます
#define _mcu_
#include "jhl_defs.h"
#include "config.h"
#include "user_define.h"
#include "hal.h"
#include "bsr_system.h"
#include "renge\renge.h"
#include "vreg_ctr.h"
#include "util_funcs.h"
//=========================================================
#endif

View File

@ -0,0 +1,49 @@
/* ========================================================
 volatileなのでタイミング依存で期待しない動作になるのを回避 
Hardware abstruct layer
$Id: asdf$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma di
#pragma ei
#pragma nop
#pragma stop
#pragma halt
#pragma section @@CODE LDR_CODE
#pragma section @@CODEL LDR_CODL
//#pragma section @@R_INIT FSL_RINT // これやるとスタートアップルーチンが初期値を
//#pragma section @@CNST FSL_CNST // セットしてくれない
#pragma section @@CNSTL LDR_CNSL
#endif
# ifdef _WIN32
// VCの赤線をどうにかする
#include "sim/simOnWin.h"
# endif
//=========================================================
#include "jhl_defs.h"
#include "config.h"
#include "user_define.h"
#include "hal.h"
#include "bsr_system.h"
#include "renge\renge.h"
#include "vreg_ctr.h"
#include "vreg_twl.h"
//=========================================================
void firm_update( );
void firm_restore( );

View File

@ -0,0 +1,347 @@
/* ========================================================
$Id$
======================================================== */
#ifndef _WIN32
#pragma nop
#endif
#include "config.h"
#ifndef _WIN32
#ifdef _WDT_CHECK_
#pragma interrupt INTWDTI fn_intwdti // wdt debug
#endif
//#pragma interrupt INTLVI fn_intlvi // 未使用
//#pragma interrupt INTP0 intp0_slp // SLP (CPUより、要求) ポーリング
//#pragma interrupt INTP1 fn_intp1 // (I2C)
//#pragma interrupt INTP2 fn_intp2 // (I2C)
//#pragma interrupt INTP3 fn_intp3 // 未搭載
#pragma interrupt INTP4 intp4_extdc // EXTDC, ただし電源offから起こすのみ。通常はポーリング
#pragma interrupt INTP5 intp5_shell // SHELL_CLOSE, ただし電源offから起こすのみ。通常はポーリング
#pragma interrupt INTP6 intp6_PM_irq // CODEC経由で旧PMICへのコマンド書き込み
//#ifdef _MCU_BSR_ // 割り込みそのものは使いません
//#pragma interrupt INTP21 intp21_RFTx // 電波送信パルス
//#else
//#pragma interrupt INTP7 intp21_RFTx
//#endif
/*
acceroへ
#ifdef _MCU_BSR_
#pragma interrupt INTP23 intp23_ACC_ready RB3 // 加速度センサ、データ準備完了
#endif
*/
//#pragma interrupt INTCMP0 fn_intcmp0
//#pragma interrupt INTCMP1 fn_intcmp1
//#pragma interrupt INTDMA0 fn_intdma0
#pragma interrupt INTDMA1 int_dma1
//#pragma interrupt INTST0 fn_intst0
/* #pragma interrupt INTCSI00 fn_intcsi00 */
//#pragma interrupt INTSR0 fn_intsr0
/* #pragma interrupt INTCSI01 fn_intcsi01 */
//#pragma interrupt INTSRE0 fn_intsre0
//#pragma interrupt INTST1 fn_intst1
/* #pragma interrupt INTCSI10 fn_intcsi10 */
#pragma interrupt INTIIC10 int_iic10
//#pragma interrupt INTSR1 fn_intsr1
//#pragma interrupt INTSRE1 fn_intsre1
/*
// TSはマザボでテレコ、WMは回路図がテレコで結局一致…
#pragma interrupt INTIICA1 int_iic_ctr RB1
#pragma interrupt INTIICA0 int_iic_twl RB2
*/
//#pragma interrupt INTTM00 fn_inttm00
//#pragma interrupt INTTM01 fn_inttm01
//#pragma interrupt INTTM02 fn_inttm02
//#pragma interrupt INTTM03 fn_inttm03
#pragma interrupt INTAD int_adc
#pragma interrupt INTRTC int_rtc
#pragma interrupt INTRTCI int_rtc_int
#pragma interrupt INTKR int_kr
//#pragma interrupt INTMD fn_intmd
//#pragma interrupt INTTM04 fn_inttm04
//#pragma interrupt INTTM05 fn_inttm05
//#pragma interrupt INTTM06 fn_inttm06
//#pragma interrupt INTTM07 fn_inttm07
//#define _irq_debug_
/****************************************************/
/* 未使用時のダミー関数定義 */
/****************************************************/
#ifdef _WDT_CHECK_
__interrupt void fn_intwdti( )
{
while( 1 )
{
NOP();
}
}
#endif
#ifdef _irq_debug_
__interrupt void fn_intlvi( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intp0(){
while( 1 )
{
NOP();
}
}
__interrupt void fn_intp1( )
{
while( 1 )
{
NOP();
}
} //
__interrupt void fn_intp2( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intp3( )
{
while( 1 )
{
NOP();
}
}
__interrupt void intp21_RFTx( )
{
while( 1 )
{
NOP();
}
}
//__interrupt void fn_intp4(){ while(1){} } // pm.c
//__interrupt void fn_intp5(){ while(1){} } // pm.c
//__interrupt void fn_intp6(){ while(1){} } // pm.c
//__interrupt void fn_intp7(){ while(1){} } // led.c
//__interrupt void fn_intp21(){ while(1){} } // led.c
__interrupt void fn_intcmp0( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intcmp1( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intdma0( )
{
while( 1 )
{
NOP();
}
}
//__interrupt void fn_intdma1(){} // i2c_mcu.cにある
__interrupt void fn_intst0( )
{
while( 1 )
{
NOP();
}
}
/* __interrupt void fn_intcsi00(){} */
__interrupt void fn_intsr0( )
{
while( 1 )
{
NOP();
}
}
/* __interrupt void fn_intcsi01(){} */
__interrupt void fn_intsre0( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intst1( )
{
while( 1 )
{
NOP();
}
}
/* __interrupt void fn_intcsi10(){} */
//__interrupt void fn_intiic10(){ while(1){} }
__interrupt void fn_intsr1( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_intsre1( )
{
while( 1 )
{
NOP();
}
}
//__interrupt void fn_intiica(){} // i2c.cにある
/* __interrupt void fn_inttm00(){} *//* sub.cにて定義 */
__interrupt void fn_inttm01( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm02( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm03( )
{
while( 1 )
{
NOP();
}
}
//__interrupt void fn_intad(){ while(1){} } // adc.c
__interrupt void fn_intrtc( )
{
while( 1 )
{
NOP();
}
}
//__interrupt void int_rtcint(){} // rtc.cにある
//__interrupt void fn_intkr(){} // main.c
__interrupt void fn_intmd( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm04( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm05( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm06( )
{
while( 1 )
{
NOP();
}
}
__interrupt void fn_inttm07( )
{
while( 1 )
{
NOP();
}
}
#endif
/* ========================================================
======================================================== */
__interrupt void int_kr( )
{
// 起きるだけ
}
/* ========================================================
ext dc
======================================================== */
__interrupt void intp4( )
{
// 起きるだけ
}
/* ========================================================
shell close
======================================================== */
__interrupt void intp5( )
{
// 起きるだけ
}
#else
#include "sim/sim_interrupt_decrare.c"
#endif

View File

@ -0,0 +1,25 @@
#ifndef __jhl_defs_h__
#define __jhl_defs_h__
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned short ux16;
typedef signed short sx16;
#define true 1
#define false 0
#define set_bit_if( cond, reg, pos ) \
{ \
if( cond ){ \
reg |= pos; \
}else{ \
reg &= ~pos; \
} \
}
#endif

View File

@ -0,0 +1,12 @@
PUBLIC _END_1,_END_2,_END_3,_END_4
@@DATA DSEG BASEP
_END_1:
@@INIT DSEG BASEP
_END_2:
@@INITL DSEG UNIT64KP
_END_3:
@@DATAL DSEG UNIT64KP
_END_4:
;
END

View File

@ -0,0 +1,18 @@
/********************************************//**
$Id$
***********************************************/
#include "incs.h"
extern unsigned char END_4;
void f()
{
unsigned char *tp;
tp = &END_4;
}

399
snake_tags/3.40_jane/led.c Normal file
View File

@ -0,0 +1,399 @@
/* ========================================================
LED.c
$Id: LED.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma sfr
#endif
#include "incs.h"
#include "led.h"
// ========================================================
static void LED_oshirase_init();
// ========================================================
// TPS0
#define BIT_PRS012 ( 1 << 2 )
#define BIT_PRS002 ( 1 << 6 )
// TMR0
#define BIT_CKS0 15
#define BIT_CCS0 12
#define BIT_MASTER0 11
#define BIT_STS0 8
#define BIT_CIS0 6
#define BIT_MD123 1
#define BIT_MD0 0
// ========================================================
bit ledInitialized;
// お知らせLED
uni_info_LED info_LED; // パターンデータ
bit info_led_off; // 電源off時など、強制消灯フラグ
bit info_led_override; // 電池残量僅少強制点滅上書きビット
// wifi led ステート
static u8 state_wifi_tx;
static u8 flag_wifi_TX;
// ========================================================
#define led_fade_to( now, goal ) now = fade_to( now, goal )
/********************************************//**
now goal inc / dec
***********************************************/
u8 fade_to( u8 now, u8 goal )
{
if( now != goal )
{
if( now > goal )
{
now --;
}
else
{
now ++;
}
}
return( now );
}
/********************************************//**
***********************************************/
#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
{
// delta が小さいときは to の値にぶつけてしまう
status->now = status->to;
}
}
return( status->now / 128 );
}
/********************************************//**
LEDの初期化
HWタイマーを使うのでそれらの初期化を行う
***********************************************/
void LED_init( )
{
/**
PWMのセット
 (P01:/reset2) 
     ( )
         
         WiFi
         (32kHz out 使)
         
         
         
*/
// LED_oshirase_init(); // お知らせパターン初期化
/// ペリフェラル初期化 ///
TAU0EN = 1;
TPS0 = BIT_PRS012 | BIT_PRS002; // マスタークロックはCK01,8M/2 /2^4 = 250kHz
TMR00 =
1 << BIT_CKS0 | 0 << BIT_CCS0 | 1 << BIT_MASTER0 | 0 << BIT_STS0 | 0
<< BIT_CIS0 | 0 << BIT_MD123 | 1 << BIT_MD0;
TMR01 = TMR02 = TMR03 = TMR04 = TMR05 = TMR06 = TMR07 =
1 << BIT_CKS0 | 0 << BIT_CCS0 | 0 << BIT_MASTER0 | 4 << BIT_STS0 | 0
<< BIT_CIS0 | 4 << BIT_MD123 | 1 << BIT_MD0;
ISC = 0;
TOM0 = 0x00FE; // 出力モード。4はPWM出力しないが1にしないとTO5以降にクロックが届かない
TOL0 = 0x0000; // 出力を反転させるかフラグ
TO0 = 0x0000; // タイマー動作中で、タイマー出力にしてないときのピンのラッチ。タイマー出力を使わないなら0
TOE0 = 0x00EE; // TOxをタイマーモジュールが制御
TS0 = 0x00EF; // 動作開始
TDR00 = LED_BRIGHT_MAX - 1; // 周期 10bit
// アップデートなどでマイコンのみリブートしたとき
if( system_status.reboot )
{
// SoC からのコマンドを待たず、自動で電源 LED をつける
vreg_ctr[VREG_C_LED_POW] = LED_POW_ILM_AUTO;
LED_duty_pow_blu = LED_BRIGHT_MAX;
}
info_led_off = false; // 強制消灯 解除
ledInitialized = true;
}
static void LED_oshirase_init()
{
char* p_tgt = &info_LED;
int i;
for( i = 0; i < sizeof(info_LED); i++ )
{
*p_tgt = 0;
p_tgt++;
}
}
/********************************************//**
LEDの停止
HWタイマーの停止
***********************************************/
void LED_stop( )
{
TT0 = 0x00EF; // 一斉停止(しないとだめ)
TOE0 = 0x0000; // TOxをタイマーモジュールが制御(GPIOになる)
TAU0EN = 0;
LED_pow_red = 0;
LED_CAM = 0;
LED_duty_notify_red = 0;
LED_duty_notify_blu = 0;
LED_duty_notify_grn = 0;
LED_pow_red = 0;
LED_CAM = 0;
WIFI_txLatch = 0;
flag_wifi_TX = 0;
state_wifi_tx = 0;
ledInitialized = false;
}
/********************************************//**
WiFi LED
- on / off
- off -_-_-_--------_-_-_-------
***********************************************/
void tsk_led_wifi( )
{
static u8 task_interval;
if( task_interval-- != 0 )
{
return;
}
// 送信パルスのラッチ
if( WIFI_txLatch ) // 割り込みフラグそのものを使ってしまう
{
WIFI_txLatch = 0;
flag_wifi_TX = 1;
}
if( flag_wifi_TX != 0 )
{
vreg_ctr[ VREG_C_STATUS_1 ] |= REG_BIT_WIFI_TX;
// 送信パターン
switch ( state_wifi_tx )
{
case ( 1 ):
case ( 3 ):
case ( 5 ):
LED_duty_WiFi = 0;
break;
default:
LED_duty_WiFi = vreg_ctr[VREG_C_LED_BRIGHT];
}
state_wifi_tx ++;
if( state_wifi_tx == 32 ) // ←点滅後、点灯している期間の長さ
{
state_wifi_tx = 0;
flag_wifi_TX = 0;
}
task_interval = 25;
return;
}
else
{
task_interval = 30;
// 送信フラグ待ち
vreg_ctr[ VREG_C_STATUS_1 ] &= ~REG_BIT_WIFI_TX;
if( vreg_ctr[VREG_C_LED_WIFI] == WIFI_LED_OFF )
{
LED_duty_WiFi = 0;
return;
}
else
{
if( LED_duty_WiFi == vreg_ctr[VREG_C_LED_BRIGHT] )
{
return;
}
else if( LED_duty_WiFi < vreg_ctr[VREG_C_LED_BRIGHT] )
{
LED_duty_WiFi ++;
}
else
{
LED_duty_WiFi --;
}
}
task_interval = 3;
return;
}
}
bit info_led_pattern_updated;
/********************************************//**
LED
***********************************************/
static void calc_info_led_fade_out( st_LED_dim_status* tgt_led )
{
tgt_led -> to = 0;
tgt_led -> delta = ( 0 - tgt_led -> now ) / 64;
// フェードアウト限定(ゼロに向かっていく。符号の向きを想定してしまう。)
if(( tgt_led -> now != 0 ) && ( tgt_led -> delta == 0 ))
{
tgt_led -> delta = (sx16)-1;
}
}
/********************************************//**
LED
***********************************************/
static void calc_info_led_next_frame( st_LED_dim_status* tgt_led, u8 color )
{
tgt_led -> to = color * 128;
// グラデーションのデルタを計算
tgt_led -> delta = (( tgt_led -> to - tgt_led -> now ) ) / info_LED.info_LED.fade_time;
}
/********************************************//**
LED
***********************************************/
void tsk_led_notify( )
{
static u8 time_to_next_frame;
static u8 frame;
static u8 loops;
static st_LED_dim_status LED_dim_status_info_R, LED_dim_status_info_G, LED_dim_status_info_B;
if( info_led_override )
{
// 電池切れが優先する
return;
}
if( system_status.pwr_state == ON_TRIG )
{
LED_duty_notify_blu = 0;
LED_duty_notify_red = 0;
LED_duty_notify_grn = 0;
LED_dim_status_info_R.now = 0;
LED_dim_status_info_G.now = 0;
LED_dim_status_info_B.now = 0;
}
if( info_led_off ) // ←電源off時など強制off
{
// フェードアウトさせる
calc_info_led_fade_out( &LED_dim_status_info_R );
calc_info_led_fade_out( &LED_dim_status_info_G );
calc_info_led_fade_out( &LED_dim_status_info_B );
}
else
{
// 通常運転
if( info_led_pattern_updated )
{
info_led_pattern_updated = false;
vreg_ctr[ VREG_C_LED_NOTIFY_FLAG ] &= ~REG_BIT_IN_LOOP;
frame = 0; // ちゃんと書こう
time_to_next_frame = 0;
}
else
{
// 次のフレームに進める?
if( time_to_next_frame == 0 )
{
time_to_next_frame = info_LED.info_LED.term;
if( frame >= NOTIFY_LED_TERM -1 )
{
vreg_ctr[ VREG_C_LED_NOTIFY_FLAG ] |= REG_BIT_IN_LOOP;
if( info_LED.info_LED.last_loop != 255 ) // 255:無限ループ
{
loops ++;
if( loops > info_LED.info_LED.last_loop )
{
frame = 0;
}
}
}
else
{
frame = (( frame + 1 ) & 0x1F ); // ←ここでマスクをかけておかないと最終フレーム~先頭間のグラデが効かない
vreg_ctr[ VREG_C_LED_NOTIFY_FLAG ] &= ~REG_BIT_IN_LOOP;
loops = 0;
}
// グラデーション計算
calc_info_led_next_frame( &LED_dim_status_info_R, info_LED.info_LED.red[frame] );
calc_info_led_next_frame( &LED_dim_status_info_G, info_LED.info_LED.grn[frame] );
calc_info_led_next_frame( &LED_dim_status_info_B, info_LED.info_LED.blu[frame] );
}
time_to_next_frame --;
}
}
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 );
}

142
snake_tags/3.40_jane/led.h Normal file
View File

@ -0,0 +1,142 @@
#ifndef __led__
#define __led__
// ====================================
//#define LED_CHARGE P2.4 // PMで定義
// LED_DUTY
#define LED_duty_pow_blu TDR06
#define LED_duty_WiFi TDR03
#define LED_duty_3d TDR01
#define LED_duty_notify_red TDR07
#define LED_duty_notify_grn TDR05
#define LED_duty_notify_blu TDR02
// これらはduty変えられません
#ifndef _WIN32
#define LED_pow_red P4.2
#define LED_CAM P7.5
#else
#define LED_pow_red mcuRegP[ _P4_2 ]
#define LED_CAM mcuRegP[ _P7_5 ]
#endif
#define NOTIFY_LED_TERM 32
#define LED_BRIGHT_MAX 0x00FF
// ====================================
#define WIFI_txLatch PIF21 // 電波送信パルス
// ====================================
enum LED_ILUM_MODE
{
LED_POW_ILM_AUTO = 0,
LED_POW_ILM_ON,
LED_POW_ILM_SLEEP,
LED_POW_ILM_OFF,
LED_POW_ILM_ONLY_RED,
LED_POW_ILM_ONLY_BLUE,
LED_POW_ILM_FORCE_BT_EMPTY
};
enum LED_MODE_3D
{
LED_3D_ILM_OFF = 0,
LED_3D_ILM_ON
};
// VREG_C_WIFI_LED
enum WIFI_LED_MODE
{
WIFI_LED_OFF = 0,
WIFI_LED_ON
};
// VREG_C_WIFI_NOTIFY
enum NOTIFY_LED_MODE
{
NOTIFY_LED_OFF = 0,
NOTIFY_LED_ON,
NOTIFY_LED_PTN0,
NOTIFY_LED_PTN1,
NOTIFY_LED_PTN2
};
// VREG_C_CAM_LED
enum CAM_LED_MODE
{
CAM_LED_OFF = 0,
CAM_LED_BLINK,
CAM_LED_ON,
CAM_LED_BY_TWL,
CAM_LED_ON_PLUSE,
CAM_LED_OFF_PLUSE
};
// お知らせLED調光関係 //
typedef struct _st_info_LED
{
u8 term; // 1フレーム何チック
u8 fade_time; // 何チックで次のフレームの色に達するか
u8 last_loop; // 最終フレームを繰り返す?
u8 resv1;
u8 red[32];
u8 grn[32];
u8 blu[32];
}st_info_LED;
typedef union _uni_info_LED
{
st_info_LED info_LED;
u8 bindata[ sizeof( st_info_LED ) ];
}uni_info_LED;
extern uni_info_LED info_LED;
// 赤LED 点滅向け //
typedef struct _st_led_red_batt_empty
{
u8 dats[4];
}st_led_red_batt_empty;
extern st_led_red_batt_empty led_red_batt_empty;
/*
LED
*/
typedef struct _st_LED_dim_status
{
sx16 to;
sx16 delta;
sx16 now; // 小数点以下を覚えておかなくてはならないため
}st_LED_dim_status;
// ====================================
void LED_init( );
void LED_stop( );
// ====================================
extern bit ledInitialized;
extern bit info_led_override;
#endif

View File

@ -0,0 +1,156 @@
/******************************************************//**
LED_Cam TO02
BLINK,*_PLUSE 1
OFFBLINK OFFが無視されます
$Id$
*********************************************************/
#ifndef _WIN32
#pragma sfr
#endif
#include "incs.h"
#include "led.h"
#include "vreg_twl.h"
// ========================================================
static u8 state_led_cam = 0;
static u16 task_interval;
bit cam_led_update;
// ========================================================
static void cam_led_twl();
/********************************************//**
twlレジスタへの書き込みのカ所から呼ばれます
***********************************************/
void tsk_led_cam( )
{
DI_wt_chk(); // レジスタへの書き込みで強制起動がかかることがあるため
if( !cam_led_update )
{
if( task_interval != 0 )
{
task_interval --;
EI();
return;
}
}
cam_led_update = false; // TWL のブリンク設定(一発だけ点灯)のため
EI();
if( system_status.pwr_state == SLEEP ) // sleep中、強制消灯
{
LED_CAM = 0;
state_led_cam = 0;
}
else
{
// ブリンクのように待たせたいとき以外は毎週起動する
// (レジスタの変更にすぐに反応する)
switch ( vreg_ctr[VREG_C_LED_CAM] )
{
case ( CAM_LED_OFF ):
default:
LED_CAM = 0;
state_led_cam = 0;
break;
case ( CAM_LED_ON ):
LED_CAM = 1;
state_led_cam = 0;
break;
case ( CAM_LED_BLINK ):
if( state_led_cam == 0 )
{
LED_CAM = 1;
state_led_cam = 1;
}
else
{
LED_CAM = 0;
state_led_cam = 0;
}
task_interval = 250;
break;
case ( CAM_LED_ON_PLUSE ):
if( state_led_cam == 0 )
{
LED_CAM = 1;
state_led_cam = 1;
task_interval = 250;
}
else
{
vreg_ctr[VREG_C_LED_CAM] = CAM_LED_OFF;
}
break;
case ( CAM_LED_OFF_PLUSE ):
if( state_led_cam == 0 )
{
LED_CAM = 0;
state_led_cam = 1;
task_interval = 250;
}
else
{
vreg_ctr[VREG_C_LED_CAM] = CAM_LED_ON;
}
break;
case( CAM_LED_BY_TWL ):
cam_led_twl();
}
} // if( system_status.pwr_state == sleep ) ... else ...
}
/********************************************//**
TWLからカメラLEDを操作される
***********************************************/
static void cam_led_twl()
{
// TWL互換 //
switch ( vreg_twl[ REG_TWL_INT_ADRS_CAM ] ){
case( TWL_CAMLED_OFF ):
LED_CAM = 0;
state_led_cam = 0;
break;
case( TWL_CAMLED_BLINK ):
if( state_led_cam == 0 )
{
LED_CAM = 1;
state_led_cam = 1;
}
else
{
LED_CAM = 0;
state_led_cam = 0;
}
task_interval = (u8)( 600 / SYS_INTERVAL_TICK ) + 250;
break;
case( TWL_CAMLED_ON ):
case( TWL_CAMLED_DEF_ON ):
default:
LED_CAM = 1;
state_led_cam = 1;
break;
}
}

View File

@ -0,0 +1,296 @@
/* ========================================================
LED
LED_POW_B,R 6,7
TDR00 (0x03FFTPS0で250kHzでカウントアップ10bitなら250Hz位になる)
TDR0x Duty 0TDR00( =0x03FF)
$Id: asdf$
======================================================== */
/* ========================================================
enum pwr_state_{
OFF_TRIG = 0,
ON_CHECK,
ON_TRIG,
ON,
SLEEP
};
enum LED_ILUM_MODE{
LED_POW_ILM_AUTO,
LED_POW_ILM_ON,
LED_POW_ILM_SLEEP,
LED_POW_ILM_CEOFF
};
======================================================== */
#ifndef _WIN32
#pragma sfr
#endif
#include "incs.h"
#include "led.h"
#include "pm.h"
// ========================================================
// スリープ中明滅のテーブル。マジか。
const u8 LED_PTN_SLEEP[] = {
25, 38, 52, 68, 83, 98, 110, 119,
125, 128, 128, 125, 119, 110, 98, 83,
68, 52, 38, 25, 16, 10, 8, 8,
8, 8, 8, 8, 8, 8, 10, 16
};
// 赤LEDの電池残量LEDの点滅パターン
st_led_red_batt_empty led_red_batt_empty = { 0x55, 0x55, 0x55, 0x55 };
#define LED_SLEEP_FRAME_LEN 71
#define LED_SLEEP_DIM_LEN 71
#define LED_SLEEP_FRAME_NUM 32
// ========================================================
static void led_pow_normal( );
static void led_pow_sleep( );
static void led_pow_bt_empty();
static u8 led_pow_batt_low();
#define led_fade_to( now, goal ) now = fade_to( now, goal )
extern u8 fade_to( u8 now, u8 goal );
#define led_fade_to2( led, status ) led = fade_to2( status )
extern u8 fade_to2( st_LED_dim_status* status );
// ========================================================
// 電源LEDのスリープパターンのステータス類
static u8 time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
static u8 frame_sleep;
static st_LED_dim_status LED_dim_status_sleep;
extern bit ledInitialized;
extern bit BT_IN_CHG_delayed_n;
/********************************************//**
LED
- > 10% master_brightnessの明るさ
- 5% (100%HW制限で調光不可)
- LED赤も同期する5%
- > 10% master_brightnessの明るさ
-
***********************************************/
void tsk_led_pow( )
{
if( ! ledInitialized )
{
return;
// おしまい
}
info_led_override = false;
switch ( vreg_ctr[VREG_C_LED_POW] )
{
case ( LED_POW_ILM_AUTO ):
default:
led_pow_normal( );
break;
case ( LED_POW_ILM_SLEEP ):
led_pow_sleep( );
break;
case ( LED_POW_ILM_ON ):
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
LED_pow_red = 0;
break;
case ( LED_POW_ILM_OFF ):
led_fade_to( LED_duty_pow_blu, 0 );
LED_pow_red = 0;
break;
case ( LED_POW_ILM_ONLY_RED ):
LED_duty_pow_blu = 0;
LED_pow_red = 1;
break;
case ( LED_POW_ILM_ONLY_BLUE ):
LED_duty_pow_blu = LED_BRIGHT_MAX;
LED_pow_red = 0;
break;
case ( LED_POW_ILM_FORCE_BT_EMPTY ):
led_pow_bt_empty();
break;
}
if( system_status.pwr_state == OFF || system_status.pwr_state == ON_CHECK )
{
LED_pow_red = 0;
info_led_override = false;
}
if( info_led_override )
{
LED_duty_notify_blu = 0;
LED_duty_notify_grn = 0;
LED_duty_notify_red = ( LED_pow_red == 0 )? 0 : 255;
}
}
/********************************************//**
 
***********************************************/
static void led_pow_normal( )
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep = 0;
LED_dim_status_sleep.now = (sx16)LED_duty_pow_blu * 128;
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
{
return;
// おしまい
}
// 青点灯
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
}
/********************************************//**
***********************************************/
static void led_pow_sleep( )
{
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep = 0;
LED_dim_status_sleep.now = (sx16)LED_duty_pow_blu * 128;
return;
// おしまい
}
LED_dim_status_sleep.to = LED_PTN_SLEEP[frame_sleep] * 128;
// グラデーションのデルタを計算
LED_dim_status_sleep.delta = (( LED_dim_status_sleep.to - LED_dim_status_sleep.now ) ) / LED_SLEEP_DIM_LEN;
led_fade_to2( LED_duty_pow_blu, &LED_dim_status_sleep );
// 次のフレームに進める?
time_to_next_frame_sleep --;
if( time_to_next_frame_sleep == 0 )
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep ++;
if( frame_sleep >= LED_SLEEP_FRAME_NUM -1 )
{
frame_sleep = 0;
}
}
}
/********************************************//**
  0 
     1 
***********************************************/
static u8 led_pow_batt_low()
{
if( vreg_ctr[VREG_C_BT_REMAIN] > BATT_TH_LO )
{
LED_pow_red = 0;
return 0;
// おしまい
}
if(( vreg_ctr[VREG_C_BT_REMAIN] > BATT_TH_EMPTY ) || !BT_IN_CHG_delayed_n )
// 電池残量が5%10%) または、それ未満でも充電中
{
// 赤点灯
led_fade_to( LED_duty_pow_blu, 0 );
{
LED_pow_red = 1;
}
}
else // 電池が5%未満 かつ アダプタなし
{
led_pow_bt_empty();
}
return 1;
}
/********************************************//**
 
  
  
***********************************************/
static void led_pow_bt_empty()
{
static u8 delay;
static u8 red_blink_poi;
info_led_override = true;
// 赤点滅
led_fade_to( LED_duty_pow_blu, 0 );
// 赤の点滅パターンも指定できる
delay ++;
if( delay < 64 ) // フレームの保持時間稼ぎ
{
return;
}
delay = 0;
if( led_red_batt_empty.dats[ red_blink_poi / 8 ] & ( 1 << ( red_blink_poi % 8 )) )
{
LED_pow_red = 1;
}
else
{
LED_pow_red = 0;
}
red_blink_poi ++;
if( red_blink_poi >= 32 )
{
red_blink_poi = 0;
}
}

View File

@ -0,0 +1,418 @@
/* ========================================================
MCU CTR BSR
2009/03/30 -
$Id: loader.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma di
#pragma ei
#pragma nop
#pragma stop
#pragma halt
#pragma opc
#endif
#include "incs_loader.h"
#include <fsl.h>
#include "fsl_user.h"
#include "i2c_ctr.h"
#include "i2c_mcu.h"
#include "pm.h"
#include "rtc.h"
#include "reboot.h"
#include "wdt.h"
#include "magic.h"
#define REG_BIT_RESF_WDT (1<<4)
#define REG_BIT_RESF_TRAP (1<<7)
#define REG_BIT_RESF_LVI (1<<0)
// ========================================================
#if (FSL_DATA_BUFFER_SIZE>0)
fsl_u08 fsl_data_buffer[FSL_DATA_BUFFER_SIZE];
#endif
#ifdef FSL_INT_BACKUP
static fsl_u08 fsl_MK0L_bak_u08; /* if (interrupt backup required) */
static fsl_u08 fsl_MK0H_bak_u08; /* { */
static fsl_u08 fsl_MK1L_bak_u08; /* reserve space for backup information */
static fsl_u08 fsl_MK1H_bak_u08; /* of interrupt mask flags */
static fsl_u08 fsl_MK2L_bak_u08; /* */
static fsl_u08 fsl_MK2H_bak_u08; /* } */
#endif
// ========================================================
void hdwinit(); // static にするとcrt0から見えなくなります。注意
static void hdwinit2();
static void chk_platform_type();
static void chk_firm_broke();
extern void main_loop();
/********************************************//**
* - WDT等のリセット
* -
* -
* -
* -
*
* main_loop()
***********************************************/
void main( )
{
while( 1 )
{
WDT_Restart( );
if( RTCEN ) // これはTRAP(自己update)にしか使えない。WDT等では立たない
{
system_status.reboot = true;
}
{
volatile u8 my_resf = RESF; // ←読むと消える
if( ( my_resf & REG_BIT_RESF_WDT ) != 0 )
{
vreg_ctr[ VREG_C_MCU_STATUS ] |= REG_BIT_STATUS_WDT_RESET;
// set_irq( VREG_C_IRQ0, REG_BIT_IRQ_WDT_RESET );
// ↑I2Cの初期化後に行う
system_status.reboot = true;
}
else if( ( my_resf & REG_BIT_RESF_TRAP ) != 0 ) // ( FSL_ForceReset, 'r' )
{
system_status.reboot = true;
}
/* LVI使用せず
else if(( my_resf & REG_BIT_RESF_LVI ) != 0 )
{
vreg_ctr[ VREG_C_MCU_STATUS ] |= ( 1 << 2 );
}
*/
}
//* ROMがどうにも足りなくなったら、評価の上コメントアウト
if( !system_status.reboot )
{
// 通常の電源投入
// 電池接続時、ちょっと待ってみる(チャタリング対策)
u16 pwup_delay0;
for( pwup_delay0 = 0xFFFF; pwup_delay0 != 0; pwup_delay0 -- ){;};
}
//*/
hdwinit2( );
#ifndef _WIN32
// ファームの整合性チェック //
chk_firm_broke(); // 壊れていたら帰ってこない
#endif
// 機種判定
chk_platform_type();
// HALデバッグリセット
hal_reset();
hal_update();
// RTC 初期化
RTC_init( ); // 内部でリブートか判定して初期化するか判断します
// 通常運転
main_loop( );
}
}
/********************************************//**
*
*
* MCUはリセットします
***********************************************/
static void chk_firm_broke()
{
u8 i;
u8 comp = 0;
// ローダーと本体は同じバージョンか?
/// 次へのアップデートの途中で終わってないか?
for( i = 0; i < sizeof( __TIME__ ); i++ ) // sizeof( __TIME__ ) = 8 らし
{
comp += ( *( __far u8 * )( MGC_LOAD + i ) == *( u8 * )( MGC_FOOT + i ) ) ? 0 : 1;
comp += ( *( u8 * )( MGC_HEAD + i ) == *( u8 * )( MGC_FOOT + i ) ) ? 0 : 1;
}
if( *( u8 * )( MGC_FOOT +2 ) != ':' ) // 消去済のまま
{
comp ++;
}
if( comp != 0 )
{
// ファームリストアを試みる
firm_restore( );
// 帰ってこない。リセットをかける。
}
}
/********************************************//**
system_statusにセットします
CTRファミリ
DEV_DET(P12.[2:1])
CTR
P40,41 !! P40がLだとMCUが起動しません
- HH
- HL NBD試遊台
- LH
- LL ISデバッガ
***********************************************/
static void chk_platform_type()
{
// ●CTRファミリ //
system_status.family = (enum family_)( DEV_DET >> 1 ); /// あぁ...
#ifdef _DBG_FORCE_FLOWER
// 強制的に機種設定をしてデバッグしたいとき
// system_status.family = FAMILY_FLOWER;
#endif
#ifdef _MCU_ARR
if( system_status.family == FAMILY_SPFL )
{
system_status.family = FAMILY_CLOSER;
}
if( system_status.family == FAMILY_FLOWER )
{
system_status.family = FAMILY_JANE;
}
#endif
if( system_status.family == FAMILY_CTR )
{
system_status.LCD_is_CGS = true;
}
else
{
// FAMILY_SPFL or FAMILY_SNAKE or FAMILY_FLOWER // アモルファスしか生産しない
system_status.LCD_is_CGS = false;
}
if( system_status.LCD_is_CGS == true )
{
pm_reg_bit_vddlcd = PM_REG_BIT_VDDLCD_CGS;
}
else
{
pm_reg_bit_vddlcd = PM_REG_BIT_VDDLCD_AMO;
}
set_vdd_voltages( system_status.family );
// ●CTRその開発機材 //
// 一応初期化
system_status.is_dev = false;
system_status.taikendai = false;
system_status.taikendai_nbd = false;
switch( DIPSW )
{
case DIPSW_TAIKENDAI: system_status.taikendai = true; break;
case DIPSW_TAIKENDAI_NBD: system_status.taikendai_nbd = true; break;
case DIPSW_ISDEV: system_status.is_dev = true; break;
}
#ifdef _FORCE_TAIKENDAI_
system_status.taikendai = true;
#endif
#ifdef _FORCE_TAIKENDAI_NBD_
system_status.taikendai_nbd = true;
#endif
}
/********************************************//**
***********************************************/
void hdwinit( void )
{ // スタートアップルーチンが勝手に呼びます
DI( ); /* マスタ割り込み禁止 */
CMC = bits8(0,0,0,1, 0,0,0,0); /* X1発振せず(入力ポート)、XT1使用、超低電力発振は不安定に付き通常で */
CSC = bits8(1,0,0,0, 0,0,0,0); /* X1発振なし、XT1発振あり、高速内蔵発振動作 */
OSMC = bits8(0,0,0,0, 0,0,0,1); /* 隠しレジスタ */
NOP();NOP();NOP(); // 3clk開ける
CKC = bits8(0,0,0,0, 1,0,0,0); /* CPU/周辺クロック=fMAIN、fMAIN=fMX、fCLK=fMX */
/*--- 低電圧検出回路の設定 ---*/
/* リセット解除時のデフォルトは、オプション・バイトにて指定される */
LVIS = 0x00; /* VLVI = 4.22±0.1V */
// LVIM = 0x00; /* LVI動作禁止 */
/* 電源電圧(VDD)<検出電圧(VLVI)時に割込発生 */
/* 電源電圧(VDD)≧検出電圧<VLVI)、または動作禁止時に低電圧検出 */
}
/********************************************//**
hdwinit
 (system_status.reboot == 1)
***********************************************/
static void hdwinit2( )
{
// ポート設定 //
// リセット後の初期値が保証されているのは省略
if( system_status.reboot ) // リセットピンだけはすぐにセットする
{
P0 = bits8(0,0,0,0, 0,0,1,1); // -,-,-,-, -,-,/reset2,/reset1
P3 = bits8(0,0,0,0, 1,1,1,1); // -,-,-,-, i2c_pu,scl_m,sda_m,/fcr_rst // 簡易I2Cは出力ラッチを1にする
}
else
{
// リセット後の初期値0が保証されているのは省略
// P0 = bits8(0,0,0,0, 0,0,0,0); // -,-,-,-, -,-,/reset2,/reset1
// P1 = bits8(0,0,0,0, 0,0,0,0); // bt_temp_p,bt_det_p,led_info_r,led_pow_b led_info_g,32khz_o,led_wifi,led_info_b
// P2 = bits8(0,0,0,0, 0,0,0,0); // ad_vol,ad_3d,acc_int1,led_chg, (sw_sel),(-),(-),(ext_vdd33)
P3 = bits8(0,0,0,0, 1,1,1,0); // -,-,-,-, i2c_pu,scl_m,sda_m,/fcr_rst // 簡易I2Cは出力ラッチを1にする
// P6 = bits8(0,0,0,0, 0,0,0,0); // -,-,-,-, -,-,sda2,scl2
// P7 = bits8(0,0,0,0, 0,0,0,0); // slp_o,/irq,led_cam,sw_wifi, sw_pow,pm_irw,shell_close,/extdc
// P12 = bits8(0,0,0,0, 0,0,0,0); // -,-,-,xtal, xtal,dip(機種判定)[1,0],slp_i
// P14 = bits8(0,0,0,0, 0,0,0,0); // -,-,-,-, -,-,i2c_pu,i2c_pu // i2c_puのポート設定はちゃんと専用関数を使って順番に。
// P15 = bits8(0,0,0,0, 0,0,0,0); // -,-,-,-, -,-,ad_bt_det,ad_bt_temp // ADはどっちでも
// P20 = bits8(0,0,0,0, 0,0,0,0); // -,-,accel2,sw_home, wl_tx,amoled_hv,sda1,sda2。 // spfl reboot時の液晶電源のケアは後ほど
/*--- タイマ・アレイ・ユニットの動作停止 ---*/
// TAU0EN = 0; /* タイマ・アレイ・ユニットへのクロック供給停止 */
TT0 = 0x00ff; /* 全タイマ・チャネルの動作停止 */
/*--- RTCの動作停止 ---*/
// 別途初期化関数
}
P4 = bits8(0,0,0,0, 1,0,0,0); // -,-,-,-, /chg_en, led_pow_r, dipsw[1,0]
P5 = bits8(0,0,0,0, 1,0,0,0); // -,-,-,-, i2c_pu,led_3d,/chg,/gyro_cs
/*--- 割り込み設定 ---------*/
// IF0 = 0x0000; /* 割り込み要求フラグクリア */
// IF1 = 0x0000;
// IF2 = 0x0000;
// MK0 = 0xFFFF; /* 割り込み禁止 */
// MK1 = 0xFFFF;
// MK2 = 0xFFFF;
// PM0 = bits8(1,1,1,1, 1,1,1,1); // BSRマイコンでは、reset1は監視のみになる。
PM1 = bits8(0,0,0,0, 0,0,0,0);
PM2 = bits8(1,1,1,0, 1,0,0,1);
PM3 = bits8(1,1,1,1, 1,0,0,0); // P31,32は簡易I2C
PM4 = bits8(1,1,1,1, 0,0,1,1);
PM5 = bits8(1,1,1,1, 1,0,1,0);
PM6 = bits8(1,1,1,1, 1,1,0,0); // I2CのラインがL出力になってしまうが、システムがOFFなのでかまわない
PM7 = bits8(0,1,0,1, 1,1,1,1);
// PM12 = bits8(1,1,1,1, 1,1,1,1); // 32kHzクロックのピン設定はどっちでもよい
PM14 = bits8(1,1,1,1, 1,1,0,0);
// PM15 = bits8(1,1,1,1, 1,1,1,1);
PM20 = bits8(1,1,1,1, 1,0,0,0); // p20.2はこれよりも前にLにしておくこと
PU20 = bits8(0,0,0,1, 0,0,0,1);
// PU0 = bits8(0,0,0,0, 0,0,0,0); // バッテリ認証後にそれぞれセット
// PU1 = bits8(0,0,0,0, 0,0,0,0);
// PU3 = bits8(0,0,0,0, 0,0,0,0); // 外部でプルアップしないと具合が悪い。CPUがプルアップする
// PU4 = bits8(0,0,0,0, 0,0,0,0); // 外部でプルアップしてほしいtool0,1)
PU5 = bits8(0,0,0,0, 0,0,1,0);
PU7 = bits8(0,0,0,1, 1,0,0,1); // irq(7.6)cpuがpu
// PU12 = bits8(0,0,0,0, 0,0,0,0);
// PU14 = bits8(0,0,0,0, 0,0,0,0);
// ポート入力モード・レジスタ設定 /////////////////////
// [0:通常入力バッファ 1:TTL入力バッファ]
// PIM3 = bits8(0,0,0,0, 0,0,0,0);
// PIM7 = bits8(0,0,0,0, 0,0,0,0);
// ポート出力モード・レジスタ設定
// [0:通常出力モード 1:N-chオープン・ドレーン出力]
POM3 = bits8(0,0,0,0, 0,1,1,0);
// POM7 = bits8(0,0,0,0, 0,0,0,0);
/* 割り込み優先順位、全て低位(LV3) */
// PR00 = 0xFFFF;
// PR01 = 0xFFFF;
// PR10 = 0xFFFF;
PR11 = 0xFFFE;
// PR02 = 0xFFFF;
// PR12 = 0xFFFF;
/*--- 外部割込の有効エッジ設定 ---*/
EGP0 = bits8(0,0,1,1, 0,0,0,1);
EGN0 = bits8(0,1,1,1, 0,0,0,0);
EGP2 = bits8(0,0,0,0, 1,0,1,0);
// EGN2 = bits8(0,0,0,0, 0,0,0,0);
/*--- キー割り込み設定 ---*/
// KRM = bits8(0,0,0,0, 0,0,0,0); /* 全キー割り込み信号を検出しない */
/*--- ADCの動作停止 ---*/
// ADCEN = 0; /* ADCへのクロック供給停止 */
// ADM = bits8(0,0,0,0, 0,0,0,0); /* 変換動作停止 */
/*--- シリアル・アレイ・ユニットの動作停止 ---*/
// SAU0EN = 0; /* シリアル・アレイ・ユニット0へのクロック供給停止 */
SCR00 = 0x0087; /* 各チャンネルの通信禁止 */
SCR01 = 0x0087;
SCR02 = 0x0087;
SCR03 = 0x0087;
// IICの動作停止
// IICA0EN = 0; /* IICA0(CTR)へのクロック供給停止 */
// IICCTL00 = 0x00; /* IICA1動作停止 */
// IICA1EN = 0; // IICA1(TWL)へのクロック供給停止
// IICCTL01 = 0x00; // IICA1動作停止
/*--- DMAの動作停止 ---*/
// DRC0 = bits8(0,0,0,0, 0,0,0,0); /* DMAチャネル0の動作禁止 */
// DRC1 = bits8(0,0,0,0, 0,0,0,0); /* DMAチャネル1の動作禁止 */
/*--- クロック出力/ブザー出力停止 ---*/
// CKS0 = bits8(0,0,0,0, 0,0,0,0);
// CKS1 = bits8(0,0,0,0, 0,0,0,0);
}

View File

@ -0,0 +1,6 @@
#ifndef _loader_h_
#define _loader_h_
#endif

View File

@ -0,0 +1,33 @@
/********************************************//**
magic.c
(touch)
$Id$
***********************************************/
#include "magic.h"
#include "config.h"
#ifndef _WIN32
#pragma section @@CNSTL MGC_LOAD AT 0x0FF6
__far const unsigned char MGC_LOADd[] = __TIME__;
#ifdef _firm_format_v3_
#pragma section @@CNST MGC_MIMI AT 0x2000
const unsigned char MGC_HEADdN[] = __TIME__;
#else
#pragma section @@CNST MGC_MIM2 AT 0x2100
const unsigned char MGC_HEADd[] = __TIME__;
#endif
#pragma section @@CNST MGC_TAIL AT 0x4FF6
const unsigned char MGC_TAILd[] = __TIME__;
#pragma section @@CNST MGC_VER AT 0x4FF4
const unsigned char MCU_VER[2] = { MCU_VER_MAJOR +'0', MCU_VER_MINOR +'0' };
#endif

View File

@ -0,0 +1,24 @@
#ifndef _magic_h_
#define _magic_h_
// magic.c の記述と違わないように注意!
#define MGC_LOAD 0x0FF6
#define MGC_FOOT 0x4FF6
#ifdef _firm_format_v3_
#define MGC_HEAD 0x2000
#else
#define MGC_HEAD 0x2100
#endif
#define MGC_LOAD_BKUP 0x1FF6
#define MGC_FOOT_BKUP 0x7FF6
#ifdef _firm_format_v3_
#define MGC_HEAD_BKUP 0x5000
#else
#define MGC_HEAD_BKUP 0x5100
#endif
#endif

100
snake_tags/3.40_jane/main.c Normal file
View File

@ -0,0 +1,100 @@
/* ========================================================
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();
}
}

View File

@ -0,0 +1,82 @@
#!/usr/bin/ruby
$KCODE = "S"
=begin
 NECの環境が吐きだしたSRECを
  0xFF
  BSRのアップデート用に必要な部分だけ切り出します
            0x0000 - 0x0FFF, 0x2000-0x47FF
=end
=begin
if( ARGV[0] == nil )
print( "input file name is nessesary!\nabort.\n" )
exit(1)
end
unless(File.exist?( ARGV[0] ))
print( "file" << ARGV[0] << " not found.\nabort.\n" )
exit(1)
end
=end
src = File.open( 'bsr.hex' )
dest = File.new( "hoge.bin","wb" )
dest.write( 'jhl' )
### get data ##########################
src_in = Hash.new
tempA = Array.new
dataTemp = Array.new
offset = Numeric.new
bindata = Array.new( 32*1024, 0xFF )
while(src.readline)
tempA = $_.scan(/(\:)(\w\w)(\w\w\w\w)(\w\w)(\w+)(\w\w)/)
break if( tempA.size == 0 )
src_in = { "len" => tempA[0][1], "offset" => tempA[0][2], "type" => tempA[0][3], "data" => tempA[0][4], "CRC" => tempA[0][5] }
break if src_in["type"].hex == 01
break if src_in["len"].hex == 00
# next if src_in["type"].hex != 00
if( src_in["type"].hex != 00 )
# p dat
next
end
offset = src_in["offset"].hex
next if(( 0x1000 <= offset ) && ( offset < 0x2000 ))
dataTemp = src_in["data"].scan(/\w\w/)
( 0...(src_in["len"].to_s.hex) ).each{|i|
bindata[ offset + i ] = ( dataTemp[ i ] ).to_s.hex
}
end
### debug enable bit check #############
# デバッグ許可になっているとISデバッガで起動しないMCUが動作しない
p bindata[0xC3]
if( bindata[0xC3] != 0x04 )
print( "!E debug enable!!" )
exit( 1 )
end
### format data and output #############
4096.times{
bindata.delete_at(4096)
}
dest.write( bindata[0..(0x4FFF - 0x1000)].pack("c*") )
dest.close
printf( "intel-HEX to bsr bin converter\n file converted!\n\n" )

View File

@ -0,0 +1,567 @@
/* ********************************************************
3
$Id$
********************************************************* */
#ifndef _WIN32
#pragma mul
#pragma div
#pragma bcd
#endif
#include "incs.h"
#ifndef _WIN32
#include <math.h>
#endif
#include "accero.h"
#include "pedometer.h"
#include "pool.h"
// ========================================================
// 履歴の最終記録時刻
// この順番はログ読み出しの順番でもあるのでいじらないでね
// 順番にアドレスの若いのから確保されるのを期待してます...
typedef struct{
u8 hour_bcd;
u8 day_bcd;
u8 month_bcd;
u8 year_bcd;
u8 min_bcd;
u8 sec_bcd;
}st_calender;
// ========================================================
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;
// ========================================================
#define _use_my_sqrt_
#ifdef _use_my_sqrt_
static unsigned long my_sqrt( unsigned long );
#endif
// 今年は閏年?
#define is_leapyear( y ) (( y & 0x03 ) == 0 )
// 「去年」は閏年?
#define is_firstyear( y ) (( y & 0x03 ) == 1 )
// 加速度センサ値をFIR-LPFに通す。それの係数
extern const s8 lpf_coeff[];
#define TAP 64
#define FIL_COEFF_QUANT 10
/********************************************//**
 
***********************************************/
void pedometer()
{
static s16 th_H = 15000; // 閾値。動的変更します
static s16 th_L = 11000;
static u16 acc_norm[3]; // 加速度の大きさのヒストリ。数字が大きい方が古い
static u16 acc_norm_temp;
static u8 interval_hh = 0xFF; // 山-山間の時間。短過ぎたらはじく。
static u8 time_l; // 前回の極小からの経過時間
static u16 peak_l; // 谷の深さ
static u16 norm_hist[TAP];
static u8 hist_indx;
signed long filterd;
u8 i;
u16 sx16,sy16,sz16;
DI_wt_chk();
sx16 = abs( (u16)vreg_ctr[VREG_C_ACC_XH] * 256 + vreg_ctr[VREG_C_ACC_XL] );
sy16 = abs( (u16)vreg_ctr[VREG_C_ACC_YH] * 256 + vreg_ctr[VREG_C_ACC_YL] );
sz16 = abs( (u16)vreg_ctr[VREG_C_ACC_ZH] * 256 + vreg_ctr[VREG_C_ACC_ZL] );
EI();
// ベクトルのノルム
#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_
norm_hist[ hist_indx & TAP-1 ] = normh * 256 + norml;
#endif
hist_indx ++;
// ヒストリにフィルタ(fir)を掛けて、今回の値を求める //
filterd = 0;
// for( i = 8; i != 55; i++ ) // 係数が0ばかりのため
for( i = 0; i != 46; i++ ) // 係数テーブルをいじりました。パラメータ調整時注意
{
filterd += (signed long)norm_hist[ ( hist_indx + i ) & TAP-1 ] * lpf_coeff[ i ];
}
filterd += (4096)*512; // DC分加算...だったと思う
acc_norm_temp = (s16)( filterd /1024 & 0xFFFF ); // ←FIL_COEFF_QUANTから正規化
/*
if( acc_norm[0] < acc_norm_temp )
{
t_rise ++;
if( t_rise == 0 )
t_rise == 254;
}
else
{
t_rise = 0;
}
*/
if( acc_norm[0] != acc_norm_temp )
{
acc_norm[2] = acc_norm[1]; // ヒストリ
acc_norm[1] = acc_norm[0];
acc_norm[0] = acc_norm_temp;
}
if( acc_norm[2] <= acc_norm[1] && acc_norm[1] > acc_norm[0]
&& acc_norm[0] > th_H )
// 極大で、閾値を超えていた
{
if( 21 < interval_hh )
// 前回の極大からの間隔がほどよい
{
if(( interval_hh < 160 ) && ( time_l < interval_hh ))
// 谷を挟んでいる
{
if( acc_norm[0] - peak_l > 4200 ){
// ■一歩増えました
hosu_increment_if_necessary();
}
}
interval_hh = 0;
}
// なんちゃって閾値の動的変更
if( acc_norm[0] > 18000 )
{
th_L = acc_norm[0] - 10000;
}
else
{
th_L = 11000;
}
}
else
{
if( interval_hh != 255 ) // 飽和加算って楽に書けたらいいのに
{
interval_hh ++;
}
}
// (2) 直近の極小からの時間
if( acc_norm[2] >= acc_norm[1] && acc_norm[1] < acc_norm[0]
&& acc_norm[0] < th_L )
{
// 極小を検出
time_l = 0;
peak_l = acc_norm[0];
}
else
{
if( time_l != 255 )
{
time_l ++;
}
}
}
/********************************************//**
 
-
-
*2011/01/20
 
***********************************************/
#define HOSU_NODATA 0xFFFF
#define HOSU_MAX 0xFFFE
void hosu_increment_if_necessary()
{
u8 year_compd; // hour境界補正済み現在年。comp(ensation -ed)
// 現在時刻取得
DI_wt_chk();
RWAIT = 1;
while( !RWST ){;}
cal_temp.hour_bcd = HOUR;
cal_temp.day_bcd = DAY;
cal_temp.month_bcd = MONTH;
cal_temp.year_bcd = YEAR;
cal_temp.min_bcd = MIN;
cal_temp.sec_bcd = SEC;
RWAIT = 0;
EI();
year_compd = bcdtob( cal_temp.year_bcd );
now_longhour = get_long_hour();
// 書き込みポインタの更新
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でゼロ判定するのはデジタル回路屋の方言みたい
{
// 歩数計が止まっていた時間を考慮して必要なら進める
// 補正計算 元旦零時台で昨日扱いになった場合、大晦日の23時台に上書き
if( now_longhour == (u16)-1 ) // 昨年大晦日の23時台扱いのとき、計算結果が -1 になってる
{
now_longhour = 365 * 24 -1;
if( is_firstyear(year_compd) )
{
now_longhour += 24;
}
year_compd --;
}
fill_hosu_hist_hours( calc_hours_spend( year_compd ) ); // ■書き込みポインタの更新も行う
// ログあふれで記録停止?
if( pedolog_overflow )
{
return;
// おしまい。ログの更新もなし。
}
}
// インクリメントして良い
cal_log_latest = cal_temp; // ■ログ時刻更新
last_hour_fny = now_longhour;
// 毎時ログ インクリメント
if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_MAX )
{
// 何もしないでおしまい
//. 小計の合計と累計があわなくなるのを避けるためだろうけど、どうなの?
return;
}
else if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA ) // その時間帯最初のカウントの時
{ // これしないと1歩足りない
pool.vreg_c_ext.pedo_log[ p_record ] = 1;
}
else
{
// 通常パス
pool.vreg_c_ext.pedo_log[ p_record ] ++;
}
// 累積の更新 //
DI_wt_chk();
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_H ] == 0 ){
vreg_ctr[ VREG_C_ACC_HOSU_L ] = 255; //. いろいろ失敗だったね...
vreg_ctr[ VREG_C_ACC_HOSU_M ] = 255;
vreg_ctr[ VREG_C_ACC_HOSU_H ] = 255;
}
}
}
EI();
}
/********************************************//**
0
***********************************************/
static void fill_hosu_hist_hours( u16 hours )
{
// ログあふれ?
if( (u16)p_record + hours >= PEDOMETER_LOG_SIZE )
{
pedolog_overflow = true;
return;
}
// 空白の数時間の設定
while( hours != 0 )
{
// 新仕様 いっぱいで停止
p_record ++;
#if 1 // debug
if( p_record >= PEDOMETER_LOG_SIZE )
{
pedolog_overflow = true;
// dbg_nop(); // ここに来るようだとバグ
break;
}
else
#endif
{
pool.vreg_c_ext.pedo_log[ p_record ] = 0;
}
hours --;
}
return;
}
/********************************************//**
***********************************************/
void clear_hosu_hist()
{
u8 hours = PEDOMETER_LOG_SIZE;
do
{
hours --;
pool.vreg_c_ext.pedo_log[ hours ] = 0xFFFF;
}
while( hours != 0 );
DI_wt_chk();
vreg_ctr[ VREG_C_ACC_HOSU_L ] = 0;
vreg_ctr[ VREG_C_ACC_HOSU_M ] = 0;
vreg_ctr[ VREG_C_ACC_HOSU_H ] = 0;
p_record = 0;
pedolog_overflow = false;
EI();
}
extern u8 iic_burst_state;
bit pedolog_read_msb;
/********************************************//**
...
***********************************************/
u8 hosu_read( )
{
u8 rv;
static u8 p_record_buffer;
static st_calender cal_buff; // 一応、アトミック処理に
if( iic_burst_state == 0 )
{
p_record_buffer = p_record;
DI_wt_chk();
cal_buff = cal_log_latest;
EI();
}
if( iic_burst_state <= 5 )
{
rv = *( (u8*)&cal_buff + iic_burst_state ); // あうあう
iic_burst_state ++;
return( rv );
}
else
{
u16 temp;
// 16ビットで記録してあるのでばらして送る /// もっと楽する方法があるんじゃ
temp = pool.vreg_c_ext.pedo_log[ p_record_buffer ];
if( !pedolog_read_msb )
{
rv = (u8)( temp & 0x00FF );
}
else
{
rv = (u8)(( temp >> 8 ) & 0x00FF );
if( p_record_buffer == 0 )
{
p_record_buffer = PEDOMETER_LOG_SIZE-1;
}
else
{
p_record_buffer --;
}
}
pedolog_read_msb ^= 1;
return( rv );
}
}
/********************************************//**
(hour)
u16 long_hour
***********************************************/
const u16 DAYS_FROM_HNY[] = {
0,
31,
31+28, // =59。 日は
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
};
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;
// まず日数の部分
long_hour = DAYS_FROM_HNY[ month -1 ]; // -1はインデックス合わせ
if( is_leapyear(year) && ( 3 <= month ))
{
// 閏年で、閏日より後
long_hour ++;
}
long_hour += day - 1;
long_hour *= 24; // 日数→時間
long_hour += hour;
// 時・分境界の前?後?
if( ( min_bcd > vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
|| ( ( min_bcd >= vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY ] )
&& ( sec_bcd >= vreg_ctr[ VREG_C_ACC_HOSU_HOUR_BOUNDARY_SEC ] ))
)
{
return( long_hour );
}
else
{
return( long_hour -1 ); // 1時間前に含める 注意:元旦で昨年扱いにするとき。-1 になる
}
}
/********************************************//**
 
 
pc上でシミュレーションして大丈夫そう
***********************************************/
static 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;
}
/********************************************//**
  fill_hosu_hist_hours
//. 引数がyear_bcd なのがちょっといやだけど...
***********************************************/
static u16 calc_hours_spend( u8 year )
{
u8 cal_log_latest_year = bcdtob( cal_log_latest.year_bcd );
// 同じ年の内
if( cal_log_latest_year == year )
{
if( now_longhour > last_hour_fny )
{
return( now_longhour - last_hour_fny );
}
else if( now_longhour == 0 && last_hour_fny != 0 )
{
// 年明けたばかりで、境界を越えた一回目。これやらないと昨年最後に加算してしまう。
return( 1 );
}
else
{
return( 0 ); // 同じ時間帯(と、巻き戻り。 どうなっても知らない)
}
}
else if( cal_log_latest_year == ( year -1 ) )
{
// 年をまたいでいるとき
u16 temp = 365 * 24 - last_hour_fny + now_longhour;
if( is_firstyear(year) )
{
temp += 24;
}
return( temp );
}
else if( cal_log_latest_year < year )
{
// 数年放置
return( PEDOMETER_LOG_SIZE +1 );
}
else
{
// カレンダーが巻き戻るなど
// ノーケアでよい…が、不定値というわけにもいかない
return( 0 );
}
}

View File

@ -0,0 +1,87 @@
/********************************************//**
使LPFのフィルタ係数
$Id$
***********************************************/
#include "incs.h"
// =========================================================
#define TAP 64
#define FIL_COEFF_QUANT 10
const s8 lpf_coeff[]={
/*
Window Function Algorithm LPF
Sampling Frequency = 100.0
cutoff1 = 6.0000000
Tap Count =64
Kaiser Constant = 7.000000
Quantized by 11 [bits]
*/
/* 0,// [0]
0,
0,
0,
0,
0,
0,
0,
*/
1,// 8
2,
2,
3,
3,
2,
0,
-2,
-5,// 16
-9,
-13,
-16,
-16,
-13,
-6,
4,
18,// 24
37,
56,
77,
95,
110,
119,
122,
119,// 32
110,
95,
77,
56,
37,
18,
4,
-6,// 40
-13,
-16,
-16,
-13,
-9,
-5,
-2,
0,// 48
2,
3,
3,
2,
2,
1,
/*
0,
0,// 56
0,
0,
0,
0,
0,
0,
0
*/
};

View File

@ -0,0 +1,84 @@
#ifndef _pedo_coeff_h_
#define _pedo_coeff_h_
// =========================================================
#define TAP 64
#define FIL_COEFF_QUANT 10
const s8 lpf_coeff[]={
/*
Window Function Algorithm LPF
Sampling Frequency = 100.0
cutoff1 = 6.0000000
Tap Count =64
Kaiser Constant = 7.000000
Quantized by 11 [bits]
*/
/* 0,// [0]
0,
0,
0,
0,
0,
0,
0,
*/
1,// 8
2,
2,
3,
3,
2,
0,
-2,
-5,// 16
-9,
-13,
-16,
-16,
-13,
-6,
4,
18,// 24
37,
56,
77,
95,
110,
119,
122,
119,// 32
110,
95,
77,
56,
37,
18,
4,
-6,// 40
-13,
-16,
-16,
-13,
-9,
-5,
-2,
0,// 48
2,
3,
3,
2,
2,
1,
/*
0,
0,// 56
0,
0,
0,
0,
0,
0,
0
*/
};
#endif

View File

@ -0,0 +1,36 @@
#ifndef _pedo_
#define _pedo_
#ifdef WIN32
typedef unsigned char bit;
typedef unsigned char u8;
typedef unsigned short u16;
#endif
// =========================================================
extern bit pedolog_read_msb;
// =========================================================
//void hosu_read_end( ); ƒ}ƒNƒ<4E>‰»
#define hosu_read_end() pedolog_read_msb = 0
u8 hosu_read( );
void hosu_increment_if_necessary();
void fill_hosu_hist_hours( u16 );
void clear_hosu_hist();
void pedometer();
// =========================================================
#define PEDOMETER_LOG_SIZE ( 24 * 7 )
// =========================================================
#endif

1554
snake_tags/3.40_jane/pm.c Normal file

File diff suppressed because it is too large Load Diff

222
snake_tags/3.40_jane/pm.h Normal file
View File

@ -0,0 +1,222 @@
#ifndef __PM__
#define __PM__
/*
$Id$
*/
#define IIC_SLA_PMIC 0x84
#define IIC_SLA_BT_GAUGE 0x6C
#define VCOM_DEFAULT_T 92
#define VCOM_DEFAULT_B 95
#define BATT_TH_LO 10
#define BATT_TH_EMPTY 5
// 電圧レジスタと直接比較できる用にオフセット
#define V_BT_4000MV (u16)( 4000 * 12.8 ) // 電圧読み出し失敗用 4000mV設定
#define V_TH_30 (u16)( 3300 * 12.8 ) // 30%
#define V_TH_LO (u16)( 3200 * 12.8 ) // 10%
#define V_TH_EMPTY (u16)( 3150 * 12.8 ) // 5%
#define V_TH_ZERO (u16)( 3100 * 12.8 ) // 0%
#define V_TH_FORCE_OFF (u16)( 2900 * 12.8 ) // 2.9V 最終強制断
//=========================================================
#ifdef _WIN32
#define LED_CHARGE mcuRegP[ _P2_4 ]
#else
#define LED_CHARGE P2.4
#endif
//=========================================================
enum PMIC_REG_ADRS
{
PM_REG_ADRS_VER = 0x00, // verinfo など
PM_REG_ADRS_VDD_SYS, // システムが使用する電源
PM_REG_ADRS_VDD_LCD, // 液晶電源
PM_REG_ADRS_CONT, // /RESET1, LoadSwitch
PM_REG_ADRS_BL, // バックライト on/off
PM_REG_ADRS_POW_SAVE, // 省電力設定
PM_REG_ADRS_POW_DAC1,
PM_REG_ADRS_POW_DAC2
};
enum BT_GAUGE_REG_ADRS
{
BT_GAUGE_REG_VCELL = 0x02, // それぞれ16ビットのため
BT_GAUGE_REG_SOC = 0x04,
BT_GAUGE_REG_MODE = 0x06,
BT_GAUGE_REG_VERSION = 0x08,
BT_GAUGE_REG_OCV = 0x0E,
BT_GAUGE_REG_RCOMP = 0x0C,
BT_GAUGE_REG_LOCK = 0x3E,
BT_GAUGE_REG_BT_PARAM = 0x40,
BT_GAUGE_REG_COMMAND = 0xFE,
BT_GAUGE_REG_RCOMP_EXT = 0x80,
};
typedef enum BT_VENDER
{
BT_VENDER_MAXELL = 0, // ショート
BT_VENDER_1, // 120
BT_VENDER_2, // 360
BT_VENDER_3, // 750
BT_VENDER_4, // 1.3k
BT_VENDER_PANA = 5, // 2.7k
BT_VENDER_6, // 8.2k
BT_VENDER_OPEN = 7, // open
BT_VENDER_NOT_CHECKED = 0xFF,
}BT_VENDER;
enum NTR_PM_BT_STATUS{
NTR_PM_BT_ENOUGH,
NTR_PM_BT_EMPTY,
NTR_PM_BT_NOT_INITIALIZED = 0xFF
};
//=========================================================
// CODEC上のPMIC互換レジスタ
#define CODEC_REG_PM 0x10
#define CODEC_REG_BL 0x11
#define CODEC_REG_BT 0x12
//#define CODEC_REG_VOL 0x13 // ...都合により、adc.hで定義
// TWLがSPIでPMICに投げたコマンド
#define REG_BIT_TWL_REQ_OFF_REQ ( 1 << 6 )
#define REG_BIT_TWL_REQ_RST_REQ ( 1 << 0 )
#define REG_BIT_TWL_REQ_BL ( 3 << 2 )
// 0x03 pw cnt3
#define PM_REG_BIT_LDSW ( 1 << 0 )
#define PM_REG_BIT_nRST1 ( 1 << 1 )
// 0x01 pw cnt1
#define PM_REG_BIT_VDD_CTR 0x0F
#define PM_REG_BIT_VDD50A ( 1 << 4 )
// 0x02 pw cnt2
#define PM_REG_BIT_VDDLCD_CGS 0x07
#define PM_REG_BIT_VDDLCD_AMO 0x05
#define PM_REG_BIT_LCD_VCS ( 0x01 << 4 )
#define PM_REG_BIT_LCD_TCOM ( 0x01 << 3 )
// 0x04 bl cnt
#define PM_REG_BIT_BL_U 0x01
#define PM_REG_BIT_BL_L 0x02
// 0x05 pow save
#define PM_REG_BIT_VDD1P_1R15 bits8(0,0,0,0, 0,0,0,0)
#define PM_REG_BIT_VDD1P_1R05 bits8(0,0,0,0, 1,0,0,0)
#define PM_REG_BIT_VDD1P_1R00 bits8(0,0,0,1, 0,0,0,0)
#define PM_REG_BIT_VDD1P_0R95 bits8(0,0,0,1, 1,0,0,0)
#define PM_REG_BIT_VDD1P_0R90 bits8(0,0,1,0, 0,0,0,0)
#define PM_REG_BIT_VDD_AUTO bits8(0,0,0,0, 0,1,1,1)
#define PM_REG_BIT_VDD_PWM bits8(0,0,0,0, 0,0,0,0)
#define DELAY_PM_TW_PWUP 16 + 2
#define DELAY_PM_TSS_50B_AND_TCOM 17 + 1
#define DELAY_PM_5V_TO_TCOM 17 + 1
#define DELAY_PM_TCOM_TO_VCS 3
#define DELAY_PM_VCS_TO_BL ( 17 + 5 )
#define DELAY_PM_LCD_OFF ( 50 + 1 )
//=========================================================
extern u8 raw_adc_temperature;
extern BT_VENDER battery_manufacturer;
extern bit bt_force_update;
extern u8 pmic_version;
extern u8 mgic_version[];
extern u8 pm_reg_bit_vddlcd; // アモルファス対応(電源シーケンスが違う)
extern u8 pmreg_v_core; // SoCのコア電圧設定。SNAKE(LAGER)で変更があるため。
//=========================================================
err PM_sys_pow_on( );
void PM_sys_pow_off( );
//err PM_bt_auth( );
void PM_LCD_vcom_set( );
err PM_LCD_on( );
void PM_LCD_off( );
err PM_BL_set( u8 );
void BT_chk();
void BT_get_left();
void pm_chk_adapter();
void codec_reg_init();
void set_vdd_voltages( enum family_ family );
void reset_release();
task_status_immed tski_BT_temp_update( );
task_status_immed tski_vcom_set( );
task_status_immed tski_PM_LCD_on();
task_status_immed tski_PM_LCD_off();
task_status_immed tski_PM_BL_set();
err send_cmd_pmic( u8 reg, u8 dat );
u8 read_pmic( u8 reg );
#define PM_Chg_Stop() { BT_TEMP_P = 0; BT_CHG_DISABLE(); LED_CHARGE = 0; bt_authorized = false; }
//  これを呼ぶ前に、現在温度を教えておく必要があります。
#define PM_reset() ( send_cmd_pmic( PM_REG_ADRS_CONT, 0x00 ) )
//=========================================================
// 元栓 //
#define PM_LDSW_on() ( send_cmd_pmic( PM_REG_ADRS_CONT, PM_REG_BIT_LDSW ))
#define PM_LDSW_off() ( send_cmd_pmic( PM_REG_ADRS_CONT, 0 ))
// システム電源 //
#define PM_VDD_on() ( send_cmd_pmic( PM_REG_ADRS_VDD_SYS, PM_REG_BIT_VDD_CTR ))
#define PM_VDD50A_on() ( send_cmd_pmic( PM_REG_ADRS_VDD_SYS, ( PM_REG_BIT_VDD_CTR | PM_REG_BIT_VDD50A )))
#define PM_VDD_off() ( send_cmd_pmic( PM_REG_ADRS_VDD_SYS, 0 ))
#define PM_off() PM_VDD_off()
// CPU電源
#define PM_VDD_normMode() ( send_cmd_pmic( PM_REG_ADRS_POW_SAVE, pmreg_v_core | PM_REG_BIT_VDD_PWM ))
#define PM_VDD_ecoMode() ( send_cmd_pmic( PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_0R90 | PM_REG_BIT_VDD_AUTO ))
// ほか //
#define PM_reset_neg() ( send_cmd_pmic( PM_REG_ADRS_CONT, ( PM_REG_BIT_LDSW | PM_REG_BIT_nRST1 )))
// #define PM_reset_ast() // ちゃんと read modify write するようにします
void PM_reset_ast();
#define PM_chk_LDSW() ( read_pmic( PM_REG_ADRS_CONT ) & PM_REG_BIT_LDSW ) // 1のとき、元電源on
// 液晶系電源 //
#define PM_VDDLCD_on() ( send_cmd_pmic( PM_REG_ADRS_VDD_LCD, pm_reg_bit_vddlcd ))
#define PM_TCOM_on() ( send_cmd_pmic( PM_REG_ADRS_VDD_LCD, ( pm_reg_bit_vddlcd | PM_REG_BIT_LCD_TCOM )))
#define PM_VCS_on() ( send_cmd_pmic( PM_REG_ADRS_VDD_LCD, ( pm_reg_bit_vddlcd | PM_REG_BIT_LCD_VCS | PM_REG_BIT_LCD_TCOM )))
#define PM_TCOM_off() ( send_cmd_pmic( PM_REG_ADRS_VDD_LCD, ( pm_reg_bit_vddlcd | PM_REG_BIT_LCD_VCS )))
#define PM_TCOM_VCS_off() PM_VDDLCD_on()
#define PM_VDDLCD_off() ( send_cmd_pmic( PM_REG_ADRS_VDD_LCD, 0 ) )
#define PM_set_BL( dat ) ( send_cmd_pmic( PM_REG_ADRS_BL, dat ) )
#define PM_set_adc1( dat ) ( send_cmd_pmic( PM_REG_ADRS_POW_DAC1, dat ) )
#define PM_set_adc2( dat ) ( send_cmd_pmic( PM_REG_ADRS_POW_DAC2, dat ) )
#endif // __PM__

View File

@ -0,0 +1,24 @@
#ifndef _pool_h_
#define _pool_h_
#include "pedometer.h"
#define VREG_C_FREE_SIZE 200
// 空いてるメモリ
typedef struct _st_vreg_c_ext{
unsigned short pedo_log[ PEDOMETER_LOG_SIZE ];
unsigned char vreg_c_free[ VREG_C_FREE_SIZE ];
}st_vreg_c_ext;
typedef union _uni_pool
{
st_vreg_c_ext vreg_c_ext;
u8 self_update_work[ 256 ]; // 256以上はまとめ書きできない
}uni_pool;
extern uni_pool pool;
#endif

View File

@ -0,0 +1,16 @@
ビルド方法
nec electronics 製の IDE、PM+ からビルド
カスタムMCUなので、一般には配布されていない定義ファイルが必要
●2.2C
SNAKE 対応 (試作プリライト)
●2.2D
SNAKE 向け system updater は mcu プロセス作成時に誤ったため、
バージョン番号のみ、2.2D になっている

View File

@ -0,0 +1,23 @@
/********************************************************//*
$Id$
**********************************************************/
#pragma SFR
#include "incs_loader.h"
void my_reboot(){
#asm
MOV PSW,#06H ; PSWをセット
MOVW AX,#000d0h ;
PUSH PSW
PUSH AX ; RETIのためのスタックを準備
RETI ;
#endasm
}

View File

@ -0,0 +1,6 @@
#ifndef __MYREBOOT__
#define __MYREBOOT__
void my_reboot();
#endif

View File

@ -0,0 +1,313 @@
#ifndef _WIN32
#pragma section @@CODE ROM_CODE
#pragma nop
#pragma ei
#pragma di
#pragma sfr
#endif
#ifdef _WIN32
typedef unsigned char bit;
typedef unsigned char u8;
#endif
/******************************************************************************
iTRONにはコンフィギュレータがあるはずだ
ctr_mcu_config.rb task_config.hが作成されます
*****************************************************************************/
#include "renge.h"
#include "renge_task_intval.h"
#include "renge_task_immediate.h"
#include "..\WDT.h"
#include "..\config.h"
#include "..\user_define.h"
#include "..\util_funcs.h"
#ifdef _WIN32
#include "../sim/simOnWin.h"
#endif
//#define _renge_test_
#define true 1
#define false 0
//******************************************************************************
u8 renge_flg_interval;
bit renge_task_interval_run_force;
bit renge_task_immediate_not_empty;
#include "..\bsr_system.h"
extern system_status_ system_status;
//******************************************************************************
static void renge_task_immed_init();
static void renge_task_immed_del();
//******************************************************************************
task_status_immed ( *tasks_immed[ TASK_IMMED_RUN_LIST_MAX ] )();
/******************************************************************************
*****************************************************************************/
void renge_init(){
renge_task_immed_init();
/*
RTCを流用しているのでコメントアウト
#define renge_tick 19xxxxxxx [ms]
renge_interval_init(); RTC_init();
*/
}
/******************************************************************************
*****************************************************************************/
/*
void renge_interval(){
// RTCがやってくれる
__interrupt void int_rtc_int();
}
*/
/******************************************************************************
*****************************************************************************/
__callt err renge_task_interval_run(){
u8 i;
// インターバル起動
DI_wt_chk();
if(( renge_flg_interval != 0 ) ||
( renge_task_interval_run_force )) /// 統合したかったな…
{
renge_task_interval_run_force = false; // 今から起動するタスク、割り込むタスクでフラグが立つかもなので
if( renge_flg_interval != 0 )
{
renge_flg_interval --;
WDT_Restart( );
}
EI();
for( i = 0; i != TSK_LAST; i ++ )
{
tasks[ i ]();
// 逐次起動タスクがあったら間に挟む
renge_task_immed_run();
}
}
EI();
return( ERR_SUCCESS );
}
/*****************************************************************************
task_immed
tickI2C通信完了など
 TSKI_FINISHED 
    
*****************************************************************************/
/**************************************
**************************************/
void renge_task_immed_init(){
u8 i;
for( i = 0; i < TASK_IMMED_RUN_LIST_MAX; i++ ){
tasks_immed[ i ] = TSK_IMM_EMPTY_;
}
}
/**************************************
36us
**************************************/
__callt err renge_task_immed_add( task_status_immed (*new_task)() ){
u8 i;
// リストの空きの先頭に登録
// 削除したばかりのタスクは、削除マーク(TSK_IMM_DELETED_)となり、空きとは明示的に区別される
// 重複登録を避ける
for( i = 0; i < TASK_IMMED_RUN_LIST_MAX; i ++ )
{
DI_wt_chk();
if( tasks_immed[ i ] == TSK_IMM_EMPTY_ )
{
// 空きを見つけた
tasks_immed[ i ] = new_task;
EI();
return( ERR_SUCCESS );
}
else
{
// 重複登録チェック
/// 歯抜けになってない、前詰めされてる前提
if( tasks_immed[ i ] == new_task )
{
// 重複登録はしない
EI();
return( ERR_ERR );
}
}
EI();
}
// タスク登録しすぎ(無いはず
return( ERR_ERR );
}
/**************************************
**************************************/
__callt err renge_task_immed_run(){
u8 list_id;
// while( tasks_immed[ 0 ] != TSK_IMM_EMPTY_ )
if( tasks_immed[ 0 ] != TSK_IMM_EMPTY_ )
{
DI_wt_chk();
for( list_id = 0; list_id < TASK_IMMED_RUN_LIST_MAX; list_id ++ ){
if( tasks_immed[ list_id ] == TSK_IMM_EMPTY_ ){
// リスト完了
EI();
break;
}
#ifdef _renge_test_
else if( tasks_immed[ list_id ] == TSK_IMM_DELETED_ )
{
EI();
NOP();
// タスク管理の不備
// 存在しないタスクを実行しようとした
// タスクの削除後の処理がまずい
// 予期しないタイミングで immed_run が呼ばれた
}
#endif
else
{
u8 rv;
EI();
rv = tasks_immed[ list_id ](); // タスク実行
if( rv == ERR_SUCCESS )
{
tasks_immed[ list_id ] = TSK_IMM_DELETED_;
}
// きわどいタイミングで同じタスクの登録があると困るのでDI状態でかえって来る事がある
}
DI_wt_chk();
}
// リスト上のタスクを一通り実行した
// タスク削除 //
{
u8 i = 0; // リストの並べ替え先
u8 j = 1;
// 必ず i < j、j < TASK_IMMED_RUN_LIST_MAX (でないとタスクあふれ)
while( 1 )
{
if( tasks_immed[ i ] == TSK_IMM_EMPTY_ )
{
// 前詰め完了 && リスト空っぽ
// break;
goto imm_list_sort_fin;
}
else if( tasks_immed[ i ] == TSK_IMM_DELETED_ )
{
for( ; j < TASK_IMMED_RUN_LIST_MAX; j++ )
{
if( tasks_immed[ j ] == TSK_IMM_DELETED_ )
{
// 隣(?)も削除対象だった
// next j
}
else
{
DI_wt_chk();
if( tasks_immed[ j ] == TSK_IMM_EMPTY_ )
{
do{
j --;
tasks_immed[ j ] = TSK_IMM_EMPTY_;
// リスト前詰め完了
}while( i < j );
EI();
goto imm_list_sort_fin;
}
else
{
// 前詰めすべきタスクを見つけた
tasks_immed[ i ] = tasks_immed[ j ];
tasks_immed[ j ] = TSK_IMM_DELETED_;
i ++;
EI();
}
}
}
}
else
{
// このタスク、滞留
}
i ++;
}
}
}
imm_list_sort_fin:
// ここまでで完全に前詰めされている
#ifdef _renge_test_
/// ほんと?
{
u8 a,b;
a = 0;
for( b = 0 ; b < TASK_IMMED_RUN_LIST_MAX; b++ )
{
if( tasks_immed[ b ] == TSK_IMM_EMPTY_ )
{
a = 1;
}
else
{
if( a != 0 )
{
NOP(); // EMPTYより後ろにタスクやdeletedが有る
}
}
}
}
#else
NOP(); // なんか無いとリンカが怒る
#endif
// }
return( ERR_SUCCESS );
}

View File

@ -0,0 +1,26 @@
#ifndef __renge__
#define __renge__
//******************************************************************************
//******************************************************************************
#include "renge_defs.h"
#include "renge_task_immediate.h"
// #include "renge_task_interval_run.h" // 外から強制起動禁止!
//******************************************************************************
void renge_init();
void renge_task_immed_init();
__callt err renge_task_immed_run();
__callt err renge_task_immed_add( task_status_immed (*p_task_func)() );
// static err renge_task_immed_del( u8 );
//******************************************************************************
__callt err renge_task_interval_run();
extern u8 renge_flg_interval;
extern bit renge_task_interval_run_force; // タスク強制実行フラグ
#endif

View File

@ -0,0 +1,55 @@
#ifndef __renge_defs__
#define __renge_defs__
/******************************************************************************
Renge Ver.0 (2009/04/09)
2009- 7k4jhl R.Fujita @ RED.nintendo
OSにはほど遠い
Range Typo
******************************************************************************/
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
// ************************************
#define SYS_INTERVAL_TICK 1.953
// ************************************
typedef enum _ERR
{
ERR_SUCCESS = 0,
ERR_ERR
}err;
typedef enum _IMMED_TASK_ERR
{
TSKI_FINISHED = 0,
TSKI_CONTINUE
}IMMED_TASK_ERR;
/**************************************
*************************************/
typedef void task_status;
/**************************************
*************************************/
typedef IMMED_TASK_ERR task_status_immed;
#endif

View File

@ -0,0 +1,59 @@
#!/usr/bin/ruby -Ks
tasklist = Array.new
if( ARGV[0] == nil )
printf( "既定ファイル renge_tasks.txt を使用します" )
datfile = "renge_tasks.txt"
else
datfile = ARGV[0]
end
if( !File.exist?( datfile ) )
printf("設定ファイルが見つかりません。")
exit( 1 )
end
setting = File.open( datfile )
setting.each{|dat|
dat.chomp!
if( dat != nil )
tasklist << dat
end
}
tasklist.each{|dat|
printf( "\n%s" , dat )
}
printf( "\n----------\nタスク数 %d \n", tasklist.size )
#----- 静的タスクの列挙 -------------------------------------------------------
conf = File.new( "renge_task_intval.h", "w+" )
conf << "/*スクリプトによる自動生成です。手動で書き換えない方がよいです*/\n\n"
conf << "#ifndef __renge_task__\n#define __renge_task__\n\n"
conf << "#include \"renge_defs.h\"\n\n"
conf << "enum {\n "
tasklist.each{|dat|
conf << "TSK_" << dat.upcase << ", "
}
conf << "TSK_LAST \n };\n\n"
tasklist.each{|dat|
conf << "extern void tsk_" << dat << "();\n"
}
conf << "\n"
conf << "const void ( *tasks[ TSK_LAST ] )() = {\n"
tasklist.each{|dat|
conf << " tsk_" << dat << ",\n"
}
conf << " };\n"
conf << "\n#endif\n"

View File

@ -0,0 +1,25 @@
#ifndef __tasks__
#define __tasks__
#include "renge_defs.h"
// *************************************
#define TASK_IMMED_RUN_LIST_MAX 10
extern task_status_immed tski_do_command0( );
extern task_status_immed tski_ntr_pmic_comm();
extern task_status_immed tski_acc_read();
extern task_status_immed tski_acc_write();
//extern task_status_immed tski_acc_setup(); // accero.h
extern task_status_immed tski_mcu_reset();
extern task_status_immed tski_vol_update();
// *************************************
#define TSK_IMM_EMPTY_ ( void * )( 0x0000 )
#define TSK_IMM_DELETED_ ( void * )( 0x0001 )
#endif

View File

@ -0,0 +1,37 @@
/*スクリプトによる自動生成です。手動で書き換えない方がよいです*/
#ifndef __renge_task__
#define __renge_task__
#include "renge_defs.h"
enum TSK
{
TSK_SW, TSK_ADC, TSK_BATT, TSK_LED_POW, TSK_LED_WIFI, TSK_LED_NOTIFY, TSK_LED_CAM, TSK_MISC, TSK_STATUS, TSK_SYS, TSK_LAST
};
extern void tsk_sw();
extern void tsk_adc();
extern void tsk_batt();
extern void tsk_led_pow();
extern void tsk_led_wifi();
extern void tsk_led_notify();
extern void tsk_led_cam();
extern void tsk_misc();
extern void tsk_status();
extern void tsk_sys();
const void ( *tasks[ TSK_LAST ] )() = {
tsk_sw,
tsk_adc,
tsk_batt,
tsk_led_pow,
tsk_led_wifi,
tsk_led_notify,
tsk_led_cam,
tsk_misc,
tsk_status,
tsk_sys,
};
#endif

View File

@ -0,0 +1,11 @@
sw
adc
batt
led_pow
led_wifi
led_notify
led_cam
misc
status
debug
sys

182
snake_tags/3.40_jane/rtc.c Normal file
View File

@ -0,0 +1,182 @@
/* ========================================================
RTC
$Id$
======================================================== */
#ifndef _WIN32
#pragma sfr
#pragma inline
#endif
#include "incs.h"
#define RTC_DATA_SIZE 7
// ========================================================
static u8 rtc_work[RTC_DATA_SIZE];
static bit rtc_lock;
static bit rtc_dirty;
bit rtc_alarm_dirty;
/********************************************//**
***********************************************/
void RTC_init( void )
{
if( !RTCEN ) // ビットが立っていたらリブート
{
RTCEN = 1; // モジュールON
// RTC設定
RTCC0 = bits8(0,0,0,0, 1,0,0,0); /* 動作停止、24時間制、32k出力「まだなし」、定周期割り込みなし */
// (RTCE 0 RCLOE1 RCLOE0 AMPM CT2 CT1 CT0)
RTCC1 = bits8(1,1,0,0, 0,0,0,0); /* アラーム割り込み有効&動作開始 */
// (WALE WALIE 0 WAFG RIFG 0 RWST RWAIT)
RTCC2 = bits8(1,0,0,0, 0,0,0,0); /* インターバル:32k/2^6=2ms、RTCDIV出力なし */
// (RINTE RCLOE2 RCKDIV 0 0 ICT2 ICT1 ICT0)
HOUR = 0x00;
MIN = 0x00;
SEC = 0x00;
MONTH = 0x01;
DAY = 0x01;
WEEK = 0x01; // Mon
YEAR = 0x01;
ALARMWW = 0x7F;
vreg_ctr[VREG_C_MCU_STATUS] |= REG_BIT_RTC_BLACKOUT;
}
// 割り込み設定
RTCIF = 0;
RTCIIF = 0;
RTCMK = 1; /* 割り込み(定周期)禁止 */
RTCIMK = 0; /* 割り込み(アラーム&インターバル)許可 */
RTCE = 1; /* 動作開始 */
RWAIT = 1;
while( !RWST )
{;}
RWAIT = 0;
rtc_lock = false;
rtc_dirty = false;
rtc_alarm_dirty = false;
}
/********************************************//**
RTC
***********************************************/
__interrupt void int_rtc( )
{
RWAIT = 1;
while( !RWST )
{;}
// 日付も指定日で
if( ( vreg_ctr[VREG_C_RTC_ALARM_DAY] == DAY )
&& ( vreg_ctr[VREG_C_RTC_ALARM_MONTH] == MONTH )
&& ( vreg_ctr[VREG_C_RTC_ALARM_YEAR] == YEAR ) )
{
set_irq( VREG_C_IRQ1, REG_BIT_RTC_ALARM );
}
RWAIT = 0;
}
/********************************************//**
RTC
sec,min,hour,week,day,month,year
***********************************************/
void rtc_buf_refresh( )
{
if( !rtc_lock )
{
rtc_lock = true;
RWAIT = 1;
while( !RWST )
{;}
memcpy( &vreg_ctr[VREG_C_RTC_SEC], &SEC, RTC_DATA_SIZE );
RWAIT = 0;
// renge_task_immed_add( tski_rtc_close );
}
}
/********************************************//**
RTC
set_rtc_close 使
RTCにセットするのはset_rtc_close()
***********************************************/
void set_rtc( u8 adrs, u8 data )
{
if( !rtc_dirty )
{
rtc_dirty = true;
memcpy( rtc_work, &SEC, RTC_DATA_SIZE );
// renge_task_immed_add( tski_rtc_close ); // I2C終了時に行う
}
rtc_work[adrs] = data;
}
/********************************************//**
RTCレジスタの更新
***********************************************/
// task_status_immed tski_rtc_close(){
void rtc_unlock( )
{
// リードロック
rtc_lock = false;
// ライトロック
if( rtc_dirty )
{
rtc_dirty = false;
RWAIT = 1;
while( !RWST )
{;}
memcpy( &SEC, rtc_work, RTC_DATA_SIZE );
RWAIT = 0;
}
// アラームセット
if( rtc_alarm_dirty )
{
rtc_alarm_dirty = false;
WALE = 0;
ALARMWM = vreg_ctr[VREG_C_RTC_ALARM_MIN];
ALARMWH = vreg_ctr[VREG_C_RTC_ALARM_HOUR];
WALE = 1;
}
}
/********************************************//**
RTC
2^6/fXT1.953125 ms
***********************************************/
__interrupt void int_rtc_int( )
{
// renge_flg_interval ++; // インクリメント/デクリメント命令を使うので DI()不要
renge_flg_interval = 1; // set1命令を使うので DI()不要
}

View File

@ -0,0 +1,24 @@
#ifndef __rtc_h__
#define __rtc_h__
// $Id: asdf$
void RTC_init( void );
void rtc_buf_refresh( );
void set_rtc( u8 adrs, u8 data );
//task_status_immed tski_rtc_close();
void rtc_unlock( );
// ------------------------------------
#define RTC_32k_on() { /*RCLOE2 = 0;*/ RCLOE0 = 1; /*P1.2 = 0;*/ PM1.2 = 0; }
#define RTC_32k_off() { PM1.2 = 0; RCLOE0 = 0; }
#define RTC_32k_HI_Z() { PM1.2 = 1; }
// ------------------------------------
extern bit rtc_alarm_dirty;
#endif

View File

@ -0,0 +1,635 @@
/* ========================================================
$Id$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma di
#pragma ei
#pragma nop
#pragma stop
#pragma halt
#endif
#include "incs_loader.h"
#include <fsl.h>
#include "fsl_user.h"
#include "i2c_ctr.h"
#include "i2c_mcu.h"
#include "pool.h"
#include "magic.h"
#include "pm.h"
#include "WDT.h"
#include "util_funcs.h"
// ========================================================
const u8 fsl_fx_MHz_u08 = 8;
const u8 fsl_low_voltage_u08 = 1;
// 自己フラッシュパラメータ
#define SAM_BLOCK_SIZE 1024
// ↓256バイト以上はまとめてかけません。
#define SELF_UPDATE_BUFF_SIZE 256
#define SELF_UPDATE_SPLIT_WRITE_NUM ( SAM_BLOCK_SIZE / SELF_UPDATE_BUFF_SIZE )
#define SAM_WORD_SIZE 4
// ↓ブロック番号1ブロック1kB
#define INACTIVE_BOOTSECT_TOP 4
#define FIRM_TOP 8
#define FIRM_SIZE 12
#define ALTERNATE_FIRMTOP 20
#ifdef _MCU_BSR_
#define ACKD ACKD1
#define ACKE ACKE1
#define COI COI1
#define IICAEN IICA1EN
#define IICAPR0 IICAPR10
#define IICRSV IICRSV1
#define IICA IICA1
#define IICAIF IICAIF1
#define IICAMK IICAMK1
#define IICAPR1 IICAPR11
#define IICCTL0 IICCTL01
#define IICE IICE1
#define IICF IICF1
#define IICS IICS1
#define IICWH IICWH1
#define IICWL IICWL1
#define LREL LREL1
#define SPD SPD1
#define SPIE SPIE1
#define STCEN STCEN1
#define STD STD1
#define SVA SVA1
#define WREL WREL1
#define WTIM WTIM1
#endif
#ifndef _WIN32
#define LED_POW1 P4.2
#define LED_PM_POW1 PM4.2
#else
#define LED_POW1 mcuRegP[ _P4_2 ]
#define LED_PM_POW1 mcuRegPM[ _P4_2 ]
#endif
// ========================================================
static void FSL_Open( void );
static void FSL_Close( void );
void firm_restore( );
static err my_FSL_Init();
static err firm_duplicate( u8 block_src, u8 block_dest );
#ifdef _DBG_LED_PRINT_
void alert( u8 );
void led_print( u8 );
#else
# define alert( x ) ;
# define led_print( x ) ;
#endif
// ========================================================
extern uni_pool pool;
// 0.D以降 新アップデータ向け
// 新ファームは大丈夫?
#define N_MGC_L 0x1FF6
#define N_MGC_T 0x4FF6
/********************************************//**
I2Cで受信して
OK  
    NG  
***********************************************/
void firm_update( )
{
u8 target_block;
u8 split_write_count; // ブロックへちまちま書き込むカウンタ
// 書き替え前準備 /////////////////////////////////////
my_FSL_Init();
/* ファームのバックアップ
( FIRM_SIZE)
0x2000 - 0x4FFF
0x5000 - 0x7FFF ( 20 - 31)
*/
firm_duplicate( FIRM_TOP,
ALTERNATE_FIRMTOP );
// 全ブロック削除 /////////////////////////////////////
// 電源断を判定するため、最初に全クラスタ消去する
//(新ファームが書かれるところに残ってる、以前のファームのフッタを消したい)
for( target_block = INACTIVE_BOOTSECT_TOP;
target_block < ALTERNATE_FIRMTOP;
target_block ++ )
{
FSL_Erase( target_block );
}
// 書き替え ///////////////////////////////////////////
// ●ストップコンディションが来るまで続ける
// ●終わったら、スタートアップルーチンに飛ぶ
for( target_block = INACTIVE_BOOTSECT_TOP;
target_block < ALTERNATE_FIRMTOP;
target_block ++ )
{
u8 my_spd;
/* すでに消してある。でないと中断されたとき終了してるか判別出来ない
// // 新ファーム領域削除
// FSL_Erase( target_block );
*/
// 分割書き込み
for( split_write_count = 0;
split_write_count < SELF_UPDATE_SPLIT_WRITE_NUM;
split_write_count ++ )
{
u8* p_buffer = &pool.self_update_work[0];
u16 buff_written_size = 0;
WDT_Restart( );
// I2Cから書き込みデータをバッファにためる
do
{
while( !IICAIF && !SPD )
{;}
my_spd = SPD;
IICAIF = 0;
*p_buffer = IICA;
WREL = 1;
p_buffer ++;
buff_written_size ++;
}
while( ( buff_written_size != SELF_UPDATE_BUFF_SIZE )
&& !SPD );
my_spd += SPD;
// 書き込み
// 最後だと、ゴミをパディングするが別にかまわない
if( FSL_Write( ( fsl_u32 ) ( target_block * SAM_BLOCK_SIZE
+ split_write_count * SELF_UPDATE_BUFF_SIZE ),
( fsl_u08 ) ( SELF_UPDATE_BUFF_SIZE / SAM_WORD_SIZE ) )
!= FSL_OK )
{
alert(1);
// 書き込み後のチェックエラー
// リストア
firm_duplicate( ALTERNATE_FIRMTOP, FIRM_TOP );
FSL_ForceReset(); // リセット
// FSL_SwapBootCluster( ); // ブートスワップ「せずに」再起動って出来ないらしい
// 戻ってこない //
}
if( my_spd != 0 )
{
break;
}
}
// 1ブロック書き込み完了。内部ベリファイを行う
if( FSL_IVerify( target_block ) != FSL_OK ){
alert(2);
// 再度消去→書き込み ベリファイを繰り返すだけじゃダメでした... /// 再書き込みすべき?
// リストア
firm_duplicate( ALTERNATE_FIRMTOP, FIRM_TOP );
FSL_ForceReset(); // リセット
// FSL_SwapBootCluster( ); // ブートスワップ「せずに」再起動って出来ないらしい
// 戻ってこない //
}
if( my_spd != 0 )
{
break;
}
}
LREL = 1;
// 書き込んだファームのチェック //
{
u8 i;
u8 comp = 0;
// ローダーのマジックと、本文の末尾のマジックは同じか確認
for( i = 0; i < sizeof( __TIME__ ); i++ )
{
comp += (u8)(( (*( __far u8 * ) ( N_MGC_L + i )) == (*( u8 * ) ( N_MGC_T + i ) )) ? 0 : 1);
}
if( *( __far u8 * )( N_MGC_L +2 ) != ':' ) // 消去済のまま
{
comp ++;
}
if( comp == 0 )
{
// OK!
FSL_InvertBootFlag( );
FSL_SwapBootCluster( ); // リセットせずに頭から。FSL_Closeは不要
}
else
{
// データ(マジックナンバーしか見てない)エラー
// リストア
alert(3);
firm_duplicate( ALTERNATE_FIRMTOP, FIRM_TOP );
FSL_ForceReset(); // リセット
// FSL_SwapBootCluster( ); // ブートスワップ「せずに」再起動って出来ないらしい
}
// 戻ってこない //
}
}
/********************************************//**
***********************************************/
void firm_restore( )
{
DBG_LED_on;
LED_PM_POW1 = 0;
// バックアップは正常? //
{
u16 i;
u8 comp = 0;
for( i = 0; i < sizeof( __TIME__ ); i++ ) // sizeof( __TIME__ ) = 8 らし
{
comp += ( *( __far u8 * )( MGC_LOAD + i ) == *( u8 * )( MGC_HEAD_BKUP + i ) ) ? 0 : 1;
comp += ( *( u8 * )( MGC_HEAD_BKUP + i ) == *( u8 * )( MGC_FOOT_BKUP + i ) ) ? 0 : 1;
}
if( *( u8 * )( MGC_FOOT_BKUP ) == 0xFF )
{
comp ++;
}
if( comp != 0 )
{
// バックアップ領域も壊れた...
comp = 0;
// 3.3Vが上がらないと困る
EI( );
iic_mcu_start( );
RESET2_ast;
FCRAM_RST_ast;
GYRO_DISABLE();
PM_LDSW_on();
wait_ms( 1 + DELAY_PM_TW_PWUP );
PM_VDD_on( );
while(1)
{
WDT_Restart();
{
// 赤LED ピコピコ
comp++;
LED_POW1 = ( comp == 1 || comp == 3 )? 1: 0;
if( comp == 8 )
{
comp = 0;
}
}
{
// 電源ボタンで電源off
static u8 sw_hold_count;
if( !SW_POW_n_RAW )
{
sw_hold_count++;
}
else
{
sw_hold_count = 0;
}
if( sw_hold_count > 16 )
{
sw_hold_count = 0;
// 電源off
PM_LDSW_off( );
// pwsw待ちで寝る
KRM = ( KR_SW_POW ); // Mask ではなく、Mode
MK0 = 0xFFFF;
MK1 = ~( INT_MSK1_KR );
MK2L = 0xFF;
// PU5 そのまま
PU7 = bits8(0,0,0,0, 1,0,0,0); // PWSWI
PU20 = bits8(0,0,0,0, 0,0,0,0); // SW_HOME 停止
STOP( );
// mcu_wdt_reset; // 無限ループするのはよくないと思う
// while(1){
// NOP(); // こない
// }
}
}
// ウェイト
for( i = 1; i != 0; i++ )
{
NOP();
NOP();
NOP();
NOP();
}
}
}
}
// else{ // バックアップは生きていた
while( my_FSL_Init() != ERR_SUCCESS ){ // FSL初期化失敗するようならもう救えない...
// todo リトライ回数上限?
alert(1);
}
/* ファームのリストア
0x4800 - 0x7FFF ( 18 - 27)
0x2000 - 0x47FF ( 8 - 17)
*/
if( firm_duplicate( ALTERNATE_FIRMTOP, FIRM_TOP ) != ERR_SUCCESS )
{
alert(2);
}
DBG_LED_off;
// todo リストア失敗したら、LEDちかちかとかさせて、サービス送りにしてもらう
FSL_ForceReset(); // リセット、戻ってこない
}
/********************************************//**
***********************************************/
static void FSL_Open( void )
{
/* save the configuration of the interrupt controller and set */
#ifdef FSL_INT_BACKUP
fsl_MK0L_bak_u08 = MK0L; /* if (interrupt backup required) */
fsl_MK0H_bak_u08 = MK0H; /* { */
fsl_MK1L_bak_u08 = MK1L; /* */
fsl_MK1H_bak_u08 = MK1H; /* save interrupt controller */
fsl_MK2L_bak_u08 = MK2L; /* configuration */
fsl_MK2H_bak_u08 = MK2H; /* */
MK0L = FSL_MK0L_MASK; /* */
MK0H = FSL_MK0H_MASK; /* */
MK1L = FSL_MK1L_MASK; /* prepare interrupt controller */
MK1H = FSL_MK1H_MASK; /* for selfprogramming */
MK2L = FSL_MK2L_MASK; /* */
MK2H = FSL_MK2H_MASK; /* } */
#endif
while( DST1 ){;} // DMA停止
DEN1 = 0;
MK0 = 0xFFFF;
MK1 = 0xFFFF;
MK2 = 0xFFFF;
/*
LVIM = bits8(0,0,0,0, 0,0,1,0);
LVIS = bits8(0,0,0,0, 1,0,0,0);
LVIM = bits8(1,0,0,0, 0,0,1,0);
*/
FSL_FLMD0_HIGH; // フラッシュ書き替え許可
}
/********************************************//**
***********************************************/
static void FSL_Close( void )
{
// 何か後始末?
FSL_FLMD0_LOW; // フラッシュライトプロテクト
#ifdef FSL_INT_BACKUP
MK0L = fsl_MK0L_bak_u08; /* do{ */
MK0H = fsl_MK0H_bak_u08; /* restore interrupt controller */
MK1L = fsl_MK1L_bak_u08; /* configuration */
MK1H = fsl_MK1H_bak_u08; /* */
MK2L = fsl_MK2L_bak_u08; /* */
MK2H = fsl_MK2H_bak_u08; /* } */
#endif
}
/********************************************//**
 
__far u8 * p_rom
block_dest
my_FSL_Initをあらかじめ実行する必要があります
***********************************************/
static err firm_duplicate( u8 block_src,
u8 block_dest )
{
u8 target_block;
u8 split_write_count; // ブロックへちまちま書き込むカウンタ
__far u8* p_src = ( __far u8* )( block_src * 0x400 );
u8 retry_error;
led_print(1);
// 書き込み先ブロックの数だけ繰り返す
for( target_block = block_dest;
target_block < ( block_dest + FIRM_SIZE );
target_block ++ )
{
led_print(2);
WDT_Restart( );
// ブロック消去
retry_error = 5 + 1;
while( FSL_BlankCheck( target_block ) != FSL_OK )
{
led_print(3);
FSL_Erase( target_block );
if( -- retry_error == 0 )
{
// フラッシュ寿命?
FSL_Close( );
return ( ERR_ERR ); // リセット&復帰を試みる どうなるか知らん
}
}
led_print(4);
// 分割書き込み分繰り返す
for( split_write_count = 0;
split_write_count < SELF_UPDATE_SPLIT_WRITE_NUM;
split_write_count ++ )
{
u16 buff_written_size;
u8* p_buff;
// 書き込みデータをバッファにためる
buff_written_size = 0;
p_buff = &pool.self_update_work[0];
do
{
*p_buff = *p_src;
p_src ++;
p_buff ++;
buff_written_size ++;
}
while( buff_written_size != SELF_UPDATE_BUFF_SIZE );
// 書き込み
if( FSL_Write( ( fsl_u32 ) ( target_block * SAM_BLOCK_SIZE
+ split_write_count * SELF_UPDATE_BUFF_SIZE ),
( fsl_u08 ) ( SELF_UPDATE_BUFF_SIZE / SAM_WORD_SIZE ) )
!= FSL_OK )
{
// リカバリはリブート時 //
FSL_Close( );
led_print(5);
// while(1){}
return ( ERR_ERR );
}
}
led_print(6);
// 1ブロック書き込み完了。内部電圧チェックを行う
while( FSL_IVerify( target_block ) != FSL_OK )
{
// リカバリはリブート時 //
led_print(7);
return ( ERR_ERR );
}
}
return( ERR_SUCCESS );
}
/********************************************//**
***********************************************/
static err my_FSL_Init()
{
u8 rv;
RTCE = 0;
// 書き替え前準備 //
DI( );
FSL_Open( ); // 割り込み禁止など
FSL_Init( &pool.self_update_work[0] ); // ライブラリ初期化。割り込み中断考慮せず
rv = FSL_ModeCheck( ); // ライトプロテクトチェック。失敗することを考慮せず
return( (err)rv );
}
/********************************************//**
MCUリセット
system_status.reboot
***********************************************/
task_status_immed tski_mcu_reset()
{
// 普通に再起動
my_FSL_Init();
FSL_ForceReset(); // リセット
FSL_Close( );
// 保険? //
mcu_wdt_reset;
return( ERR_SUCCESS ); // no reach
}
/********************************************//**
LEDを点滅させてエラーを通知
使 LEDprintf
***********************************************/
#ifdef _DBG_LED_PRINT_
// P1.5 = led_pow_red_old
void alert( u8 num )
{
u8 i;
while(1)
{
WDT_Restart();
LED_POW1 = 1;
for( i = 0; i < num; i++ )
{
DBG_LED_on;
DBG_LED_off;
}
LED_POW1 = 0;
}
}
/********************************************//**
LEDを点滅させてエラーを通知
使 LEDprintf
***********************************************/
void led_print( u8 num )
{
u8 i;
DBG_LED_on;
for( i = 0; i < num; i++ )
{
LED_POW1 = 1;
LED_POW1 = 0;
}
DBG_LED_off;
}
#endif

View File

@ -0,0 +1,9 @@
#ifndef _self_flash_h_
#define _self_flash_h_
void firm_update();
#endif

215
snake_tags/3.40_jane/sw.c Normal file
View File

@ -0,0 +1,215 @@
/* ========================================================
HOME
POWER
WiFi
$Id$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs.h"
#include "i2c_twl.h"
#include "i2c_ctr.h"
#include "led.h"
#include "pm.h"
#include "rtc.h"
#include "sw.h"
//=========================================================
/*
vreg_ctrから読みたいのでヘッダへ
#define INTERVAL_TSK_SW
#define CLICK_THRESHOLD
#define HOLD_THREASHOLD
#define FORCEOFF_THREASHOLD
*/
#define TIME_MUKAN ( u8)( 300 / INTERVAL_TSK_SW )
#define TIME_MUKAN_PWSW_RED_TRIAL (u16)( 15000 / INTERVAL_TSK_SW ) // 試遊台、homeマスク時間
//=========================================================
u16 SW_pow_count;
bit SW_pow_mask;
static u8 SW_home_count, SW_wifi_count, SW_home_count_rel;
static u8 sw_wifi_mukan_time;
u16 off_timeout_timer;
static u16 sw_pwsw_mukan_time;
/********************************************//**
0
maskが非0の時は
***********************************************/
#define count_sw_n( sw, counter, mask ) \
{ \
if( sw ){ \
mask = 0; \
counter = 0; \
}else{ \
if( mask != 0 ){ \
counter = 0; \
}else{ \
counter ++; \
if( counter == 0 ) counter = -1; \
} \
} \
}
/********************************************//**
()
***********************************************/
#define chk_clicked( button, count, irq_bit_name ) \
if( !button ) \
{ \
if( count < CLICK_THRESHOLD ) \
{ \
count ++; \
if( count == CLICK_THRESHOLD ) \
{ \
count ++; \
set_irq( VREG_C_IRQ0, irq_bit_name ); \
} \
} \
} \
else \
{ \
count = 0; \
}
/********************************************//**
 
***********************************************/
void tsk_sw( )
{
static u8 task_interval;
if( system_status.pwr_state == OFF_TRIG )
{
SW_pow_count = 0; // 電源投入に備えてクリア
// task_interval = 0;
}
if( system_status.pwr_state != ON_CHECK ) // 測定時間(PWSW_POWON_TIME)が短いのでプリスケーラ無し でないとチャタ除去があまりきかない
{
if( task_interval != 0 )
{
task_interval--;
return;
// おしまい
}
task_interval = (u8)( INTERVAL_TSK_SW / SYS_INTERVAL_TICK ) -1; // プリスケーラ代わりに使ってますね…
// -1はポストデクリメントのための調整
}
// 8ms 毎にきます
switch ( system_status.pwr_state )
{
case ( ON ):
case ( SLEEP ):
case ( OFF ):
case ( ON_CHECK ):
// 実機の場合
if( ! system_status.taikendai )
{
// 電源スイッチの監視 //
if( SW_pow_count == ( TIME_PWSW_CLICK ) ) // クリック時間に到達
{
if( is_wifi_calib_resets_ast ) // wifi キャリブレーション時なら、SoCに通知せずにoffに遷移
{
system_status.pwr_state = OFF_TRIG;
}
if( SHELL_OPEN ) // PWSW が露出している関係で、「蓋閉じ」 時、クリックは無視
{
set_irq( VREG_C_IRQ0, REG_BIT_SW_POW_CLICK );
}
}
else if( SW_pow_count == ( HOLD_THREASHOLD ) ) // 長押しに到達
{
set_irq( VREG_C_IRQ0, REG_BIT_SW_POW_HOLD );
if( off_timeout_timer == 0 ) // 強制電源断カウントダウン開始、何度も発動しないように。
{
off_timeout_timer = vreg_ctr[ VREG_C_OFF_DELAY ] * 16;
}
}
if( off_timeout_timer != 0 ) // 長押し割り込み後、タイムアウトで強制オフ。
{
off_timeout_timer --;
if( off_timeout_timer == 0 )
{
force_off = true;
}
}
}else{
// スタンドアロン試遊台
// 電源スイッチの監視 //
if( SW_pow_count == ( TIME_PWSW_CLICK ) )
{
if( sw_pwsw_mukan_time == 0 )
{
set_irq( VREG_C_IRQ0, REG_BIT_SW_POW_CLICK );
// いやなタイミングでPWSWを押すとHOMEメニューに入れてしまうのを回避するためのマスクタイマー
sw_pwsw_mukan_time = TIME_MUKAN_PWSW_RED_TRIAL;
}
}
else if( SW_pow_count == ( HOLD_THREASHOLD ) )
{
force_off = true;
}
if( sw_pwsw_mukan_time != 0 )
{
sw_pwsw_mukan_time--;
}
}
// 実機・体験台共通
count_sw_n( SW_POW_n, SW_pow_count, SW_pow_mask ); // ボタン押し時間のカウント
// HOME sw //
chk_clicked( SW_HOME_n, SW_home_count, REG_BIT_SW_HOME_CLICK );
chk_clicked( !SW_HOME_n, SW_home_count_rel, REG_BIT_SW_HOME_RELEASE );
// wifi sw //
/// 最悪な実装なのはわかっているが、市場に出てしまった不良スイッチを救うため
if( sw_wifi_mukan_time != 0 )
{
sw_wifi_mukan_time--;
}
else
{
chk_clicked( SW_WIFI_n, SW_wifi_count, REG_BIT_SW_WIFI_CLICK );
if( SW_wifi_count == CLICK_THRESHOLD +1 ) // 押した判定発生!
{
sw_wifi_mukan_time = TIME_MUKAN;
}
}
break;
default:
break;
}// switch()
}

20
snake_tags/3.40_jane/sw.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef _sw_
#define _sw_
#include "config.h"
extern u16 SW_pow_count;
extern bit SW_pow_mask;
#define INTERVAL_TSK_SW 8
#define CLICK_THRESHOLD 5
#define HOLD_THREASHOLD (u16)( 3000 /INTERVAL_TSK_SW )
#define TIME_PWSW_CLICK (u8)( 220 /INTERVAL_TSK_SW )
#define FORCEOFF_THREASHOLD (u8)( 12000 /INTERVAL_TSK_SW /16 )
extern u16 off_timeout_timer;
#define clear_pow_off_countdown(){ off_timeout_timer = 0; force_off = false; }
#endif

View File

@ -0,0 +1,122 @@
/* ========================================================
$Id$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs_loader.h"
//#include "incs.h"
#include "renge\renge.h"
#include "pm.h"
#include "accero.h"
// ========================================================
// 7セグ 4バイト版
#define IIC_SLA_DBG_MONITOR 0x44
#if 0 // デバッグモニタ用タスク
 使
/********************************************//**
***********************************************/
void tsk_debug( )
{
// u8 temp;
/*
if( system_status.pwr_state == ON_TRIG ){
{
static u8 count = 0;
// デバッグLED8bitの初期化
temp = iic_mcu_read_a_byte( IIC_SLA_8LEDS, IIC_8LEDS_REG_DO );
count ++;
iic_mcu_write_a_byte( IIC_SLA_8LEDS, IIC_8LEDS_REG_DO, count );
iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 3, count );
}
}
*/
// 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_3D ] );
// 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_3D ] );
// 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_STATUS ] );
// iic_mcu_write_a_byte( IIC_SLA_DBG_MONITOR, 0, vreg_ctr[ VREG_C_ACC_ZH ] );
/*
{
u8 str[4];
if( ( system_status.pwr_state == ON ) || ( system_status.pwr_state == SLEEP ) )
{
str[3] = vreg_ctr[ VREG_C_FREE0 ];
str[2] = vreg_ctr[ VREG_C_FREE1 ];
str[1] = vreg_ctr[ VREG_C_STATUS ];
str[0] = vreg_ctr[ VREG_C_RTC_SEC ];
str[3] = vreg_ctr[ VREG_C_SND_VOL ];
str[2] = vreg_ctr[ VREG_C_3D ];
str[1] = vreg_ctr[ VREG_C_ACC_CONFIG ];
str[0] = SEC;
iic_mcu_write( IIC_SLA_DBG_MONITOR, 0x03, 4, &str );
}
}
*/
}
#endif
#if 0 // タスクひな形
/********************************************//**
***********************************************/
task_interval tsk_hina( )
{
switch ( system_status.pwr_state )
{
case ON_CHECK:
case ON_TRIG:
case ON:
case SLEEP:
case OFF_TRIG:
default:
}
return; // 毎 tic 呼ばれることになります
}
// ポインタで何かもらうのは危険な気がしてきた
/* このように使う
renge_task_immed_add( );
*/
/********************************************//**
()
***********************************************/
task_status_immed tski_hina( u8 * arg )
{
return ( TSKI_FINISHED );
// TSKI_FINISHED タスクを削除
// TSKI_CONTINUE 次になんか割り込みなり、ユーザー操作なり、システムチックが
// 来たときに再度実行
}
#endif

View File

@ -0,0 +1,429 @@
/* ========================================================
$Id: task_misc.c 418 2011-09-22 01:35:37Z n2232 $
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs.h"
#include "renge\renge.h"
#include "pm.h"
#include "accero.h"
#include "adc.h"
#include "i2c_mcu.h"
#include "led.h"
#include "vreg_twl.h"
#ifdef _MCU_BSR_
#define ACKD ACKD1
#define ACKE ACKE1
#define COI COI1
#define IICAEN IICA1EN
#define IICRSV IICRSV1
#define IICA IICA1
#define IICAIF IICAIF1
#define IICAMK IICAMK1
#define IICAPR0 IICAPR11
#define IICAPR1 IICAPR01
#define IICCTL0 IICCTL10
#define IICE IICE1
#define IICF IICF1
#define IICS IICS1
#define IICWH IICWH1
#define IICWL IICWL1
#define LREL LREL1
#define SPD SPD1
#define SPIE SPIE1
#define STCEN STCEN1
#define STD STD1
#define SVA SVA1
#define WREL WREL1
#define WTIM WTIM1
#define TRC TRC1
#define SMC SMC1
#define DFC DFC1
#endif
// ========================================================
extern void f(); // スタックの最後を得る
// ========================================================
bit twl_ver_read; // twl home menuがverを読んだら互換カーネルに割り込みを入れるため
bit going_to_sleep; // SoCから、sleepに入る通知をもらう。slp_i のH期間が0になると
// スリープから復帰できなくなるのを防ぐため
// 自動テスト用
bit reserve_pedo_increnent;
// ========================================================
static void update_LED_3D();
static void check_twl_vol_irq();
/********************************************//**
- ()
- TWL PM互換レジスタへの書き込みがあれば読みに行く
- TWLランチャーの起動を通知
- TWLの音量変化割り込みをチェック
- 3Dランプの更新
- (HAL)
- () SEL押し続けるとWDTリセットを発生させる
***********************************************/
void tsk_misc( )
{
// 割り込みの取りこぼし?
if( ACC_VALID && ( ( vreg_ctr[ VREG_C_STATUS_1 ] & REG_BIT_ACCERO_ERR ) == 0 ))
{
if( renge_task_immed_add( tski_cbk_accero ) == ERR_SUCCESS ){
// dbg_nop();
}
}
if( system_status.pwr_state == ON )
{
/* ========================================================
PM互換レジスタへの書き込み
======================================================== */
if( !PM_IRQ_n )
{
renge_task_immed_add( tski_ntr_pmic_comm );
// dbg_nop();
}
/* ========================================================
TWLランチャーが起動したことをCTRが知りたいらしい
======================================================== */
if( twl_ver_read )
{
twl_ver_read = false;
set_irq( VREG_C_IRQ2, REG_BIT_TWL_VER_READ );
}
// TWL の音量変化割り込みチェック //
check_twl_vol_irq();
}
// 3D ランプ更新 //
update_LED_3D();
#ifdef _ENABLE_HAL_
// デバッグHAL 歩数を一歩増やす //
if( reserve_pedo_increnent )
{
reserve_pedo_increnent = 0;
hosu_increment_if_necessary();
}
#endif
#ifdef _ENABLE_PRESS_SEL_TO_WDT_
if(( system_status.pwr_state == ON )
|| ( system_status.pwr_state == SLEEP ))
{
static u16 timer;
if( !SW_SEL_n )
{
timer += 1;
if( timer == 2000 )
{
DI();
timer = 0;
while(1)
{
NOP(); // そのうちWDTが発生する
}
}
}
}
#endif
//. スタックテスト
// f();
}
/********************************************//**
TWLがVolを書くのと
TWLでは通常時8
***********************************************/
void check_twl_vol_irq()
{
static u8 vol_level_twl_sent;
static u8 mabiki;
if( !is_TWL )
{
return;
// おしまい
}
if( mabiki != 0 )
{
mabiki--;
return;
// おしまい
}
mabiki = 9; // 1フレームは開ける
if( vol_level_twl != vol_level_twl_sent )
{
vol_level_twl_sent = vol_level_twl;
set_irq( VREG_C_IRQ2, REG_BIT_SLIDE_VOL_ACROSS_TWL_BOUNDARY );
}
}
/********************************************//**
3Dランプ更新
***********************************************/
void update_LED_3D()
{
if( system_status.pwr_state != ON )
{
LED_duty_3d = 0;
return;
// おしまい //
}
if( vreg_ctr[VREG_C_LED_3D] == LED_3D_ILM_OFF )
{
if( LED_duty_3d != 0 )
{
LED_duty_3d --;
}
}
else
{
if( LED_duty_3d != vreg_ctr[VREG_C_LED_BRIGHT] )
{
if( LED_duty_3d < vreg_ctr[VREG_C_LED_BRIGHT] )
{
LED_duty_3d ++;
}
else
{
LED_duty_3d --;
}
}
}
}
/********************************************//**
COMMANDレジスタへの書き込み
0
- sleep ()
-
***********************************************/
task_status_immed tski_do_command0( )
{
u8 temp_command;
// command0 本体電源など
DI_wt_chk();
temp_command = vreg_ctr[VREG_C_COMMAND0];
vreg_ctr[VREG_C_COMMAND0] = 0;
EI();
// SLPO(SoC->mcu) が非同期のため、パルス幅がゼロになってしまい、mcu が SoCの一瞬の
// スリープを検出出来ず、SLPIをトグル出来ない事がある。あらかじめ通知してもらい、
// タイムアウト処理を行う。
if( temp_command & REG_BIT_GOING_TO_SLEEP )
{
going_to_sleep = true;
}
// リセット系のコマンド //
if( ( temp_command & ( REG_BIT_OFF_REQ | REG_BIT_RESET1_REQ | REG_BIT_FCRAM_RESET_REQ | REG_BIT_RESET2_REQ )) != 0x00 )
{
if( temp_command & REG_BIT_OFF_REQ )
{
system_status.pwr_state = OFF_TRIG;
}
else
{
if( temp_command & REG_BIT_RESET1_REQ )
{
PM_reset_ast( );
RESET2_ast;
FCRAM_RST_ast;
}
if( temp_command & REG_BIT_RESET2_REQ )
{
RESET2_ast;
if( vreg_twl[ REG_TWL_INT_ADRS_MODE ] == 0 )
{
FCRAM_RST_ast; // twlはntrモードで動作してる
}
// TWLモードからDSモードへの切り替え中にリセットすると
// IRQが読まれない場合があるのでTWLレジスタを初期化する
vreg_twl_init();
}
if( temp_command & REG_BIT_FCRAM_RESET_REQ )
{
FCRAM_RST_ast;
}
wait_ms( 5 ); // 時間稼ぎ
FCRAM_RST_neg;
PM_reset_neg();
RESET2_neg;
// CODEC 不定レジスタ初期化 //
codec_reg_init();
}
}
/*
OFF
if( vreg_ctr[VREG_C_COMMAND0] != 0 )
{
return ( TSKI_CONTINUE );
}
*/
return ( TSKI_FINISHED );
}
/* デバッグ・自動テスト用 ============================== */
u16 _dbg_rcomp;
extern u8 raw_adc_temperature;
extern u8 iic_burst_state;
extern bit temp_zone_charge_disable;
extern bit bt_authorized;
#define KOUMOKU 19
static u8 infos_bits[2];
static u8 infos_temp[5];
static const u8 *infos_table[ KOUMOKU ] = {
&infos_temp[0], /* 0 */
&pmic_version,
(u8*)&battery_manufacturer,
&mgic_version[0],
&mgic_version[1],
&infos_temp[1], /* 5 */
&raw_adc_temperature,
&infos_temp[2],
&infos_temp[3],
(u8*)&system_status.family, /* 9 */
&infos_bits[0], /* 10 */
(u8*)&LED_duty_pow_blu,
(u8*)&LED_duty_3d,
(u8*)&LED_duty_notify_red,
(u8*)&LED_duty_notify_grn,
(u8*)&LED_duty_notify_blu, /* 15 */
&infos_bits[1],
(u8*)&LED_duty_WiFi,
&infos_temp[4] /* 18 */
/* 項目足すときは KOUMOKU に注意 */
};
/********************************************//**
  0x7F
 
- 1)
- 2) PMIC
- 3)
- 4)
- 5)
- 6) ( rcomp & 0xFF )
- 7) raw_adc_temperature
- 8) ( !temp_zone_charge_disable | ( bt_authorized << 1 ) )
- 9) LEDはフルカラー
- 10) system_status.family
***********************************************/
u8 extinfo_read(void)
{
u8 ret = 0xFF;
/*
* tempは計算処理が必要なデータ
* /
*/
if( iic_burst_state < KOUMOKU )
{
infos_temp[0] = system_status.captureBox? ( system_status.is_dev? MODEL_IS_CAPTURE :MODEL_KUC_CAPTURE )
: ( system_status.is_dev? MODEL_IS_DEBUGGER: (u8)system_status.model );
infos_temp[1] = (u8)( _dbg_rcomp & 0xFF );
infos_temp[2] = ( !temp_zone_charge_disable | ( bt_authorized << 1 ) );
infos_temp[3] = 1; /* 仕様変更により1固定になった */
infos_temp[4] = 0
// | ( PM_EXTDC_n ? REG_BIT_HAL0_PM_EXTDC_n : 0 ) // status0にある
| ( BT_IN_CHG_n ? REG_BIT_HAL0_BT_IN_CHG_n : 0 )
| ( BT_CHG_Ena_n ? REG_BIT_HAL0_RSV_5 : 0 ) // 空きビット使用,out pin
| 0 // WL_TX 使えない
// | ( SHELL_OPEN ? REG_BIT_HAL0_SHELL_OPEN : 0 ) // status0にある
| ( SW_WIFI_n ? REG_BIT_HAL0_SW_WIFI_n : 0 )
| ( SW_HOME_n ? REG_BIT_HAL0_SW_HOME_n : 0 )
| ( SW_POW_n ? REG_BIT_HAL0_SW_POW_n : 0 );
infos_bits[0] = (u8)LED_pow_red;
infos_bits[1] = (u8)LED_CAM;
ret = *infos_table[iic_burst_state];
#if 0
// debug //
/// システムに機種識別で嘘をつく
if( iic_burst_state == 9 )
{
ret = (u8)FAMILY_FLOWER;
}
#endif
iic_burst_state ++;
}
return ret;
}
#ifdef i2c_timeout_test
/********************************************//**
I2C_mcu ()LEDを点灯して通知する
***********************************************/
void i2c_mcu_error_monitor()
{
LED_duty_pow_blu = 0xff;
LED_duty_3d = 0xff;
LED_duty_notify_red = 0xff;
LED_duty_notify_grn = 0xff;
LED_duty_notify_blu = 0xff;
LED_pow_red = 1;
LED_CAM = 1;
}
#endif

View File

@ -0,0 +1,89 @@
/* ********************************************************
$Id$
********************************************************* */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs_loader.h"
#include "renge\renge.h"
#include "pm.h"
#include "accero.h"
#include "adc.h"
#include "i2c_mcu.h"
#include "led.h"
/********************************************//**
-
todo:
***********************************************/
void tsk_status( )
{
static u8 state_old; // ステータス変化検出→割り込み の為
u8 diff;
// 蓋開けチェック
set_bit_if( SHELL_OPEN, vreg_ctr[VREG_C_STATUS], REG_BIT_ST_SHELL_OPEN );
// ステータスレジスタ関係 → 割り込み //
// pm.c で、その場で行います。
// REG_BIT_LCD_ON/OFF
// REG_BIT_BL_ON/OFF
// REG_BIT_BT_DC_CONNECT/DISC
// REG_BIT_BT_CHG_START/STOP
diff = (u8)( vreg_ctr[VREG_C_STATUS] ^ state_old );
if( diff != 0 )
{
state_old = vreg_ctr[VREG_C_STATUS];
if( system_status.pwr_state == ON )
{
if( diff & REG_BIT_BATT_CHARGE )
{
// 充電状態反映
if( is_bt_charging ) // set_irqを別々に呼ぶ方がコンパクト
{
set_irq( VREG_C_IRQ1, REG_BIT_BT_CHG_START );
}
else
{
set_irq( VREG_C_IRQ1, REG_BIT_BT_CHG_STOP );
}
}
}
if(( system_status.pwr_state == ON ) ||
( system_status.pwr_state == SLEEP )
)
{
if( diff & REG_BIT_ST_SHELL_OPEN )
{
// 蓋の開け閉め
if( is_shell_open )
{
set_irq( VREG_C_IRQ0, REG_BIT_SHELL_OPEN );
}
else
{
set_irq( VREG_C_IRQ0, REG_BIT_SHELL_CLOSE );
}
}
}
}
}

View File

@ -0,0 +1,685 @@
/* ========================================================
task_sys
$Id$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma NOP
#pragma HALT
#pragma STOP
#endif
#include "incs.h"
#include "i2c_twl.h"
#include "i2c_ctr.h"
#include "led.h"
#include "accero.h"
#include "pm.h"
#include "rtc.h"
#include "sw.h"
#include "adc.h"
#include "self_flash.h"
#include "i2c_mcu.h"
#include "vreg_twl.h"
//=========================================================
#define WAIT_SHIROBAKO_POW_CONTROL 240
//=========================================================
extern void nop8();
static void chk_emergencyExit();
static void force_off_check();
static void send_getup_to_soc();
#ifdef _DBG_CHK_OFF_LEAK_
static void leak_check();
#endif
//=========================================================
extern bit info_led_off;
extern bit going_to_sleep;
extern bit bt_authorized;
static u8 timeout_sleep;
extern u8 chg_led_override;
#ifdef i2c_timeout_test
extern bit i2c_mcu_time_out_error;
#endif
//=========================================================
#define PWSW_POWON_TIME (u8)( 20 / SYS_INTERVAL_TICK ) // [ms] // INTERVAL_TSK_SW で割らない。値が元から小さいので
#define PWSW_ON_CHECK_TIMEOUT 100 // 適当 電源onの為に電源スイッチが操作されたとき、この時間経過したらmcuを省電力に戻す
/********************************************//**
***********************************************/
void tsk_sys( )
{
static u8 pwsw_timeout = 0; // 電源ボタンチャタリング回避。 タイムアウトするまでに電源投入確定しないとoffに戻る
hal_update();
switch ( system_status.pwr_state )
{
case ON_CHECK: //-------------------------------------------------------
// 強制電源断カウントダウンタイマクリア
clear_pow_off_countdown();
// 他の割り込みでHALT(スリープ)が解除 / アダプタ有時
// 電源スイッチでHALT解除 //
if( system_status.poweron_reason == RSN_PWSW )
{
if( PM_EXTDC_n )
{
// アダプタなし
if( SW_pow_count != 0 )
{
pwsw_timeout = 0;
}
else
{
pwsw_timeout ++;
}
if( pwsw_timeout > PWSW_ON_CHECK_TIMEOUT )
{
SW_pow_count = 0;
system_status.pwr_state = OFF_TRIG; // スイッチはノイズだった。寝る。
renge_task_interval_run_force = true;
return;
}
}
else
{
BT_chk();
}
if( SW_pow_count < PWSW_POWON_TIME )
{
// 押し時間が短くて電源onに到達していない
return;
}
}
// else { if( system_status.poweron_reason == RSN_TRIAL、… ) 電源投入 }
SW_pow_mask = true; // pwsw押しっぱなしで電源入/切 を繰り返さないように
// 電源投入 //
iic_mcu_start( );
bt_force_update = false;
BT_chk(); // 実機やバッテリの判定、電池残量ICの設定
#ifndef _ALLOW_NOBATT_
if( system_status.model == MODEL_JIKKI_NOBATT )
{
renge_task_interval_run_force = true;
system_status.pwr_state = OFF_TRIG;
return;
}
#endif
// 残量チェック
BT_get_left(); // 先に、BT_chk()が実行されている必要があります。
if(
// ( vreg_ctr[VREG_C_BT_REMAIN] < 1 ) // こっちで判定すると電池がほとんど無いときに
// // アダプタ差しても数分起動できなくなっちゃう
( vreg_ctr[VREG_C_BT_VOLTAGE] < ( V_TH_ZERO / 256 ) ) // 電池空っぽ
)
{
// 電池が少ないので起動させない(電圧チェックもされてる)
renge_task_interval_run_force = true;
system_status.pwr_state = OFF_TRIG;
return;
}
// ポートの方向設定 電源入れる前に。
PM_SW_WIFI_n = 1;
PM_SW_HOME_n_JIKKI = 1;
PM_WL_TX = 1;
PM_SW_SEL_n = 1;
PM_ACCEL_INT1 = 1;
PM_ACC_VALID = 1;
if( PM_sys_pow_on( ) != ERR_SUCCESS )
{ // 電源起動不可エラー
renge_task_interval_run_force = true;
system_status.pwr_state = OFF_TRIG;
return;
}
// ここまで来ると、電源投入確定 //
// プルアップon
PU_BT_IN_CHG_n = 1;
PU7 = bits8(0,0,0,1, 1,1,0,1); // 4:SW_WIFI 3:SW_PWSW 2:PM_IRQ 0:PM_EXTDC_n
PU_SW_HOME_n_JIKKI = 1; // SW_HOME
reset_release();
if( system_status.poweron_reason == RSN_PWSW ||
system_status.poweron_reason == RSN_TRIAL )
{
// 電源ボタンでのonの時は、LEDを点灯させる
vreg_ctr[VREG_C_LED_POW] = LED_POW_ILM_AUTO;
}
else
{
// とりあえず、LED消灯状態で起動させる
vreg_ctr[VREG_C_LED_POW] = LED_POW_ILM_OFF;
}
system_status.pwr_state = ON_TRIG;
PM_LCD_vcom_set( ); // LCDの対向電圧値など書き込み
break;
case ON_TRIG: //-------------------------------------------------------
#ifdef i2c_timeout_test
LED_duty_pow_blu = 0; // debug
LED_duty_3d = 0;
LED_duty_notify_red = 0;
LED_duty_notify_grn = 0;
LED_duty_notify_blu = 0;
LED_pow_red = 0;
LED_CAM = 0;
i2c_mcu_time_out_error = false;
#endif
/// ここでやるべきでは?
// プルアップon
PU_BT_IN_CHG_n = 1;
PU7 = bits8(0,0,0,1, 1,1,0,1); // 4:SW_WIFI 3:SW_PWSW 2:PM_IRQ 0:PM_EXTDC_n
PU_SW_HOME_n_JIKKI = 1; // SW_HOME
IIC_ctr_Init( );
IIC_twl_Init( );
vreg_twl_init( );
vreg_ctr_reset( );
KRM = bits8(0,0,0,0, 0,0,0,0);
PIF0 = 0;
system_status.poweron_reason = NONE;
renge_task_interval_run_force = true;
MK0 = INT_MSK0_RSV;
MK1 = INT_MSK1_RSV;
iic_mcu_start();
// MK2 = ~( INT_MSK2_IIC_TWL | INT_MSK2_WIFI_TX_BSR | INT_MSK2_CODEC_PMIRQ );
// PMK21 = 0; // wifi 使わない
PMK6 = 0; // pm_irq
// リブート時、ステータスを辻褄合わせ
if( system_status.reboot )
{
u8 bl_status_temp;
// LCD 電源onだったか ステータスの更新をする。
/// ファーム更新時、必ず液晶offかも
if( read_pmic( PM_REG_ADRS_VDD_LCD ) != 0 )
{
vreg_ctr[ VREG_C_STATUS ] |= REG_BIT_LCD_POW;
// LCD_AMOL_HV_CTRL = 1; 不要。ファーム更新時、ピン状態は保持のため。
}
// バックライトが点いていた? ステータスの更新をする。
bl_status_temp = read_pmic( PM_REG_ADRS_BL );
vreg_ctr[ VREG_C_STATUS ] |= (( bl_status_temp & 0x03 ) << 5 );
// バッテリ&本体識別
BT_chk();
}
LED_init( ); // reboot時の↑BT_Chk,BT_chk後に行いたい
system_status.reboot = 0;
system_status.pwr_state = ON;
// WDTリセット時、I2Cの初期化まで割り込み保留
// ほんとはここにべた書きしたくないが...
if( ( vreg_ctr[ VREG_C_MCU_STATUS ] & REG_BIT_STATUS_WDT_RESET ) != 0 )
{
set_irq( VREG_C_IRQ0, REG_BIT_IRQ_WDT_RESET );
}
break;
case ON: //---------------------------------------------
// PMICによる強制電源断チェック
// デバッガがreset1をアサートすることもある。そのときは全部リセット
chk_emergencyExit();
// SLP監視
if( going_to_sleep ) // 絶対に SLP_REQ の前に予告が来る
{
timeout_sleep ++;
if( timeout_sleep == 0 || // オーバーフローを期待。sleepするって言ったけど一瞬で起きて気がつかなかった
( PIF0 && !SLP_REQ )) // slp割り込みが入った気がしたが、もう起きてしまった
{
PIF0 = 0;
send_getup_to_soc();
}
if( PIF0 && SLP_REQ ){
PIF0 = 0;
PM_VDD_ecoMode();
system_status.pwr_state = SLEEP;
renge_task_interval_run_force = true;
}
}
// 強制offカウント
force_off_check();
#ifndef _TAIKENDAI_SEISAN_SPECIAL_
if( system_status.taikendai ) // アダプタが抜けたら自動で電源off
{
if( PM_EXTDC_n )
{
system_status.pwr_state = OFF_TRIG;
}
}
#endif
break;
case SLEEP: //------------------------------------------
chk_emergencyExit();
// スリープから復帰
if( !SLP_REQ ){
PM_VDD_normMode();
wait_ms( 5 ); // tdly_sw
send_getup_to_soc();
system_status.pwr_state = ON;
}
force_off_check();
// leak_check();
#ifndef _TAIKENDAI_SEISAN_SPECIAL_
if( system_status.taikendai ) // アダプタが抜けたら自動で電源off
{
if( PM_EXTDC_n )
{
system_status.pwr_state = OFF_TRIG;
}
}
break; // ←ここでよい。
#else
/* FALLTHROUGH */
#endif
default: //---------------------------------------
system_status.pwr_state = OFF_TRIG; // あり得ないステート。デバッグ用
// dbg_nop();
/* FALLTHROUGH */
case OFF_TRIG: //---------------------------------------
// LED消灯を待つ
vreg_ctr[ VREG_C_LED_POW ] = LED_POW_ILM_OFF;
vreg_ctr[ VREG_C_LED_WIFI ] = WIFI_LED_OFF;
vreg_ctr[ VREG_C_LED_3D ] = LED_3D_ILM_OFF;
info_led_off = true;
if( LED_duty_pow_blu != 0 )
{
return;
}
// 強制電源断カウントダウンタイマクリア
clear_pow_off_countdown();
// 加速度センサ停止
vreg_ctr[ VREG_C_ACC_CONFIG ] = 0x00;
tski_acc_setup();
EI(); // DI状態でかえって来るので、I2C_mcu 完了させるのに必要を
// その他ペリフェラル停止
LED_stop( );
IIC_ctr_Stop( );
IIC_twl_Stop( );
RTC_32k_off();
// 電源オン条件の割り込みセット
// PWSW KR3 押すとL
// BG24 KR4
// ふた開け INTP5 閉じるとL
// ACアダプタ INTP4 アダプタありでL
// RTC
while( iic_mcu_busy )
{;}
// irqマスク設定
KRM = ( KR_SW_POW ); // Mask ではなく、Modeなのだそうだ。紛らわしい
MK0 = ~( INT_MSK0_EXTDC | INT_MSK0_WDTI );
MK1 = ~( INT_MSK1_KR | INT_MSK1_RTCINTVAL ); // INT_MSK1_RTCALARM | RTCアラーム封印中
MK2L = 0xFF;
// irqフラグクリア
vreg_ctr[VREG_C_IRQ0] = 0;
vreg_ctr[VREG_C_IRQ1] = 0;
vreg_ctr[VREG_C_IRQ2] = 0;
vreg_ctr[VREG_C_IRQ3] = 0;
// PU5 そのまま
PU7 = bits8(0,0,0,0, 1,0,0,1); // PWSWI,PM_EXTTDC,( IRQ0_deactive(), PM_IRQ_deactive )
PU_SW_HOME_n_JIKKI = 0; // SW_HOME 停止
IF0 = 0;
IF1 = 0;
IF2 = 0;
IRQ0_disable;
PM_sys_pow_off( ); // 電源カットオフ
// ポート類を停止モードに。こういう回路でも、L出力にしなきゃだめだそうな。
SW_WIFI_n_RAW = 0;
PM_SW_WIFI_n = 0;
SW_HOME_n_JIKKI_RAW = 0;
PM_SW_HOME_n_JIKKI = 0;
WL_TX = 0;
PM_WL_TX = 0;
SW_SEL_n = 0;
PM_SW_SEL_n = 0;
ACCEL_INT1 = 0;
PM_ACCEL_INT1 = 0;
ACC_VALID = 0;
PM_ACC_VALID = 0;
system_status.pwr_state = OFF;
SW_pow_mask = true;
SW_pow_count = 0;
// HALデバッグリセット 忘れると電源on出来なくなることが…
hal_reset();
/* FALLTHROUGH */
case OFF:
// 注:現状では電源ボタンしか電源投入はありません。
system_status.poweron_reason = NONE;
pwsw_timeout = 0;
LCD_AMOL_HV_CTRL = 0; // 異常終了時、アモルファスLCD用電源を切り忘れてしまう
if( !PM_EXTDC_n
|| chg_led_override != 0 ) // これがゼロになるまで待つ
{
// アダプタ有り /////////////////////////////// または、アダプタさして秒は充電LEDを点けている期間
// 電源ボタン押しチェックへ
system_status.poweron_reason = RSN_PWSW;
system_status.pwr_state = ON_CHECK;
#ifndef _TAIKENDAI_SEISAN_SPECIAL_
// 試遊台なら自動で電源再投入
if( system_status.taikendai )
{
vreg_ctr[ VREG_C_HAL_OVW_CONT0 ] = vreg_ctr[ VREG_C_HAL_OVW_CONT1 ] = 0;
wait_ms(46); // pmicの電源再投入仕様のため
system_status.poweron_reason = RSN_TRIAL;
system_status.pwr_state = ON_CHECK;
}
#endif
}
else
{
// アダプタなし ///////////////////////////////
// 省電力へ移行
iic_mcu_stop( );
pm_chk_adapter();
PM_Chg_Stop();
bt_force_update = true;
while( RWST )
{;}
// 割り込み待ちで寝る //
RTCIMK = 1; // systick用インターバルタイマー割り込みマスク
#ifdef _DBG_CHK_OFF_LEAK_
leak_check();
#endif
CKC = bits8(0,0,0,0, 1,0,0,1); // 4MHzに落として(bit0)からSTOPしなくてはならない
OSMC = bits8(0,0,0,0, 0,0,0,0); // 5MHz以下モードへ。
if( PM_EXTDC_n_RAW ) // きわどいタイミングで挿抜が起きることがある。HAL通さないべきoff中ですし
{
STOP();
}
// 起きる //
// 起きる条件は
// ・KeyReturn割り込み電源ボタン
// ・RTCアラーム現在封印
// クロック復帰
OSMC = bits8(0,0,0,0, 0,0,0,1); // 8MHz動作準備
renge_flg_interval = 0;
hal_update();
CKC = bits8(0,0,0,0, 1,0,0,0); // OSMC.FSEL = 1 後3clk以上開ける
// 起きた理由は?
if( !PM_EXTDC_n ){
system_status.pwr_state = OFF; // 一回回ってきて、ON_CHECKに行く
}
/* // RTCアラーム。封印中
else if( vreg_ctr[ VREG_C_IRQ1 ] & REG_BIT_RTC_ALARM )
{
system_status.poweron_reason = RSN_RTC_ALARM;
system_status.pwr_state = ON_CHECK;
}
// else if( 他の割り込みで電源on ){
// 現状他の要因では起きない
// }
*/
else // if( !SW_POW_n ) // (それ以外なら)電源ボタンで起きた
{
SW_pow_mask = false;
system_status.poweron_reason = RSN_PWSW;
system_status.pwr_state = ON_CHECK;
}
RTCIMK = 0; // sys tick タイマー有効
#ifndef _TAIKENDAI_SEISAN_SPECIAL_
if( system_status.taikendai )
{
system_status.pwr_state = OFF_TRIG;
}
#endif
}
}
}
/********************************************//**
PMICが電源異常で止めたか確認
***********************************************/
static void chk_emergencyExit(){
static u8 shirobako_power_control_count;
// wifi モジュールキャリブレーションモードでreset1を自分から下げてるときはチェックをパス
if( is_wifi_calib_resets_ast )
{
return;
}
if( shirobako_power_control_count == 0 )
{
if( !RESET1_n ) // PM_chk_LDSW() はI2C_mを使用し、高コスト
{
if( !PM_chk_LDSW() )
{
// リセットが下がってる
/// PMICが異常終了判断をした
system_status.pwr_state = OFF_TRIG;
renge_task_interval_run_force = true;
}
else
{
// 白箱の仕業
shirobako_power_control_count = 1;
}
}
}
else
{
if( shirobako_power_control_count == WAIT_SHIROBAKO_POW_CONTROL ) // マジックナンバー
// デバッガが何かした。reset1を解除するまでは無視
{
if( RESET1_n ) // リセットネゲート待ち
{
shirobako_power_control_count = 0;
}
else
{
// nothing to do
}
}
else if( shirobako_power_control_count == 200 ) // * (sys_tick)[ms]
// デバッガが何かしたいらしい
{
#ifndef _RVD_
// 白箱は電源を切りたいらしい
system_status.pwr_state = OFF_TRIG;
renge_task_interval_run_force = true;
shirobako_power_control_count = WAIT_SHIROBAKO_POW_CONTROL;
#endif
}
else
{
if( !RESET1_n )
{
if( shirobako_power_control_count != 255 )
shirobako_power_control_count ++;
}
else
{
// (TSボードで手動で/デバッガが)リセットをかけたらしい
send_cmd_pmic( PM_REG_ADRS_BL, 0 );
vreg_ctr[VREG_C_STATUS] = ( vreg_ctr[VREG_C_STATUS] & bits8(1,0,0,1, 1,1,1,1) );
vreg_ctr[VREG_C_COMMAND0] |= REG_BIT_RESET1_REQ;
renge_task_immed_add( tski_do_command0 );
shirobako_power_control_count = WAIT_SHIROBAKO_POW_CONTROL;
}
}
}
}
/********************************************//**
-
-
-
OFF
***********************************************/
static void force_off_check()
{
if( force_off )
{
system_status.pwr_state = OFF_TRIG;
renge_task_interval_run_force = true;
}
}
/********************************************//**
SoCを起こす
  
***********************************************/
void send_getup_to_soc()
{
going_to_sleep = false;
timeout_sleep = 0;
#ifdef _MODEL_CTR_
SLP_ACK = 1;
nop8();
SLP_ACK = 0;
#endif
}
/********************************************//**
firm_update() isr中から実行できないので
task_status_immed型 ...
***********************************************/
task_status_immed tski_firm_update(){
firm_update();
return( ERR_SUCCESS );
}
#ifdef _DBG_CHK_OFF_LEAK_
/********************************************//**
pin設定ミスチェック
***********************************************/
static void leak_check()
{
volatile u8 ports_i[12];
volatile u8 ports_o[12];
ports_i[0] = ( PM0 & PU0 & ~P0 ); // プルアップ切り忘れ?
ports_i[1] = ( PM1 & PU1 & ~P1 );
ports_i[2] = 0;
ports_i[3] = ( PM3 & PU3 & ~P3 );
ports_i[4] = ( PM4 & PU4 & ~P4 );
ports_i[5] = ( PM5 & PU5 & ~P5 );
ports_i[6] = 0;
ports_i[7] = ( PM7 & PU7 & ~P7 );
ports_i[8] = ( PM12 & PU12 & ~P12 );
ports_i[9] = ( PM14 & PU14 & ~P14 );
ports_i[10] = 0;
ports_i[11] = ( PM20 & PU20 & ~P20 );
ports_o[0] = ( ~PM0 & P0 ); // H 出力しちゃってるかも
ports_o[1] = ( ~PM1 & P1 );
ports_o[2] = ( ~PM2 & P2 );
ports_o[3] = ( ~PM3 & P3 & ~POM3 );
ports_o[4] = ( ~PM4 & P4 ); // bit3はchg_enなので1でもよい
ports_o[5] = ( ~PM5 & P5 );
ports_o[6] = ( ~PM6 & P6 );
ports_o[7] = ( ~PM7 & P7 );
ports_o[8] = ( ~PM12 & P12 );
ports_o[9] = ( ~PM14 & P14 );
ports_o[10] = ( ~PM15 & P15 );
ports_o[11] = ( ~PM20 & P20 );
NOP(); // ←ブレーク置くため
}
#endif _DBG_CHK_OFF_LEAK_

View File

@ -0,0 +1,214 @@
#ifndef _USER_DEF_
#define _USER_DEF_
// $Id: asdf$
#define IIC_T_SLAVEADDRESS 0x4A
#define IIC_C_SLAVEADDRESS 0x4A
#define IIC_C_SLAVEADDRESS_DMY 0x4C
//#define IIC_SLA_DCP 0x50
#define bits8(a,b,c,d,e,f,g,h) ( a<<7 | b<<6 | c<<5 | d<<4 | e<<3 | f<<2 | g<<1 | h )
#ifndef _WIN32
// 実機環境
#ifdef _debug_led_
/*spfl対応以降、ncでなくなるので使えません
# define DBG_LED_on { PM2.1 = 0; P2.1 = 1; }
# define DBG_LED_off { P2.1 = 0; }
# define DBG_LED_toggle ( P2.1 ^= 1 )
# define DBG_LED2_on { PM2.2 = 0; P2.2 = 1; }
# define DBG_LED2_off { P2.2 = 0; }
# define DBG_LED2_toggle ( P2.2 ^= 1 )
*/
#else
# define DBG_LED_on ;
# define DBG_LED_off ;
# define DBG_LED_toggle ;
# define DBG_LED2_on ;
# define DBG_LED2_off ;
# define DBG_LED2_toggle ;
#endif // _debug_led_
#define IIC_SLA_CODEC 0xA4
#define IIC_SLA_ACCEL 0x30 // ST LIS331DLH
#define SLP_ACK P7.7
// PMxは0で出力モード
// SoC
#define IRQ0_ast { P7.6 = 0; PM7.6 = 0; } // B4
#define IRQ0_neg { P7.6 = 1; }
#define IRQ0_enable { PM7.6 = 0; }
#define IRQ0_disable { PM7.6 = 1; }
#define IRQ0 ( P7.6 )
// ↓誤代入防止
#define RESET1_n ( P0.0 ) // G7
#if 1 // 普段はPM_RESET1を使うが、WiFiモジュールのテストの時は直たたきする
# define RESET1_ast { P0.0 = 0; PM0.0 = 0; }
# define RESET1_neg { PM0.0 = 1; }
#endif
#define RESET2_ast { P0.1 = 0; PM0.1 = 0; } // F7
#define RESET2_neg { PM0.1 = 1; }
#define SLP_REQ P12.0 // H8
// CTR,SPFL,SNAKE,まだ見ぬ派生機識別
#define DEV_DET ( P12 & 0b00000110 ) // [2:1] = D8,C8
#define DEV_CTR ( 0b00 << 1 )
#define DEV_SPFL ( 0b01 << 1 )
#define DEV_SNAKE ( 0b10 << 1 )
#define DEV_RSV2 ( 0b11 << 1 )
// FCRAM
#define FCRAM_RST P3.0 // B6
#define FCRAM_RST_ast { P3.0 = 0; }
#define FCRAM_RST_neg { P3.0 = 1; }
// CODEC
#define PM_IRQ_n P7.2 // A3
// INTP6
// PM
#define PM_EXTDC_n_RAW P7.0 // B2
// INTP7
//#define BT_TEMP P15.0 // G3(a)
// ANI8
//#define BT_DET P15.1 // H2(a)
// ANI9
#define BT_DET_P P1.6 // D4
#define BT_TEMP_P P1.7 // C4
// SPFLのアモルファスLCDで必要な±15Vの電源。
#define LCD_AMOL_HV_CTRL P20.2 // F2
// 充電せよ(out)
// 負論理です。注意。
#define BT_CHG_ENABLE() ( P4.3 = 0 ) // F6
#define BT_CHG_DISABLE() ( P4.3 = 1 )
#define BT_CHG_Ena_n ( P4.3 )
// 充電中(in)
#define BT_IN_CHG_n_RAW P5.1 // B1
#define PM_BT_IN_CHG_n PM5.1
#define PU_BT_IN_CHG_n PU5.1
#define SW_WIFI_n_RAW P7.4 // C3
#define PM_SW_WIFI_n PM7.4
// KR4
#define SW_POW_n_RAW P7.3 // B3
// KR3
#define SW_SEL_n P2.3 // G5
#define PM_SW_SEL_n PM2.3
//#define VOL P2.7 // H4(a)
// ANI7
#define SW_HOME_n_JIKKI_RAW P20.4 // G2
#define PM_SW_HOME_n_JIKKI PM20.4
#define PU_SW_HOME_n_JIKKI PU20.4
// INTP22
#define SW_HOME_n_TSBOARD_RAW P2.0 // TSマザー上でpull up(P2は内蔵p.u.無い) // G6
#define PM_SW_HOME_n_TSBOARD PM2.0
// WiFi
#define WL_TX P20.3 // INTP21 // F3
#define PM_WL_TX PM20.3 // INTP21
//#define VOL_P P2.1 // E5 現状open
//#define VOL_N P2.2 // F5 〃
//#define LED_CAM P1.0 // TO02 // E4
//#define LED_WIFI P1.1 // TO03 // E3
//#define LED_NOTIFY P1.3 // TO05 // D3
//#define LED_3D P5.2 // SLTO ← TO01 // A2
//#define LED_POW2 P1.4 // TO06 ( 青 ) // D2
//#define LED_POW1 P1.5 // TO07 ( 赤 ) // D1
//#define LED_CHARGE P2.4 // H5
// P5.3 に加え、P5.5, P140 P141
// P140が出力専用なので...
#define I2C_PU_on() { P14 |= 0x03; PM5.3 = 0; PM3.3 = 0; } // P14[1:0] H6,H7 P5.3,3.3 A1,C5
#define I2C_PU_off() { PM5.3 = 1; PM3.3 = 1; P14 &= ~0x03; }
#define GYRO_ENABLE() P5.0 = 0 // C1
#define GYRO_DISABLE() P5.0 = 1
//#define I2C_M_SDA P3.1 // SDA10 // C6
//#define I2C_M_SCL P3.2 // SCL10 // B5
//#define I2C_0_SCL P6.0 // IIC_TWL SCL0 // A7
//#define I2C_0_SDA P6.1 // SDA0 // A6
//#define I2C_1_SCL P20.0 // IIC CTR SCL1 // E1
//#define I2C_1_SDA P20.1 // SDA1 // F1
//#define 32kHz_O P1.2 // RTCCL // E2
//#define 32k_I1 P12.3 // XT1 // F8
//#define 32k_I2 P12.4 // XT2 // G8
// 実機、開発機、試遊台判別。
#define DIPSW ( P4 & 0b00000011 ) // mini cube & ソフトウェアディップスイッチ TOOL0,1。 P4.0は L 注意!
#define DIPSW_CTR 0b11 // 未使用
#define DIPSW_ISDEV 0b00 // KuCはBattGaugeで判別
#define DIPSW_TAIKENDAI 0b10
#define DIPSW_TAIKENDAI_NBD 0b01
#define SHELL_OPEN_RAW P7.1 // INTP5 ふた開閉 (閉じるとL) // C2
#define ACC_VALID P20.5 // H3
#define PM_ACC_VALID PM20.5
#define ACCEL_INT1 P2.5 // F4
#define PM_ACCEL_INT1 PM2.5
#endif // _WIN32
// win32 sim環境と共通
#define KR_SW_POW ( 1 << 3 )
#define KR_SW_WIFI ( 1 << 4 )
///////////////////////////////////////////////////////////
#ifdef _WDT_CHECK_
# define INT_MSK0_WDTI 1<<15
#else
# define INT_MSK0_WDTI 0
#endif
#define INT_MSK0_IIC_M_DMA 1<<12
#define INT_MSK0_SHELL 1<<7
#define INT_MSK0_EXTDC 1<<6
//#define INT_MSK0_SLP 1<<2
#define INT_MSK0_RSV ~( INT_MSK0_IIC_M_DMA | INT_MSK0_SHELL | INT_MSK0_EXTDC | INT_MSK0_WDTI )
#define INT_MSK1_KR 1<<11
#define INT_MSK1_RTCINTVAL 1<<10
#define INT_MSK1_RTCALARM 1<<9
#define INT_MSK1_ADC 1<<8
#define INT_MSK1_IIC_CTR 1<<3
#define INT_MSK1_IIC_MCU 1<<0
#define INT_MSK1_RSV ~( INT_MSK1_KR | INT_MSK1_RTCINTVAL | INT_MSK1_RTCALARM | INT_MSK1_ADC \
| INT_MSK1_IIC_CTR | INT_MSK1_IIC_MCU )
#define INT_MSK2_WIFI_TX_KE3 1<<4
#define INT_MSK2L_RSV ~( INT_MSK2_WIFI_TX_KE3 )
#define INT_MSK2_IIC_TWL 1<<8
#define INT_MSK2_WIFI_TX_BSR 1<<10
#define INT_MSK2_CODEC_PMIRQ 1<<3
#define INT_MSK2_RSV ~( INT_MSK2_IIC_TWL | INT_MSK2_WIFI_TX_BSR | INT_MSK2_CODEC_PMIRQ )
#endif // dupe include guard

View File

@ -0,0 +1,65 @@
/* ========================================================
util_funcs
$Id$
======================================================== */
#ifndef _WIN32
#pragma SFR
#pragma di
#pragma ei
#pragma nop
#pragma stop
#pragma halt
#pragma opc
#endif
#include "incs_loader.h"
#include "wdt.h"
/********************************************//**
ms
NOPを回すだけCPUを **
***********************************************/
void wait_ms( u8 ms ){
u16 fine;
WDT_Restart();
while( ms != 0 ){
ms--;
fine = 860;
while( fine != 0 ){
fine --;
}
}
}
extern unsigned char get_ei();
#ifdef _DI_WITH_CHECK_
/********************************************//**
#ifdef DI
***********************************************/
void DI_wt_chk()
{
if( !get_ei() )
{
dbg_nop();
}
DI();
}
#endif // _DI_WITH_CHECK_

View File

@ -0,0 +1,16 @@
#ifndef _util_funcs_h_
#define _util_funcs_h_
void wait_ms( u8 );
# ifdef _DI_WITH_CHECK_
void DI_wt_chk();
# else
# define DI_wt_chk() DI()
# endif /* _DI_WITH_CHECK_ */
#endif

View File

@ -0,0 +1,64 @@
/* ========================================================
voltable.c
$Id$
======================================================== */
#include "incs.h"
#define _10db_
/********************************************//**
CODEC Volの関係で
***********************************************/
#ifdef _10db_
// max -10db
const u8 slider_to_codec[64] =
{
127, 126, 125, 124, 122, 121, 120, 119,
118, 117, 116, 114, 113, 112, 111, 110,
109, 108, 106, 105, 104, 103, 102, 101,
100, 98, 97, 96, 95, 94, 93, 92,
90, 89, 88, 87, 86, 85, 83, 82,
81, 80, 79, 78, 77, 75, 74, 73,
73, 72, 71, 70, 69, 67, 66, 65,
64, 63, 62, 61, 59, 58, 57, 56
};
#endif
#ifdef _15db_
// max -15db
const u8 slider_to_codec[64] =
{
127, 127, 127, 127, 127, 126, 125, 123,
122, 121, 120, 119, 118, 117, 116, 115,
114, 113, 112, 110, 109, 108, 107, 106,
105, 104, 103, 102, 101, 100, 99, 97,
96, 95, 94, 93, 92, 91, 90, 89,
88, 87, 86, 85, 84, 83, 82, 81,
80, 79, 78, 77, 76, 75, 74, 73,
71, 70, 69, 68, 67, 66, 66, 66
};
#endif
#ifdef _4db_
// max -4db
const u8 slider_to_codec[64] =
{
127, 127, 126, 125, 123, 122, 121, 119,
118, 117, 115, 114, 112, 111, 110, 108,
107, 106, 104, 103, 101, 100, 99, 97,
96, 94, 93, 92, 90, 89, 88, 86,
85, 83, 82, 81, 79, 78, 77, 75,
74, 72, 71, 70, 68, 67, 66, 64,
64, 63, 61, 60, 59, 57, 56, 54,
53, 52, 50, 49, 48, 46, 44, 44
};
#endif

View File

@ -0,0 +1,57 @@
#ifdef _10db_
// max -10db
/*
const u8 slider_to_codec[64] =
{
127, 127, 127, 127, 126, 125, 123, 122,
121, 120, 118, 117, 116, 115, 113, 112,
111, 110, 108, 107, 106, 105, 103, 102,
101, 100, 98, 97, 96, 95, 93, 92,
91, 90, 88, 87, 86, 85, 83, 82,
81, 80, 78, 77, 76, 75, 73, 72,
72, 71, 70, 68, 67, 66, 64, 63,
62, 61, 59, 58, 57, 56, 55, 55
};
*/
const u8 slider_to_codec[64] =
{
127, 126, 125, 124, 122, 121, 120, 119,
118, 117, 116, 114, 113, 112, 111, 110,
109, 108, 106, 105, 104, 103, 102, 101,
100, 98, 97, 96, 95, 94, 93, 92,
90, 89, 88, 87, 86, 85, 83, 82,
81, 80, 79, 78, 77, 75, 74, 73,
73, 72, 71, 70, 69, 67, 66, 65,
64, 63, 62, 61, 59, 58, 57, 56
};
#endif
#ifdef _15db_
// max -15db
const u8 slider_to_codec[64] =
{
127, 127, 127, 127, 127, 126, 125, 123,
122, 121, 120, 119, 118, 117, 116, 115,
114, 113, 112, 110, 109, 108, 107, 106,
105, 104, 103, 102, 101, 100, 99, 97,
96, 95, 94, 93, 92, 91, 90, 89,
88, 87, 86, 85, 84, 83, 82, 81,
80, 79, 78, 77, 76, 75, 74, 73,
71, 70, 69, 68, 67, 66, 66, 66
};
#endif
#ifdef _4db_
// max -4db
const u8 slider_to_codec[64] =
{
127, 127, 126, 125, 123, 122, 121, 119,
118, 117, 115, 114, 112, 111, 110, 108,
107, 106, 104, 103, 101, 100, 99, 97,
96, 94, 93, 92, 90, 89, 88, 86,
85, 83, 82, 81, 79, 78, 77, 75,
74, 72, 71, 70, 68, 67, 66, 64,
64, 63, 61, 60, 59, 57, 56, 54,
53, 52, 50, 49, 48, 46, 44, 44
};
#endif

View File

@ -0,0 +1,638 @@
/* ========================================================
CTR MCU I2Cレジスタ
$Id$
====================================================== */
#include "incs.h"
#include "vreg_ctr.h"
#include "rtc.h"
#include "led.h"
#include "accero.h"
#include "pm.h"
#include "pool.h"
#include "vreg_twl.h"
#include "sw.h"
#include "WDT.h"
#include <fsl.h>
#include "fsl_user.h"
extern u8 extinfo_read(); // task_misc.c
extern u8 iic_burst_state; // 特殊バーストアクセスする時のカウンタ
extern bit info_led_pattern_updated; // お知らせLEDのパターンを先頭に戻す
extern bit pedolog_overflow;
extern bit reserve_pedo_increnent;
// ********************************************************
u8 vreg_ctr[VREG_C_ENDMARK_];
static u8 vreg_free_adrs; // アドレス飛んでるのでしばらくはこれで
bit irq_readed; // AAA型のため。
// ********************************************************
extern task_status_immed tski_firm_update();
extern task_status_immed tski_mcu_reset();
extern unsigned char get_ei();
// ********************************************************
#ifdef _MCU_BSR_
#define IICAMK IICAMK1
#endif
/********************************************//**
***********************************************/
void vreg_ctr_init( )
{
vreg_ctr[ VREG_C_VCOM_T ] = VCOM_DEFAULT_T;
vreg_ctr[ VREG_C_VCOM_B ] = VCOM_DEFAULT_B;
vreg_ctr[ VREG_C_OFF_DELAY ] = FORCEOFF_THREASHOLD;
vreg_ctr[ VREG_C_VOL_CAL_MIN ] = 0x36;
vreg_ctr[ VREG_C_VOL_CAL_MAX ] = 0xFF - 0x36;
}
/********************************************//**
***********************************************/
void vreg_ctr_reset( )
{
vreg_ctr[ VREG_C_MCU_VER_MAJOR ] = MCU_VER_MAJOR | 0x10;
vreg_ctr[ VREG_C_MCU_VER_MINOR ] = MCU_VER_MINOR;
// vreg_ctr[ VREG_C_STATUS ] &= bits8(0,0,0,1, 1,1,1,1);
vreg_ctr[ VREG_C_LED_BRIGHT ] = 0xFF;
vreg_ctr[ VREG_C_LED_POW ] = 0;
vreg_ctr[ VREG_C_LED_WIFI ] = 0;
vreg_ctr[ VREG_C_LED_CAM ] = 0;
vreg_ctr[ VREG_C_LED_3D ] = 0;
{
u8 i;
for( i = 0; i < sizeof( uni_info_LED ); i++ )
{
info_LED.bindata[ i ] = 0;
}
}
vreg_ctr[ VREG_C_WIFI_CALIB ] = 0;
// ここでやるのは気持ち悪いが…
RTC_32k_on();
RESET1_neg;
RESET2_neg;
FCRAM_RST_neg;
}
/********************************************//**
I2C仮想レジスタに書きます
  adrs
 
I2C_mcu通信が発生する場合renge_task_immed_add()
使I2C_mcu使用中でエラー終了した場合にリトライしません
***********************************************/
void vreg_ctr_write( u8 adrs, u8 data )
{
switch ( adrs )
{
case VREG_C_COMMAND0:
if( data != 0 )
{
renge_task_immed_add( tski_do_command0 );
vreg_ctr[ VREG_C_COMMAND0 ] |= data;
}
break;
case VREG_C_COMMAND2:
// こちらからの完了割り込みを待ってくれないそうです。 #-ω-) 何のための割り込みだ
// 液晶電源
if(( data & REG_BIT_CMD_LCD_ON ) != 0 )
{
renge_task_immed_add( tski_PM_LCD_on );
}
else if(( data & REG_BIT_CMD_LCD_OFF ) != 0 )
{
renge_task_immed_add( tski_PM_LCD_off );
}
// バックライト設定
/// 今のところさらに細かくは分けないけど…
if(( data & REG_BITS_CMD_BL ) != 0 )
{
renge_task_immed_add( tski_PM_BL_set );
vreg_ctr[adrs] = (u8)( data & REG_BITS_CMD_BL );
}
break;
case VREG_C_COMMAND1:
if( data != 0 )
{
// u8 temp; 中間変数使ったらばかでかくなった...
// TWLに割り込みを入れる
/// 実際に割り込みを入れるのはSoC
/// ビットの並びが違うから面倒
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] = ( ( data & REG_BIT_SEND_TWL_PWSW_DET ) != 0 ) ? REG_BIT_TWL_IRQ_PWSW_DET : 0x00; //pwsw_det
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] |= ( ( data & REG_BIT_SEND_TWL_RESET_DET ) != 0 ) ? REG_BIT_TWL_IRQ_RESET : 0x00; //reset_req
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] |= ( ( data & REG_BIT_SEND_TWL_OFF_DET ) != 0 ) ? REG_BIT_TWL_IRQ_OFF : 0x00; //off_req
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] |= ( ( data & REG_BIT_SEND_TWL_BATT_LOW ) != 0 ) ? REG_BIT_TWL_IRQ_BT_LOW : 0x00; //batt_low
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] |= ( ( data & REG_BIT_SEND_TWL_BATT_EMPTY ) != 0 ) ? REG_BIT_TWL_IRQ_BT_EMPTY : 0x00; //batt_empty
if(( data & REG_BIT_SEND_TWL_VOL_CLICK ) != 0 )
{
vreg_twl[ REG_TWL_INT_ADRS_IRQ ] |= REG_BIT_TWL_IRQ_VOL_CHANGE; //vol_changed
}
}
break;
case VREG_CX_FREE_DATA:
if( vreg_free_adrs < VREG_C_FREE_SIZE )
{
pool.vreg_c_ext.vreg_c_free[ vreg_free_adrs ] = data;
vreg_free_adrs ++;
}
else
{
dbg_nop();
}
break;
case VREG_CX_FREE_ADRS:
vreg_free_adrs = data;
break;
case VREG_C_LED_POW:
if( iic_burst_state == 0 )
{
vreg_ctr[ VREG_C_LED_POW ] = data;
iic_burst_state ++;
}
else if( iic_burst_state < 5 )
{
led_red_batt_empty.dats[ iic_burst_state -1 ] = data;
iic_burst_state ++;
}
break;
case VREG_C_LED_WIFI:
case VREG_C_LED_CAM:
case VREG_C_LED_3D:
vreg_ctr[adrs] = (u8)( data & 0x0F );
break;
case VREG_C_LED_NOTIFY_DATA:
if( iic_burst_state < sizeof( uni_info_LED ) )
{
if(( iic_burst_state == 1 ) && ( data == 0 )) // fade_time == 0 禁止
{
data = 1;
}
info_LED.bindata[ iic_burst_state ] = data;
iic_burst_state ++;
if( iic_burst_state > 4 ) // パターンを1文字でも書いた
{
info_led_pattern_updated = true;
}
}
break;
case VREG_C_MCU_STATUS:
// vreg_twl[ REG_TWL_INT_ADRS_MODE ] = (u8)( ( data >> 6 ) & 0x03 ); Rでよい。その代わりリセットでクリア
vreg_ctr[ VREG_C_MCU_STATUS ] &= data; // bitクリアはするがセットはしない。
// 上の方のtwlレジスタミラーは読み出され時に合成
break;
case VREG_C_VCOM_T:
case VREG_C_VCOM_B:
renge_task_immed_add( tski_vcom_set );
vreg_ctr[adrs] = data;
break;
case VREG_C_DBG03:
if( ( vreg_ctr[VREG_C_DBG01] == 'j' )
&& ( vreg_ctr[VREG_C_DBG02] == 'h' )
&& ( data == 'l' ) )
{
renge_task_immed_add( tski_firm_update );
IICAMK = 1;
}
vreg_ctr[ VREG_C_DBG03 ] = data;
break;
/// 非同期で動いているためここでは書かない。
// 予約するだけでstopで書く
case VREG_C_RTC_SEC:
case VREG_C_RTC_MIN:
set_rtc( adrs - VREG_C_RTC_SEC, data & 0x7F );
break;
case VREG_C_RTC_DAY:
case VREG_C_RTC_HOUR:
set_rtc( adrs - VREG_C_RTC_SEC, data & 0x3F );
break;
case VREG_C_RTC_YOBI:
set_rtc( adrs - VREG_C_RTC_SEC, data & 0x07 );
break;
case VREG_C_RTC_MONTH:
set_rtc( adrs - VREG_C_RTC_SEC, data & 0x1F );
break;
case VREG_C_RTC_YEAR:
set_rtc( adrs - VREG_C_RTC_SEC, data );
break;
case VREG_C_RTC_COMP:
WDT_Restart();
while(1)
{
RWAIT = 1;
while( !RWST ){}
if( SEC != 0 )
{
break;
}
RWAIT = 0;
}
SUBCUD = data;
RWAIT = 0;
vreg_ctr[ VREG_C_RTC_COMP ] = data;
break;
case VREG_C_RTC_ALARM_MIN:
rtc_alarm_dirty = true;
vreg_ctr[ VREG_C_RTC_ALARM_MIN ] = (u8)( data & 0x7F );
break;
case VREG_C_RTC_ALARM_HOUR:
rtc_alarm_dirty = true;
vreg_ctr[ VREG_C_RTC_ALARM_HOUR ] = (u8)( data & 0x3F );
break;
// 書くだけでよい
case VREG_C_RTC_ALARM_DAY:
vreg_ctr[ VREG_C_RTC_ALARM_DAY ] = (u8)( data & 0x3F );
break;
case VREG_C_RTC_ALARM_MONTH:
vreg_ctr[ VREG_C_RTC_ALARM_MONTH ] = (u8)( data & 0x1F );
break;
case VREG_C_ACC_CONFIG:
renge_task_immed_add( tski_acc_setup );
vreg_ctr[ VREG_C_ACC_CONFIG ] = data;
break;
case VREG_C_ACC_R_ADRS:
renge_task_immed_add( tski_acc_read );
vreg_ctr[ VREG_C_ACC_R_ADRS ] = data;
break;
case VREG_C_ACC_W_BUF:
renge_task_immed_add( tski_acc_write );
vreg_ctr[ VREG_C_ACC_W_BUF ] = data;
break;
case VREG_C_ACC_HOSU_SETTING:
if( ( data & 0x01 ) != 0 )
{
clear_hosu_hist(); // 履歴クリア
}
break;
case VREG_C_WIFI_CALIB:
if( data & REG_BIT_WIFI_CALIB_32K_HI_Z )
{
RTC_32k_HI_Z();
}
else{
RTC_32k_on();
}
if( data & REG_BIT_WIFI_CALIB_RSTS_AST )
{
RESET1_ast;
// RESET2_ast; RESET1のみ。
// FCRAM_RST_ast;
}
else{
/*
SoC
RESET1_neg;
RESET2_neg;
FCRAM_RST_neg;
*/
}
vreg_ctr[ VREG_C_WIFI_CALIB ] = data;
break;
case VREG_C_COMMAND3:
switch ( data )
{
#ifdef _ENABLE_COMMAND3_
case 'r':
// 割り込みルーチンからFSLライブラリを呼ぶのは禁止
// マイコンを再起動。 レジスタ類も初期化される。
renge_task_immed_add( tski_mcu_reset );
break;
case 'w':
// WDTで再起動テスト向け
// mcu_wdt_reset; // このコマンド使ったら意味ないでしょ!
while(1)
{
dbg_nop();
}
break;
#endif //_ENABLE_COMMAND3_
#ifdef _ENABLE_HAL_
case 'p':
reserve_pedo_increnent = 1;
// ここで増やすにはスタックが足りない。↑で予約のみ、task_misc内で処理
// hosu_increment_if_necessary(); // 今、一歩増えた
break;
#endif //_ENABLE_HAL_
}
// vreg_ctr[ VREG_C_COMMAND3 ] = data; // 書く必要なし
break;
case VREG_C_RBR_CONTROL:
// vreg_ctr[ VREG_C_RBR_CONTROL ] = data; // todo debug ブレークポイントを置くため。現状、フリーレジスタ
break;
// read only //////////////////////////////////////////
case VREG_C_MCU_VER_MAJOR:
case VREG_C_MCU_VER_MINOR:
case VREG_C_3D: // すぐにリフレッシュされる
case VREG_C_SND_VOL: // すぐにリフレッシュされる
case VREG_C_BT_TEMP: // すぐにリフレッシュされる
case VREG_C_BT_REMAIN: // すぐにリフレッシュされる
case VREG_C_BT_REMAIN_FINE: // すぐにリフレッシュされる
case VREG_C_BT_VOLTAGE: // すぐにリフレッシュされる
case VREG_C_STATUS_1: // 適当にリフレッシュされる
case VREG_C_STATUS: // 適当にリフレッシュされる
case VREG_C_IRQ0: // 次のついでに割り込み起こしてほしいなら...
case VREG_C_IRQ1:
case VREG_C_IRQ2:
case VREG_C_IRQ3:
case VREG_C_IRQ4:
case VREG_C_LED_NOTIFY_FLAG: // すぐリフレッシュされる
case VREG_C_RTC_SEC_FINE_L: // すぐリフレッシュされる
case VREG_C_RTC_SEC_FINE_H: // すぐリフレッシュされる
// VREG_C_ACC_RESERVE, // 何も起きない
// VREG_C_ACC_HOSU_HIST = 0x4F,
case VREG_C_ACC_XH: // すぐリフレッシュされる
case VREG_C_ACC_XL:
case VREG_C_ACC_YH:
case VREG_C_ACC_YL:
case VREG_C_ACC_ZH:
case VREG_C_ACC_ZL:
// dbg_nop();
// return( ERROR )
break;
case VREG_C_ACC_HOSU_L: // 書けてもいいけど、デバッグ用。(アドレス0x4B == mcu sla(r))
// dbg_nop();
/* FALLTHROUGH */
// 普通に書かれるだけ /////////////////////////////////
default:
/*
case VREG_C_IRQ_MASK0:
case VREG_C_IRQ_MASK1:
case VREG_C_IRQ_MASK2:
case VREG_C_IRQ_MASK3:
case VREG_C_IRQ_MASK4:
case VREG_C_DBG01:
case VREG_C_DBG02:
case VREG_C_LED_BRIGHT:
case VREG_C_ACC_HOSU_L:
case VREG_C_ACC_HOSU_M:
case VREG_C_ACC_HOSU_H:
case VREG_C_ACC_HOSU_HOUR_BOUNDARY:
case VREG_C_FREE_ADRS:
case VREG_C_RTC_ALARM_YEAR:
case VREG_C_ACC_W_ADRS:
case VREG_C_OFF_DELAY:
case VREG_C_HAL_OVW_CONT0:
case VREG_C_HAL_OVW_DAT0:
case VREG_C_HAL_OVW_CONT1:
case VREG_C_HAL_OVW_DAT1:
*/
if( adrs < VREG_C_ENDMARK_ )
{
vreg_ctr[adrs] = data;
break;
}
else
{
// dbg_nop(); // 未定義アドレスに書いた なんかバグってない?
// return( ERROR )
break;
}
}
// return( SUCCESS )
return;
}
/********************************************//**
I2C仮想レジスタから読みます
xx
( vreg_ctr_after_read( u8 adrs ) )
***********************************************/
u8 vreg_ctr_read( u8 adrs )
{
static u16 rsub_temp;
u8 temp;
// RTCは読み出し途中に繰り上がるのを避けるため
if( ( VREG_C_RTC_SEC <= adrs ) && ( adrs <= VREG_C_RTC_YEAR ) )
{
rtc_buf_refresh( );
}
else if( adrs == VREG_C_MCU_STATUS )
{
return( ( vreg_ctr[ VREG_C_MCU_STATUS ] & 0x03 ) |
( ( vreg_twl[ REG_TWL_INT_ADRS_MODE ] & 0x03 ) << 6 ) | // sys_mode
( ( vreg_twl[ REG_TWL_INT_ADRS_MODE ] & 0x80 ) >> 2 )); // vol32
}
else if( adrs == VREG_C_RTC_SEC_FINE_L )
{
rsub_temp = RSUBC;
return( (u8)( rsub_temp & 0xFF ) );
}
else if( adrs == VREG_C_RTC_SEC_FINE_H )
{
return( (u8)( ( rsub_temp >> 8 ) & 0xFF ) );
}
/*
// debug 的な
else if( adrs == VREG_C_IRQ_MASK0 )
{
return( vreg_ctr[ VREG_C_IRQ_MASK0 ] & 0x7F ); // ぜったいにMSBは0。1なら通信エラー
}
*/
else if( adrs == VREG_C_ACC_HOSU_HIST )
{
return( hosu_read() );
}
else if( adrs == VREG_CX_FREE_DATA )
{
if( vreg_free_adrs >= VREG_C_FREE_SIZE )
{
temp = 0x00;
}
else
{
temp = pool.vreg_c_ext.vreg_c_free[ vreg_free_adrs ];
// vreg_free_adrs ++; // ここで加算してしまうとインデックスがずれる
}
return( temp );
}
else if( adrs == VREG_CX_INFO )
{
return( extinfo_read() );
}
else if( adrs == VREG_C_ACC_HOSU_SETTING )
{
if( pedolog_overflow )
{
return( 0x10 );
}
else
{
return( 0 );
}
}
if( adrs >= VREG_C_ENDMARK_ )
{
// VREG_C_INFO > VREG_C_ENDMARK_ なのでいじるとき注意
return( 0xFF );
}
return ( vreg_ctr[adrs] );
}
/********************************************//**
I2C仮想レジスタから読まれて何かするレジスタ
***********************************************/
void vreg_ctr_after_read( u8 adrs, u8 data )
{
// 割り込みフラグはリードでクリア
switch( adrs )
{
case VREG_C_IRQ0:
case VREG_C_IRQ1:
case VREG_C_IRQ2:
case VREG_C_IRQ3:
case VREG_C_IRQ4:
DI_wt_chk();
vreg_ctr[ adrs ] ^= data;
EI();
irq_readed = true;
break;
case VREG_CX_FREE_DATA:
vreg_free_adrs ++;
break;
default:
break;
}
}
/********************************************//**
-  
-  SoC上の処理キュー上には
IRQを読むタスクが積んであるので
 
DIかのチェック不要
 DI中に来るのはI2C_twlかRTC_アラームEIして実使用上問題ない
***********************************************/
void set_irq( u8 irqreg, u8 irq_flg )
{
u8 tot;
//0 u8 ei_orig; // EIフラグ保存
if(( system_status.pwr_state == ON ) ||
( system_status.pwr_state == SLEEP ))
{
/*0 すでにDI状態ならケアが必要かもしれない
ei_orig = get_ei();
//. debug
if( !ei_orig )
{
dbg_nop();
}
DI_wt_chk();
*/
DI();
if( ( vreg_ctr[ irqreg + 8 ] & irq_flg ) == 0 )
{
vreg_ctr[ irqreg ] |= irq_flg;
IRQ0_neg; // 一瞬上げて...
//0 if( ei_orig )
{
EI();
}
tot = 0;
while( !IRQ0 && ( ++tot != 0 ) ){;} // O.D.なのでちゃんとあがるのを待つ IRQ_mcu がLに縛られてると困る(基板不良)
IRQ0_ast; // 落とし直す。(エッジ割り込みの為)
}
//0 if( ei_orig )
{
EI();
}
}
}

Some files were not shown because too many files have changed in this diff Show More