Created
February 11, 2020 12:00
-
-
Save zignig/2ef6703fcb45eb8b3b31eb96466ad02e to your computer and use it in GitHub Desktop.
boneless echo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from .registers import * | |
| from boneless.arch.opcode import * | |
| from boneless.arch.asm import Assembler | |
| import pprint | |
| from .uart import Serial | |
| from .leds import Blinker | |
| from .lister import register | |
| @register | |
| class Echo(Firmware): | |
| def instr(self): | |
| w = self.w | |
| w.req("current_value") | |
| ll = LocalLabels() | |
| s = Serial() | |
| return [ | |
| # s.read(ret=w.current_value), | |
| # s.write(w.current_value), | |
| s.readword(ret=w.current_value), | |
| s.writeword(w.current_value), | |
| ] | |
| becomes | |
| Gizmotronic Boneless | |
| Show info | |
| FIRMWARE Echo | |
| [ Rem("['current_value', '', '', '', '', '', 'fp', 'ret']"), | |
| Label('init'), | |
| MOVI(R6, 512), | |
| LDW(R6, 0), | |
| Label('main'), | |
| [ [ JAL(R7, 'Serial.ReadWord'), | |
| Rem("Return word"), | |
| LD(R0, R6, -5)], | |
| [ Rem("Load word"), | |
| ST(R0, R6, -8), | |
| JAL(R7, 'Serial.WriteWord')]], | |
| J('main'), | |
| Label('lib_code'), | |
| [ [ [ Label('Serial.ReadBlock'), | |
| Rem("['rx_status', 'counter', 'leds', 'char', '', '', 'fp', 'ret']"), | |
| ADJW(-8), | |
| LDW(R6, 0), | |
| MOVI(R2, 1), | |
| MOVI(R1, 65535), | |
| Label('checkrx_3097986442'), | |
| Rem("load the RX status from the serial port"), | |
| [ SUBI(R1, R1, 1), | |
| CMPI(R1, 0), | |
| BEQ('blink_3097986442'), | |
| J('next_3097986442'), | |
| Label('blink_3097986442'), | |
| STXA(R2, 1), | |
| MOVI(R1, 65535), | |
| XORI(R2, R2, 65535), | |
| Label('next_3097986442')], | |
| LDXA(R0, 4), | |
| CMPI(R0, 1), | |
| BEQ('rxnext_3097986442'), | |
| J('checkrx_3097986442'), | |
| Label('rxnext_3097986442'), | |
| LDXA(R3, 5), | |
| MOVI(R0, 1), | |
| STXA(R0, 4), | |
| Label('rxwait_3097986442'), | |
| LDXA(R0, 4), | |
| CMPI(R0, 0), | |
| BEQ('rxack_3097986442'), | |
| J('rxwait_3097986442'), | |
| Label('rxack_3097986442'), | |
| MOVI(R0, 0), | |
| STXA(R0, 4), | |
| MOVI(R2, 0), | |
| MOVI(R1, 0), | |
| STXA(R2, 1), | |
| ADJW(8), | |
| JR(R7, 0)]], | |
| [ [ Label('Serial.Write'), | |
| Rem("['char', 'status', '', '', '', '', 'fp', 'ret']"), | |
| ADJW(-8), | |
| LDW(R6, 0), | |
| Label('txchar_86520491'), | |
| STXA(R0, 3), | |
| MOVI(R1, 1), | |
| STXA(R1, 2), | |
| MOVI(R1, 1), | |
| STXA(R1, 2), | |
| MOVI(R1, 0), | |
| STXA(R1, 2), | |
| Label('waitup_86520491'), | |
| LDXA(R1, 2), | |
| CMPI(R1, 1), | |
| BEQ('waitup_86520491'), | |
| Label('waitdown_86520491'), | |
| LDXA(R1, 2), | |
| CMPI(R1, 0), | |
| BEQ('waitdown_86520491'), | |
| ADJW(8), | |
| JR(R7, 0)]], | |
| [ [ Label('Serial.ReadWord'), | |
| Rem("['first', 'second', 'holding', 'word', '', '', 'fp', 'ret']"), | |
| ADJW(-8), | |
| LDW(R6, 0), | |
| MOVI(R2, 0), | |
| Rem("low byte"), | |
| [ JAL(R7, 'Serial.ReadBlock'), | |
| Rem("Return char"), | |
| LD(R0, R6, -5)], | |
| AND(R3, R0, R0), | |
| Rem("high byte"), | |
| [ JAL(R7, 'Serial.ReadBlock'), | |
| Rem("Return char"), | |
| LD(R1, R6, -5)], | |
| AND(R2, R1, R1), | |
| SLLI(R2, R2, 8), | |
| OR(R3, R3, R2), | |
| ADJW(8), | |
| JR(R7, 0)]], | |
| [ [ Label('Serial.WriteWord'), | |
| Rem("['word', 'holding', 'extra', '', '', '', 'fp', 'ret']"), | |
| ADJW(-8), | |
| LDW(R6, 0), | |
| NOP(0), | |
| NOP(0), | |
| Rem("write low byte"), | |
| ANDI(R1, R0, 255), | |
| [ Rem("Load char"), | |
| ST(R1, R6, -8), | |
| JAL(R7, 'Serial.Write')], | |
| NOP(0), | |
| NOP(0), | |
| Rem("write high byte"), | |
| SRLI(R1, R0, 8), | |
| [ Rem("Load char"), | |
| ST(R1, R6, -8), | |
| JAL(R7, 'Serial.Write')], | |
| ADJW(8), | |
| JR(R7, 0)]]], | |
| Label('program_start')] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment