Skip to content

Commit 6893c01

Browse files
committed
update functionality
1 parent 2a111d9 commit 6893c01

File tree

1 file changed

+74
-18
lines changed
  • secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X

1 file changed

+74
-18
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/main.c

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,28 @@
3838
static void ClearTerminalScreen(void);
3939
static void ClearTerminalLine(void);
4040
static void MoveCursor(int row);
41-
static void HideCursor(void);
41+
static void EnableCursor(bool enable);
4242
static void PrintWarning(void);
4343
static uint32_t GetResetAddress();
4444
static bool WasLoadedByBootloader();
4545
static void PrintBootloaderRequired(void);
46-
static char* ScanInput(void);
46+
static char* ScanINPUT(void);
4747
static void DisableProgrammingPort(void);
4848
static void InvalidKeyword(void);
49+
static void PrintProgrammingDisabled(void);
50+
51+
// Local Variables
4952
static char userInput[USER_INPUT_BUFFER_SIZE] = {0};
5053
static bool ICSP_INHIBIT_IsEnabled(void); //temp stub - replace with real version
54+
static bool ICSP_INHIBIT_Enable(); //temp stub - replace with real version
55+
static bool errorPresent = false;
56+
static bool icspEnabled = false;
57+
5158

5259
int main(void)
5360
{
5461
SYSTEM_Initialize();
55-
HideCursor();
56-
ClearTerminalScreen();
57-
62+
5863
// if(WasLoadedByBootloader() == false)
5964
// {
6065
// PrintBootloaderRequired();
@@ -75,14 +80,14 @@ int main(void)
7580

7681
if(ICSP_INHIBIT_IsEnabled())
7782
{
78-
printf("ICSP Programming/Debugging permanently disabled.");
83+
PrintProgrammingDisabled();
7984

8085
while(1)
8186
{
8287
}
8388
}
8489

85-
userInput = ScanInput();
90+
userInput = ScanINPUT();
8691

8792
if(strcmp(userInput, keyword) == MATCHES)
8893
{
@@ -96,27 +101,50 @@ int main(void)
96101
}
97102
}
98103

104+
static void PrintProgrammingDisabled(void)
105+
{
106+
EnableCursor(false);
107+
MoveCursor(1);
108+
ClearTerminalScreen();
109+
110+
printf("\r\n");
111+
printf("\r\n");
112+
printf("\r\n");
113+
printf("*** ICSP Programming/Debugging permanently disabled. ***\r\n");
114+
printf("\r\n");
115+
printf("Use the bootloader to load all future applications into this board.");
116+
}
117+
99118
//temp stub - replace with real version
100119
static bool ICSP_INHIBIT_IsEnabled(void)
101120
{
102-
return false;
121+
return icspEnabled;
122+
}
123+
124+
static bool ICSP_INHIBIT_Enable()
125+
{
126+
icspEnabled = true;
103127
}
104128

105129
static void InvalidKeyword(void)
106130
{
107-
MoveCursor(10);
131+
MoveCursor(7);
108132
ClearTerminalLine();
133+
printf("Invalid keyword entered. Try again.");
134+
errorPresent = true;
135+
109136
MoveCursor(5);
110137
ClearTerminalLine();
111-
printf("Invalid character entered. Try again.");
138+
printf(">> ");
139+
112140
}
113141

114142
static void DisableProgrammingPort(void)
115143
{
116-
//ICSP_INHIBIT_Enable(true);
144+
ICSP_INHIBIT_Enable();
117145
}
118146

119-
static char* ScanInput(void)
147+
static char* ScanINPUT(void)
120148
{
121149
uint8_t offset = 0;
122150
char key;
@@ -127,6 +155,15 @@ static char* ScanInput(void)
127155
{
128156
key = UART1_Read();
129157

158+
if(errorPresent)
159+
{
160+
MoveCursor(7);
161+
ClearTerminalLine();
162+
MoveCursor(5);
163+
printf(">> ");
164+
errorPresent = false;
165+
}
166+
130167
if(key != ENTER)
131168
{
132169
userInput[offset++] = key;
@@ -153,23 +190,42 @@ static void MoveCursor(int row)
153190
printf("\033[%d;0f", row);
154191
}
155192

156-
static void HideCursor(void)
193+
194+
/*
195+
* "\033[?25h" for cursor enable
196+
* "\033[?25l" for cursor disable
197+
*/
198+
static void EnableCursor(bool enable)
157199
{
158-
printf("\033[?25l");
200+
printf("\033[?25%c", enable ? 'h' : 'l');
159201
}
160202

161203
static void PrintWarning(void)
162204
{
205+
EnableCursor(false);
163206
MoveCursor(1);
164-
printf("Type LOCKDEVICE to enable the ICSP Inhibit feature.\r\n\r\n");
165-
printf("WARNING: THIS PERMANENTLY DISABLES DIRECT PROGRAMMING OF THE BOARD.");
207+
ClearTerminalScreen();
208+
209+
printf("Type LOCKDEVICE (plus ENTER) to enable the ICSP Inhibit feature.\r\n");
210+
printf("\r\n");
211+
printf("WARNING: THIS PERMANENTLY DISABLES DIRECT PROGRAMMING OF THE BOARD.\r\n");
212+
printf("\r\n");
213+
printf(">> ");
214+
215+
EnableCursor(true);
166216
}
167217

168218
static void PrintBootloaderRequired(void)
169219
{
220+
EnableCursor(false);
170221
MoveCursor(1);
171-
printf("NO BOOTLOADER DETECTED!\r\n\r\n");
172-
printf("Because programming will be permanently disabled, \r\na bootloader is required to run this demo. \r\nPlease see the readme.md for more information.");
222+
ClearTerminalScreen();
223+
224+
printf("NO BOOTLOADER DETECTED!\r\n");
225+
printf("\r\n");
226+
printf("Because programming will be permanently disabled, \r\n");
227+
printf("a bootloader is required to run this demo. \r\n");
228+
printf("Please see the readme.md for more information.\r\n");
173229
}
174230

175231
/* The following code finds the address used by GOTO instruction programmed

0 commit comments

Comments
 (0)