mega

package
v0.241210.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2024 License: CC0-1.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PROTOCOL_HEADER_FLAG_MASK as defined in mega-firmware/protocol.h:10
	PROTOCOL_HEADER_FLAG_MASK = 240
	// PROTOCOL_HEADER_VERSION_MASK as defined in mega-firmware/protocol.h:11
	PROTOCOL_HEADER_VERSION_MASK = 15
	// PROTOCOL_FLAG_REQUEST_BUSY as defined in mega-firmware/protocol.h:12
	PROTOCOL_FLAG_REQUEST_BUSY = 128
	// PROTOCOL_FLAG_PAYLOAD as defined in mega-firmware/protocol.h:13
	PROTOCOL_FLAG_PAYLOAD = 64
	// PROTOCOL_PAD_OK as defined in mega-firmware/protocol.h:14
	PROTOCOL_PAD_OK = 1
	// PROTOCOL_PAD_ERROR as defined in mega-firmware/protocol.h:15
	PROTOCOL_PAD_ERROR = 254
	// PACKET_FIELDS_MAX_LENGTH as defined in mega-firmware/protocol.h:17
	PACKET_FIELDS_MAX_LENGTH = 49
	// FIELD_MAX_LENGTH as defined in mega-firmware/protocol.h:18
	FIELD_MAX_LENGTH = 40
	// TWI_LISTEN_MAX_LENGTH as defined in mega-firmware/protocol.h:20
	TWI_LISTEN_MAX_LENGTH = 36
	// MDB_BLOCK_SIZE as defined in mega-firmware/protocol.h:79
	MDB_BLOCK_SIZE = 36
	// MDB_ACK as defined in mega-firmware/protocol.h:80
	MDB_ACK = 0
	// MDB_RET as defined in mega-firmware/protocol.h:81
	MDB_RET = 170
	// MDB_NAK as defined in mega-firmware/protocol.h:82
	MDB_NAK = 255
	// MDB_TIMEOUT_MS as defined in mega-firmware/config.h:7
	MDB_TIMEOUT_MS = 6
	// BUFFER_SIZE as defined in mega-firmware/config.h:8
	BUFFER_SIZE = 50
)
View Source
const (
	DefaultTimeout  = 20 * time.Millisecond
	DefaultSpiSpeed = 200 * physic.KiloHertz
)
View Source
const (
	ResetFlagPowerOn = ResetFlag(1 << iota)
	ResetFlagExternal
	ResetFlagBrownOut
	ResetFlagWatchdog
)
View Source
const MDB_STATE_BUS_RESET byte = 5

MDB_STATE_BUS_RESET as declared in mega-firmware/protocol.h:90

View Source
const MDB_STATE_DONE byte = 6

MDB_STATE_DONE as declared in mega-firmware/protocol.h:91

View Source
const MDB_STATE_ERROR byte = 1

MDB_STATE_ERROR as declared in mega-firmware/protocol.h:86

View Source
const MDB_STATE_IDLE byte = 0

MDB_STATE_IDLE as declared in mega-firmware/protocol.h:85

View Source
const MDB_STATE_RECV byte = 3

MDB_STATE_RECV as declared in mega-firmware/protocol.h:88

View Source
const MDB_STATE_RECV_END byte = 4

MDB_STATE_RECV_END as declared in mega-firmware/protocol.h:89

View Source
const MDB_STATE_SEND byte = 2

MDB_STATE_SEND as declared in mega-firmware/protocol.h:87

View Source
const ProtocolVersion = 4

Variables

View Source
var (
	ErrCriticalProtocol = errors.New("CRITICAL mega protocol error")
	ErrResponseEmpty    = errors.New("mega response empty")
	ErrRequestBusy      = errors.New("mega request busy")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Log     *log2.Log
	TwiChan chan uint16
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *Config, log *log2.Log) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

Thread-safe and idempotent.

func (*Client) DecRef

func (c *Client) DecRef(debug string) error

func (*Client) DoMdbBusReset

func (c *Client) DoMdbBusReset(d time.Duration) (Frame, error)

func (*Client) DoMdbTxSimple

func (c *Client) DoMdbTxSimple(data []byte) (Frame, error)

func (*Client) DoStatus

func (c *Client) DoStatus() (Frame, error)

func (*Client) DoTimeout

func (c *Client) DoTimeout(cmd Command_t, data []byte, timeout time.Duration) (Frame, error)

func (*Client) IncRef

func (c *Client) IncRef(debug string)

func (*Client) Stat

func (c *Client) Stat() Stat

func (*Client) Tx

func (c *Client) Tx(command, response *Frame, timeout time.Duration) error

func (*Client) XXX_RawTx

func (c *Client) XXX_RawTx(command []byte) ([]byte, error)

type Command_t

type Command_t byte

Command_t type as declared in mega-firmware/protocol.h:22

const COMMAND_CONFIG Command_t = 2

COMMAND_CONFIG as declared in mega-firmware/protocol.h:24

