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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [pipesetup.c] - Blame information for rev 45

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    pipesetup.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     The routines in this file were split from syspipe.c for the
8
//              purposes of limiting the amount of RAM memory a process would
9
//      use.  Specifically, these routines are not time critical and hence can
10
//      run from FLASH, whereas the other set must run from block RAM.
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
#include "errno.h"
42
#include "board.h"
43
#include "taskp.h"
44
#include "syspipe.h"
45
#include "zipsys.h"
46
#include "ktraps.h"
47 45 dgisselq
#include "txfns.h"
48 27 dgisselq
 
49
#ifndef NULL
50
#define NULL    (void *)0
51
#endif
52
 
53
// Since this is only called with new_syspipe, we're good here
54
static  void    clear_syspipe(SYSPIPE *p) {
55
        p->m_head  = 0;
56
        p->m_tail  = 0;
57
        p->m_error = 0;
58
 
59
        for(int i=0; i<=(int)p->m_mask; i++)
60
                p->m_buf[i] = 0;
61
 
62
        if ((p->m_rdtask)&&(p->m_rdtask != INTERRUPT_READ_TASK)) {
63
                p->m_rdtask->context[1] = p->m_nread;
64
                if (p->m_nread == 0)
65
                        p->m_rdtask->errno = -EFAULT;
66
                p->m_rdtask->state = SCHED_READY;
67
        } else if (p->m_wrtask) {
68
                p->m_wrtask->context[1] = p->m_nwritten;
69
                if (p->m_nwritten == 0)
70
                        p->m_wrtask->errno = -EFAULT;
71
                p->m_wrtask->state = SCHED_READY;
72
        }
73
 
74
        if (p->m_rdtask != INTERRUPT_READ_TASK)
75
                p->m_rdtask   = 0;
76
        p->m_wrtask   = 0;
77
        p->m_nread    = 0;
78
        p->m_nwritten = 0;
79
}
80
 
81
void    pipe_panic(SYSPIPE *pipe) {
82
        extern void     kpanic(void);
83
 
84 45 dgisselq
        _sys->io_spio = 0x0fa;
85 27 dgisselq
 
86
        txstr("SYSPIPE PANIC!\r\n");
87
        txstr("ADDR: "); txhex((int)pipe);
88
        txstr("MASK: "); txhex(pipe->m_mask);
89
        txstr("HEAD: "); txhex(pipe->m_head);
90
        txstr("TAIL: "); txhex(pipe->m_tail);
91
        kpanic();
92
}
93
 
94
SYSPIPE *new_syspipe(const unsigned int len) {
95
        unsigned        msk;
96
 
97 45 dgisselq
        for(msk=16; msk<len; msk<<=1)
98 27 dgisselq
                ;
99
        SYSPIPE *pipe = sys_malloc(sizeof(SYSPIPE)-1+msk);
100
        pipe->m_mask = msk-1;
101
        pipe->m_rdtask = pipe->m_wrtask = 0;
102
        clear_syspipe(pipe);
103
        return pipe;
104
}
105
 

powered by: WebSVN 2.1.0

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