This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
forked from capiman/lpc21isp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpcterm.c
138 lines (112 loc) · 4.03 KB
/
lpcterm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/******************************************************************************
Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
and Analog Devices ADUC70xx
Filename: lpcterm.c
Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
GCC Cygwin, GCC Linux, GCC ARM ELF
Author: Martin Maurer (Martin.Maurer@clibb.de)
Copyright: (c) Martin Maurer 2003-2011, All rights reserved
Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
This file is part of lpc21isp.
lpc21isp is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
lpc21isp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
and GNU General Public License along with lpc21isp.
If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(_WIN32)
#if !defined __BORLANDC__
#include "StdAfx.h"
#endif
#endif // defined(_WIN32)
#include "lpc21isp.h"
#include "lpcterm.h"
#ifdef TERMINAL_SUPPORT
/***************************** Terminal *********************************/
/** Acts as a simple dumb terminal. Press 'ESC' to exit.
*/
BOOL CheckTerminalParameters(ISP_ENVIRONMENT *IspEnvironment, char* pstr)
{
if (stricmp(pstr, "-localecho") == 0)
{
IspEnvironment->LocalEcho = 1;
DebugPrintf(3, "Local echo in terminal mode.\n");
return TRUE;
}
if (stricmp(pstr, "-term") == 0)
{
IspEnvironment->TerminalAfterUpload = 1;
DebugPrintf(3, "Invoke terminal after upload.\n");
return TRUE;
}
if (stricmp(pstr, "-termonly") == 0)
{
IspEnvironment->TerminalOnly = 1;
IspEnvironment->ProgramChip = 0;
DebugPrintf(3, "Only provide terminal.\n");
return TRUE;
}
return FALSE;
}
void Terminal(ISP_ENVIRONMENT *IspEnvironment)
{
if (IspEnvironment->TerminalAfterUpload || IspEnvironment->TerminalOnly)
{
int ch = 0;
char buffer[128];
int fdlogfile = -1;
unsigned long realsize;
// When logging is switched on, output terminal output to lpc21isp.log
if (IspEnvironment->LogFile)
{
fdlogfile = open("lpc21isp.log", O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0777);
}
PrepareKeyboardTtySettings();
DebugPrintf(1, "Terminal started (press Escape to abort)\n\n");
fflush(stdout);
do
{
ReceiveComPort(IspEnvironment, buffer, sizeof(buffer) - 1, &realsize, 0,200); // Check for received characters
if (realsize)
{
write(1, buffer, realsize);
fflush(stdout);
if (IspEnvironment->LogFile) // When logging is turned on, then copy output to logfile
{
write(fdlogfile, buffer, realsize);
}
}
// check for keypress, and write any out the port.
if (kbhit())
{
ch = getch();
if (ch == 0x1b)
{
break;
}
buffer[0] = (unsigned char)ch;
buffer[1] = 0;
if (IspEnvironment->LocalEcho)
{
write(1, buffer, 1);
}
SendComPort(IspEnvironment, buffer);
}
}
while (ch != 0x1b);
DebugPrintf(1, "\n\nTerminal stopped\n\n");
fflush(stdout);
ResetKeyboardTtySettings();
if (IspEnvironment->LogFile)
{
close(fdlogfile);
}
}
}
#endif