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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [pipesetup.c] - Diff between revs 27 and 45

Only display areas with differences | Details | Blame | View Log

Rev 27 Rev 45
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    pipesetup.c
// Filename:    pipesetup.c
//
//
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
//
//
// Purpose:     The routines in this file were split from syspipe.c for the
// Purpose:     The routines in this file were split from syspipe.c for the
//              purposes of limiting the amount of RAM memory a process would
//              purposes of limiting the amount of RAM memory a process would
//      use.  Specifically, these routines are not time critical and hence can
//      use.  Specifically, these routines are not time critical and hence can
//      run from FLASH, whereas the other set must run from block RAM.
//      run from FLASH, whereas the other set must run from block RAM.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
#include "errno.h"
#include "errno.h"
#include "board.h"
#include "board.h"
#include "taskp.h"
#include "taskp.h"
#include "syspipe.h"
#include "syspipe.h"
#include "zipsys.h"
#include "zipsys.h"
#include "ktraps.h"
#include "ktraps.h"
 
#include "txfns.h"
 
 
#ifndef NULL
#ifndef NULL
#define NULL    (void *)0
#define NULL    (void *)0
#endif
#endif
 
 
// Since this is only called with new_syspipe, we're good here
// Since this is only called with new_syspipe, we're good here
static  void    clear_syspipe(SYSPIPE *p) {
static  void    clear_syspipe(SYSPIPE *p) {
        p->m_head  = 0;
        p->m_head  = 0;
        p->m_tail  = 0;
        p->m_tail  = 0;
        p->m_error = 0;
        p->m_error = 0;
 
 
        for(int i=0; i<=(int)p->m_mask; i++)
        for(int i=0; i<=(int)p->m_mask; i++)
                p->m_buf[i] = 0;
                p->m_buf[i] = 0;
 
 
        if ((p->m_rdtask)&&(p->m_rdtask != INTERRUPT_READ_TASK)) {
        if ((p->m_rdtask)&&(p->m_rdtask != INTERRUPT_READ_TASK)) {
                p->m_rdtask->context[1] = p->m_nread;
                p->m_rdtask->context[1] = p->m_nread;
                if (p->m_nread == 0)
                if (p->m_nread == 0)
                        p->m_rdtask->errno = -EFAULT;
                        p->m_rdtask->errno = -EFAULT;
                p->m_rdtask->state = SCHED_READY;
                p->m_rdtask->state = SCHED_READY;
        } else if (p->m_wrtask) {
        } else if (p->m_wrtask) {
                p->m_wrtask->context[1] = p->m_nwritten;
                p->m_wrtask->context[1] = p->m_nwritten;
                if (p->m_nwritten == 0)
                if (p->m_nwritten == 0)
                        p->m_wrtask->errno = -EFAULT;
                        p->m_wrtask->errno = -EFAULT;
                p->m_wrtask->state = SCHED_READY;
                p->m_wrtask->state = SCHED_READY;
        }
        }
 
 
        if (p->m_rdtask != INTERRUPT_READ_TASK)
        if (p->m_rdtask != INTERRUPT_READ_TASK)
                p->m_rdtask   = 0;
                p->m_rdtask   = 0;
        p->m_wrtask   = 0;
        p->m_wrtask   = 0;
        p->m_nread    = 0;
        p->m_nread    = 0;
        p->m_nwritten = 0;
        p->m_nwritten = 0;
}
}
 
 
// These routines really belong elsewhere in a uartdump.c file or some such.
 
// However, until placed there, they'll stay put here for a bit longer.
 
void    txchr(char v) {
 
        volatile IOSPACE        *sys = (IOSPACE *)IOADDR;
 
        if (v < 10)
 
                return;
 
        v &= 0x0ff;
 
        sys->io_pic = INT_UARTTX;
 
        while((sys->io_pic&INT_UARTTX)==0)
 
                ;
 
        sys->io_uart = v;
 
}
 
 
 
void    txstr(const char *str) {
 
        const char *ptr = str;
 
        while(*ptr) {
 
                txchr(*ptr++);
 
        }
 
}
 
 
 
void    txhex(int num) {
 
        for(int ds=28; ds>=0; ds-=4) {
 
                int     ch;
 
                ch = (num>>ds)&0x0f;
 
                if (ch >= 10)
 
                        ch = 'A'+ch-10;
 
                else
 
                        ch += '0';
 
                txchr(ch);
 
        } txstr("\r\n");
 
}
 
 
 
void    pipe_panic(SYSPIPE *pipe) {
void    pipe_panic(SYSPIPE *pipe) {
        extern void     kpanic(void);
        extern void     kpanic(void);
        volatile IOSPACE        *sys = (IOSPACE *)IOADDR;
 
 
 
        sys->io_spio = 0x0fa;
        _sys->io_spio = 0x0fa;
 
 
        txstr("SYSPIPE PANIC!\r\n");
        txstr("SYSPIPE PANIC!\r\n");
        txstr("ADDR: "); txhex((int)pipe);
        txstr("ADDR: "); txhex((int)pipe);
        txstr("MASK: "); txhex(pipe->m_mask);
        txstr("MASK: "); txhex(pipe->m_mask);
        txstr("HEAD: "); txhex(pipe->m_head);
        txstr("HEAD: "); txhex(pipe->m_head);
        txstr("TAIL: "); txhex(pipe->m_tail);
        txstr("TAIL: "); txhex(pipe->m_tail);
        kpanic();
        kpanic();
}
}
 
 
SYSPIPE *new_syspipe(const unsigned int len) {
SYSPIPE *new_syspipe(const unsigned int len) {
        unsigned        msk;
        unsigned        msk;
 
 
        for(msk=2; msk<len; msk<<=1)
        for(msk=16; msk<len; msk<<=1)
                ;
                ;
        SYSPIPE *pipe = sys_malloc(sizeof(SYSPIPE)-1+msk);
        SYSPIPE *pipe = sys_malloc(sizeof(SYSPIPE)-1+msk);
        pipe->m_mask = msk-1;
        pipe->m_mask = msk-1;
        pipe->m_rdtask = pipe->m_wrtask = 0;
        pipe->m_rdtask = pipe->m_wrtask = 0;
        clear_syspipe(pipe);
        clear_syspipe(pipe);
        return pipe;
        return pipe;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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