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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [kernel.c] - Diff between revs 27 and 29

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

Rev 27 Rev 29
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  int     nwritten, nread, nstarts;
 
 
 
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;
Line 181... Line 179...
                                        sys->io_pwm_audio = (audiostate>>2)&0x0ffff;
                                        sys->io_pwm_audio = (audiostate>>2)&0x0ffff;
                                        audiostate = 1;
                                        audiostate = 1;
                                } else if (kpop_syspipe(pwmpipe, &v)==0) {
                                } else if (kpop_syspipe(pwmpipe, &v)==0) {
                                        audiostate = (2|(v<<2))&0x03ffff;
                                        audiostate = (2|(v<<2))&0x03ffff;
                                        sys->io_pwm_audio = (v>>16)&0x0ffff;
                                        sys->io_pwm_audio = (v>>16)&0x0ffff;
                                        nread++;
 
                                } 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
Line 201... Line 198...
                                // cleared here.
                                // cleared here.
                                sys->io_pic = INT_AUDIO;
                                sys->io_pic = INT_AUDIO;
                        }} else { // if (audiostate == 0)
                        }} else { // if (audiostate == 0)
                                int     sample;
                                int     sample;
                                if (kpop_syspipe(pwmpipe, &sample)==0) {
                                if (kpop_syspipe(pwmpipe, &sample)==0) {
                                        nstarts++;
 
                                        nread++;
 
                                        audiostate = (2|(sample<<2))&0x03ffff;
                                        audiostate = (2|(sample<<2))&0x03ffff;
                                        sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
                                        sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
                                        enableset |= (INT_ENABLEV(INT_AUDIO));
                                        enableset |= (INT_ENABLEV(INT_AUDIO));
                                        sys->io_spio = 0x022;
                                        sys->io_spio = 0x022;
                                        sys->io_pic = INT_AUDIO;
                                        sys->io_pic = INT_AUDIO;
                                } // else sys->io_spio = 0x020;
                                } // 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 {
Line 227... Line 223...
                                audiostate = (2|(sample<<2))&0x03ffff;
                                audiostate = (2|(sample<<2))&0x03ffff;
                                sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
                                sys->io_pwm_audio = 0x310000 | ((sample>>16)&0x0ffff);
                                sys->io_pic = INT_AUDIO;
                                sys->io_pic = INT_AUDIO;
                                enableset |= (INT_ENABLEV(INT_AUDIO));
                                enableset |= (INT_ENABLEV(INT_AUDIO));
                                sys->io_spio = 0x022;
                                sys->io_spio = 0x022;
                                nstarts++;
 
                                nread++;
 
                        } // 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;
                                int     v;
Line 324... Line 318...
                                                < (unsigned)MAX_KFILDES)
                                                < (unsigned)MAX_KFILDES)
                                        fd = current->fd[last_context[2]];
                                        fd = current->fd[last_context[2]];
                                else { kpanic(); zip_halt(); }
                                else { kpanic(); zip_halt(); }
                                if ((!fd)||(!fd->dev))
                                if ((!fd)||(!fd->dev))
                                        last_context[1] = -EBADF;
                                        last_context[1] = -EBADF;
                                else
                                else {
                                        fd->dev->write(current, fd->id,
                                        fd->dev->write(current, fd->id,
                                           (void *)last_context[3], last_context[4]);
                                           (void *)last_context[3], last_context[4]);
                                } break;
                                }}
 
                                break;
                        case TRAPID_TIME:
                        case TRAPID_TIME:
                                last_context[1] = tickcount;
                                last_context[1] = tickcount;
                                break;
                                break;
                        case TRAPID_MALLOC:
                        case TRAPID_MALLOC:
                                last_context[1] = (int)sys_malloc(last_context[2]);
                                last_context[1] = (int)sys_malloc(last_context[2]);
Line 390... Line 385...
                        break;
                        break;
                }
                }
        }
        }
 
 
        // Now let's see if we can find the next ready task to run
        // Now let's see if we can find the next ready task to run
        for(; nxtid<LAST_TASK; nxtid++)
        for(; nxtid<LAST_TASK; nxtid++) {
                if (tasklist[nxtid]->state == SCHED_READY) {
                if (tasklist[nxtid]->state == SCHED_READY) {
                        current=tasklist[nxtid];
                        current=tasklist[nxtid];
                        break;
                        break;
                }
                }
 
        }
        // The last task (the idle task) doesn't count
        // The last task (the idle task) doesn't count
        if (nxtid >= LAST_TASK) {
        if (nxtid >= LAST_TASK) {
                nxtid = 0; // Don't automatically run idle task
                nxtid = 0; // Don't automatically run idle task
                for(; nxtid<LAST_TASK; nxtid++)
                for(; nxtid<LAST_TASK; nxtid++)
                        if (tasklist[nxtid]->state == SCHED_READY) {
                        if (tasklist[nxtid]->state == SCHED_READY) {
                                break;
                                break;
                        }
                        }
                // Now we stop at the idle task, if nothing else is ready
                // Now we stop at the idle task, if nothing else is ready
                current = tasklist[nxtid];
                current = tasklist[nxtid];
        }
        } 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_TIMA)

powered by: WebSVN 2.1.0

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