mco_flashsim_close

Close a flash memory simulator instance and release its resources.

Prototype

    MCO_RET mco_flashsim_close(
        /*IN*/ mco_flashsim_h fs
    );

Arguments

fs
Handle to the flash simulator instance previously returned by mco_flashsim_open().

Description

This function decrements the reference count of the flash simulator instance. When the reference count reaches zero, the simulator’s internal state is destroyed and the underlying memory device is released.

The flash simulator supports shared access: multiple calls to mco_flashsim_open() with the same memory device return the same instance with an incremented reference count. Therefore, each mco_flashsim_open() must be matched with a corresponding mco_flashsim_close().

If the simulator was configured in file-based mode (file_based = MCO_YES), any pending data is already persisted to the image file during normal operations; this function does not perform an explicit flush.

After closing, the memory device may be reused or freed by the application.

Return Codes

MCO_S_OK
Simulator instance successfully closed (or reference count decremented).
MCO_E_INVALID_HANDLE
The provided handle is invalid or already closed.

Example

    mco_device_t dev;
    mco_flashsim_params_t params = {0};
    mco_flashsim_h fs;

    // ... initialize params and allocate dev ...

    MCO_RET rc = mco_flashsim_open(&dev, &params, &fs);
    if (rc == MCO_S_OK) {
        // Use simulator...

        // Close when done
        mco_flashsim_close(fs);
        free(dev.dev.conv.ptr); // if allocated on heap
    }

Files

Header file:
mcoflashsim.h
Source file:
mcoflashsim.c
Library:
libmcoflashsim.a