mirror of
https://github.com/BertoldVdb/ms-tools.git
synced 2025-12-10 07:44:46 +01:00
Run hooks with IRQ disabled + add UART tx function
This commit is contained in:
parent
9f971aab98
commit
22ddf782f5
10 changed files with 116 additions and 7 deletions
|
|
@ -40,6 +40,8 @@ var CLI struct {
|
|||
I2CScan I2CScan `cmd name:"i2c-scan" help:"Scan I2C bus and show discovered devices."`
|
||||
I2CTransfer I2CTransfer `cmd name:"i2c-txfr" help:"Perform I2C transfer."`
|
||||
|
||||
UARTTx UARTTx `cmd name:"uart-tx" help:"Transmit data over UART."`
|
||||
|
||||
GPIOSet GPIOSet `cmd name:"gpio-set" help:"Set GPIO pin value and direction."`
|
||||
GPIOGet GPIOGet `cmd name:"gpio-get" help:"Get GPIO values."`
|
||||
}
|
||||
|
|
|
|||
19
cli/uart.go
Normal file
19
cli/uart.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
type UARTTx struct {
|
||||
Data string `arg name:"data" help:"Hex string to write to device"`
|
||||
Baud int `optional help:"Data rate in bits per second" default:"57600"`
|
||||
}
|
||||
|
||||
func (l *UARTTx) Run(c *Context) error {
|
||||
buf, err := hex.DecodeString(l.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.hal.UARTTransmit(l.Baud, buf)
|
||||
}
|
||||
|
|
@ -10,3 +10,4 @@ as31 -Fbin gpio.asm
|
|||
as31 -Fbin code.asm
|
||||
as31 -Fbin i2cRead2109.asm
|
||||
as31 -Fbin i2cRead2107.asm
|
||||
as31 -Fbin uart_tx.asm
|
||||
|
|
|
|||
|
|
@ -16,10 +16,14 @@ hookRun:
|
|||
RLC A
|
||||
MOV HID, A
|
||||
|
||||
SETB EA
|
||||
|
||||
hookRet:
|
||||
RET
|
||||
|
||||
hookWork:
|
||||
CLR EA
|
||||
|
||||
MOV DPH, HID+3
|
||||
MOV DPL, HID+4
|
||||
MOV R3, HID+3
|
||||
|
|
@ -28,7 +32,7 @@ hookWork:
|
|||
MOV R6, HID+6
|
||||
MOV R7, HID+7
|
||||
MOV A, R7
|
||||
RRC A
|
||||
RRC A
|
||||
MOV A, R7
|
||||
|
||||
PUSH HID+2
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
50
mshal/asm/uart_tx.asm
Normal file
50
mshal/asm/uart_tx.asm
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
.FLAG PIN, P2.2
|
||||
.FLAG DIR, P3.2
|
||||
.EQU BAUD0, 120
|
||||
.EQU BAUD1, 121
|
||||
.EQU PDIR, 122
|
||||
|
||||
MOV BAUD0, R5 ;Save baud rate param
|
||||
MOV BAUD1, R6
|
||||
MOV PDIR, P3
|
||||
CLR DIR
|
||||
|
||||
more:
|
||||
MOVX A, @DPTR
|
||||
INC DPTR
|
||||
|
||||
MOV R0, #8 ;Send 8 bits from A
|
||||
CLR PIN ;Send start bit
|
||||
|
||||
MOV R5, BAUD0 ;Delay between bits
|
||||
MOV R6, BAUD1
|
||||
d1:
|
||||
DJNZ R5, d1
|
||||
DJNZ R6, d1
|
||||
|
||||
bits:
|
||||
RRC A ;Rotate bits via carry
|
||||
MOV PIN,C ;Output bits
|
||||
|
||||
MOV R5, BAUD0 ;Delay between bits
|
||||
MOV R6, BAUD1
|
||||
d2:
|
||||
DJNZ R5, d2
|
||||
DJNZ R6, d2
|
||||
|
||||
DJNZ R0, bits ;Send all bits
|
||||
|
||||
RRC A ;Not needed, but makes timing equal
|
||||
SETB PIN ;Send stop bit
|
||||
|
||||
MOV R5, BAUD0 ;Delay between bits
|
||||
MOV R6, BAUD1
|
||||
d3:
|
||||
DJNZ R5, d3
|
||||
DJNZ R6, d3
|
||||
|
||||
DJNZ R7, more ;Send all characters
|
||||
|
||||
MOV P3, PDIR
|
||||
|
||||
RET
|
||||
1
mshal/asm/uart_tx.bin
Normal file
1
mshal/asm/uart_tx.bin
Normal file
|
|
@ -0,0 +1 @@
|
|||
峹巠叞z虏啵x垄瓁畒蔺撄挗瓁畒蔺撄伢尧瓁畒蔺撄哓厇<E59393>"
|
||||
|
|
@ -122,13 +122,14 @@ var codeCallgate2106 []byte
|
|||
var codeCallgate2109 []byte
|
||||
|
||||
func relocateCallgate(result []byte, addr int) (int, []byte) {
|
||||
if result[5] != 0x12 {
|
||||
panic("Offset 5 is not LCALL")
|
||||
lcall := 5
|
||||
if result[lcall] != 0x12 {
|
||||
panic("Offset is not LCALL")
|
||||
}
|
||||
|
||||
callAddr := binary.BigEndian.Uint16(result[6:])
|
||||
callAddr := binary.BigEndian.Uint16(result[lcall+1:])
|
||||
callAddr += uint16(addr)
|
||||
binary.BigEndian.PutUint16(result[6:], callAddr)
|
||||
binary.BigEndian.PutUint16(result[lcall+1:], callAddr)
|
||||
|
||||
return addr, result
|
||||
}
|
||||
|
|
@ -142,6 +143,9 @@ var codeMOVC []byte
|
|||
//go:embed asm/i2cRead2107.bin
|
||||
var codei2cRead2107 []byte
|
||||
|
||||
//go:embed asm/uart_tx.bin
|
||||
var codeUartTX []byte
|
||||
|
||||
//go:embed asm/i2cRead2109.bin
|
||||
var codei2cRead2109 []byte
|
||||
|
||||
|
|
@ -153,6 +157,10 @@ var installBlobs2106 = []CodeBlob{
|
|||
Data: codeGpio,
|
||||
}, {
|
||||
Data: codeMOVC,
|
||||
}, {
|
||||
Data: codeMOVC,
|
||||
}, {
|
||||
Data: codeUartTX,
|
||||
}}
|
||||
|
||||
var installBlobs2107 = []CodeBlob{
|
||||
|
|
@ -165,6 +173,8 @@ var installBlobs2107 = []CodeBlob{
|
|||
Data: codeMOVC,
|
||||
}, {
|
||||
Data: codei2cRead2107,
|
||||
}, {
|
||||
Data: codeUartTX,
|
||||
}}
|
||||
|
||||
var installBlobs2109 = []CodeBlob{
|
||||
|
|
@ -177,8 +187,9 @@ var installBlobs2109 = []CodeBlob{
|
|||
Data: codeMOVC,
|
||||
}, {
|
||||
Data: codei2cRead2109,
|
||||
},
|
||||
}
|
||||
}, {
|
||||
Data: codeUartTX,
|
||||
}}
|
||||
|
||||
func (h *HAL) EEPROMReloadUser() error {
|
||||
if h.config.LogFunc != nil {
|
||||
|
|
|
|||
21
mshal/hal_patch_uart.go
Normal file
21
mshal/hal_patch_uart.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package mshal
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
func (h *HAL) UARTTransmit(baud int, buf []byte) error {
|
||||
region := h.MemoryRegionGet(MemoryRegionUserRAM)
|
||||
parent, addr := region.GetParent()
|
||||
addr += region.GetLength() - len(buf)
|
||||
|
||||
if _, err := parent.Access(true, addr, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var div [2]byte
|
||||
binary.LittleEndian.PutUint16(div[:], uint16((1.0/float64(baud))/108.125e-9))
|
||||
|
||||
_, err := h.PatchExecFunc(false, h.patchCallAddrs[4], PatchExecFuncRequest{DPTR: uint16(addr), R5: div[0] + 1, R6: div[1] + 1, R7_A: uint8(len(buf))})
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue