The close(D2) entry point routine is called for each open channel. There may be more than one channel per instance, so the close of this channel may not be the last close for the instance.
The code is fairly similar to that for samp_open( ): use ASSERT( ) to verify that this is a valid channel number and to confirm that the pl(D5) priority level is set correctly when the entry point routine is entered. It then locks the idata, updates it, and unlocks it.
statement verifies that there is at least one
open channel for the idata
before it is updated.
Resources should be freed
if and only if
open_count == 0 and
cfg_state == REMOVED.
The instance has received a CFG_REMOVE,
but resources can only be freed
when all channels are closed.
The code calls the
subordinate driver routine
to free the resources (locks and memory)
that were allocated for this instance.
The samp_close( ) routine returns 0 on success. Again, if this driver were for a hardware peripheral device, more error checking would be implemented, with errors returned as appropriate.