HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_Port::Dispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack )
{
    TINYCLR_HEADER();
    {
        CLR_RT_HeapBlock* pThis = stack.This();  FAULT_ON_NULL(pThis);
        CLR_RT_HeapBlock_NativeEventDispatcher* port;
        TINYCLR_CHECK_HRESULT(Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::GetEventDispatcher( stack, port ));
        // Check if HW port was not closed.  - 
        if ( ( pThis[ FIELD__m_flags ].NumericByRefConst().s4 & GPIO_PortParams::c_Disposed ) == 0 )   
        {
            CLR_UINT32 portID = pThis[ FIELD__m_portId ].NumericByRefConst().u4;
            
            // Cleanup the HAL queue from the instance of assiciated CLR_RT_HeapBlock_NativeEventDispatcher 
            port->RemoveFromHALQueue();
            
            // Set flag in managed object that port is closed.
            pThis[ FIELD__m_flags ].NumericByRef().s4 |= GPIO_PortParams::c_Disposed;

            // Set pin to input state so the pin is in "weak" state and does not drain power. 
            ::CPU_GPIO_EnableInputPin2( portID,
                                        false,
                                        NULL,
                                        0,
                                        GPIO_INT_NONE,
                                        RESISTOR_PULLUP
                                      );
            // Releases the pin
            ::CPU_GPIO_ReservePin( portID, FALSE );
            
        }
    }
    TINYCLR_NOCLEANUP();
}
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::Dispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack )
{
    TINYCLR_HEADER();
        
    CLR_RT_HeapBlock_NativeEventDispatcher *pNativeDisp = NULL;
    
    CLR_RT_HeapBlock*  pThis = stack.This();  FAULT_ON_NULL(pThis);
    
    TINYCLR_CHECK_HRESULT(GetEventDispatcher( stack, pNativeDisp ));
    
    // Cleanup the HAL queue from the instance of assiciated CLR_RT_HeapBlock_NativeEventDispatcher 
    pNativeDisp->RemoveFromHALQueue();
    
    // Calls driver to de-initilaze hardware.
    TINYCLR_CHECK_HRESULT(pNativeDisp->m_DriverMethods->m_CleanupProc( pNativeDisp )); 
    
    TINYCLR_NOCLEANUP();
}
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::Dispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack )
{
    TINYCLR_HEADER();
        
    CLR_RT_HeapBlock_NativeEventDispatcher *pNativeDisp = NULL;
    
    CLR_RT_HeapBlock*  pThis = stack.This();  FAULT_ON_NULL(pThis);
    
    TINYCLR_CHECK_HRESULT(GetEventDispatcher( stack, pNativeDisp ));
    
    // Cleanup the HAL queue from the instance of assiciated CLR_RT_HeapBlock_NativeEventDispatcher 
    pNativeDisp->RemoveFromHALQueue();
    
    // Calls driver to enable interrupts.  Consider that there could be no driver 
    // associated to this object so check that the driver methods are set 
    // we will be tolerant in this case and not throw any exception
    if(pNativeDisp->m_DriverMethods != NULL)
    {
        TINYCLR_CHECK_HRESULT(pNativeDisp->m_DriverMethods->m_CleanupProc( pNativeDisp )); 
    }
    
    TINYCLR_NOCLEANUP();
}