protocol

package
v0.0.0-...-d1fcd08 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Overview

Copyright © 2019 Erin Shepherd

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package protocol defines and implements the NuLink communications protocol

Index

Constants

View Source
const (
	// M2351 family (taken from Nuvoton's OpenOCD patch)
	ChipFamilyM2351 = 0x321
	ChipFamily8051  = 0x800
)
View Source
const (
	// N76E003, Observed in trace
	//
	// Matches IAP registers:
	//   0x00CCDDDD where
	//		CC   = Company ID
	// 		DDDD = Device ID
	DeviceN76E003   = 0xDA3650
	DeviceMS51FB9AE = 0xDA4B21
)
View Source
const FlagIsNulinkPro = 0x00000001

Variables

View Source
var (
	ErrWriteSizeIncorrect      = errors.New("Write of incorrect size")
	ErrReadSizeIncorrect       = errors.New("Read of incorrect size")
	ErrSequenceNumberIncorrect = errors.New("Incorrect sequence number")
)
View Source
var ErrBodyLengthTooLong = errors.New("Body length too long")
View Source
var ErrFrameLengthIncorrect = errors.New("Frame length incorrect")
View Source
var ErrTooShortForCommand = errors.New("Frame too short to contain command")

Functions

This section is empty.

Types

type ChipFamily

type ChipFamily uint32

func (ChipFamily) String

func (f ChipFamily) String() string

type Config

type Config struct {
	Clock       uint32
	ChipFamily  ChipFamily
	Voltage     uint32
	PowerTarget uint32
	USBFuncE    uint32
}

type Device

type Device struct {
	// contains filtered or unexported fields
}

func Connect

func Connect() ([]*Device, error)

func (*Device) CheckID

func (d *Device) CheckID() (DeviceID, error)

func (*Device) Close

func (d *Device) Close()

func (*Device) EraseFlashChip

func (d *Device) EraseFlashChip() error

func (*Device) GetVersion

func (d *Device) GetVersion() (VersionInfo, error)

func (*Device) MaxPayloadSize

func (d *Device) MaxPayloadSize() int

func (*Device) Path

func (d *Device) Path() string

func (*Device) ReadMemory

func (d *Device) ReadMemory(space MemorySpace, address uint16, length uint8) ([]byte, error)

func (*Device) Receive

func (d *Device) Receive() ([]byte, error)

func (*Device) Request

func (d *Device) Request(body []byte) ([]byte, error)

func (*Device) Reset

func (d *Device) Reset(r Reset) error

func (*Device) Send

func (d *Device) Send(body []byte) error

func (*Device) SetConfig

func (d *Device) SetConfig(c Config) error

func (*Device) UnknownA5

func (d *Device) UnknownA5() error

Not sure what this command does, but Nuvoton's software issues it

func (*Device) WriteMemory

func (d *Device) WriteMemory(space MemorySpace, address uint16, data []byte) error

type DeviceID

type DeviceID uint32

func (DeviceID) String

func (id DeviceID) String() string

type FirmwareVersion

type FirmwareVersion uint32
const (
	FirmwareVersion6909 FirmwareVersion = 6069

	FirmwareVersionRequired = FirmwareVersion6909
)

func (FirmwareVersion) String

func (v FirmwareVersion) String() string

type Frame

type Frame interface {
	SequenceNumber() byte
	BodyLength() int
	Body() []byte
	Command() (uint32, error)
	Bytes() []byte
}

type Framer

type Framer interface {
	FrameLength() int
	MaxBodyLength() int
	Frame(seqno byte, body []byte) (Frame, error)
	Unframe(pkg []byte) (Frame, error)
}

func NewV1Framer

func NewV1Framer() Framer

type MemorySpace

type MemorySpace uint16
const (
	ProgramSpace MemorySpace = 0x0000
	ConfigSpace  MemorySpace = 0x0003
)

func (MemorySpace) String

func (s MemorySpace) String() string

type ProductID

type ProductID uint32
const (
	ProductIDNuLinkME ProductID = 0x00550501
)

func (ProductID) String

func (p ProductID) String() string

type Reset

type Reset struct {
	Type       ResetType
	Connection ResetConnType
	Mode       ResetMode
}

type ResetConnType

type ResetConnType uint32

Type of connection after reset. Constants taken from OpenOCD patch

const (
	ConnectNormal     ResetConnType = 0
	ConnectPreReset   ResetConnType = 1
	ConnectUnderReset ResetConnType = 2
	ConnectNone       ResetConnType = 3
	ConnectDisconnect ResetConnType = 4
	ConnectICPMode    ResetConnType = 5
)

func (ResetConnType) String

func (ct ResetConnType) String() string

type ResetMode

type ResetMode uint32

Reset mode

const (
	// Described as "ext mode" by OpenOCD patch?
	ResetExtMode ResetMode = 0

	// Mode 1, used when disconnecting device
	ResetMode1 ResetMode = 1
)

func (ResetMode) String

func (rm ResetMode) String() string

type ResetType

type ResetType uint32

Reset Type. Constants taken from OpenOCD patch

const (
	ResetAuto             ResetType = 0
	ResetHW               ResetType = 1
	ResetSysResetReq      ResetType = 2
	ResetVecReset         ResetType = 3
	ResetFastRescue       ResetType = 4
	ResetNoneNuLink       ResetType = 5
	ResetNone2_8051T1Only ResetType = 6
)

func (ResetType) String

func (t ResetType) String() string

type V1Frame

type V1Frame []byte

func (V1Frame) Body

func (f V1Frame) Body() []byte

func (V1Frame) BodyLength

func (f V1Frame) BodyLength() int

func (V1Frame) Bytes

func (f V1Frame) Bytes() []byte

func (V1Frame) Command

func (f V1Frame) Command() (uint32, error)

func (V1Frame) SequenceNumber

func (f V1Frame) SequenceNumber() byte

type V1Framer

type V1Framer struct{}

func (V1Framer) Frame

func (f V1Framer) Frame(seqno byte, body []byte) (Frame, error)

func (V1Framer) FrameLength

func (f V1Framer) FrameLength() int

func (V1Framer) MaxBodyLength

func (f V1Framer) MaxBodyLength() int

func (V1Framer) Unframe

func (f V1Framer) Unframe(pkg []byte) (Frame, error)

type VersionInfo

type VersionInfo struct {
	FirmwareVersion FirmwareVersion
	ProductID       ProductID
	Flags           uint32

	// [NuLink pro only] Target voltage
	TargetVoltage uint16
	// [NuLink pro only] USB voltage
	USBVoltage uint16
}

func (VersionInfo) String

func (vi VersionInfo) String() string

Jump to

Keyboard shortcuts

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