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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [ksetup.c] - Blame information for rev 29

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    ksetup.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     These are the routines from kernel.c that didn't need to be
8
//              in RAM memory.  They are specifically the pre-run setup
9 29 dgisselq
//      routines that are executed from FLASH memory.
10 27 dgisselq
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
#include "zipsys.h"
41
#include "board.h"
42
#include "ksched.h"
43
#include "kfildes.h"
44
#include "taskp.h"
45
#include "syspipe.h"
46
#include "ktraps.h"
47
#include "errno.h"
48
#include "swint.h"
49
 
50
extern int      kntasks(void);
51
extern void     kinit(TASKP *tasklist);
52
extern  void    restore_context(int *), save_context(int *);
53
SYSPIPE *rxpipe, *txpipe, *keypipe, *lcdpipe, *pwmpipe, *cmdpipe;
54
KDEVICE *pipedev, *txdev, *pwmdev;
55
void    *heap; //  = _top_of_heap; // Need to wait on startup to set this
56
 
57
#define CONTEXT_LENGTH  100000  // 1ms
58
 
59
int     LAST_TASK;
60
 
61 29 dgisselq
__attribute__((cold))
62 27 dgisselq
TASKP   *ksetup(void) {
63
        TASKP   *tasklist;
64
        IOSPACE *sys = (IOSPACE *)IOADDR;
65
 
66
        sys->io_spio = 0x0f0;
67
        sys->io_timb = 0;        // Turn off the watchdog timer
68
        LAST_TASK = kntasks();
69
        heap = _top_of_heap;
70
 
71
        pipedev = sys_malloc(sizeof(KDEVICE));
72
        pipedev->write = (RWFDFUN)kwrite_syspipe;
73
        pipedev->read  = (RWFDFUN)kread_syspipe;
74
        pipedev->close = NULL;
75
 
76
        txdev = pwmdev = pipedev;
77
 
78
        rxpipe  = new_syspipe(16);      //rxpipe->m_wrtask=INTERRUPT_WRITE_TASK;
79
        txpipe  = new_syspipe(8);       txpipe->m_rdtask = INTERRUPT_READ_TASK;
80
        keypipe = new_syspipe(16);
81
        lcdpipe = new_syspipe(16);
82 29 dgisselq
        pwmpipe = new_syspipe(128);     pwmpipe->m_rdtask= INTERRUPT_READ_TASK;
83 27 dgisselq
        cmdpipe = new_syspipe(16);
84
 
85
        tasklist = sys_malloc(sizeof(TASKP)*(1+LAST_TASK));
86
        kinit(tasklist);
87
        tasklist[LAST_TASK] = new_task(2, idle_task);
88
 
89
        // Turn all interrupts off, acknowledge all at the same time
90
        sys->io_pic = 0x7fff7fff;
91
 
92
        sys->io_tima = CONTEXT_LENGTH | TM_REPEAT;
93
 
94
        {
95
                // Reset our wishbone scope for debug later
96
                SCOPE   *scope = (SCOPE *)SCOPEADDR;
97
                scope->s_control = 2;
98
        }
99
        sys->io_spio = 0x0f1;
100
 
101
        return tasklist;
102
}
103
 
104
void    kwait_on_buttonpress(void) {
105
        IOSPACE *sys = (IOSPACE *)IOADDR;
106
 
107
        // Wait on a button press before starting
108
        while((sys->io_spio & 0x0f0)==0)
109
                ;
110
        sys->io_spio = 0x0f3;
111
        for(int i=0; i<40000; i++)
112
                sys->io_spio = ((i>>14)&2)|0x020;
113
        sys->io_spio = 0x0f7;
114
}
115
 
116 29 dgisselq
// __attribute__((noreturn))
117 27 dgisselq
void    kuserexit(int a) {
118
        syscall(TRAPID_EXIT, a, 0, 0);
119
}
120
 
121 29 dgisselq
__attribute__((malloc))
122 27 dgisselq
void    *sys_malloc(int sz) {
123 29 dgisselq
        if (0) {
124 27 dgisselq
                SCOPE   *s = (SCOPE *)SCOPEADDR;
125
                s->s_control = TRIGGER_SCOPE_NOW | (s->s_control & 0x0ffff);
126
        }
127
 
128
        void    *res = heap;
129
        heap += sz;
130
        if ((int)heap > ((int)&res)-32) {
131
                IOSPACE *sys = (IOSPACE *)IOADDR;
132
                sys->io_spio = 0xf3;
133
                asm("break 0");
134
        }
135
        return res;
136
}
137
 
138 29 dgisselq
KFILDES *kopen(int id, KDEVICE *dev) {
139
        KFILDES *fd = (KFILDES *)sys_malloc(sizeof(KFILDES));
140
        fd->id = (int)id;
141
        fd->dev= dev;
142
        return fd;
143
}

powered by: WebSVN 2.1.0

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