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

Subversion Repositories s6soc

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

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 45 dgisselq
#include "txfns.h"
50 27 dgisselq
 
51 45 dgisselq
typedef unsigned        size_t;
52
 
53 27 dgisselq
extern int      kntasks(void);
54
extern void     kinit(TASKP *tasklist);
55
extern  void    restore_context(int *), save_context(int *);
56
SYSPIPE *rxpipe, *txpipe, *keypipe, *lcdpipe, *pwmpipe, *cmdpipe;
57
KDEVICE *pipedev, *txdev, *pwmdev;
58 45 dgisselq
char    *heap; //  = _top_of_heap; // Need to wait on startup to set this
59 27 dgisselq
 
60 45 dgisselq
#define CONTEXT_LENGTH  (80000-1)       // 1ms
61 27 dgisselq
 
62
int     LAST_TASK;
63
 
64 29 dgisselq
__attribute__((cold))
65 27 dgisselq
TASKP   *ksetup(void) {
66
        TASKP   *tasklist;
67 45 dgisselq
        volatile IOSPACE *const sys = _sys;
68 27 dgisselq
 
69
        sys->io_spio = 0x0f0;
70 45 dgisselq
        sys->io_watchdog = 0;    // Turn off the watchdog timer
71 27 dgisselq
        LAST_TASK = kntasks();
72 45 dgisselq
        heap = (char *)_top_of_heap;
73 27 dgisselq
 
74
        pipedev = sys_malloc(sizeof(KDEVICE));
75
        pipedev->write = (RWFDFUN)kwrite_syspipe;
76
        pipedev->read  = (RWFDFUN)kread_syspipe;
77
        pipedev->close = NULL;
78
 
79
        txdev = pwmdev = pipedev;
80
 
81 45 dgisselq
        rxpipe  = new_syspipe(64);      //rxpipe->m_wrtask=INTERRUPT_WRITE_TASK;
82
        txpipe  = new_syspipe(64);      txpipe->m_rdtask = INTERRUPT_READ_TASK;
83
        keypipe = new_syspipe(64);
84
        lcdpipe = new_syspipe(64);
85
        pwmpipe = new_syspipe(512);     pwmpipe->m_rdtask= INTERRUPT_READ_TASK;
86
        cmdpipe = new_syspipe(64);
87 27 dgisselq
 
88
        tasklist = sys_malloc(sizeof(TASKP)*(1+LAST_TASK));
89
        kinit(tasklist);
90 45 dgisselq
        tasklist[LAST_TASK] = new_task(8, idle_task);
91 27 dgisselq
 
92
        // Turn all interrupts off, acknowledge all at the same time
93 45 dgisselq
        sys->io_pic = INT_CLEARPIC;
94 27 dgisselq
 
95 45 dgisselq
        sys->io_timer = CONTEXT_LENGTH | TM_REPEAT;
96 27 dgisselq
 
97
        {
98
                // Reset our wishbone scope for debug later
99 45 dgisselq
                _scope->s_ctrl = 2;
100 27 dgisselq
        }
101
        sys->io_spio = 0x0f1;
102
 
103
        return tasklist;
104
}
105
 
106
void    kwait_on_buttonpress(void) {
107
        // Wait on a button press before starting
108 45 dgisselq
        while((_sys->io_spio & 0x0f0)==0)
109 27 dgisselq
                ;
110 45 dgisselq
        _sys->io_spio = 0x0f3;
111 27 dgisselq
        for(int i=0; i<40000; i++)
112 45 dgisselq
                _sys->io_spio = ((i>>14)&2)|0x020;
113
        _sys->io_spio = 0x0f7;
114 27 dgisselq
}
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 45 dgisselq
void    *sys_malloc(size_t sz) {
123 27 dgisselq
        void    *res = heap;
124 45 dgisselq
        heap = heap + ((sz+3)&-4);
125 27 dgisselq
        return res;
126
}
127
 
128 29 dgisselq
KFILDES *kopen(int id, KDEVICE *dev) {
129
        KFILDES *fd = (KFILDES *)sys_malloc(sizeof(KFILDES));
130
        fd->id = (int)id;
131
        fd->dev= dev;
132
        return fd;
133
}

powered by: WebSVN 2.1.0

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