diff --git a/config/Configuration b/config/Configuration index 690786d..c1aa777 100644 --- a/config/Configuration +++ b/config/Configuration @@ -58,6 +58,12 @@ ram: -w ramwrite -s ioerr -n ioerr -intr ionull FIN DE RAFA */ +eeprom: + on disk + -i eeprom_init -o eeprom_open -c eeprom_close + -r eeprom_read -g ioerr -p ioerr + -w eeprom_write -s ioerr -n ioerr + -intr ionull /* type of namespace device */ nam: @@ -104,6 +110,7 @@ FIN DE RAFA */ /* Define a ram disk device */ /* RAFA RAM0 is ram on mem */ + EEPROM0 is eeprom on disk %% @@ -111,10 +118,5 @@ FIN DE RAFA */ #define NPROC 4 /* number of user processes */ // RAFA #define NSEM 4 /* number of semaphores */ +// #define NSEM 2 /* number of semaphores */ #define NSEM 2 /* number of semaphores */ -#define IRQBASE 32 /* base ivec for IRQ0 */ -#define IRQ_TIMER IRQ_HW5 /* timer IRQ is wired to hardware 5 */ -#define IRQ_ATH_MISC IRQ_HW4 /* Misc. IRQ is wired to hardware 4 */ -#define CLKFREQ 200000000 /* 200 MHz clock */ - -// #define LF_DISK_DEV RAM0 diff --git a/config/config.y b/config/config.y index a2ad0d3..37d59fa 100644 --- a/config/config.y +++ b/config/config.y @@ -96,7 +96,9 @@ char *devstab[] = { "\tint32 dvnum;", "\tint32 dvminor;", // RAFA "\tchar *dvname;", - "\tchar dvname[16];", +// "\tchar dvname[16];", + // RAFA BIEN "\tchar dvname[8];", + "\tchar dvname[10];", "\tdevcall (*dvinit) (struct dentry *);", "\tdevcall (*dvopen) (struct dentry *, char *, char *);", "\tdevcall (*dvclose)(struct dentry *);", @@ -110,9 +112,12 @@ char *devstab[] = { "\tvoid (*dvintr)(void);", "\tbyte dvirq;", "};\n", - "extern struct dentry devtab[]; /* one entry per device */", + "extern const __flash struct dentry devtab[] ; /* one entry per device */", +// "extern struct dentry devtab[] ; /* one entry per device */", NULL }; + //"};\n", + // "extern struct dentry devtab[] PROGMEM; /* one entry per device */", char saveattrid[MAXNAME]; /* Holds the IDENT from an attribute */ @@ -392,8 +397,8 @@ int main(int argc, char **argv) { { // fprintf(confc, "typedef unsigned int size_t;\n"); // fprintf(confc, "#include \n"); - // fprintf(confc, "const struct dentry devtab[] PROGMEM =\n{\n"); - fprintf(confc, "struct dentry devtab[] =\n{\n"); + fprintf(confc, "const __flash struct dentry devtab[] =\n{\n"); + // fprintf(confc, "struct dentry devtab[] =\n{\n"); fprintf(confc, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n", "/**", " * Format of entries is:", diff --git a/device/nam/naminit.c b/device/nam/naminit.c index feb4044..2a7c174 100644 --- a/device/nam/naminit.c +++ b/device/nam/naminit.c @@ -38,6 +38,10 @@ status naminit(void) nnames = 0; + // RAFA + /* avr specific */ + char name[10]; + for (i=0; idvname; /* Move to device name */ + /* avr specific */ + strncpy_P(name, devptr->dvname, 10); + nptr = name; /* Map device name to lower case and append */ @@ -65,17 +72,18 @@ status naminit(void) } if (len > NM_MAXLEN) { - // RAFA kprintf("namespace: device name %s too long\r\n", avr_kprintf(m5); - kprintf("%s", devptr->dvname); + //kprintf("%s", devptr->dvname); continue; } + // RAFA + kprintf("m:%s\n",tmpstr); retval = mount(tmpstr, NULLSTR, devptr->dvnum); if (retval == SYSERR) { // RAFA kprintf("namespace: cannot mount device %d\r\n", avr_kprintf(m4); - kprintf("%s", devptr->dvname); + // kprintf("%s", devptr->dvname); continue; } } diff --git a/device/nam/nammap.c b/device/nam/nammap.c index 1aa23e7..7612cf3 100644 --- a/device/nam/nammap.c +++ b/device/nam/nammap.c @@ -19,6 +19,8 @@ devcall nammap( char tmpname[NM_MAXLEN]; /* Temporary buffer for name */ int32 iter; /* Number of iterations */ + //RAFA + // kprintf("no:%s", name); /* Place original name in temporary buffer and null terminate */ if (namcpy(tmpname, name, NM_MAXLEN) == SYSERR) { @@ -28,6 +30,7 @@ devcall nammap( /* Repeatedly substitute the name prefix until a non-namespace */ /* device is reached or an iteration limit is exceeded */ + for (iter=0; iternprefix; /* Start at beginning of prefix */ + // RAFA +// kprintf("pr:%s", pptr); /* Compare prefix to string and count prefix size */ diff --git a/device/nam/namopen.c b/device/nam/namopen.c index 9097582..92f0c6d 100644 --- a/device/nam/namopen.c +++ b/device/nam/namopen.c @@ -16,6 +16,8 @@ devcall namopen( char newname[NM_MAXLEN]; /* Name with prefix replaced */ did32 newdev; /* Device ID after mapping */ + //RAFA +// kprintf("i:%s", name); /* Use namespace to map name to a new name and new descriptor */ newdev = nammap(name, newname, devptr->dvnum); diff --git a/device/tty/ttygetc.c b/device/tty/ttygetc.c index 16c52f3..59d3f95 100644 --- a/device/tty/ttygetc.c +++ b/device/tty/ttygetc.c @@ -22,9 +22,18 @@ devcall ttygetc( // struct sentry * semptr; // semptr = &semtab[typtr->tyisem]; // while(--(semptr->scount) < 0); + + wait(typtr->tyisem); + + // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER + ch = 0; // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER + while (ch == 0) { // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER + ch = *typtr->tyihead++; + } // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER + /* Wrap around to beginning of buffer, if needed */ if (typtr->tyihead >= &typtr->tyibuff[TY_IBUFLEN]) { diff --git a/device/tty/ttyhandle_in.c b/device/tty/ttyhandle_in.c index 35f0398..01c31dd 100644 --- a/device/tty/ttyhandle_in.c +++ b/device/tty/ttyhandle_in.c @@ -132,7 +132,12 @@ void ttyhandle_in ( if (typtr->tyitail>=&typtr->tyibuff[TY_IBUFLEN]) { typtr->tyitail = typtr->tyibuff; } + // RAFA + // serial_put_char('*'); /* Make entire line (plus \n or \r) available */ + + //RAFA + //semreset(typtr->tyisem, 1); signaln(typtr->tyisem, typtr->tyicursor + 1); typtr->tyicursor = 0; /* Reset for next line */ return; @@ -177,6 +182,9 @@ void ttyhandle_in ( typtr->tyicursor++; *typtr->tyitail++ = ch; + // RAFA +// signal(typtr->tyisem); + /* Wrap around if needed */ if (typtr->tyitail >= &typtr->tyibuff[TY_IBUFLEN]) { diff --git a/device/tty/ttyread.c b/device/tty/ttyread.c index df1204e..0eddab3 100644 --- a/device/tty/ttyread.c +++ b/device/tty/ttyread.c @@ -42,6 +42,16 @@ devcall ttyread( return nread; } + + // RAFA: HORRIBLE WORKAROUND TO THE FOREVER BUG + char *c; // RAFA: HORRIBLE WORKAROUND TO THE FOREVER BUG + int i; // RAFA: HORRIBLE WORKAROUND TO THE FOREVER BUG + c = typtr->tyibuff; // RAFA: HORRIBLE WORKAROUND TO THE FOREVER BUG + for (i=0; ityihead = typtr->tyitail = typtr->tyibuff; // RAFA: HORRIBLE WORKAROUND TO THE FOREVER BUG + + /* Block until input arrives */ firstch = ttygetc(devptr); diff --git a/include/name.h b/include/name.h index 5a2f1ed..3e5e4e2 100644 --- a/include/name.h +++ b/include/name.h @@ -5,8 +5,10 @@ /* Constants that define the namespace mapping table sizes */ #define NM_PRELEN 16 /* Max size of a prefix string */ -#define NM_REPLLEN 8 /* Maximum size of a replacement*/ -#define NM_MAXLEN 8 /* Maximum size of a file name */ +// RAFA #define NM_REPLLEN 8 /* Maximum size of a replacement*/ +// RAFA #define NM_MAXLEN 8 /* Maximum size of a file name */ +#define NM_REPLLEN 16 /* Maximum size of a replacement*/ +#define NM_MAXLEN 16 /* Maximum size of a file name */ #define NNAMES 4 /* Number of prefix definitions */ /* Definition of the name prefix table that defines all name mappings */ diff --git a/include/shprototypes.h b/include/shprototypes.h index 69ecab8..2f676fa 100644 --- a/include/shprototypes.h +++ b/include/shprototypes.h @@ -84,3 +84,4 @@ extern shellcmd xsh_basic (int32, char *[]); extern shellcmd xsh_ps (int32, char *[]); extern shellcmd xsh_free (int32, char *[]); extern shellcmd xsh_forever (int32, char *[]); +extern shellcmd xsh_reboot (int32, char *[]); diff --git a/lib/avr_messages.c b/lib/avr_messages.c index d277e5d..31e2a05 100644 --- a/lib/avr_messages.c +++ b/lib/avr_messages.c @@ -5,8 +5,21 @@ typedef unsigned int size_t; #include // const char CONSOLE_RESET[] PROGMEM = " \033[0m\033[2J\033[;H"; -// const char m0[] PROGMEM = "Welcome to Xinu for AVR microcontrollers!\n v0.1 rafa@fi.uncoma.edu.ar"; const char m0[] PROGMEM = "\nWelcome to Xinu!\n\n\r\tXinu OS Copyright (c) 2012, 2015\n\r\tDouglas E. Comer and CRC Press, Inc.\n\n\r\tThis version for AVR atmega328p v0.1 (c) 2020\n\r\tRafael Ignacio Zurita \n\n\r"; +const char m1[] PROGMEM = "\n\nRecreating shell\n\n"; +const char m2[] PROGMEM = "Out of message nodes"; +const char m3[] PROGMEM = "\n\nAll user processes have completed.\n\n"; +const char m4[] PROGMEM = "namespace: cannot mount %d\r\n"; +const char m5[] PROGMEM = "namespace: device name %s too long\r\n"; +const char m6[] PROGMEM = "Can't startup system"; +const char m7[] PROGMEM = "ptinit - insufficient memory"; +const char m8[] PROGMEM = "freemem: %10d bytes. Free-list:\n"; +const char m9[] PROGMEM = "Syscall not implemented\n"; +const char m10[] PROGMEM = "ERROR GETSTK %s\n"; +const char m11[] PROGMEM = "0x%08x %d\n"; +const char m12[] PROGMEM = "looping... press reset\n"; + +/* orig : const char m1[] PROGMEM = "\n\nMain process recreating shell\n\n"; const char m2[] PROGMEM = "Port system ran out of message nodes"; const char m3[] PROGMEM = "\n\nAll user processes have completed.\n\n"; @@ -19,4 +32,5 @@ const char m9[] PROGMEM = "System call not implemented\n"; const char m10[] PROGMEM = "ERROR GETSTK %s\n"; const char m11[] PROGMEM = "0x%08x %d\n"; const char m12[] PROGMEM = "looping... press reset\n"; +*/ diff --git a/lib/printf.c b/lib/printf.c index cce4284..46db13a 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -41,10 +41,19 @@ int printf( + char *c; char buf[PRINTF_BUF]; va_list ap; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); + c = buf; + while(*c) { + if(*c == '\n') + putc(stdout, '\r'); + putc(stdout, *c); + c++; + }; +/* for(char *p = &buf[0]; *p; p++) // emulate cooked mode for newlines { if(*p == '\n') @@ -53,6 +62,7 @@ int printf( } putchar(*p); } - va_end(ap); +*/ + va_end(ap); return 0; } diff --git a/main/main.c b/main/main.c index 6fc6f06..59af2e0 100644 --- a/main/main.c +++ b/main/main.c @@ -25,6 +25,7 @@ const __flash uint8_t * const __flash cmdtab_cname[] = (const __flash uint8_t[]) { "sleep" }, (const __flash uint8_t[]) { "forever" }, (const __flash uint8_t[]) { "uptime" }, + (const __flash uint8_t[]) { "reboot" }, (const __flash uint8_t[]) { "kill" }, (const __flash uint8_t[]) { "free" }, (const __flash uint8_t[]) { "clear" }, @@ -36,13 +37,14 @@ const __flash uint8_t * const __flash cmdtab_help[] = { (const __flash uint8_t[]) { "[from to] : display SRAM memory contents" }, (const __flash uint8_t[]) { ": text editor" }, - (const __flash uint8_t[]) { ": basic language interpreter" }, + (const __flash uint8_t[]) { ": BASIC language interpreter" }, (const __flash uint8_t[]) { ": this help" }, (const __flash uint8_t[]) { "n : sleep n seconds" }, - (const __flash uint8_t[]) { ": for (;;); for ever" }, + (const __flash uint8_t[]) { ": for (;;);" }, (const __flash uint8_t[]) { ": tell how long the Xinu system has been running" }, - (const __flash uint8_t[]) { "n : kill (terminates) the n ID process" }, - (const __flash uint8_t[]) { ": display amount of free and used memory in the system" }, + (const __flash uint8_t[]) { ": reset the Xinu system sw. THIS IS NOT a hw reset" }, + (const __flash uint8_t[]) { "n : kill (terminates) the n (ID) process" }, + (const __flash uint8_t[]) { ": display amount of free and used memory" }, (const __flash uint8_t[]) { ": clear the terminal screen" }, (const __flash uint8_t[]) { ": display current processes table" }, (const __flash uint8_t[]) { "[arg ...] : write arguments to standard output" } @@ -57,21 +59,24 @@ const cmdent_t __flash cmdtab[] = { {FALSE, xsh_sleep}, {FALSE, xsh_forever}, {FALSE, xsh_uptime}, + {FALSE, xsh_reboot}, {TRUE, xsh_kill}, {TRUE, xsh_free}, {TRUE, xsh_clear}, - {TRUE, xsh_ps}, +// {TRUE, xsh_ps}, + {FALSE, xsh_ps}, {FALSE, xsh_echo} }; const __flash int cmdtab_stk[] = { 256, /* memdump */ 400, /* editor */ - 400, /* basic */ + 500, /* basic */ 128, /* help */ 128, /* sleep */ - 256, /* forever */ + 128, /* forever */ 200, /* uptime */ + 128, /* reboot */ 300, /* kill */ 128, 64, @@ -178,6 +183,8 @@ process main(void) change_proc_name("shell"); + for (i=0;i +#include +#include + +/*------------------------------------------------------------------------ + * xsh_reboot - reset Xinu system. WARNING: this is not a hardware reset + *------------------------------------------------------------------------ + */ +shellcmd xsh_reboot(int nargs, char *args[]) +{ + void(* reset_func) (void) = 0;//declare reset function at address 0 + cli(); // disable interrupts + reset_func(); +} diff --git a/system/clkhandler.c b/system/clkhandler.c index 572282e..7305f9e 100644 --- a/system/clkhandler.c +++ b/system/clkhandler.c @@ -26,6 +26,7 @@ ISR(TIMER0_COMPA_vect) + /* Increment 1000ms counter */ count1000++; @@ -38,7 +39,7 @@ ISR(TIMER0_COMPA_vect) count1000 = 0; } - /* check if sleep queue is empty */ + /* check if sleep queue is empty every 100ms */ //if ((count1000 % 10) == 0) /* every 100ms */ if ((count1000 % 100) == 0) /* every 100ms */ @@ -52,15 +53,16 @@ ISR(TIMER0_COMPA_vect) } } - /* our MCU is slow 16Mhz, so we do clkhandler every 100ms */ + /* our MCU is slow (16Mhz), so we do resched/preemption every 300ms */ avr_ticks ++; -// if (avr_ticks > 100) { +//// if (avr_ticks > 100) { if (avr_ticks > 300) { - // if (avr_ticks > 10) { +// // if (avr_ticks > 10) { avr_ticks=0; + + /* Decrement the preemption counter */ /* Reschedule if necessary */ - if((--preempt) == 0) { preempt = QUANTUM; resched(); diff --git a/system/conf.c b/system/conf.c new file mode 100644 index 0000000..56237d6 --- /dev/null +++ b/system/conf.c @@ -0,0 +1,49 @@ +/* conf.c (GENERATED FILE; DO NOT EDIT) */ + +#include + + +extern devcall ioerr(void); +extern devcall ionull(void); + +/* Device independent I/O switch */ + +const __flash struct dentry devtab[] = +{ +/** + * Format of entries is: + * dev-number, minor-number, dev-name, + * init, open, close, + * read, write, seek, + * getc, putc, control, + * dev-csr-address, intr-handler, irq + */ + +/* CONSOLE is tty */ + { 0, 0, "CONSOLE", + (void *)ttyinit, (void *)ionull, (void *)ionull, + (void *)ttyread, (void *)ttywrite, (void *)ioerr, + (void *)ttygetc, (void *)ttyputc, (void *)ttycontrol, + (void *)0x40013800, (void *)ttyhandler, 53 }, + +/* NULLDEV is null */ + { 1, 0, "NULLDEV", + (void *)ionull, (void *)ionull, (void *)ionull, + (void *)ionull, (void *)ionull, (void *)ioerr, + (void *)ionull, (void *)ionull, (void *)ioerr, + (void *)0x0, (void *)ioerr, 0 }, + +/* NAMESPACE is nam */ + { 2, 0, "NAMESPACE", + (void *)naminit, (void *)namopen, (void *)ioerr, + (void *)ioerr, (void *)ioerr, (void *)ioerr, + (void *)ioerr, (void *)ioerr, (void *)ioerr, + (void *)0x0, (void *)ioerr, 0 }, + +/* EEPROM0 is eeprom */ + { 3, 0, "EEPROM0", + (void *)eeprom_init, (void *)eeprom_open, (void *)eeprom_close, + (void *)eeprom_read, (void *)eeprom_write, (void *)ioerr, + (void *)ioerr, (void *)ioerr, (void *)ioerr, + (void *)0x0, (void *)ionull, 0 } +}; diff --git a/system/initialize.c b/system/initialize.c index 53b5ae0..198351f 100644 --- a/system/initialize.c +++ b/system/initialize.c @@ -64,7 +64,7 @@ void nullprocess(void) { // resume(create((void *)main, INITSTK, INITPRIO, "Main Process", 0, NULL)); // 200 ok and 400 ok // resume(create((void *)shell, 360, INITPRIO, "shell", 0, NULL)); - resume(create((void *)main, 500, INITPRIO, "main", 0, NULL)); + resume(create((void *)main, 400, INITPRIO, "main", 0, NULL)); // resume(create((void *)test, 256, INITPRIO, "test", 0, NULL)); diff --git a/system/serial_avr.c b/system/serial_avr.c index f0d7217..f2bed5e 100644 --- a/system/serial_avr.c +++ b/system/serial_avr.c @@ -67,11 +67,9 @@ char value; * RX interrupt service rutine */ ISR(USART_RX_vect){ - cli(); value = UDR0; //read UART register into value -// serial_put_char (value); ttyhandler (1, value, 0); - sei(); + } char serial_get_char(void) diff --git a/system/wait.c b/system/wait.c index 647fbcb..ee832cf 100644 --- a/system/wait.c +++ b/system/wait.c @@ -26,6 +26,7 @@ syscall wait( return SYSERR; } +// serial_put_char('%'); if (--(semptr->scount) < 0) { /* If caller must block */ prptr = &proctab[currpid]; prptr->prstate = PR_WAIT; /* Set state to waiting */