# CTRDG_WriteAndVerifyAgbFlashAsync

## Syntax

      #include <nitro/ctrdg.h>

      void CTRDG_WriteAndVerifyAgbFlashAsync(u16 sec_num, u8* src, u32 verifysize, CTRDG_TASK_FUNC callback);

## Arguments

sec_num | Destination flash sector number.
src | Source address.
verifysize | Verify size in bytes.
callback | Callback function called when WriteAndVerify processing ends

## Return Values

None.

## Description

Internally, this function asynchronously uses the `CTRDG_WriteAgbFlashSector` function to write data and then the `CTRDG_VerifyAgbFlash` function to verify data for the number of bytes given by verifysize. If there is an error, the function retries up to the number of times specified by `CTRDB_AGB_FLASH_RETRY_MAX` (defined in `AgbFlash.h`). To find out whether the WriteAndVerify process succeeded, access the result member of the `CTRDGTaskInfo` structure used as an argument to the callback function that returns after this function is called. It returns zero if the WriteAndVerify process succeeded, a nonzero value if the process failed, and the error address on the device side if there was a verification error. Note: When checking error codes, this function returns an error code using 16 out of 32 bits when there is a write error, but returns a 32-bit error address on the device side when there is a verification error.

The access cycle setting does not need to be set in advance because it is created inside the function. In addition, the `OS_InitTick` function must be called in advance because clock ticks are used by this function to measure timeouts.

Note: All interrupts are disabled inside this function, and the cartridge bus is locked for a set period. In particular, when this function is called, do not use DMA that starts automatically during direct sound and V-Blank/H-Blank synchronization, display synchronization, cartridge request, and so on.

Note that the AGB backup device cannot be accessed normally with IS-NITRO-DEBUGGER version 1.66 or earlier.

    /*  callback  function  */
    typedef u32 (*CTRDG_TASK_FUNC) (struct CTRDGiTaskInfo_tag *);

## See Also

`CTRDG_WriteAgbFlashSector`
`CTRDG_VerifyAgbFlash`
`CTRDG_WriteAndVerifyAgbFlash`

## Revision History

2006/05/25 Added a description that the AGB backup device cannot be accessed normally with IS-NITRO-DEBUGGER version 1.66 or earlier.
2006/04/07 Initial version.

CONFIDENTIAL