OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [kernel.c] - Diff between revs 44 and 45

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 44 Rev 45
Line 70... Line 70...
TASKP   kschedule(int LAST_TASK, TASKP *tasklist, TASKP last);
TASKP   kschedule(int LAST_TASK, TASKP *tasklist, TASKP last);
extern TASKP    *ksetup(void);
extern TASKP    *ksetup(void);
 
 
int     LAST_TASK;
int     LAST_TASK;
 
 
 
extern void txstr(const char *);
 
 
void    kernel_entry(void) {
void    kernel_entry(void) {
        int     nheartbeats= 0, tickcount = 0, milliseconds=0, ticks = 0;
        int     nheartbeats= 0, tickcount = 0, milliseconds=0, ticks = 0;
        int     audiostate = 0, buttonstate = 0;
        int     audiostate = 0, buttonstate = 0;
        TASKP   *tasklist, current;
        TASKP   *tasklist, current;
        int     *last_context;
        int     *last_context;
        IOSPACE *sys = (IOSPACE *)IOADDR;
 
 
 
        tasklist = ksetup();
        tasklist = ksetup();
 
 
        current = tasklist[0];
        current = tasklist[0];
        restore_context(current->context);
        restore_context(current->context);
        last_context = current->context;
        last_context = current->context;
 
 
        unsigned enableset =
        unsigned enableset =
                INT_ENABLEV(INT_BUTTON)
                INT_ENABLEV(INT_BUTTON)
                |INT_ENABLEV(INT_TIMA)
                |INT_ENABLEV(INT_TIMER)
                // |INT_ENABLEV(INT_UARTRX)
                // |INT_ENABLEV(INT_UARTRX)
                // |INT_ENABLEV(INT_UARTTX) // Needs to be turned on by driver
                // |INT_ENABLEV(INT_UARTTX) // Needs to be turned on by driver
                // |INT_ENABLEV(INT_AUDIO // Needs to be turned on by driver)
                // |INT_ENABLEV(INT_AUDIO // Needs to be turned on by driver)
                // |INT_ENABLEV(INT_GPIO)
                // |INT_ENABLEV(INT_GPIO)
                // |INT_ENABLEV(INT_TIMB);
 
                ;
                ;
        // Then selectively turn some of them back on
        // Then selectively turn some of them back on
        sys->io_pic = INT_ENABLE | enableset | 0x07fff;
        _sys->io_pic = INT_ENABLE | enableset | 0x07fff;
 
 
 
        txstr("HEAP: "); txhex(heap);
 
 
        do {
        do {
                int need_resched = 0, context_has_been_saved, pic;
                int need_resched = 0, context_has_been_saved, pic;
                nheartbeats++;
                nheartbeats++;
 
 
                zip_rtu();
                zip_rtu();
 
 
                last_context = current->context;
                last_context = current->context;
                context_has_been_saved = 0;
                context_has_been_saved = 0;
                pic = sys->io_pic;
                pic = _sys->io_pic;
 
 
                if (pic & 0x8000) { // If there's an active interrupt
                if (pic & 0x8000) { // If there's an active interrupt
                        // Interrupt processing
                        // Interrupt processing
                        sys->io_spio = 0x44;
                        _sys->io_spio = 0x44;
 
 
                        // First, turn off pending interrupts
                        // First, turn off pending interrupts
                        // Although we migt just write 0x7fff7fff to the
                        // Although we migt just write 0x7fff7fff to the
                        // interrupt controller, how do we know another
                        // interrupt controller, how do we know another
                        // interrupt hasn't taken place since we read it?
                        // interrupt hasn't taken place since we read it?
                        // Thus we turn off the pending interrupts that we
                        // Thus we turn off the pending interrupts that we
                        // know about.
                        // know about.
                        pic &= 0x7fff;
                        pic &= 0x7fff;
                        // Acknowledge current ints, and turn off pending ints
                        // Acknowledge current ints, and turn off pending ints
                        sys->io_pic = INT_DISABLEV(pic)|(INT_CLEAR(pic));
                        _sys->io_pic = INT_DISABLEV(pic)|(INT_CLEAR(pic));
                        if(pic&INT_TIMA) {
                        if(pic&INT_TIMER) {
                                if (++ticks >= TICKS_PER_SECOND) {//(pic & SYSINT_PPS)
                                if (++ticks >= TICKS_PER_SECOND) {//(pic & SYSINT_PPS)
                                        // Toggle the low order LED
                                        // Toggle the low order LED
                                        tickcount++;
                                        tickcount++;
                                        ticks = 0;
                                        ticks = 0;
                                        sys->io_spio = ((sys->io_spio&1)^1)|0x010;
                                        _sys->io_spio = ((_sys->io_spio&1)^1)|0x010;
                                        pic |= SWINT_CLOCK;
                                        pic |= SWINT_CLOCK;
                                }
                                }
                                if (buttonstate)
                                if (buttonstate)
                                        buttonstate--;
                                        buttonstate--;
                                else
                                else if ((_sys->io_spio & 0x0f0)==0)
                                        enableset |= INT_ENABLEV(INT_BUTTON);
                                        enableset |= INT_ENABLEV(INT_BUTTON);
                        }
                        }
                        // 
                        // 
                        if (pic&INT_BUTTON) {
                        if (pic&INT_BUTTON) {
                                // Need to turn the button interrupt off
                                // Need to turn the button interrupt off
                                enableset &= ~(INT_ENABLEV(INT_BUTTON));
                                enableset &= ~(INT_ENABLEV(INT_BUTTON));
                                if ((sys->io_spio&0x0f0)==0x030)
                                if ((_sys->io_spio&0x0f0)==0x030)
                                        kpanic();
                                        kpanic();
                                buttonstate = 3;
                                if (buttonstate)
 
                                        pic &= ~INT_BUTTON;
 
                                buttonstate = 50;
                        }
                        }
                        if (pic & INT_UARTRX) {
                        if (pic & INT_UARTRX) {
                                int v = sys->io_uart;
                                int v = _sys->io_uart;
 
 
                                if ((v & (~0x7f))==0) {
                                if ((v & (~0x7f))==0) {
                                        kpush_syspipe(rxpipe, v);
                                        kpush_syspipe(rxpipe, v);
 
 
                                        // Local Echo
                                        // Local Echo
                                        if (pic & INT_UARTTX) {
                                        if (pic & INT_UARTTX) {
                                                sys->io_uart = v;
                                                _sys->io_uart = v;
                                                sys->io_pic = INT_UARTTX;
                                                _sys->io_pic = INT_UARTTX;
                                                pic &= ~INT_UARTTX;
                                                pic &= ~INT_UARTTX;
                                        }
                                        }
                                }
                                }
                        } if (pic & INT_UARTTX) {
                        } if (pic & INT_UARTTX) {
                                int     v;
                                char    ch;
                                if (kpop_syspipe(txpipe, &v)==0) {
                                if (kpop_syspipe(txpipe, &ch)==0) {
 
                                        unsigned        v = ch;
                                        enableset |= (INT_ENABLEV(INT_UARTTX));
                                        enableset |= (INT_ENABLEV(INT_UARTTX));
                                        sys->io_uart= v;
                                        _sys->io_uart= v;
                                        sys->io_pic = INT_UARTTX;
                                        _sys->io_pic = INT_UARTTX;
                                        // if (v == 'W')
                                        // if (v == 'W')
                                                // sys->io_timb = 5;
                                                // sys->io_watchdog = 5;
                                                // 75k was writing the 'e'
                                                // 75k was writing the 'e'
                                } else
                                } else
                                        enableset &= ~(INT_ENABLEV(INT_UARTTX));
                                        enableset&= ~(INT_DISABLEV(INT_UARTTX));
                        } if (audiostate) {
                        } if (audiostate) {
                                if (pic & INT_AUDIO) {
                                if (pic & INT_AUDIO) {
                                int v;
                                unsigned short  sample;
 
 
                                // States: 
                                // States: 
                                //      0 -- not in use
                                //      0 -- not in use
                                //      1 -- First sample, buffer empty
                                //      1 -- in use
                                //              time to read a new sample
 
                                //      2 -- second sample,  to read new
                                if (kpop_short_syspipe(pwmpipe, &sample)==0) {
                                //      3 -- Need to turn off
                                        _sys->io_pwm_audio = sample;
                                if ((audiostate & 3)==2) {
                                        _sys->io_spio = 0x022;
                                        sys->io_pwm_audio = (audiostate>>2)&0x0ffff;
                                        // audiostate = 1;
                                        audiostate = 1;
 
                                } else if (kpop_syspipe(pwmpipe, &v)==0) {
 
                                        audiostate = (2|(v<<2))&0x03ffff;
 
                                        sys->io_pwm_audio = (v>>16)&0x0ffff;
 
                                } else {
                                } else {
                                        audiostate = 0;
                                        audiostate = 0;
                                        // Turn the device off
                                        // Turn the device off
                                        sys->io_pwm_audio = 0x10000;
                                        _sys->io_pwm_audio = 0x10000;
                                        // Turn the interrupts off
                                        // Turn the interrupts off
                                        enableset &= ~(INT_ENABLEV(INT_AUDIO));
                                        enableset &= ~(INT_ENABLEV(INT_AUDIO));
                                        sys->io_spio = 0x020;
                                        _sys->io_spio = 0x020;
                                }
                                }
 
 
                                // This particular interrupt cannot be cleared
                                // This particular interrupt cannot be cleared
                                // until the port has been written to.  Hence,
                                // until the port has been written to.  Hence,
                                // now that we've written to the port, we clear
                                // now that we've written to the port, we clear
                                // it now.  If it needs retriggering, the port
                                // it now.  If it needs retriggering, the port
                                // will retrigger itself -- despite being
                                // will retrigger itself -- despite being
                                // cleared here.
                                // cleared here.
                                sys->io_pic = INT_AUDIO;
                                _sys->io_pic = INT_AUDIO;
                        }} else { // if (audiostate == 0)
                        }}
                                int     sample;
/*
                                if (kpop_syspipe(pwmpipe, &sample)==0) {
                        else { // if (audiostate == 0)
                                        audiostate = (2|(sample<<2))&0x03ffff;
                                unsigned short  sample;
                                        sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
 
                                        enableset |= (INT_ENABLEV(INT_AUDIO));
                                if (kpop_short_syspipe(pwmpipe, &sample)==0) {
                                        sys->io_spio = 0x022;
                                        audiostate = 1;
                                        sys->io_pic = INT_AUDIO;
                                        _sys->io_pwm_audio = 0x310000 | sample;
                                } // else sys->io_spio = 0x020;
                                        enableset |= (INT_ENABLEV(INT_AUDIO));
                        }
                                        _sys->io_spio = 0x022;
 
                                        _sys->io_pic = INT_AUDIO;
 
                                } // else sys->io_spio = 0x020;
 
                        }
 
*/
                        milliseconds = kpost(tasklist, pic, milliseconds);
                        milliseconds = kpost(tasklist, pic, milliseconds);
 
 
                        // Restart interrupts
                        // Restart interrupts
                        enableset &= (~0x0ffff); // Keep the bottom bits off
                        enableset &= (~0x0ffff); // Keep the bottom bits off
                        sys->io_pic = INT_ENABLE|enableset;
                        _sys->io_pic = INT_ENABLE|enableset;
                } else {
                } else {
                        sys->io_pic = INT_ENABLE; // Make sure interrupts are on
                        _sys->io_pic = INT_ENABLE; // Make sure interrupts are on
                        int     sample;
                        unsigned short  sample;
 
 
                        // Check for the beginning of an audio pipe.  If the
                        // Check for the beginning of an audio pipe.  If the
                        // interrupt is not enabled, we still might need to
                        // interrupt is not enabled, we still might need to
                        // enable it.
                        // enable it.
                        if ((audiostate==0)&&(kpop_syspipe(pwmpipe, &sample)==0)) {
 
                                audiostate = (2|(sample<<2))&0x03ffff;
                        if ((audiostate==0)&&(kpop_short_syspipe(pwmpipe, &sample)==0)) {
                                sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
                                audiostate = 1;
                                sys->io_pic = INT_AUDIO;
                                _sys->io_pwm_audio = 0x310000 | (sample);
 
                                _sys->io_pic = INT_AUDIO;
                                enableset |= (INT_ENABLEV(INT_AUDIO));
                                enableset |= (INT_ENABLEV(INT_AUDIO));
                                sys->io_spio = 0x022;
                                _sys->io_spio = 0x022;
                        } // else sys->io_spio = 0x020;
                        } // else sys->io_spio = 0x020;
 
 
                        // Or the beginning of a transmit pipe.  
                        // Or the beginning of a transmit pipe.  
                        if (pic & INT_UARTTX) {
                        if (pic & INT_UARTTX) {
                                int     v;
                                char    ch;
                                if (kpop_syspipe(txpipe, &v)==0) {
                                if (kpop_syspipe(txpipe, &ch)==0) {
 
                                        unsigned        v = ch;
                                        enableset |= (INT_ENABLEV(INT_UARTTX));
                                        enableset |= (INT_ENABLEV(INT_UARTTX));
                                        sys->io_uart = v;
                                        _sys->io_uart = v;
                                        sys->io_pic = INT_UARTTX;
                                        _sys->io_pic = INT_UARTTX;
                                        // if (v == 'W')
 
                                                // sys->io_timb = 5;
 
                                } else
                                } else
                                        enableset &= ~(INT_ENABLEV(INT_UARTTX));
                                        enableset &= ~(INT_ENABLEV(INT_UARTTX));
                        }
                        }
 
 
                        // What if someone left interrupts off?
                        // What if someone left interrupts off?
                        // This might happen as part of a wait trap call, such
                        // This might happen as part of a wait trap call, such
                        // as syspipe() accomplishes within uwrite_syspipe()
                        // as syspipe() accomplishes within uwrite_syspipe()
                        // (We also might've just turned them off ... ooops)
                        // (We also might've just turned them off ... ooops)
                        enableset &= (~0x0ffff); // Keep the bottom bits off
                        enableset &= (~0x0ffff); // Keep the bottom bits off
                        sys->io_pic = INT_ENABLE | enableset;
                        _sys->io_pic = INT_ENABLE | enableset;
                }
                }
                sys->io_spio = 0x40;
                _sys->io_spio = 0x40;
 
 
                int zcc = zip_ucc();
                int zcc = zip_ucc();
                if (zcc & CC_TRAPBIT) {
                if (zcc & CC_TRAPBIT) {
                        // sys->io_spio = 0x0ea;
                        // sys->io_spio = 0x0ea;
 
 
Line 352... Line 358...
                        }
                        }
 
 
                        restore_context(last_context);
                        restore_context(last_context);
                } else if (zcc & (CC_BUSERR|CC_DIVERR|CC_FPUERR|CC_ILL)) {
                } else if (zcc & (CC_BUSERR|CC_DIVERR|CC_FPUERR|CC_ILL)) {
                        current->state = SCHED_ERR;
                        current->state = SCHED_ERR;
                        // current->errno = -EBUS;
                        current->errno = (int)_sys->io_buserr;
                        current->errno = (int)sys->io_buserr;
 
                        save_context(last_context);
                        save_context(last_context);
                        context_has_been_saved = 1;
                        context_has_been_saved = 1;
                        kpanic();
                        kpanic();
                        zip_halt();
                        zip_halt();
                }
                }
Line 407... Line 412...
        } return current;
        } return current;
}
}
 
 
int     kpost(TASKP *tasklist, unsigned events, int milliseconds) {
int     kpost(TASKP *tasklist, unsigned events, int milliseconds) {
        int     i;
        int     i;
        if (events & INT_TIMA)
        if (events & INT_TIMER)
                milliseconds++;
                milliseconds++;
        if (milliseconds<0) {
        if (milliseconds<0) {
                milliseconds -= 0x80000000;
                milliseconds -= 0x80000000;
                for(i=0; i<=LAST_TASK; i++) {
                for(i=0; i<=LAST_TASK; i++) {
                        if(tasklist[i]->timeout) {
                        if(tasklist[i]->timeout) {

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.