/************************************************************************************************************************** * RESOURCE.C SigmaTel STIR4200 memory allocation module ************************************************************************************************************************** * (C) Unpublished Copyright of Sigmatel, Inc. All Rights Reserved. * * * Created: 04/06/2000 * Version 0.9 * * **************************************************************************************************************************/ #define DOBREAKS // enable debug breaks #include #include // defines OID's #include #include #include "debug.h" #include "ircommon.h" #include "irndis.h" /***************************************************************************** * * Function: MyMemAlloc * * Synopsis: allocates a block of memory using NdisAllocateMemory * * Arguments: size - size of the block to allocate * * Returns: a pointer to the allocated block of memory * * *****************************************************************************/ PVOID MyMemAlloc( UINT size ) { PVOID pMem; NDIS_STATUS status; status = NdisAllocateMemoryWithTag( &pMem, size, IRUSB_TAG ); if( status != NDIS_STATUS_SUCCESS ) { DEBUGMSG(DBG_ERR, (" Memory allocation failed\n")); pMem = NULL; } return pMem; } /***************************************************************************** * * Function: MyMemFree * * Synopsis: frees a block of memory allocated by MyMemAlloc * * Arguments: memptr - memory to free * size - size of the block to free * * *****************************************************************************/ VOID MyMemFree( PVOID pMem, UINT size ) { NdisFreeMemory( pMem, size, 0 ); } /***************************************************************************** * * Function: MyUrbAlloc * * Synopsis: allocates an URB using NdisAllocateMemory * * Arguments: size - size of urb to allocate * * Returns: a pointer to the urb * *****************************************************************************/ PURB MyUrbAlloc( UINT size ) { PURB pUrb = NULL; pUrb = MyMemAlloc( size ); if( NULL == pUrb ) { DEBUGMSG(DBG_ERR, (" IrUsb failed to alloc urb\n")); } else { NdisZeroMemory( pUrb, size ); } return pUrb; } /***************************************************************************** * * Function: MyUrbFree * * Synopsis: frees an Urb allocated by MyUrbAlloc * * Arguments: pUrb - urb to free * size - size of the urb to free * * *****************************************************************************/ VOID MyUrbFree( PURB pUrb, UINT size ) { MyMemFree(pUrb, size); } /***************************************************************************** * * Function: NewDevice * * Synopsis: allocates an IR device and zeros the memory * * Arguments: none * * Returns: initialized IR device or NULL (if alloc failed) * * *****************************************************************************/ PIR_DEVICE NewDevice() { PIR_DEVICE pNewDev; pNewDev = MyMemAlloc( sizeof(IR_DEVICE) ); if( pNewDev != NULL ) { NdisZeroMemory( (PVOID)pNewDev, sizeof(IR_DEVICE) ); if( !AllocUsbInfo( pNewDev ) ) { MyMemFree( pNewDev, sizeof(IR_DEVICE) ); pNewDev = NULL; } } return pNewDev; } /***************************************************************************** * * Function: FreeDevice * * Synopsis: frees an IR device structure * * Arguments: pThisDev - pointer to device to free * * Returns: none * * *****************************************************************************/ VOID FreeDevice( IN OUT PIR_DEVICE pThisDev ) { FreeUsbInfo( pThisDev ); MyMemFree( (PVOID)pThisDev, sizeof(IR_DEVICE) ); }