sieve.pwp


//-------------------------------------------------------------------------
//
// PicoWeb Project File for "sieve"
// 
// This sample PicoWeb project demonstrates the use of the gcc C-compiler.
// A Web page is presented with a list of prime numbers calculated using a
// Sieve of Eratosthenes prime number program.  This Sieve of Eratosthenes
// prime number program was adapted from January 1983 BYTE Magazine PC
// benchmark C-program "sieve.c". The PicoWeb version uses a bit-array in
// place of a byte-array for the "sieve" in order to conserve RAM.
// 
// The program prints out prime numbers as it finds them.  This is done using
// the PicoWeb routine "do_putchar".  This AVR assembly language routine
// prints out the character passed to it in register r25.  It preserves all
// of the AVR registers that it uses and therefore call be called directly
// from C-code.  Because the machine code from the gcc compiler passes
// integer parameters in registers, starting with the register pair r24/r25,
// "do_putchar" can be called directly from C-code as shown in the following
// example:
// 
//    void putchar(unsigned char ch) {
//        do_putchar(ch<<8);
//    }
// 
// After computing and displaying primes on the Web page, this project
// also displays a count of the total number of primes found, as well as
// displaying a "real-time" calcuation of the size of the "flags" bit-array
// and the size of the "sieve" subroutine itself.
// 
// PicoWeb "tags" in the HTML code for the Web page are used to call
// pcode routine (see below) that in turn call the C-code.  Because pcode
// instructions are free to use any of the AVR registers, C-code can be
// called from these routines without first preserving any of the AVR
// registers.
//
//-------------------------------------------------------------------------
//
// application-specific preprocessor definitions
//
#define BANNER "\r\nPicoWeb Sieve\r\n"
#define EEPROM_IP         /* use file "ip" for default IP address */
#define NET_CONFIG_IP     /* allow IP address reconfiguration via net */
#define ENABLE_WATCHDOG   /* use Atmel watchdog timer hardware */
//#define DEBUGGER          /* include debugger firmware */
#undef DEBUGGER

//#define CLOCK 8000000     /* processor clock rate */
#define CLOCK 7372000     /* processor clock rate */
#define BAUD_RATE 19200   /* serial port baud rate */

//
// application-specific HTML and image file names
//
sieve.htm            // (default Web page)
picoweb.jpg          // (PicoWeb logo image)
csieve.c text/plain  // C source code

psieve.cgi

link add csieve.o
//link search libc.a
link search libgcc.a

//
// included application-specific pcode and/or AVR assembly language follows
//
#avr_reset
;--------------------------------------------------------------------------
; this code is executed each time microcontroller is reset
;--------------------------------------------------------------------------
;

#avr_slow
;--------------------------------------------------------------------------
; this code is executed each trip through "slow idle" loop (~1 sec period)
;--------------------------------------------------------------------------
;

#avr_fast
;--------------------------------------------------------------------------
; this code is executed each trip through "fast idle" loop
;--------------------------------------------------------------------------
;

#avr_asm
;--------------------------------------------------------------------------
; application-specific CGI pcode and AVR assembly routines go here
;--------------------------------------------------------------------------
;
psieve:
    pend
    clr r1
    rcall sieve                  ; call C routine to calculate primes
    pbegin
    pret

pshow_count:
    pprintswi [count]            ; output contents of count
    pret

pshow_flags_bytes:
    pprintswi [flags_bytes]      ; output contents of flags_bytes
    pret

pshow_sieve_size:
    pend
    clr r1
    rcall setsize                ; call C routine to get size of sieve program
    pbegin
    pprintswi [sieve_size]       ; output contents of sieve_size
    pret


Back