disk_writep

The disk_writep function writes data to the sector.

DRESULT disk_writep (
  BYTE* buff,  /* [IN] Pointer to the data to be written */
  DWORD sc,    /* [IN] Sector number or Number of bytes to wtite */
);

Parameters

buff
Pointer to the data to be written to the sector. If a NULL is given, the function initiate/finalize a write transaction to the sector.
sc
Specifies nubmer of bytes to write if buff is not a NULL. If buff is a NULL and sc is not a zero, the function initiates a write transactin to the sector. If buff and sc are zero, the function finalize the current sector write transactin.

Return Value

RES_OK (0)
The function succeeded.
RES_ERROR
Any hard error occured during the write operation and could not recover it or the medium is write protected.
RES_PARERR
Invalid parameter.
RES_NOTRDY
The device has not been initialized.

Description

A sector write operation is done in following sequence.

  1. disk_writep(0, sector_number); Initiate a sector write transaction.
  2. disk_writep(data, byte_to_write); Start to write data to the sector.
  3. disk_writep(data, byte_to_write); And data can be written upto 512 bytes with one or more calls.
  4. disk_writep(data, byte_to_write); ...
  5. disk_writep(0, 0); Finalize the write transaction. If number of bytes sent is less than 512, left bytes in the sector is filled by zero.

If a write transaction is in progress, disk_readp() function will fail and disk_initialize() function finalize the current write transaction.

Remarks

This funciton is needed when _USE_WRITE == 1.

Return