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

Subversion Repositories s6soc

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

Go to most recent revision | 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
 
48
#ifndef NULL
49
#define NULL    (void *)0
50
#endif
51
 
52
// Since this is only called with new_syspipe, we're good here
53
static  void    clear_syspipe(SYSPIPE *p) {
54
        p->m_head  = 0;
55
        p->m_tail  = 0;
56
        p->m_error = 0;
57
 
58
        for(int i=0; i<=(int)p->m_mask; i++)
59
                p->m_buf[i] = 0;
60
 
61
        if ((p->m_rdtask)&&(p->m_rdtask != INTERRUPT_READ_TASK)) {
62
                p->m_rdtask->context[1] = p->m_nread;
63
                if (p->m_nread == 0)
64
                        p->m_rdtask->errno = -EFAULT;
65
                p->m_rdtask->state = SCHED_READY;
66
        } else if (p->m_wrtask) {
67
                p->m_wrtask->context[1] = p->m_nwritten;
68
                if (p->m_nwritten == 0)
69
                        p->m_wrtask->errno = -EFAULT;
70
                p->m_wrtask->state = SCHED_READY;
71
        }
72
 
73
        if (p->m_rdtask != INTERRUPT_READ_TASK)
74
                p->m_rdtask   = 0;
75
        p->m_wrtask   = 0;
76
        p->m_nread    = 0;
77
        p->m_nwritten = 0;
78
}
79
 
80
// These routines really belong elsewhere in a uartdump.c file or some such.
81
// However, until placed there, they'll stay put here for a bit longer.
82
void    txchr(char v) {
83
        volatile IOSPACE        *sys = (IOSPACE *)IOADDR;
84
        if (v < 10)
85
                return;
86
        v &= 0x0ff;
87
        sys->io_pic = INT_UARTTX;
88
        while((sys->io_pic&INT_UARTTX)==0)
89
                ;
90
        sys->io_uart = v;
91
}
92
 
93
void    txstr(const char *str) {
94
        const char *ptr = str;
95
        while(*ptr) {
96
                txchr(*ptr++);
97
        }
98
}
99
 
100
void    txhex(int num) {
101
        for(int ds=28; ds>=0; ds-=4) {
102
                int     ch;
103
                ch = (num>>ds)&0x0f;
104
                if (ch >= 10)
105
                        ch = 'A'+ch-10;
106
                else
107
                        ch += '0';
108
                txchr(ch);
109
        } txstr("\r\n");
110
}
111
 
112
void    pipe_panic(SYSPIPE *pipe) {
113
        extern void     kpanic(void);
114
        volatile IOSPACE        *sys = (IOSPACE *)IOADDR;
115
 
116
        sys->io_spio = 0x0fa;
117
 
118
        txstr("SYSPIPE PANIC!\r\n");
119
        txstr("ADDR: "); txhex((int)pipe);
120
        txstr("MASK: "); txhex(pipe->m_mask);
121
        txstr("HEAD: "); txhex(pipe->m_head);
122
        txstr("TAIL: "); txhex(pipe->m_tail);
123
        kpanic();
124
}
125
 
126
SYSPIPE *new_syspipe(const unsigned int len) {
127
        unsigned        msk;
128
 
129
        for(msk=2; msk<len; msk<<=1)
130
                ;
131
        SYSPIPE *pipe = sys_malloc(sizeof(SYSPIPE)-1+msk);
132
        pipe->m_mask = msk-1;
133
        pipe->m_rdtask = pipe->m_wrtask = 0;
134
        clear_syspipe(pipe);
135
        return pipe;
136
}
137
 

powered by: WebSVN 2.1.0

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