add magnetic field level service
This commit is contained in:
Родитель
48c9c737cb
Коммит
131163b420
|
@ -0,0 +1,28 @@
|
|||
[Ram_Break]
|
||||
Break1=No 0000
|
||||
Break2=No 0000
|
||||
Break3=No 0000
|
||||
Break4=No 0000
|
||||
[Stack_Break]
|
||||
Break1=No 0000 00FF
|
||||
Break2=No 0000 00FF
|
||||
Break3=No 0000 00FF
|
||||
Break4=No 0000 00FF
|
||||
Break5=No 0000 00FF
|
||||
Break6=No 0000 00FF
|
||||
Break7=No 0000 00FF
|
||||
Break8=No 0000 00FF
|
||||
[Ctrl_Break]
|
||||
Mark=51 1
|
||||
ICE=0 6 2 CE4
|
||||
[INI]
|
||||
PROJECT=SINGLE
|
||||
[LINKS]
|
||||
~main.asm
|
||||
[HEAD]
|
||||
[DEPEND]
|
||||
~$:INC_PDK\PFS122.INC
|
||||
~..\jd\jdheader.asm
|
||||
~..\services\magneticlevel.asm
|
||||
~..\services\analog.asm
|
||||
~..\jd\jdmain.asm
|
|
@ -0,0 +1,49 @@
|
|||
.CHIP PFS122
|
||||
//{{PADAUK_CODE_OPTION
|
||||
.Code_Option Security Disable
|
||||
.Code_Option Bootup_Time Fast
|
||||
.Code_Option LVR 3.0V
|
||||
.Code_Option Comparator_Edge All_Edge
|
||||
.Code_Option GPC_PWM Disable
|
||||
.Code_Option TMx_Bit 6BIT
|
||||
.Code_Option TMx_Source 16MHz
|
||||
.Code_Option Interrupt_Src1 PB.0
|
||||
.Code_Option Interrupt_Src0 PA.0
|
||||
.Code_Option PB4_PB7_Drive Strong
|
||||
//}}PADAUK_CODE_OPTION
|
||||
|
||||
//#define RELEASE 1
|
||||
|
||||
/*
|
||||
Assignment (S8 package):
|
||||
|
||||
VDD | GND
|
||||
PA6 - Jacdac | PA4
|
||||
PA5 - sink of status LED | PA3
|
||||
PB7 - | PB1 - mag
|
||||
*/
|
||||
|
||||
#define ADC_12BIT 1
|
||||
|
||||
// all pins on PA
|
||||
#define PIN_LED 5
|
||||
// #define LED_SINK 1
|
||||
#define PIN_JACDAC 6
|
||||
// #define PIN_LOG 1
|
||||
|
||||
// Cost given in comment: words of flash/bytes of RAM
|
||||
#define CFG_FW_ID 0x3a7e069d // 24/0
|
||||
|
||||
.include ../jd/jdheader.asm
|
||||
|
||||
#define PIN_ADC PB1
|
||||
// #define PIN_ANALOG_PWR 7 // ???
|
||||
|
||||
.include ../services/magneticlevel.asm
|
||||
|
||||
main:
|
||||
.ADJUST_IC SYSCLK=IHRC/2, IHRC=16MHz, VDD=3.3V
|
||||
PADIER = (1 << PIN_JACDAC)
|
||||
PBDIER = 0
|
||||
|
||||
.include ../jd/jdmain.asm
|
|
@ -25,10 +25,18 @@ txp_reading_error equ txp_serv1
|
|||
|
||||
.serv_process EXPAND
|
||||
.t16_chk t16_1ms, t_sample, <goto do_analog_sample>
|
||||
#ifdef EVENTS
|
||||
.ev_process
|
||||
#endif
|
||||
.sensor_process
|
||||
ENDM
|
||||
|
||||
.serv_prep_tx EXPAND
|
||||
#ifdef EVENTS
|
||||
ifset txp_event
|
||||
goto ev_prep_tx
|
||||
#endif
|
||||
|
||||
#ifdef VARIANT
|
||||
if (txp_variant) {
|
||||
set0 txp_variant
|
||||
|
@ -69,8 +77,8 @@ do_analog_sample:
|
|||
$ ADCC Enable, PIN_ADC
|
||||
AD_START = 1
|
||||
while (!AD_DONE) {}
|
||||
mov a, ADC_H
|
||||
|
||||
mov a, ADC_H
|
||||
.analog_reading
|
||||
|
||||
$ ADCC Disable
|
||||
|
@ -80,7 +88,6 @@ do_analog_sample:
|
|||
PA.PIN_ANALOG_PWR = 0
|
||||
#endif
|
||||
|
||||
|
||||
goto loop
|
||||
|
||||
serv_rx:
|
||||
|
@ -102,3 +109,14 @@ serv_rx:
|
|||
}
|
||||
.sensor_rx
|
||||
|
||||
#ifdef EVENTS
|
||||
BYTE ev_code
|
||||
|
||||
.serv_ev_payload EXPAND
|
||||
.mova pkt_service_command_l, ev_code
|
||||
ENDM
|
||||
|
||||
ev_send_ex:
|
||||
mov ev_code, a
|
||||
.ev_impl
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#ifndef THR_LO
|
||||
#define THR_LO 20
|
||||
#define THR_HI 25
|
||||
#endif
|
||||
|
||||
#ifndef MIN_VAL
|
||||
#define MIN_VAL 57
|
||||
#endif
|
||||
|
||||
#define SERVICE_CLASS 0x12fe180f
|
||||
#define SENSOR_SIZE 2
|
||||
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_ANALOG_NS 0x1
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_ANALOG_N 0x2
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_ANALOG_S 0x3
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_DIGITAL_NS 0x4
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_DIGITAL_N 0x5
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_VARIANT_DIGITAL_S 0x6
|
||||
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_REG_DETECTED 0x181
|
||||
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_EV_ACTIVE JD_EV_ACTIVE
|
||||
#define JD_MAGNETIC_FIELD_LEVEL_EV_INACTIVE JD_EV_INACTIVE
|
||||
|
||||
#ifndef VARIANT
|
||||
#define VARIANT JD_MAGNETIC_FIELD_LEVEL_VARIANT_ANALOG_NS
|
||||
#endif
|
||||
|
||||
#define EVENTS 1
|
||||
|
||||
#define f_detected f_serv0
|
||||
|
||||
.serv_init EXPAND
|
||||
.mova streaming_interval, 100
|
||||
ENDM
|
||||
|
||||
#define s_l sensor_state[0]
|
||||
#define s_h sensor_state[1]
|
||||
BYTE abs_v
|
||||
|
||||
.analog_reading EXPAND
|
||||
.mova s_h, ADC_H
|
||||
.mova s_l, ADC_L
|
||||
mov a, MIN_VAL
|
||||
sub s_h, a
|
||||
if (CF) {
|
||||
clear s_h
|
||||
clear s_l
|
||||
}
|
||||
sl s_l
|
||||
slc s_h
|
||||
if (CF) {
|
||||
mov a, 0xff
|
||||
mov s_h, a
|
||||
mov s_l, a
|
||||
}
|
||||
mov a, 0x80
|
||||
sub s_h, a
|
||||
|
||||
mov a, s_h
|
||||
sl a
|
||||
mov a, s_h
|
||||
ifset CF
|
||||
neg a
|
||||
mov abs_v, a
|
||||
if (f_detected) {
|
||||
mov a, THR_LO
|
||||
} else {
|
||||
mov a, THR_HI
|
||||
}
|
||||
sub a, abs_v
|
||||
if (CF) {
|
||||
if (!f_detected) {
|
||||
set1 f_detected
|
||||
mov a, JD_EV_ACTIVE
|
||||
goto ev_send_ex
|
||||
}
|
||||
} else {
|
||||
if (f_detected) {
|
||||
set0 f_detected
|
||||
mov a, JD_EV_INACTIVE
|
||||
goto ev_send_ex
|
||||
}
|
||||
}
|
||||
ENDM
|
||||
|
||||
.include analog.asm
|
Загрузка…
Ссылка в новой задаче