spimock

package
v3.0.0-...-66753ca Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package spimock provides a fake SPI flash part for unit testing. This simulates an MX66L51235F.

Index

Constants

View Source
const FakeSize = 64 * 1024 * 1024

FakeSize is the size of the mocked flash chip.

View Source
const WriteWaitStates = 5

WriteWaitStates is the number WritePending is set to after a write.

Variables

View Source
var FakeSFDP = []byte{}/* 112 elements not displayed */

FakeSFDP is the SFDP from the MX66L51235F datasheet.

Functions

This section is empty.

Types

type MockSPI

type MockSPI struct {
	// Data contains fake contents of the flash chip.
	Data []byte

	// SFDPData contains fake SFDP.
	SFDP []byte

	SpeedHz uint32

	// Is4BA is set to true if the chip is currently in 4-byte addressing
	// mode.
	Is4BA bool
	// IsWriteEnabled is set to true if data can be written.
	IsWriteEnabled bool
	// WritePending is non-zero while a write is pending. It decreases on
	// every read of the status register.
	WritePending int

	// Transfers is a recording of the transfers.
	Transfers []spidev.Transfer
	// ForceTransferError is returned by Transfer when set.
	ForceTransferErr error
	// ForceSetSpeedHzError is returned by SetSpeedHz when set.
	ForceSetSpeedHzErr error
	// contains filtered or unexported fields
}

MockSPI is an implementation of flash.SPI which records the transfers.

func New

func New() *MockSPI

New returns a new MockSPI in memory.

func NewFromFile

func NewFromFile(filename string) (*MockSPI, error)

NewFromFile returns a new MockSPI which is backed by a file. If the file does not exist, it will be created. Ideally, the file's size should match FlashSize.

func (*MockSPI) Close

func (s *MockSPI) Close() error

Close closes the mock.

func (*MockSPI) SetSpeedHz

func (s *MockSPI) SetSpeedHz(hz uint32) error

SetSpeedHz sets the SPI speed. The value set is recorded in the mock.

func (*MockSPI) Transfer

func (s *MockSPI) Transfer(transfers []spidev.Transfer) error

Transfer implements flash.SPI.

Jump to

Keyboard shortcuts

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