MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / writeblocks

Method writeblocks

mpython/lib/sdcard.py:276–301  ·  view source on GitHub ↗
(self, block_num, buf)

Source from the content-addressed store, hash-verified

274 raise OSError(5) # EIO
275
276 def writeblocks(self, block_num, buf):
277 # workaround for shared bus, required for (at least) some Kingston
278 # devices, ensure MOSI is high before starting transaction
279 self.spi.write(b"\xff")
280
281 nblocks, err = divmod(len(buf), 512)
282 assert nblocks and not err, "Buffer length is invalid"
283 if nblocks == 1:
284 # CMD24: set write address for single block
285 if self.cmd(24, block_num * self.cdv, 0) != 0:
286 raise OSError(5) # EIO
287
288 # send the data
289 self.write(_TOKEN_DATA, buf)
290 else:
291 # CMD25: set write address for first block
292 if self.cmd(25, block_num * self.cdv, 0) != 0:
293 raise OSError(5) # EIO
294 # send the data
295 offset = 0
296 mv = memoryview(buf)
297 while nblocks:
298 self.write(_TOKEN_CMD25, mv[offset : offset + 512])
299 offset += 512
300 nblocks -= 1
301 self.write_token(_TOKEN_STOP_TRAN)
302
303 def ioctl(self, op, arg):
304 if op == 4: # get number of blocks

Callers

nothing calls this directly

Calls 3

writeMethod · 0.95
cmdMethod · 0.95
write_tokenMethod · 0.95

Tested by

no test coverage detected