Browse Source

concurrent processes ok

pull/1/head
Rafael Zurita 6 years ago
parent
commit
46ffc27c2c
  1. 3
      device/nam/naminit.c
  2. 3
      device/nam/namopen.c
  3. 3
      device/tty/ttycontrol.c
  4. 3
      device/tty/ttygetc.c
  5. 3
      device/tty/ttyhandler.c
  6. 3
      device/tty/ttyinit.c
  7. 3
      device/tty/ttyputc.c
  8. 3
      device/tty/ttyread.c
  9. 3
      device/tty/ttywrite.c
  10. 23
      include/prototypes.h
  11. 5
      include/shell.h
  12. 3
      include/shprototypes.h
  13. 16
      lib/change_proc_name.c
  14. 81
      main/main.c
  15. 2
      main/xsh_echo.c
  16. 17
      main/xsh_forever.c
  17. 47
      main/xsh_kill.c
  18. 47
      main/xsh_uptime.c
  19. 15
      system/clkhandler.c
  20. 3
      system/close.c
  21. 3
      system/control.c
  22. 3
      system/getc.c
  23. 3
      system/init.c
  24. 3
      system/open.c
  25. 3
      system/putc.c
  26. 3
      system/read.c
  27. 3
      system/seek.c
  28. 3
      system/write.c
  29. 2
      xinu-avr-port.txt

3
device/nam/naminit.c