const COMMAND_DEBUG Command_t = 4

COMMAND_DEBUG as declared in mega-firmware/protocol.h:26

const COMMAND_FLASH Command_t = 5

COMMAND_FLASH as declared in mega-firmware/protocol.h:27

const COMMAND_MDB_BUS_RESET Command_t = 7

COMMAND_MDB_BUS_RESET as declared in mega-firmware/protocol.h:28

const COMMAND_MDB_TRANSACTION_CUSTOM Command_t = 9

COMMAND_MDB_TRANSACTION_CUSTOM as declared in mega-firmware/protocol.h:30

const COMMAND_MDB_TRANSACTION_SIMPLE Command_t = 8

COMMAND_MDB_TRANSACTION_SIMPLE as declared in mega-firmware/protocol.h:29

const COMMAND_RESET Command_t = 3

COMMAND_RESET as declared in mega-firmware/protocol.h:25

const COMMAND_STATUS Command_t = 1

COMMAND_STATUS as declared in mega-firmware/protocol.h:23

func (Command_t) String

func (i Command_t) String() string

type Config

type Config struct {
	SpiBus        string
	SpiMode       int
	SpiSpeed      string
	NotifyPinChip string
	NotifyPinName string

	DontUseRawMode bool // skip ioLoop, used to bring real hardware to invalid state
	// contains filtered or unexported fields
}

type Errcode_t

type Errcode_t byte

Errcode_t type as declared in mega-firmware/protocol.h:54

const ERROR_BUFFER_OVERFLOW Errcode_t = 5

ERROR_BUFFER_OVERFLOW as declared in mega-firmware/protocol.h:60

const ERROR_FRAME_HEADER Errcode_t = 1

ERROR_FRAME_HEADER as declared in mega-firmware/protocol.h:55

const ERROR_FRAME_LENGTH Errcode_t = 2

ERROR_FRAME_LENGTH as declared in mega-firmware/protocol.h:56

const ERROR_INVALID_ACK Errcode_t = 4

ERROR_INVALID_ACK as declared in mega-firmware/protocol.h:59

const ERROR_INVALID_CRC Errcode_t = 2

ERROR_INVALID_CRC as declared in mega-firmware/protocol.h:57

const ERROR_INVALID_DATA Errcode_t = 17

ERROR_INVALID_DATA as declared in mega-firmware/protocol.h:62

const ERROR_NOT_IMPLEMENTED Errcode_t = 18

ERROR_NOT_IMPLEMENTED as declared in mega-firmware/protocol.h:63

const ERROR_REQUEST_OVERWRITE Errcode_t = 3

ERROR_REQUEST_OVERWRITE as declared in mega-firmware/protocol.h:58

const ERROR_UNKNOWN_COMMAND Errcode_t = 16

ERROR_UNKNOWN_COMMAND as declared in mega-firmware/protocol.h:61

func (Errcode_t) String

func (i Errcode_t) String() string

type Field_t

type Field_t byte

Field_t type as declared in mega-firmware/protocol.h:66

const FIELD_CLOCK10U Field_t = 2

FIELD_CLOCK10U as declared in mega-firmware/protocol.h:69

const FIELD_ERROR2 Field_t = 9

FIELD_ERROR2 as declared in mega-firmware/protocol.h:72

const FIELD_ERRORN Field_t = 8

FIELD_ERRORN as declared in mega-firmware/protocol.h:71

const FIELD_FIRMWARE_VERSION Field_t = 1

FIELD_FIRMWARE_VERSION as declared in mega-firmware/protocol.h:68

const FIELD_INVALID Field_t = 0

FIELD_INVALID as declared in mega-firmware/protocol.h:67

const FIELD_MCUSR Field_t = 3

FIELD_MCUSR as declared in mega-firmware/protocol.h:70

const FIELD_MDB_DATA Field_t = 17

FIELD_MDB_DATA as declared in mega-firmware/protocol.h:74

const FIELD_MDB_DURATION10U Field_t = 18

FIELD_MDB_DURATION10U as declared in mega-firmware/protocol.h:75

const FIELD_MDB_RESULT Field_t = 16

FIELD_MDB_RESULT as declared in mega-firmware/protocol.h:73

const FIELD_TWI_ADDR Field_t = 32

FIELD_TWI_ADDR as declared in mega-firmware/protocol.h:76

const FIELD_TWI_DATA Field_t = 33

FIELD_TWI_DATA as declared in mega-firmware/protocol.h:77

func (Field_t) String

func (i Field_t) String() string

type Fields

type Fields struct {
	ErrorNs [][]byte
	Error2s []uint16
	MdbData []byte
	TwiData []byte

	Clock10u        uint32
	MdbDuration     uint32
	FirmwareVersion uint16
	Len             uint8
	Mcusr           byte
	MdbResult       Mdb_result_t
	MdbError        byte
	MdbLength       uint8
	TwiAddr         byte
	// contains filtered or unexported fields
}

