#include "hal.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFLEN 64
static void delay_2_ms(void);
void my_puts(char *c)
{
do {
putch(*c);
} while (*++c);
}
static void delay_2_ms()
{
for (volatile unsigned int i=0; i < 0xfff; i++ ){
;
}
}
void my_read(char *buf, int len)
{
for(int i = 0; i < len; i++) {
while (buf[i] = getch(), buf[i] == '\0');
if (buf[i] == '\n') {
buf[i] = '\0';
return;
}
}
buf[len - 1] = '\0';
}
int main(void)
{
platform_init();
init_uart();
char passwd[32];
char correct_passwd[] = "xxxxx";
while(1){
my_puts("*****Safe-o-matic 3000 Booting...\n");
my_puts("WARNING: UNAUTHORIZED ACCESS WILL BE PUNISHED\n");
my_puts("Please enter password to continue: ");
my_read(passwd, 32);
uint8_t passbad = 0;
for(uint8_t i = 0; i < sizeof(correct_passwd); i++){
if (correct_passwd[i] != passwd[i]){
passbad = 1;
break;
}
}
if (passbad){
delay_2_ms();
delay_2_ms();
my_puts("Wrong password. Access denied!\n");
my_puts("\n");
led_error(1);
} else {
my_puts("Access granted, welcome!\n");
led_ok(1);
}
while(1);
}
return 1;
}