/* Resets the target leaving it in either download (program) mode or run mode.  */
void ResetTarget(ISP_ENVIRONMENT *IspEnvironment, TARGET_MODE mode)
/* Resets the target leaving it in either download (program) mode or run mode.  */
void ResetTarget(ISP_ENVIRONMENT *IspEnvironment, TARGET_MODE mode)
{
    if (IspEnvironment->ControlLines)
    {
        switch (mode)
        {
        case PROGRAM_MODE:
            ControlModemLines(IspEnvironment, 1, 1);
            Sleep(100);
            ClearSerialPortBuffers(IspEnvironment);
            Sleep(100);
            ControlModemLines(IspEnvironment, 0, 1);
            Sleep(500);
            ControlModemLines(IspEnvironment, 0, 0);
            break;
        case RUN_MODE:
            ControlModemLines(IspEnvironment, 1, 0);
            Sleep(100);
            ClearSerialPortBuffers(IspEnvironment);
            Sleep(100);
            ControlModemLines(IspEnvironment, 0, 0);
            Sleep(100);
            break;
        }
    }
}