@ -24,7 +24,8 @@ int32 nnames; /* Number of entries allocated */
status naminit(void)
{
did32 i; /* Index into devtab */
struct dentry *devptr; /* Pointer to device table entry*/
// struct dentry *devptr; /* Pointer to device table entry*/
const __flash struct dentry *devptr; /* Pointer to device table entry*/
char tmpstr[NM_MAXLEN]; /* String to hold a name */
status retval; /* Return value */
char *tptr; /* Pointer into tempstring */

3
device/nam/namopen.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall namopen(
struct dentry *devptr, /* Entry in device switch table */
// struct dentry *devptr, /* Entry in device switch table */
const __flash struct dentry *devptr, /* Entry in device switch table */
char *name, /* Name to open */
char *mode /* Mode argument */
)

3
device/tty/ttycontrol.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall ttycontrol(
struct dentry *devptr, /* Entry in device switch table */
// struct dentry *devptr, /* Entry in device switch table */
const __flash struct dentry *devptr, /* Entry in device switch table */
int32 func, /* Function to perform */
int32 arg1, /* Argument 1 for request */
int32 arg2 /* Argument 2 for request */

3
device/tty/ttygetc.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall ttygetc(
struct dentry *devptr /* Entry in device switch table */
// struct dentry *devptr /* Entry in device switch table */
const __flash struct dentry *devptr /* Entry in device switch table */
)
{
char ch; /* Character to return */

3
device/tty/ttyhandler.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
void ttyhandler(uint32 xnum, char c, int flag) {
struct dentry *devptr; /* Address of device control blk*/
// struct dentry *devptr; /* Address of device control blk*/
const __flash struct dentry *devptr; /* Address of device control blk*/
struct ttycblk *typtr; /* Pointer to ttytab entry */
struct uart_csreg *csrptr; /* Address of UART's CSR */
// uint32 iir = 0; /* Interrupt identification */

3
device/tty/ttyinit.c

@ -9,7 +9,8 @@ struct ttycblk ttytab[Ntty];
*------------------------------------------------------------------------
*/
devcall ttyinit(
struct dentry *devptr /* Entry in device switch table */
// struct dentry *devptr /* Entry in device switch table */
const __flash struct dentry *devptr /* Entry in device switch table */
)
{
struct ttycblk *typtr; /* Pointer to ttytab entry */

3
device/tty/ttyputc.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall ttyputc(
struct dentry *devptr, /* Entry in device switch table */
// struct dentry *devptr, /* Entry in device switch table */
const __flash struct dentry *devptr, /* Entry in device switch table */
char ch /* Character to write */
)
{

3
device/tty/ttyread.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall ttyread(
struct dentry *devptr, /* Entry in device switch table */
// struct dentry *devptr, /* Entry in device switch table */
const __flash struct dentry *devptr, /* Entry in device switch table */
char *buff, /* Buffer of characters */
int32 count /* Count of character to read */
)

3
device/tty/ttywrite.c

@ -7,7 +7,8 @@
*------------------------------------------------------------------------
*/
devcall ttywrite(
struct dentry *devptr, /* Entry in device switch table */
// struct dentry *devptr, /* Entry in device switch table */
const __flash struct dentry *devptr, /* Entry in device switch table */
char *buff, /* Buffer of characters */
int32 count /* Count of character to write */
)

23
include/prototypes.h

@ -313,7 +313,8 @@ extern did32 namrepl(char *, char[]);
extern status namcpy(char *, char *, int32);
/* in file namopen.c */
extern devcall namopen(struct dentry *, char *, char *);
// extern devcall namopen(struct dentry *, char *, char *);
extern devcall namopen(const __flash struct dentry *, char *, char *);
/* in file newqueue.c */
extern qid16 newqueue(void);
@ -537,10 +538,12 @@ extern int32 insw(int32, int32 ,int32);
extern syscall suspend(pid32);
/* in file ttycontrol.c */
extern devcall ttycontrol(struct dentry *, int32, int32, int32);
// extern devcall ttycontrol(struct dentry *, int32, int32, int32);
extern devcall ttycontrol(const __flash struct dentry *, int32, int32, int32);
/* in file ttygetc.c */
extern devcall ttygetc(struct dentry *);
// extern devcall ttygetc(struct dentry *);
extern devcall ttygetc(const __flash struct dentry *);
/* in file ttyhandle_in.c */
extern void ttyhandle_in(struct ttycblk *, struct uart_csreg *, char c);
@ -552,19 +555,23 @@ extern void ttyhandle_out(struct ttycblk *, struct uart_csreg *);
extern void ttyhandler(uint32, char c, int tipo);
/* in file ttyinit.c */
extern devcall ttyinit(struct dentry *);
// extern devcall ttyinit(struct dentry *);
extern devcall ttyinit(const __flash struct dentry *);
/* in file ttykickout.c */
extern void ttykickout(struct uart_csreg *);
/* in file ttyputc.c */
extern devcall ttyputc(struct dentry *, char);
// extern devcall ttyputc(struct dentry *, char);
extern devcall ttyputc(const __flash struct dentry *, char);
/* in file ttyread.c */
extern devcall ttyread(struct dentry *, char *, int32);
// extern devcall ttyread(struct dentry *, char *, int32);
extern devcall ttyread(const __flash struct dentry *, char *, int32);
/* in file ttywrite.c */
extern devcall ttywrite(struct dentry *, char *, int32);
// extern devcall ttywrite(struct dentry *, char *, int32);
extern devcall ttywrite(const __flash struct dentry *, char *, int32);
/* in file udp.c */
@ -635,6 +642,8 @@ extern devcall spiputc(struct dentry *, char);
/* avr specific */
extern void avr_printf(char mess[]);
extern void avr_kprintf(const unsigned char *msg);
extern void change_proc_name( char *name);
// extern void avr_kprintf(char mess[]);
extern void blink_avr();

5
include/shell.h

@ -70,12 +70,13 @@
//typedef void (*cfunc)(void);
// typedef void (*CmdFunc_t)(char);
//typedef char *cname;
//typedef int32 (*cfunc_t)(int32,char*[]);/* Function for command */
typedef int32 (*cfunc_t)(int,char*[]);/* Function for command */
struct cmdent { /* Entry in command table */
//char *cname; /* Name of command */
bool8 cbuiltin; /* Is this a builtin command? */
int32 (*cfunc)(int32,char*[]);/* Function for command */
int32 (*cfunc)(int,char*[]);/* Function for command */
};
extern uint32 ncmd;

3
include/shprototypes.h

@ -32,7 +32,7 @@ extern shellcmd xsh_exit (int32, char *[]);
// extern shellcmd xsh_help (int32, char *[]);
/* in file xsh_kill.c */
extern shellcmd xsh_kill (int32, char *[]);
// extern shellcmd xsh_kill (int32, char *[]);
/* in file xsh_ls.c */
extern shellcmd xsh_ls (int32, char *[]);
@ -83,3 +83,4 @@ extern shellcmd xsh_editor (int32, char *[]);
extern shellcmd xsh_basic (int32, char *[]);
extern shellcmd xsh_ps (int32, char *[]);
extern shellcmd xsh_free (int32, char *[]);
extern shellcmd xsh_forever (int32, char *[]);

16
lib/change_proc_name.c

@ -0,0 +1,16 @@
#include <xinu.h>
void change_proc_name( char *name)
{
struct procent *prptr; /* pointer to proc. table entry */
int i;
prptr = &proctab[currpid];
prptr->prname[PNMLEN-1] = NULLCH;
for (i=0 ; i<PNMLEN-1 && (prptr->prname[i]=name[i])!=NULLCH; i++)
;
}

81
main/main.c

@ -4,10 +4,10 @@
#include <xinu.h>
//#include <stdio.h>
#include "shprototypes.h"
void xsh_help(void);
shellcmd xsh_kill(int nargs, char *args[]);
typedef void (*CmdFunc_t)(char);
typedef struct cmdent cmdent_t;
@ -23,40 +23,72 @@ const __flash uint8_t * const __flash cmdtab_cname[] =
(const __flash uint8_t[]) { "basic" },
(const __flash uint8_t[]) { "help" },
(const __flash uint8_t[]) { "sleep" },
(const __flash uint8_t[]) { "forever" },
(const __flash uint8_t[]) { "uptime" },
(const __flash uint8_t[]) { "kill" },
(const __flash uint8_t[]) { "free" },
(const __flash uint8_t[]) { "clear" },
(const __flash uint8_t[]) { "ps" },
(const __flash uint8_t[]) { "echo" }
};
// {"sleep", FALSE, xsh_sleep},
const __flash uint8_t * const __flash cmdtab_help[] =
{
(const __flash uint8_t[]) { "[from to] : tisplay SRAM memory contents using ASCII." },
(const __flash uint8_t[]) { ": text editor." },
(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[]) { ": display amount of free and used memory in the system." },
(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." }
(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[]) { ": this help" },
(const __flash uint8_t[]) { "n : sleep n seconds" },
(const __flash uint8_t[]) { ": for (;;); for ever" },
(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[]) { ": clear the terminal screen" },
(const __flash uint8_t[]) { ": display current processes table" },
(const __flash uint8_t[]) { "[arg ...] : write arguments to standard output" }
};
typedef int32 (*cmdfunc_t)(int32,char*[]);
const __flash cmdent_t cmdtab[] = {
const cmdent_t __flash cmdtab[] = {
{FALSE, xsh_memdump},
{FALSE, xsh_editor},
{FALSE, xsh_basic},
{TRUE, xsh_help},
{FALSE, xsh_sleep},
{FALSE, xsh_forever},
{FALSE, xsh_uptime},
{TRUE, xsh_kill},
{TRUE, xsh_free},
{TRUE, xsh_clear},
{TRUE, xsh_ps},
{FALSE, xsh_echo}
};
const __flash int cmdtab_stk[] = {
256, /* memdump */
400, /* editor */
400, /* basic */
128, /* help */
128, /* sleep */
256, /* forever */
200, /* uptime */
300, /* kill */
128,
64,
128,
256,
};
//const __flash int32 (*f2)(int32,char*[]);
//struct cmdent p[2];
//shellcmd rafa(int a, char*args[]) {
// printf("a:%d\n",a);
//}
const __flash char shell_commands[] = "\n\rCommands:\n\n\r";
const __flash char shell_init_msg[] = "\n\rfor a list of programs on this system type 'help'\nREADY\n\r";
void xsh_help(void)
{
@ -93,7 +125,6 @@ void xsh_help(void)
//};
uint32 ncmd = sizeof(cmdtab) / sizeof(struct cmdent);
//uint32 ncmd = 5;
/************************************************************************/
/* shell - Provide an interactive user interface that executes */
@ -144,6 +175,9 @@ process main(void)
did32 dev = 0; /* ID of tty device from which */
char cname[8];
change_proc_name("shell");
/* Print shell banner and startup message */
/*
@ -154,7 +188,6 @@ process main(void)
fprintf(dev, "%s\n\n", SHELL_STRTMSG);
*/
cmdfunc_t f;
int len_p;
/* Continually prompt the user, read input, and execute command */
@ -297,7 +330,6 @@ process main(void)
if (diff || (*(cmp+len_p) != NULLCH)) {
continue;
} else {
//printf("IGUA:j2:%d\n",j);
break;
}
}
@ -326,8 +358,6 @@ process main(void)
/* Call builtin shell function */
if ((*cmdtab[j].cfunc)(ntok, args)
//f = cmdtab_cfunc[j];
//if (f(ntok, args)
== SHELL_EXIT) {
break;
}
@ -354,38 +384,27 @@ process main(void)
}
}
// int eeprom_fd = open(RAM0, nombre, "w");
// char raf[32] = "pepe";
// write(fd, pepe, 32);
// int eeprom_fd = open(RAM0, nombre, "w");
/* Spawn child thread for non-built-in commands */
// RAFA child = create(cmdtab[j].cfunc,
// RAFA SHELL_CMDSTK, SHELL_CMDPRIO,
// RAFA cmdtab[j].cname, 2, ntok, &tmparg);
/* 160 bytes de stack perfecto */
// f = cmdtab_cfunc[j];
strncpy_P(cname, cmdtab_cname[j], len_p);
cname[len_p] = 0;
child = create(cmdtab[j].cfunc,
// 560, SHELL_CMDPRIO,
// 470, SHELL_CMDPRIO,
// 360, SHELL_CMDPRIO,
128, SHELL_CMDPRIO,
cmdtab_stk[j], SHELL_CMDPRIO,
cname, 2, ntok, &tmparg);
// cmdtab_cname[j], 2, ntok, &tmparg);
//cmdtab[j].cname, 2, ntok, &tmparg);
/* If creation or argument copy fails, report error */
// serial_put_char('X');
// if (child == SYSERR)
// serial_put_char('Y');
if ((child == SYSERR) ||
(addargs(child, ntok, tok, tlen, tokbuf, &tmparg)
== SYSERR) ) {
// serial_put_char('Z');
// fprintf(dev, SHELL_CREATMSG);
fprintf(dev, "?\n\r");
continue;
@ -399,10 +418,6 @@ process main(void)
msg = recvclr();
resume(child);
// RAFA AGREGA
resched();
// serial_put_char('X');
if (! backgnd) {
msg = receive();
while (msg != child) {

2
main/xsh_echo.c

@ -4,7 +4,7 @@
#include <stdio.h>
/*------------------------------------------------------------------------
* xhs_echo - write argument strings to stdout
* xsh_echo - write argument strings to stdout
*------------------------------------------------------------------------
*/
shellcmd xsh_echo(int nargs, char *args[])

17
main/xsh_forever.c

@ -0,0 +1,17 @@
/* xsh_forever.c - xsh_forever */
#include <xinu.h>
#include <stdio.h>
/*------------------------------------------------------------------------
* xsh_forever
*------------------------------------------------------------------------
*/
shellcmd xsh_forever(int nargs, char *args[])
{
for (;;)
printf("a");
return 0;
}

47
main/xsh_kill.c

@ -0,0 +1,47 @@
/* xsh_kill.c - xsh_kill */
#include <xinu.h>
#include <string.h>
#include <stdio.h>
/*------------------------------------------------------------------------
* xsh_kill - obtain and print the current month, day, year, and time
*------------------------------------------------------------------------
*/
shellcmd xsh_kill(int nargs, char *args[]) {
int32 retval; /* return value */
pid32 pid; /* ID of process to kill */
char ch; /* next character of argument */
char *chptr; /* walks along argument string */
/* Check argument count */
if (nargs != 2) {
return SYSERR;
}
/* compute process ID from argument string */
chptr = args[1];
ch = *chptr++;
pid = 0;
while(ch != NULLCH) {
if ( (ch < '0') || (ch > '9') ) {
return 1;
}
pid = 10*pid + (ch - '0');
ch = *chptr++;
}
if (pid == 0) {
return 1;
}
retval = kill(pid);
if (retval == SYSERR) {
//fprintf(stderr, "%s: cannot kill process %d\n",
// args[0], pid);
return 1;
}
return 0;
}

47
main/xsh_uptime.c

@ -0,0 +1,47 @@
/* xsh_uptime.c - xsh_uptime */
#include <xinu.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------
* xsh_uptime - shell to print the time the system has been up
*------------------------------------------------------------------------
*/
shellcmd xsh_uptime(int nargs, char *args[])
{
long days, hrs, mins, secs; /* days, hours, minutes, and */
/* seconds since system boot */
long secperday = 86400; /* seconds in a day */
long secperhr = 3600; /* seconds in an hour */
long secpermin = 60; /* seconds in a minute */
/* Check for valid number of arguments */
if (nargs > 1) {
return 1;
}
secs = clktime; /* total seconds since boot */
/* subtract number of whole days */
days = secs/secperday;
secs -= days*secperday;
/* subtract number of hours */
hrs = secs/secperhr;
secs -= hrs*secperhr;
/* subtract number of minutes */
mins = secs/secpermin;
secs -= mins*secpermin;
printf(" %d day(s) &", days);
printf(" %dh:", hrs);
printf("%dm:", mins);
printf("%ds\n", secs);
return 0;
}

15
system/clkhandler.c

@ -24,10 +24,6 @@ ISR(TIMER0_COMPA_vect)
/* every second */
/* if avr_ticks == 1000 then 1 second */
/* our MCU is slow 16Mhz, so we do clkhandler every 100ms */
avr_ticks ++;
if (avr_ticks > 100) {
avr_ticks=0;
/* Increment 1000ms counter */
@ -36,13 +32,16 @@ ISR(TIMER0_COMPA_vect)
/* After 1 sec, increment clktime */
if(count1000 >= 10) { /* previous was: if(count1000 >= 1000) */
//if(count1000 >= 100) { /* previous was: if(count1000 >= 1000) */
if(count1000 >= 1000) { /* previous was: if(count1000 >= 1000) */
clktime++;
count1000 = 0;
}
/* check if sleep queue is empty */
//if ((count1000 % 10) == 0) /* every 100ms */
if ((count1000 % 100) == 0) /* every 100ms */
if(!isempty(sleepq)) {
/* sleepq nonempty, decrement the key of */
/* topmost process on sleepq */
@ -53,6 +52,12 @@ ISR(TIMER0_COMPA_vect)
}
}
/* our MCU is slow 16Mhz, so we do clkhandler every 100ms */
avr_ticks ++;
// if (avr_ticks > 100) {
if (avr_ticks > 300) {
// if (avr_ticks > 10) {
avr_ticks=0;
/* Decrement the preemption counter */
/* Reschedule if necessary */

3
system/close.c

@ -11,7 +11,8 @@ syscall close(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/control.c

@ -14,7 +14,8 @@ syscall control(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/getc.c

@ -11,7 +11,8 @@ syscall getc(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/init.c

@ -11,7 +11,8 @@ syscall init(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/open.c

@ -13,7 +13,8 @@ syscall open(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/putc.c

@ -12,7 +12,8 @@ syscall putc(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/read.c

@ -13,7 +13,8 @@ syscall read(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/seek.c

@ -12,7 +12,8 @@ syscall seek(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

3
system/write.c

@ -13,7 +13,8 @@ syscall write(
)
{
intmask mask; /* Saved interrupt mask */
struct dentry *devptr; /* Entry in device switch table */
// struct dentry *devptr; /* Entry in device switch table */
const __flash struct dentry *devptr; /* Entry in device switch table */
int32 retval; /* Value to return to caller */
mask = disable();

2
xinu-avr-port.txt

@ -12,6 +12,8 @@ y como qkey en queue.h es char (originalmente es int32, pero
con int32 nos quita muchisima RAM) tenemos un hack/workaround
para lograr el sleepms acorde, pero no es en ms.
SOLUCIONAR.
- ademas como las key en queue son char, podemos tener
sleep de maximo 20 segundos aprox. (de la llamada 20*10ms de sleep100ms())
- agregar a la tabla de cmdtab del shell que pueda indicar
el stack para cada proceso.

Loading…
Cancel
Save