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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [ksetup.c] - Diff between revs 29 and 37

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 29 Rev 37
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    ksetup.c
// Filename:    ksetup.c
//
//
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
//
//
// Purpose:     These are the routines from kernel.c that didn't need to be
// Purpose:     These are the routines from kernel.c that didn't need to be
//              in RAM memory.  They are specifically the pre-run setup
//              in RAM memory.  They are specifically the pre-run setup
//      routines that are executed from FLASH memory.
//      routines that are executed from FLASH memory.
//
//
// 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 "zipsys.h"
#include "zipsys.h"
#include "board.h"
#include "board.h"
#include "ksched.h"
#include "ksched.h"
#include "kfildes.h"
#include "kfildes.h"
#include "taskp.h"
#include "taskp.h"
#include "syspipe.h"
#include "syspipe.h"
#include "ktraps.h"
#include "ktraps.h"
#include "errno.h"
#include "errno.h"
#include "swint.h"
#include "swint.h"
 
 
extern int      kntasks(void);
extern int      kntasks(void);
extern void     kinit(TASKP *tasklist);
extern void     kinit(TASKP *tasklist);
extern  void    restore_context(int *), save_context(int *);
extern  void    restore_context(int *), save_context(int *);
SYSPIPE *rxpipe, *txpipe, *keypipe, *lcdpipe, *pwmpipe, *cmdpipe;
SYSPIPE *rxpipe, *txpipe, *keypipe, *lcdpipe, *pwmpipe, *cmdpipe;
KDEVICE *pipedev, *txdev, *pwmdev;
KDEVICE *pipedev, *txdev, *pwmdev;
void    *heap; //  = _top_of_heap; // Need to wait on startup to set this
void    *heap; //  = _top_of_heap; // Need to wait on startup to set this
 
 
#define CONTEXT_LENGTH  100000  // 1ms
#define CONTEXT_LENGTH  80000   // 1ms
 
 
int     LAST_TASK;
int     LAST_TASK;
 
 
__attribute__((cold))
__attribute__((cold))
TASKP   *ksetup(void) {
TASKP   *ksetup(void) {
        TASKP   *tasklist;
        TASKP   *tasklist;
        IOSPACE *sys = (IOSPACE *)IOADDR;
        IOSPACE *sys = (IOSPACE *)IOADDR;
 
 
        sys->io_spio = 0x0f0;
        sys->io_spio = 0x0f0;
        sys->io_timb = 0;        // Turn off the watchdog timer
        sys->io_timb = 0;        // Turn off the watchdog timer
        LAST_TASK = kntasks();
        LAST_TASK = kntasks();
        heap = _top_of_heap;
        heap = _top_of_heap;
 
 
        pipedev = sys_malloc(sizeof(KDEVICE));
        pipedev = sys_malloc(sizeof(KDEVICE));
        pipedev->write = (RWFDFUN)kwrite_syspipe;
        pipedev->write = (RWFDFUN)kwrite_syspipe;
        pipedev->read  = (RWFDFUN)kread_syspipe;
        pipedev->read  = (RWFDFUN)kread_syspipe;
        pipedev->close = NULL;
        pipedev->close = NULL;
 
 
        txdev = pwmdev = pipedev;
        txdev = pwmdev = pipedev;
 
 
        rxpipe  = new_syspipe(16);      //rxpipe->m_wrtask=INTERRUPT_WRITE_TASK;
        rxpipe  = new_syspipe(16);      //rxpipe->m_wrtask=INTERRUPT_WRITE_TASK;
        txpipe  = new_syspipe(8);       txpipe->m_rdtask = INTERRUPT_READ_TASK;
        txpipe  = new_syspipe(8);       txpipe->m_rdtask = INTERRUPT_READ_TASK;
        keypipe = new_syspipe(16);
        keypipe = new_syspipe(16);
        lcdpipe = new_syspipe(16);
        lcdpipe = new_syspipe(16);
        pwmpipe = new_syspipe(128);     pwmpipe->m_rdtask= INTERRUPT_READ_TASK;
        pwmpipe = new_syspipe(128);     pwmpipe->m_rdtask= INTERRUPT_READ_TASK;
        cmdpipe = new_syspipe(16);
        cmdpipe = new_syspipe(16);
 
 
        tasklist = sys_malloc(sizeof(TASKP)*(1+LAST_TASK));
        tasklist = sys_malloc(sizeof(TASKP)*(1+LAST_TASK));
        kinit(tasklist);
        kinit(tasklist);
        tasklist[LAST_TASK] = new_task(2, idle_task);
        tasklist[LAST_TASK] = new_task(2, idle_task);
 
 
        // Turn all interrupts off, acknowledge all at the same time
        // Turn all interrupts off, acknowledge all at the same time
        sys->io_pic = 0x7fff7fff;
        sys->io_pic = 0x7fff7fff;
 
 
        sys->io_tima = CONTEXT_LENGTH | TM_REPEAT;
        sys->io_tima = CONTEXT_LENGTH | TM_REPEAT;
 
 
        {
        {
                // Reset our wishbone scope for debug later
                // Reset our wishbone scope for debug later
                SCOPE   *scope = (SCOPE *)SCOPEADDR;
                SCOPE   *scope = (SCOPE *)SCOPEADDR;
                scope->s_control = 2;
                scope->s_control = 2;
        }
        }
        sys->io_spio = 0x0f1;
        sys->io_spio = 0x0f1;
 
 
        return tasklist;
        return tasklist;
}
}
 
 
void    kwait_on_buttonpress(void) {
void    kwait_on_buttonpress(void) {
        IOSPACE *sys = (IOSPACE *)IOADDR;
        IOSPACE *sys = (IOSPACE *)IOADDR;
 
 
        // Wait on a button press before starting
        // Wait on a button press before starting
        while((sys->io_spio & 0x0f0)==0)
        while((sys->io_spio & 0x0f0)==0)
                ;
                ;
        sys->io_spio = 0x0f3;
        sys->io_spio = 0x0f3;
        for(int i=0; i<40000; i++)
        for(int i=0; i<40000; i++)
                sys->io_spio = ((i>>14)&2)|0x020;
                sys->io_spio = ((i>>14)&2)|0x020;
        sys->io_spio = 0x0f7;
        sys->io_spio = 0x0f7;
}
}
 
 
// __attribute__((noreturn))
// __attribute__((noreturn))
void    kuserexit(int a) {
void    kuserexit(int a) {
        syscall(TRAPID_EXIT, a, 0, 0);
        syscall(TRAPID_EXIT, a, 0, 0);
}
}
 
 
__attribute__((malloc))
__attribute__((malloc))
void    *sys_malloc(int sz) {
void    *sys_malloc(int sz) {
        if (0) {
        if (0) {
                SCOPE   *s = (SCOPE *)SCOPEADDR;
                SCOPE   *s = (SCOPE *)SCOPEADDR;
                s->s_control = TRIGGER_SCOPE_NOW | (s->s_control & 0x0ffff);
                s->s_control = TRIGGER_SCOPE_NOW | (s->s_control & 0x0ffff);
        }
        }
 
 
        void    *res = heap;
        void    *res = heap;
        heap += sz;
        heap += sz;
        if ((int)heap > ((int)&res)-32) {
        if ((int)heap > ((int)&res)-32) {
                IOSPACE *sys = (IOSPACE *)IOADDR;
                IOSPACE *sys = (IOSPACE *)IOADDR;
                sys->io_spio = 0xf3;
                sys->io_spio = 0xf3;
                asm("break 0");
                asm("break 0");
        }
        }
        return res;
        return res;
}
}
 
 
KFILDES *kopen(int id, KDEVICE *dev) {
KFILDES *kopen(int id, KDEVICE *dev) {
        KFILDES *fd = (KFILDES *)sys_malloc(sizeof(KFILDES));
        KFILDES *fd = (KFILDES *)sys_malloc(sizeof(KFILDES));
        fd->id = (int)id;
        fd->id = (int)id;
        fd->dev= dev;
        fd->dev= dev;
        return fd;
        return fd;
}
}
 
 

powered by: WebSVN 2.1.0

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