Fork from bluejay at github and modified for my custom ESC. I need to modify it because some mistake design on my ESC hardware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
6.3 KiB

  1. ;**** **** **** **** ****
  2. ;
  3. ; Bluejay digital ESC firmware for controlling brushless motors in multirotors
  4. ;
  5. ; Copyright 2020 Mathias Rasmussen
  6. ; Copyright 2011, 2012 Steffen Skaug
  7. ;
  8. ; This file is part of Bluejay.
  9. ;
  10. ; Bluejay is free software: you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation, either version 3 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; Bluejay is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with Bluejay. If not, see <http://www.gnu.org/licenses/>.
  22. ;
  23. ;**** **** **** **** ****
  24. ;
  25. ; BLHeliTxPgm SiLabs
  26. ;
  27. ; EEPROM is not available in SiLabs MCUs
  28. ; Therefore a segment of the flash is used as "EEPROM"
  29. ;
  30. ;**** **** **** **** ****
  31. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  32. ;
  33. ; Read all eeprom parameters routine
  34. ;
  35. ; No assumptions
  36. ;
  37. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  38. read_all_eeprom_parameters:
  39. ; Check initialized signature
  40. mov DPTR, #Eep_Initialized_L
  41. mov Temp1, #Bit_Access
  42. call read_eeprom_byte
  43. mov A, Bit_Access
  44. cjne A, #055h, read_eeprom_store_defaults
  45. inc DPTR ; Now Eep_Initialized_H
  46. call read_eeprom_byte
  47. mov A, Bit_Access
  48. cjne A, #0AAh, read_eeprom_store_defaults
  49. jmp read_eeprom_read
  50. read_eeprom_store_defaults:
  51. mov Flash_Key_1, #0A5h
  52. mov Flash_Key_2, #0F1h
  53. call set_default_parameters
  54. call erase_and_store_all_in_eeprom
  55. mov Flash_Key_1, #0
  56. mov Flash_Key_2, #0
  57. jmp read_eeprom_exit
  58. read_eeprom_read:
  59. ; Read eeprom
  60. mov DPTR, #_Eep_Pgm_Gov_P_Gain
  61. mov Temp1, #_Pgm_Gov_P_Gain
  62. mov Temp4, #10
  63. read_eeprom_block1:
  64. call read_eeprom_byte
  65. inc DPTR
  66. inc Temp1
  67. djnz Temp4, read_eeprom_block1
  68. mov DPTR, #_Eep_Enable_TX_Program
  69. mov Temp1, #_Pgm_Enable_TX_Program
  70. mov Temp4, #26 ; 26 parameters
  71. read_eeprom_block2:
  72. call read_eeprom_byte
  73. inc DPTR
  74. inc Temp1
  75. djnz Temp4, read_eeprom_block2
  76. mov DPTR, #Eep_Dummy ; Set pointer to uncritical area
  77. read_eeprom_exit:
  78. ret
  79. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  80. ;
  81. ; Erase flash and store all parameter value in EEPROM routine
  82. ;
  83. ; No assumptions
  84. ;
  85. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  86. erase_and_store_all_in_eeprom:
  87. clr IE_EA ; Disable interrupts
  88. call read_tags
  89. call erase_flash ; Erase flash
  90. mov DPTR, #Eep_FW_Main_Revision ; Store firmware main revision
  91. mov A, #EEPROM_FW_MAIN_REVISION
  92. call write_eeprom_byte_from_acc
  93. inc DPTR ; Now firmware sub revision
  94. mov A, #EEPROM_FW_SUB_REVISION
  95. call write_eeprom_byte_from_acc
  96. inc DPTR ; Now layout revision
  97. mov A, #EEPROM_LAYOUT_REVISION
  98. call write_eeprom_byte_from_acc
  99. ; Write eeprom
  100. mov DPTR, #_Eep_Pgm_Gov_P_Gain
  101. mov Temp1, #_Pgm_Gov_P_Gain
  102. mov Temp4, #10
  103. write_eeprom_block1:
  104. call write_eeprom_byte
  105. inc DPTR
  106. inc Temp1
  107. djnz Temp4, write_eeprom_block1
  108. mov DPTR, #_Eep_Enable_TX_Program
  109. mov Temp1, #_Pgm_Enable_TX_Program
  110. mov Temp4, #26 ; 26 parameters
  111. write_eeprom_block2:
  112. call write_eeprom_byte
  113. inc DPTR
  114. inc Temp1
  115. djnz Temp4, write_eeprom_block2
  116. call write_tags
  117. call write_eeprom_signature
  118. mov DPTR, #Eep_Dummy ; Set pointer to uncritical area
  119. ret
  120. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  121. ;
  122. ; Read eeprom byte routine
  123. ;
  124. ; Gives data in A and in address given by Temp1. Assumes address in DPTR
  125. ; Also assumes address high byte to be zero
  126. ;
  127. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  128. read_eeprom_byte:
  129. clr A
  130. movc A, @A+DPTR ; Read from flash
  131. mov @Temp1, A
  132. ret
  133. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  134. ;
  135. ; Write eeprom byte routine
  136. ;
  137. ; Assumes data in address given by Temp1, or in accumulator. Assumes address in DPTR
  138. ; Also assumes address high byte to be zero
  139. ;
  140. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  141. write_eeprom_byte:
  142. mov A, @Temp1
  143. write_eeprom_byte_from_acc:
  144. orl PSCTL, #01h ; Set the PSWE bit
  145. anl PSCTL, #0FDh ; Clear the PSEE bit
  146. mov Temp8, A
  147. clr C
  148. mov A, DPH ; Check that address is not in bootloader area
  149. subb A, #1Ch
  150. jc ($+3)
  151. ret
  152. mov A, Temp8
  153. mov FLKEY, Flash_Key_1 ; First key code
  154. mov FLKEY, Flash_Key_2 ; Second key code
  155. movx @DPTR, A ; Write to flash
  156. anl PSCTL, #0FEh ; Clear the PSWE bit
  157. ret
  158. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  159. ;
  160. ; Erase flash routine (erases the flash segment used for "eeprom" variables)
  161. ;
  162. ; No assumptions
  163. ;
  164. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  165. erase_flash:
  166. orl PSCTL, #02h ; Set the PSEE bit
  167. orl PSCTL, #01h ; Set the PSWE bit
  168. mov FLKEY, Flash_Key_1 ; First key code
  169. mov FLKEY, Flash_Key_2 ; Second key code
  170. mov DPTR, #Eep_Initialized_L
  171. movx @DPTR, A
  172. anl PSCTL, #0FCh ; Clear the PSEE and PSWE bits
  173. ret
  174. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  175. ;
  176. ; Write eeprom signature routine
  177. ;
  178. ; No assumptions
  179. ;
  180. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  181. write_eeprom_signature:
  182. mov DPTR, #Eep_Initialized_L
  183. mov A, #055h
  184. call write_eeprom_byte_from_acc
  185. mov DPTR, #Eep_Initialized_H
  186. mov A, #0AAh
  187. call write_eeprom_byte_from_acc
  188. ret
  189. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  190. ;
  191. ; Read all tags from flash and store in temporary storage
  192. ;
  193. ; No assumptions
  194. ;
  195. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  196. read_tags:
  197. mov Temp3, #48 ; Number of tags
  198. mov Temp2, #Temp_Storage ; Set RAM address
  199. mov Temp1, #Bit_Access
  200. mov DPTR, #Eep_ESC_Layout ; Set flash address
  201. read_tag:
  202. call read_eeprom_byte
  203. mov A, Bit_Access
  204. mov @Temp2, A ; Write to RAM
  205. inc Temp2
  206. inc DPTR
  207. djnz Temp3, read_tag
  208. ret
  209. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  210. ;
  211. ; Write all tags from temporary storage and store in flash
  212. ;
  213. ; No assumptions
  214. ;
  215. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  216. write_tags:
  217. mov Temp3, #48 ; Number of tags
  218. mov Temp2, #Temp_Storage ; Set RAM address
  219. mov DPTR, #Eep_ESC_Layout ; Set flash address
  220. write_tag:
  221. mov A, @Temp2 ; Read from RAM
  222. call write_eeprom_byte_from_acc
  223. inc Temp2
  224. inc DPTR
  225. djnz Temp3, write_tag
  226. ret