Sorry for inhumane field order, it's used often and probably worth align optimisation.

func (Fields) FieldString

func (f Fields) FieldString(tag Field_t) string

func (*Fields) Parse

func (f *Fields) Parse(b []byte) error

func (Fields) String

func (f Fields) String() string

type Frame

type Frame struct {
	Fields Fields

	Version byte
	Flag    byte

	Errcode Errcode_t
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(cmd Command_t, data ...byte) Frame

func (*Frame) Bytes

func (f *Frame) Bytes() []byte

func (*Frame) CommandString

func (f *Frame) CommandString() string

func (*Frame) HeaderString

func (f *Frame) HeaderString() string

func (*Frame) Parse

func (f *Frame) Parse(b []byte) error

Overwrites frame state

func (*Frame) ParseFields

func (f *Frame) ParseFields() error

func (*Frame) Payload

func (f *Frame) Payload() []byte

func (*Frame) ResponseKind

func (f *Frame) ResponseKind() Response_t

func (*Frame) ResponseString

func (f *Frame) ResponseString() string

type Mdb_result_t

type Mdb_result_t byte

Mdb_result_t type as declared in mega-firmware/protocol.h:93

const MDB_RESULT_BUSY Mdb_result_t = 8

MDB_RESULT_BUSY as declared in mega-firmware/protocol.h:95

const MDB_RESULT_CODE_ERROR Mdb_result_t = 15

MDB_RESULT_CODE_ERROR as declared in mega-firmware/protocol.h:102

const MDB_RESULT_INVALID_CHK Mdb_result_t = 9

MDB_RESULT_INVALID_CHK as declared in mega-firmware/protocol.h:96

const MDB_RESULT_INVALID_END Mdb_result_t = 12

MDB_RESULT_INVALID_END as declared in mega-firmware/protocol.h:99

const MDB_RESULT_NAK Mdb_result_t = 10

MDB_RESULT_NAK as declared in mega-firmware/protocol.h:97

const MDB_RESULT_RECEIVE_OVERFLOW Mdb_result_t = 13

MDB_RESULT_RECEIVE_OVERFLOW as declared in mega-firmware/protocol.h:100

const MDB_RESULT_SEND_OVERFLOW Mdb_result_t = 14

MDB_RESULT_SEND_OVERFLOW as declared in mega-firmware/protocol.h:101

const MDB_RESULT_SUCCESS Mdb_result_t = 1

MDB_RESULT_SUCCESS as declared in mega-firmware/protocol.h:94

const MDB_RESULT_TIMEOUT Mdb_result_t = 11

MDB_RESULT_TIMEOUT as declared in mega-firmware/protocol.h:98

const MDB_RESULT_TIMER_CODE_ERROR Mdb_result_t = 24

MDB_RESULT_TIMER_CODE_ERROR as declared in mega-firmware/protocol.h:109

const MDB_RESULT_UART_READ_ERROR Mdb_result_t = 17

MDB_RESULT_UART_READ_ERROR as declared in mega-firmware/protocol.h:104

const MDB_RESULT_UART_READ_OVERFLOW Mdb_result_t = 18

MDB_RESULT_UART_READ_OVERFLOW as declared in mega-firmware/protocol.h:105

const MDB_RESULT_UART_READ_PARITY Mdb_result_t = 19

MDB_RESULT_UART_READ_PARITY as declared in mega-firmware/protocol.h:106

const MDB_RESULT_UART_READ_UNEXPECTED Mdb_result_t = 16

MDB_RESULT_UART_READ_UNEXPECTED as declared in mega-firmware/protocol.h:103

const MDB_RESULT_UART_SEND_BUSY Mdb_result_t = 20

MDB_RESULT_UART_SEND_BUSY as declared in mega-firmware/protocol.h:107

const MDB_RESULT_UART_TXC_UNEXPECTED Mdb_result_t = 21

MDB_RESULT_UART_TXC_UNEXPECTED as declared in mega-firmware/protocol.h:108

func (Mdb_result_t) String

func (i Mdb_result_t) String() string

type ResetFlag

type ResetFlag uint8

func (ResetFlag) String

func (i ResetFlag) String() string

type Response_t

type Response_t byte

Response_t type as declared in mega-firmware/protocol.h:32

const RESPONSE_ERROR Response_t = 128

RESPONSE_ERROR as declared in mega-firmware/protocol.h:36

const RESPONSE_OK Response_t = 1

RESPONSE_OK as declared in mega-firmware/protocol.h:33

const RESPONSE_RESET Response_t = 2

RESPONSE_RESET as declared in mega-firmware/protocol.h:34

const RESPONSE_TWI_LISTEN Response_t = 3

RESPONSE_TWI_LISTEN as declared in mega-firmware/protocol.h:35

func (Response_t) String

func (i Response_t) String() string

type SpiTxFunc

type SpiTxFunc func(send, recv []byte) error

type Stat

type Stat struct {
	Request   uint32
	Error     uint32
	TwiListen uint32
	Reset     uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL