Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored duplicate assignments #99 #101

Merged
merged 4 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/BLHeliBootLoad.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

XTAL EQU 25000000

; Bootloader segment address
IF MCU_TYPE < 2
BOOT_START EQU 1C00h
ELSEIF MCU_TYPE == 2
BOOT_START EQU 0F000h
ENDIF

BOOT_DELAY EQU XTAL/4 ; About 250ms (don't set to fast to avoid connection problems)
BOOT_BAUDRATE EQU 19200 ; Only used if no baudrate detection activated,XTAL is than important
BOOT_VERSION EQU 6 ; Version 6 (must be not changed)
Expand Down Expand Up @@ -51,7 +44,7 @@ Byte_Cnth: DS 1
BL_Flash_Key_1: DS 1 ; Flash keys
BL_Flash_Key_2: DS 1

CSEG AT BOOT_START ; Bootloader start
CSEG AT CSEG_BOOT_START ; Bootloader start
init:
clr IE_EA

Expand All @@ -66,7 +59,7 @@ init:
mov SP, #0c0h ; Stack = 64 upper bytes of RAM
; Initialize clock
mov CLKSEL, #00h ; Set clock divider to 1
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE = MCU_BB2
; Initialize VDD monitor
orl VDM0CN, #080h ; Enable the VDD monitor
ENDIF
Expand Down Expand Up @@ -139,7 +132,7 @@ id5:
jz ($+4) ; Check CRC
ajmp abd

; Send info about chip/bootloader (BOOT_MSG + BOOT_INFO)
; Send info about chip/bootloader (BOOT_MSG + BOOT_INFO)
mov Parah, #((BOOT_INFO - BOOT_MSG) + 4)
in1:
clr A
Expand Down Expand Up @@ -236,9 +229,9 @@ mai4:
mov Paral, #ERRORPROG
clr C
mov A, DPL
subb A, #low(BOOT_START)
subb A, #low(CSEG_BOOT_START)
mov A, DPH
subb A, #high(BOOT_START)
subb A, #high(CSEG_BOOT_START)
jnc mai1 ; Jump if in bootloader segment
jb Bit_Reg.0, pro3 ; Jump if program command

Expand Down Expand Up @@ -266,9 +259,9 @@ pro4:
pro5:
clr C
mov A, DPH ; Check that address is not in bootloader area
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE = MCU_BB2
subb A, #1Ch
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
subb A, #0F0h
ENDIF
jc ($+5)
Expand Down
55 changes: 21 additions & 34 deletions src/Bluejay.asm
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****

$include (Modules\Mcus.asm)

; List of enumerated supported ESCs
; PORT 0 | PORT 1 | PWM COM PWM LED
; P0 P1 P2 P3 P4 P5 P6 P7 | P0 P1 P2 P3 P4 P5 P6 P7 | inv inv side n
; ----------------------- | ----------------------- | -------------------------
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
A_ EQU 1 ; Vn Am Bm Cm __ RX __ __ | Ap Ac Bp Bc Cp Cc __ __ | no no high _
B_ EQU 2 ; Vn Am Bm Cm __ RX __ __ | Cc Cp Bc Bp Ac Ap __ __ | no no high _
C_ EQU 3 ; RX __ Vn Am Bm Cm Ap Ac | Bp Bc Cp Cc __ __ __ __ | no no high _
Expand Down Expand Up @@ -106,7 +108,7 @@ IF MCU_TYPE < 2
ENDIF

; BB51 - Required
IF MCU_TYPE = 2
IF MCU_TYPE == MCU_BB51
A_ EQU 1 ; __ Bm Cm Am Vn RX __ __ | Ap Ac Bp Bc Cp Cc __ __ | no no low _
B_ EQU 2 ; __ Bm Cm Am Vn RX __ __ | Ac Ap Bc Bp Cc Cp __ __ | no yes high _
C_ EQU 3 ; __ Bm Cm Am Vn RX __ __ | Ac Ap Bc Bp Cc Cp __ __ | yes yes high _
Expand All @@ -128,17 +130,18 @@ ENDIF

PWM_CENTERED EQU DEADTIME > 0 ; Use center aligned pwm on ESCs with dead time

IF MCU_TYPE == 0
IF MCU_TYPE == MCU_BB1
IS_MCU_48MHZ EQU 0
ELSE
IS_MCU_48MHZ EQU 1
ENDIF

IF MCU_TYPE < 3 AND PWM_FREQ < 3
IF PWM_FREQ < 3
; Number of bits in pwm high byte
PWM_BITS_H EQU (2 + IS_MCU_48MHZ - PWM_CENTERED - PWM_FREQ)
ENDIF

$include (Modules\Codespace.asm)
$include (Modules\Common.asm)
$include (Modules\Macros.asm)

Expand Down Expand Up @@ -340,11 +343,7 @@ Temp_Storage: DS 48 ; Temporary storage (internal memory)
; EEPROM code segments
; A segment of the flash is used as "EEPROM", which is not available in SiLabs MCUs
;**** **** **** **** **** **** **** **** **** **** **** **** ****
IF MCU_TYPE == 2
CSEG AT 3000h
ELSE
CSEG AT 1A00h
ENDIF
CSEG AT CSEG_EEPROM
EEPROM_FW_MAIN_REVISION EQU 0 ; Main revision of the firmware
EEPROM_FW_SUB_REVISION EQU 19 ; Sub revision of the firmware
EEPROM_LAYOUT_REVISION EQU 206 ; Revision of the EEPROM layout
Expand Down Expand Up @@ -395,22 +394,14 @@ Eep_Pgm_LED_Control: DB DEFAULT_PGM_LED_CONTROL ; EEPROM copy of programmed LED
Eep_Pgm_Power_Rating: DB DEFAULT_PGM_POWER_RATING ; EEPROM copy of programmed power rating

Eep_Dummy: DB 0FFh ; EEPROM address for safety reason
IF MCU_TYPE == 2
CSEG AT 3060h
ELSE
CSEG AT 1A60h
ENDIF
CSEG AT CSEG_NAME
Eep_Name: DB "Bluejay " ; Name tag (16 Bytes)

IF MCU_TYPE == 2
CSEG AT 3070h
ELSE
CSEG AT 1A70h
ENDIF
CSEG AT CSEG_MELODY
Eep_Pgm_Beep_Melody: DB 2,58,4,32,52,66,13,0,69,45,13,0,52,66,13,0,78,39,211,0,69,45,208,25,52,25,0

Interrupt_Table_Definition ; SiLabs interrupts
CSEG AT 80h ; Code segment after interrupt vectors
CSEG AT CSEG_APP ; Code segment after interrupt vectors

; Submodule includes
$include (Modules\Isrs.asm)
Expand All @@ -436,7 +427,7 @@ pgm_start:
mov WDTCN, #0DEh ; Disable watchdog (WDT)
mov WDTCN, #0ADh
mov SP, #Stack ; Initialize stack (16 bytes of indirect RAM)
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
orl VDM0CN, #080h ; Enable the VDD monitor
ENDIF
mov RSTSRC, #06h ; Set missing clock and VDD monitor as a reset source if not 1S capable
Expand All @@ -454,11 +445,11 @@ ENDIF
mov P1, #P1_INIT
mov P1SKIP, #P1_SKIP
mov P2MDOUT, #P2_PUSHPULL
IF MCU_TYPE >= 1
IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51
; Not available on BB1
mov SFRPAGE, #20h
mov P2MDIN, #P2_DIGITAL
IF MCU_TYPE == 1
IF MCU_TYPE == MCU_BB2
; Not available on BB51
mov P2SKIP, #P2_SKIP
ENDIF
Expand Down Expand Up @@ -495,7 +486,7 @@ init_no_signal:
mov Flash_Key_2, #0
call switch_power_off

IF MCU_TYPE >= 1
IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51
Set_MCU_Clk_24MHz ; Set clock frequency
ENDIF

Expand All @@ -510,7 +501,7 @@ input_high_check:

call beep_enter_bootloader

IF MCU_TYPE == 2
IF MCU_TYPE == MCU_BB51
ljmp 0F000h ; Jump to bootloader
ELSE
ljmp 1C00h ; Jump to bootloader
Expand Down Expand Up @@ -564,7 +555,7 @@ setup_dshot:
setb IE_EA ; Enable all interrupts

; Setup variables for DShot150 (Only on 24MHz because frame length threshold cannot be scaled up)
IF MCU_TYPE == 0
IF MCU_TYPE == MCU_BB1
mov DShot_Timer_Preset, #-64 ; Load DShot sync timer preset (for DShot150)
mov DShot_Pwm_Thr, #8 ; Load DShot qualification pwm threshold (for DShot150)
mov DShot_Frame_Length_Thr, #160 ; Load DShot frame length criteria
Expand Down Expand Up @@ -594,7 +585,7 @@ ENDIF
jz arming_begin

; Setup variables for DShot600 (Only on 48MHz for performance reasons)
IF MCU_TYPE >= 1
IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51
mov DShot_Timer_Preset, #-64 ; Load DShot sync timer preset (for DShot600)
mov DShot_Pwm_Thr, #8 ; Load DShot pwm threshold (for DShot600)
mov DShot_Frame_Length_Thr, #40 ; Load DShot frame length criteria
Expand Down Expand Up @@ -733,7 +724,7 @@ motor_start:
mov Temp_Pwm_Level_Setpoint, Pwm_Limit_Beg

; Begin startup sequence
IF MCU_TYPE >= 1
IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51
Set_MCU_Clk_48MHz

; Scale DShot criteria for 48MHz
Expand Down Expand Up @@ -994,7 +985,7 @@ exit_run_mode:
mov Flags0, #0 ; Clear run time flags (in case they are used in interrupts)
mov Flags1, #0

IF MCU_TYPE >= 1
IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51
Set_MCU_Clk_24MHz

; Scale DShot criteria for 24MHz
Expand Down Expand Up @@ -1061,11 +1052,7 @@ exit_run_mode_brake_done:
; as code flash after offset 1A00 is used for EEPROM storage
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
IF MCU_TYPE == 2
CSEG AT 2FFDh
ELSE
CSEG AT 19FDh
ENDIF
CSEG AT CSEG_RESET
reset:
ljmp pgm_start

Expand Down
22 changes: 6 additions & 16 deletions src/Layouts/A.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,13 @@ COM_ACTIVE_HIGH EQU 1 ; Damping inverted
COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0

PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1
ELSE
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0

PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1
ENDIF
PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; PORT 0 definitions
Expand Down
28 changes: 14 additions & 14 deletions src/Layouts/Base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,27 @@ ENDM

; Set comparator multiplexer to phase A
Set_Comparator_Phase_A MACRO
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov CMP_MX, #((A_Mux SHL 4) + V_Mux)
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov CMP_MX, #12h
ENDIF
ENDM

; Set comparator multiplexer to phase B
Set_Comparator_Phase_B MACRO
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov CMP_MX, #((B_Mux SHL 4) + V_Mux)
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov CMP_MX, #10h
ENDIF
ENDM

; Set comparator multiplexer to phase C
Set_Comparator_Phase_C MACRO
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov CMP_MX, #((C_Mux SHL 4) + V_Mux)
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov CMP_MX, #11h
ENDIF
ENDM
Expand Down Expand Up @@ -325,7 +325,7 @@ TEMP_LIMIT_STEP EQU 9 ; Temperature measurement ADC value incr

Initialize_Adc MACRO
LOCAL initialize_adc_use_internal_1V65_vref initialize_adc_use_vdd_3V3_vref initialize_adc_vref_selected
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov Temp1, #Pgm_Power_Rating
cjne @Temp1, #01h, initialize_adc_use_vdd_3V3_vref

Expand All @@ -336,31 +336,31 @@ initialize_adc_use_vdd_3V3_vref:
mov REF0CN, #0Ch ; Set vdd (3.3V) as reference on 2S+. Enable temp sensor and bias

initialize_adc_vref_selected:
IF MCU_TYPE == 0
IF MCU_TYPE == MCU_BB1
mov ADC0CF, #59h ; ADC clock 2MHz,PGA gain 1
ELSEIF MCU_TYPE == 1
ELSEIF MCU_TYPE == MCU_BB2
mov ADC0CF, #0B9h ; ADC clock 2MHz,PGA gain 1
ENDIF
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov CLKGRP0, #18h ; Enable SAR clock,at 12MHz
mov ADC0CF1, #0Ah ; 800ns tracking time
mov ADC0CF2, #2Fh ; 1.65V reference
ENDIF

mov ADC0MX, #10h ; Select temp sensor input
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov ADC0CN0, #80h ; ADC enabled
mov ADC0CN1, #01h ; Common mode buffer enabled
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov ADC0CN0, #85h ; ADC enabled (gain 0.5,temp sensor enabled)
mov ADC0CN1, #20h ; 10bit mode
ENDIF
ENDM

Start_Adc MACRO
IF MCU_TYPE < 2
IF MCU_TYPE == MCU_BB1 or MCU_TYPE == MCU_BB2
mov ADC0CN0, #90h ; Initiate conversion
ELSEIF MCU_TYPE == 2
ELSEIF MCU_TYPE == MCU_BB51
mov ADC0CN0, #95h ; Initiate conversion (gain 0.5,temp sensor enabled)
ENDIF
ENDM
Expand Down
22 changes: 6 additions & 16 deletions src/Layouts/C.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,13 @@ COM_ACTIVE_HIGH EQU 1 ; Damping inverted
COMPARATOR_PORT EQU 0 ; All comparator (mux) pins must be on the same port
COMPARATOR_INVERT EQU 0 ; Comparator output non-inverted

IF DEADTIME == 0
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0

PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1
ELSE
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0
PCA0CPM_POWER EQU PCA0CPM0
PCA0CPL_POWER EQU PCA0CPL0
PCA0CPH_POWER EQU PCA0CPH0

PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1
ENDIF
PCA0CPM_DAMP EQU PCA0CPM1
PCA0CPL_DAMP EQU PCA0CPL1
PCA0CPH_DAMP EQU PCA0CPH1

;**** **** **** **** **** **** **** **** **** **** **** **** ****
; PORT 0 definitions
Expand Down
Loading