Browse Source

working 4 proc

pull/1/head
Rafael Zurita 6 years ago
parent
commit
60870c9580
  1. 246
      apps/shell/TinyBasicPlus_README
  2. 0
      apps/shell/xsh_memdump.c
  3. 9
      include/prototypes.h
  4. 1
      include/queue.h
  5. 6
      include/shprototypes.h
  6. 60
      main/main.c
  7. 16
      main/xsh_basic.c
  8. 16
      main/xsh_clear.c
  9. 2
      main/xsh_editor.c
  10. 35
      main/xsh_free.c
  11. 51
      main/xsh_memdump.c
  12. 122
      main/xsh_memstat.c
  13. 35
      main/xsh_ps.c
  14. 37
      main/xsh_sleep.c
  15. 2
      system/initialize.c
  16. 3
      system/insert.c
  17. 3
      system/insertd.c
  18. 10
      system/sleep.c
  19. 31
      xinu-avr-port.txt

246
apps/shell/TinyBasicPlus_README

@ -0,0 +1,246 @@
TinyBasic Plus
==============
A C implementation of Tiny Basic, with a focus on support for
Arduino. It was originally written by Gordon Brandly in the form
of "68000 Tiny Basic", and then ported to C by Michael Field as
"Arduino Basic", though still called "Tiny Basic" in the source
files.
TinyBasic Plus is an extension and modification upon the original
"Tiny Basic" by adding support for a few more devices, configurable
at build time. It is designed for use on the Arduino, although
builds will soon be easily possible for other platforms through
command line makefiles. Provided is a makefile that builds for
unix-ey type OSes. It has only been tested for Darwin (OS X).
Features added include support for fileio (SD Library), autorunning
a program from the SD card, smaller footprint (PROGMEM), support
for pin data IO, and support for the on-chip EEProm storage for your
program.
# Full list of supported statements and functions
## System
- BYE - *exits Basic, soft reboot on Arduino*
- END - *stops execution from the program, also "STOP"*
- MEM - *displays memory usage statistics*
- NEW - *clears the current program*
- RUN - *executes the current program*
## File IO/SD Card
- FILES - *lists the files on the SD card*
- LOAD filename.bas - *loads a file from the SD card*
- CHAIN filename.bas - *equivalent of: new, load filename.bas, run*
- SAVE filename.bas - *saves the current program to the SD card, overwriting*
## EEProm - nonvolatile on-chip storage
- EFORMAT - clears the EEProm memory
- ELOAD - load the program in from EEProm
- ESAVE - save the current program to the EEProm
- ELIST - print out the contents of EEProm
- ECHAIN - load the program from EEProm and run it
## IO, Documentation
- INPUT variable - *let the user input an expression (number or variable name*
- PEEK( address ) - *get a value in memory* (unimplemented)
- POKE address - *set a value in memory* (unimplemented)
- PRINT expression - *print out the expression, also "?"*
- REM stuff - *remark/comment, also "'"*
## Expressions, Math
- A=V, LET A=V - *assign value to a variable*
- +, -, \*, / - *Math*
- <,<=,=,<>,!=,>=,> - *Comparisons*
- ABS( expression ) - *returns the absolute value of the expression*
- RSEED( v ) - *sets the random seed to v*
- RND( m ) - *returns a random number from 0 to m*
## Control
- IF expression statement - *perform statement if expression is true*
- FOR variable = start TO end - *start for block*
- FOR variable = start TO end STEP value - *start for block with step*
- NEXT - *end of for block*
- GOTO linenumber - *continue execution at this line number*
- GOSUB linenumber - *call a subroutine at this line number*
- RETURN - *return from a subroutine*
## Pin IO
- DELAY timems*- wait (in milliseconds)*
- DWRITE pin,value - *set pin with a value (HIGH,HI,LOW,LO)*
- AWRITE pin,value - *set pin with analog value (pwm) 0..255*
- DREAD( pin ) - *get the value of the pin*
- AREAD( analogPin ) - *get the value of the analog pin*
NOTE: "PINMODE" command removed as of version 0.11
## Sound - Piezo wired with red/+ on pin 5 and black/- to ground
- TONE freq,timems - play "freq" for "timems" milleseconds (1000 = 1 second)
- TONEW freq,timems - same as above, but also waits for it to finish
- NOTONE - stop playback of all playing tones
NOTE: TONE commands are by default disabled
# Example programs
Here are a few example programs to get you started...
## User Input
Let a user enter a new value for a variable, enter a number like '33' or '42',
or a varaible like 'b'.
10 A=0
15 B=999
20 PRINT "A is ", A
30 PRINT "Enter a new value ";
40 INPUT A
50 PRINT "A is now ", A
## Blink
hook up an LED between pin 3 and ground
10 FOR A=0 TO 10
20 DWRITE 3, HIGH
30 DELAY 250
40 DWRITE 3, LOW
50 DELAY 250
60 NEXT A
## Fade
hook up an LED between pin 3 and ground
10 FOR A=0 TO 10
20 FOR B=0 TO 255
30 AWRITE 3, B
40 DELAY 10
50 NEXT B
60 FOR B=255 TO 0 STEP -1
70 AWRITE 3, B
80 DELAY 10
90 NEXT B
100 NEXT A
## LED KNOB
hook up a potentiometeter between analog 2 and ground, led from digital 3 and ground. If knob is at 0, it stops
10 A = AREAD( 2 )
20 PRINT A
30 B = A / 4
40 AWRITE 3, B
50 IF A == 0 GOTO 100
60 GOTO 10
100 PRINT "Done."
## ECHAIN example
Write a small program, store it in EEPROM. We'll show that variables don't
get erased when chaining happens
EFORMAT
10 A = A + 2
20 PRINT A
30 PRINT "From eeprom!"
40 IF A = 12 GOTO 100
50 PRINT "Shouldn't be here."
60 END
100 PRINT "Hi!"
Then store it in EEProm
ESAVE
Now, create a new program in main memory and run it
NEW
10 A = 10
20 PRINT A
30 PRINT "From RAM!"
40 ECHAIN
List both, and run
ELIST
LIST
RUN
# Device Support
## Current
- Arduino - ATMega 168 (~100 bytes available)
- Arduino - ATMega 368 (~1100 bytes available)
- SD cards (via SD Library, for FILES, LOAD, SAVE commands, uses 9k of ROM)
- EEProm (via EEProm Library, uses 500 bytes of ROM)
- Serial IO - command console
## Future
- PS2 Keyboard for standalone use (maybe)
- Graphics support via common function names and ANSI/ReGIS escape codes
# Known Quirks and Limitations
- If LOAD or SAVE are called, FILES fails subsequent listings
- SD cards are not hot-swappable. A reset is required between swaps.
# Authors and Contributors
- Tiny Basic 68k - Gordon Brandly [Project Page (via archive.org)](https://web.archive.org/web/20170306113457/http://members.shaw.ca:80/gbrandly/68ktinyb.html)
- Arduino Basic / Tiny Basic C - Michael Field [Project Page](http://hamsterworks.co.nz/mediawiki/index.php/Arduino_Basic)
- Tiny Basic Plus - Scott Lawrence <yorgle@gmail.com> [Github Page](http://github.com/BleuLlama/TinyBasicPlus)
- Jurg Wullschleger - Fix for unary operations and whitespace in expressions
# Links
- [Arduino Microcontroller](http://arduino.cc)
# Licensing
Mike Field based his C port of Tiny Basic on the 68000 Tiny BASIC which carried
the following license:
~~~
******************************************************************
* *
* Tiny BASIC for the Motorola MC68000 *
* *
* Derived from Palo Alto Tiny BASIC as published in the May 1976 *
* issue of Dr. Dobb's Journal. Adapted to the 68000 by: *
* Gordon Brandly *
* 12147 - 51 Street *
* Edmonton AB T5W 3G8 *
* Canada *
* (updated mailing address for 1996) *
* *
* This version is for MEX68KECB Educational Computer Board I/O. *
* *
******************************************************************
* Copyright (C) 1984 by Gordon Brandly. This program may be *
* freely distributed for personal use only. All commercial *
* rights are reserved. *
******************************************************************
~~~
However, Mike did not include a license of his own for his
version of this. From discussions with him, I felt that the MIT license is
the most applicable to his intent.
I am in the process of further determining what should be done wrt licensing
further. This entire header will likely change with the next version 0.16,
which will hopefully nail down the whole thing so we can get back to
implementing features instead of licenses. Thank you for your time.
# MIT License
Copyright (c) 2012-2013
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0
apps/shell/xsh_memstat.c → apps/shell/xsh_memdump.c

9
include/prototypes.h

@ -157,10 +157,12 @@ extern void icmp_ntoh(struct netpacket *);
extern syscall init(did32);
/* in file insert.c */
extern status insert(pid32, qid16, int32);
// extern status insert(pid32, qid16, int32);
extern status insert(pid32, qid16, char);
/* in file insertd.c */
extern status insertd(pid32, qid16, int32);
// extern status insertd(pid32, qid16, int32);
extern status insertd(pid32, qid16, char);
/* in file intr.S */
extern intmask disable(void);
@ -511,7 +513,8 @@ extern syscall signal(sid32);
extern syscall signaln(sid32, int32);
/* in file sleep.c */
extern syscall sleepms(int32);
// extern syscall sleepms(int32);
extern syscall sleep100ms(int32); /* avr atmega328p specific */
extern syscall sleep(int32);
/* in file spicontrol.c */

1
include/queue.h

@ -14,6 +14,7 @@
struct qentry { /* One per process plus two per list */
char qkey; /* Key on which the queue is ordered */
// int32 qkey; /* Key on which the queue is ordered */
qid16 qnext; /* Index of next process or tail */
qid16 qprev; /* Index of previous process or head */
};

6
include/shprototypes.h

@ -43,8 +43,8 @@ extern shellcmd xsh_led (int32, char *[]);
/* in file xsh_memdump.c */
extern shellcmd xsh_memdump (int32, char *[]);
/* in file xsh_memstat.c */
extern shellcmd xsh_memstat (int32, char *[]);
/* in file xsh_memdump.c */
extern shellcmd xsh_memdump (int32, char *[]);
/* in file xsh_netinfo.c */
extern shellcmd xsh_netinfo (int32, char *[]);
@ -81,3 +81,5 @@ extern shellcmd xsh_uptime (int32, char *[]);
/* in file xsh_editor.c */
extern shellcmd xsh_editor (int32, char *[]);
extern shellcmd xsh_basic (int32, char *[]);
extern shellcmd xsh_ps (int32, char *[]);
extern shellcmd xsh_free (int32, char *[]);

60
main/main.c

@ -18,38 +18,41 @@ typedef struct cmdent cmdent_t;
const __flash uint8_t * const __flash cmdtab_cname[] =
{
(const __flash uint8_t[]) { "memstat" },
(const __flash uint8_t[]) { "memdump" },
(const __flash uint8_t[]) { "editor" },
(const __flash uint8_t[]) { "basic" },
(const __flash uint8_t[]) { "help" },
(const __flash uint8_t[]) { "sleep" },
(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." }
};
typedef int32 (*cmdfunc_t)(int32,char*[]);
//typedef void (*cmdfunc_t)(char);
// const cmdfunc_t __flash cmdtab_cfunc[] = {
/*
cmdfunc_t cmdtab_cfunc[] = {
xsh_memstat,
xsh_editor,
xsh_basic,
xsh_help,
xsh_echo};
const __flash int cmdtab_cbuiltin[] = {
FALSE,
FALSE,
FALSE,
TRUE,
FALSE};
*/
const __flash cmdent_t cmdtab[] = {
{FALSE, xsh_memstat},
{FALSE, xsh_memdump},
{FALSE, xsh_editor},
{FALSE, xsh_basic},
{TRUE, xsh_help},
{FALSE, xsh_sleep},
{TRUE, xsh_free},
{TRUE, xsh_clear},
{TRUE, xsh_ps},
{FALSE, xsh_echo}
};
@ -61,7 +64,7 @@ void xsh_help(void)
printf("%S", shell_commands);
for (i=0; i<ncmd; i++)
printf("%S\n", cmdtab_cname[i]);
printf(" %S %S\n", cmdtab_cname[i], cmdtab_help[i]);
printf("\n\r");
}
@ -89,8 +92,8 @@ void xsh_help(void)
//};
// uint32 ncmd = sizeof(cmdtab) / sizeof(struct cmdent);
uint32 ncmd = 5;
uint32 ncmd = sizeof(cmdtab) / sizeof(struct cmdent);
//uint32 ncmd = 5;
/************************************************************************/
/* shell - Provide an interactive user interface that executes */
@ -140,6 +143,7 @@ process main(void)
/* builtin commands */
did32 dev = 0; /* ID of tty device from which */
char cname[8];
/* Print shell banner and startup message */
/*
@ -362,9 +366,15 @@ process main(void)
// 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,
552, SHELL_CMDPRIO,
cmdtab_cname[j], 2, ntok, &tmparg);
// 560, SHELL_CMDPRIO,
// 470, SHELL_CMDPRIO,
// 360, SHELL_CMDPRIO,
128, 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 */

16
main/xsh_basic.c

@ -233,7 +233,8 @@ shellcmd xsh_basic(int nargs, char *args[])
// size of our program ram
// RAFA #define kRamSize 64*1024 /* arbitrary - not dependant on libraries */
#define kRamSize 400 /* arbitrary - not dependant on libraries */
// RAFA #define kRamSize 320 /* arbitrary - not dependant on libraries */
#define kRamSize 260 /* arbitrary - not dependant on libraries */
// RAFA AGREGA
@ -457,7 +458,7 @@ const static unsigned char highlow_tab[] PROGMEM = {
//RAFA ANTES DECIA 5
//#define STACK_SIZE (sizeof(struct stack_for_frame)*5)
#define STACK_SIZE (sizeof(struct stack_for_frame)*5)
#define STACK_SIZE (sizeof(struct stack_for_frame)*3)
#define VAR_SIZE sizeof(short int) // Size of variables in bytes
@ -478,8 +479,9 @@ static const unsigned char okmsg[] PROGMEM = "OK";
static const unsigned char whatmsg[] PROGMEM = "What? ";
static const unsigned char howmsg[] PROGMEM = "How?";
static const unsigned char sorrymsg[] PROGMEM = "Sorry!";
static const unsigned char initmsg[] PROGMEM = "TinyBasic Plus " kVersion;
static const unsigned char initmsg[] PROGMEM = "\nWelcome to TinyBasic Plus interpreter " kVersion;
static const unsigned char memorymsg[] PROGMEM = " bytes free.";
static const unsigned char avr_vars_msg[] PROGMEM = "available VARS: A - J";
static const unsigned char breakmsg[] PROGMEM = "break!";
static const unsigned char unimplimentedmsg[] PROGMEM = "Unimplemented";
static const unsigned char backspacemsg[] PROGMEM = "\b \b";
@ -983,15 +985,19 @@ void loop()
#ifdef ALIGN_MEMORY
// Ensure these memory blocks start on even pages
stack_limit = ALIGN_DOWN(program+sizeof(program)-STACK_SIZE);
variables_begin = ALIGN_DOWN(stack_limit - 27*VAR_SIZE);
// RAFA variables_begin = ALIGN_DOWN(stack_limit - 27*VAR_SIZE);
variables_begin = ALIGN_DOWN(stack_limit - 10*VAR_SIZE);
#else
stack_limit = program+sizeof(program)-STACK_SIZE;
variables_begin = stack_limit - 27*VAR_SIZE;
// RAFA variables_begin = stack_limit - 27*VAR_SIZE;
variables_begin = stack_limit - 10*VAR_SIZE;
#endif
// memory free
printmsg(initmsg);
printnum(variables_begin-program_end);
printmsg(memorymsg);
printmsg(avr_vars_msg);
warmstart:
// this signifies that it is running in 'direct' mode.

16
main/xsh_clear.c

@ -0,0 +1,16 @@
/* xsh_clear.c - xsh_clear */
#include <xinu.h>
#include <stdio.h>
/*------------------------------------------------------------------------
* xsh_clear - clear the terminal screen
*------------------------------------------------------------------------
*/
shellcmd xsh_clear(int nargs, char *args[])
{
fprintf(0, "\033[2J");
fprintf(0, "\033[H");
return 0;
}

2
main/xsh_editor.c

@ -55,7 +55,7 @@ void editor_del(char * buf, int line, int i)
// printf("\033[D");
}
void clear(void)
static void clear(void)
{
fprintf(0, "\033[2J");
fprintf(0, "\033[H");

35
main/xsh_free.c

@ -0,0 +1,35 @@
/* xsh_free.c - xsh_free */
#include <xinu.h>
#include <stdio.h>
const __flash char free_msg0[] = "\nfree mem list:\n\raddr\t\tlen\n";
const __flash char free_msg1[] = "\n\t\ttotal\tused\tfree\nSRAM Mem\t";
/*------------------------------------------------------------------------
* xsh_free - show free memory available
*------------------------------------------------------------------------
*/
shellcmd xsh_free(int nargs, char *args[])
{
int32 i; /* walks through args array */
long free_mem;
struct memblk *block;
printf("%S", free_msg0);
/* Output Xinu memory layout */
free_mem = 0;
for (block = memlist.mnext; block != NULL;
block = block->mnext) {
free_mem += block->mlength;
printf("0x%08x\t%d\n", block,
(uint32) block->mlength);
}
printf("%S", free_msg1);
printf("%d\t%d\t%d\n", maxheap, maxheap-free_mem, free_mem);
return 0;
}

51
main/xsh_memdump.c

@ -0,0 +1,51 @@
/* xsh_memdump.c - xsh_memdump */
#include <xinu.h>
#include <stdio.h>
#include <string.h>
// RAFA
#include <avr/interrupt.h>
static void printnl(void)
{
printf("\n\r");
}
/*------------------------------------------------------------------------
* xsh_memdump - Print memory content
*------------------------------------------------------------------------
*/
shellcmd xsh_memdump(int nargs, char *args[])
{
int from = 0;
int to = 0x8FF; /* AVR atmega328p top RAM address */
if (nargs == 3) {
from = args[1];
to = args[2];
}
long i;
int j=0;
char * c = 0;
for (i = from; i < to ; i++) {
c = (char *)i;
if (j==0) {
printf("\n");
printf ("0x%08x ", c);
}
j++;
if (j==16) j=0;
if (*c < 33)
printf("-");
else
printf("%c", *c);
}
printnl();
return 0;
}

122
main/xsh_memstat.c

@ -1,122 +0,0 @@
/* xsh_memstat.c - xsh_memstat */
#include <xinu.h>
#include <stdio.h>
#include <string.h>
// RAFA
#include <avr/interrupt.h>
static void printMemUse(void);
static void printFreeList(void);
static void printnl(void)
{
printf("\n\r");
}
/*------------------------------------------------------------------------
* xsh_memstat - Print statistics about memory use and dump the free list
*------------------------------------------------------------------------
*/
shellcmd xsh_memstat(int nargs, char *args[])
{
// printMemUse();
printFreeList();
return 0;
}
/*------------------------------------------------------------------------
* printFreeList - Walk the list of free memory blocks and print the
* location and size of each
*------------------------------------------------------------------------
*/
static void printFreeList(void)
{
// char t[80];
struct memblk *block;
/* Output a heading for the free list */
// printf("Free:\n");
printf("FreeMEM: addr len\n");
// avr_printf(m11);
for (block = memlist.mnext; block != NULL; block = block->mnext) {
printf("0x%08x %d\n", block,
(uint32) block->mlength);
}
long i;
int j=0;
char * c = 0;
for (i=0; i<0x5bd ; i++) {
c = (char *)i;
if (j==0) {
serial_put_char('\n');
serial_put_char('\r');
printf ("0x%08x ", c);
}
j++;
if (j==16) j=0;
if (*c < 33)
serial_put_char('-');
else
serial_put_char(*c);
}
printnl();
}
extern void start(void);
extern void *_end;
/*------------------------------------------------------------------------
* printMemUse - Print statistics about memory use
*------------------------------------------------------------------------
*/
static void printMemUse(void)
{
int i; /* Index into process table */
uint32 code = 0; /* Total Xinu code memory */
uint32 stack = 0; /* Total used stack memory */
uint32 kheap = 0; /* Free kernel heap memory */
uint32 kfree = 0; /* Total free memory */
struct memblk *block; /* Ptr to memory block */
/* Calculate amount of text memory */
// code = (uint32)&etext - (uint32)&text;
/* Calculate amount of allocated stack memory */
/* Skip the NULL process since it has a private stack */
for (i = 0; i < NPROC; i++) {
if (proctab[i].prstate != PR_FREE) {
stack += (uint32)proctab[i].prstklen;
}
}
/* Calculate the amount of memory on the free list */
for (block = memlist.mnext; block != NULL; block = block->mnext) {
kfree += block->mlength;
}
/* Calculate the amount of free kernel heap memory */
kheap = kfree - stack;
/* Output statistics on current memory use */
// printf("code: %10d\n", (uint32) code);
// printf("stack:%10d bytes\n", (uint32) stack);
// printf("kernel stk:%10d bytes\n", (uint32) mspstack);
// printf("heap:%10d bytes\n\n", (uint32) kheap);
}

35
main/xsh_ps.c

@ -0,0 +1,35 @@
/* xsh_ps.c - xsh_ps */
#include <xinu.h>
#include <stdio.h>
const __flash char ps_msg0[] = "\nTable of current process\n";
const __flash char ps_msg1[] = "\nname\tid\tparent\tprio\tstate\tstklen\tsem waits\n--\n";
/*------------------------------------------------------------------------
* xsh_ps - show processes
*------------------------------------------------------------------------
*/
shellcmd xsh_ps(int nargs, char *args[])
{
int32 i; /* walks through args array */
/* check all NPROC slots */
printf("%S", ps_msg0);
printf("%S", ps_msg1);
for (i = 0; i < NPROC; i++) {
if (proctab[i].prstate == PR_FREE)
continue;
printf("%s\t%d", proctab[i].prname, i);
printf("\t%d ", proctab[i].prparent);
printf("\t%d ", proctab[i].prprio);
printf("\t%d ", proctab[i].prstate);
printf("\t%d ", proctab[i].prstklen);
printf("\t%d ", proctab[i].prsem);
printf("\n");
}
return 0;
}

37
main/xsh_sleep.c

@ -0,0 +1,37 @@
/* xsh_sleep.c - xsh_sleep */
#include <xinu.h>
#include <stdio.h>
#include <string.h>
/*------------------------------------------------------------------------
* xsh_sleep - Shell command to delay for a specified number of seconds
*------------------------------------------------------------------------
*/
shellcmd xsh_sleep(int nargs, char *args[])
{
int32 delay; /* Delay in seconds */
char *chptr; /* Walks through argument */
char ch; /* Next character of argument */
/* Check for valid number of arguments */
if (nargs != 2) {
return 1;
}
chptr = args[1];
ch = *chptr++;
delay = 0;
while (ch != NULLCH) {
if ( (ch < '0') || (ch > '9') ) {
// fprintf(stderr, "%s: nondigit in argument\n",
// args[0]);
return 1;
}
delay = 10*delay + (ch - '0');
ch = *chptr++;
}
sleep(delay);
return 0;
}

2
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, 360, INITPRIO, "main", 0, NULL));
resume(create((void *)main, 500, INITPRIO, "main", 0, NULL));
// resume(create((void *)test, 256, INITPRIO, "test", 0, NULL));

3
system/insert.c

@ -9,7 +9,8 @@
status insert(
pid32 pid, /* ID of process to insert */
qid16 q, /* ID of queue to use */
int32 key /* Key for the inserted process */
// int32 key /* Key for the inserted process */
char key /* Key for the inserted process */
)
{
qid16 curr; /* Runs through items in a queue*/

3
system/insertd.c

@ -9,7 +9,8 @@
status insertd( /* Assumes interrupts disabled */
pid32 pid, /* ID of process to insert */
qid16 q, /* ID of queue to use */
int32 key /* Delay from "now" (in ms.) */
// int32 key /* Delay from "now" (in ms.) */
char key /* Delay from "now" (in ms.) */
)
{
int32 next; /* Runs through the delta list */

10
system/sleep.c

@ -15,15 +15,19 @@ syscall sleep(
if ( (delay < 0) || (delay > MAXSECONDS) ) {
return SYSERR;
}
sleepms(1000*delay);
// sleepms(1000*delay);
sleep100ms(10*delay);
return OK;
}
/*------------------------------------------------------------------------
* sleepms - Delay the calling process n milliseconds
* sleep100ms - Delay the calling process n x 100 milliseconds
* for example: 1 second = sleep100ms(10)
* avr atmega328p specific
*------------------------------------------------------------------------
*/
syscall sleepms(
// syscall sleepms(
syscall sleep100ms(
int32 delay /* Time to delay in msec. */
)
{

31
xinu-avr-port.txt

@ -1,3 +1,34 @@
Datos importantes sobre el port actual:
- Podemos tener varios procesos en ejecución en el shell
con background &
- En config/Configuration necesitamos al menos NPROC 4
TODO
----
- sleep usa sleepms. Como tenemos interrupciones cada 100ms
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.
- agregar a la tabla de cmdtab del shell que pueda indicar
el stack para cada proceso.
- agregar al help la ayuda de si el programa es un comando
interno al shell o externo.
- agregar el eeprom fs
-
Demas
-----
BASIC: https://github.com/robinhedwards/ArduinoBASIC/blob/master/arduino_BASIC.ino
Si en include/shell.c achicamos maxtokens podemos achicar la cantidad

Loading…
Cancel
Save