////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: syspipe.h
|
// Filename: syspipe.h
|
//
|
//
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
//
|
//
|
// Purpose: This "device" handles the primary device level interaction of
|
// Purpose: This "device" handles the primary device level interaction of
|
// almost all devices on the ZipOS: the pipe. A pipe, as defined
|
// almost all devices on the ZipOS: the pipe. A pipe, as defined
|
// here, is an O/S supported FIFO. Information written to the FIFO will
|
// here, is an O/S supported FIFO. Information written to the FIFO will
|
// be read from the FIFO in the order it was received. Attempts to read
|
// be read from the FIFO in the order it was received. Attempts to read
|
// from an empty FIFO, or equivalently to write to a full FIFO, will block
|
// from an empty FIFO, or equivalently to write to a full FIFO, will block
|
// the reading (writing) process until memory is available.
|
// the reading (writing) process until memory is available.
|
//
|
//
|
// In general, each PIPE has three interface functions for reading and
|
// In general, each PIPE has three interface functions for reading and
|
// another three for writing, together with one for creating an empty pipe.
|
// another three for writing, together with one for creating an empty pipe.
|
// The read functions are:
|
// The read functions are:
|
//
|
//
|
// kpop_syspipe
|
// kpop_syspipe
|
// Attempts to read one value from the pipe in an interrupt
|
// Attempts to read one value from the pipe in an interrupt
|
// context. It is not allowed to fail. An empty pipe
|
// context. It is not allowed to fail. An empty pipe
|
// simply becomes a return value of '1'.
|
// simply becomes a return value of '1'.
|
//
|
//
|
// kread_syspipe
|
// kread_syspipe
|
// This is where the user trap read() ends up. When a user
|
// This is where the user trap read() ends up. When a user
|
// tries to read from a pipe, kread_syspipe checks that the
|
// tries to read from a pipe, kread_syspipe checks that the
|
// users request is valid, then transfers control to a
|
// users request is valid, then transfers control to a
|
// user task level (interrupts enabled) read function.
|
// user task level (interrupts enabled) read function.
|
//
|
//
|
// uread_syspipe
|
// uread_syspipe
|
// The user read task. This task is invoked from the user
|
// The user read task. This task is invoked from the user
|
// trap, calling kread_syspipe at the kernel mode, which
|
// trap, calling kread_syspipe at the kernel mode, which
|
// then transitions the read to user mode using
|
// then transitions the read to user mode using
|
// uread_syspipe.
|
// uread_syspipe.
|
//
|
//
|
// Writing has it's analogous functions:
|
// Writing has it's analogous functions:
|
// kpush_syspipe
|
// kpush_syspipe
|
// Attempts to write a value from an interrupt context
|
// Attempts to write a value from an interrupt context
|
// to the pipe. Primarily used when reading from a
|
// to the pipe. Primarily used when reading from a
|
// UART driven device.
|
// UART driven device.
|
// kwrite_syspipe
|
// kwrite_syspipe
|
// uwrite_syspipie
|
// uwrite_syspipie
|
//
|
//
|
//
|
//
|
// 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-2017, 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
|
//
|
//
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
//
|
//
|
#ifndef SYSPIPE_H
|
#ifndef SYSPIPE_H
|
#define SYSPIPE_H
|
#define SYSPIPE_H
|
|
|
extern void *sys_malloc(int sz);
|
typedef unsigned size_t;
|
|
|
|
extern void *sys_malloc(size_t sz);
|
|
|
typedef struct {
|
typedef struct {
|
unsigned int m_mask;
|
unsigned int m_mask;
|
int m_head, m_tail;
|
int m_head, m_tail;
|
volatile TASKP m_rdtask, m_wrtask;
|
volatile TASKP m_rdtask, m_wrtask;
|
unsigned int m_nread, m_nwritten;
|
unsigned int m_nread, m_nwritten;
|
int dummy;
|
int dummy;
|
int m_error;
|
int m_error;
|
|
|
int m_buf[1];
|
char m_buf[1];
|
} SYSPIPE;
|
} SYSPIPE;
|
|
|
SYSPIPE *new_syspipe(const unsigned int len);
|
SYSPIPE *new_syspipe(const unsigned int len);
|
extern void kread_syspipe( TASKP tsk, int dev, int *dst, int len);
|
extern void kread_syspipe( TASKP tsk, int dev, char *dst, int len);
|
extern void kwrite_syspipe(TASKP tsk, int dev, int *src, int len);
|
extern void kwrite_syspipe(TASKP tsk, int dev, char *src, int len);
|
void kpush_syspipe(SYSPIPE *p, int val);
|
void kpush_syspipe(SYSPIPE *p, char val);
|
int kpop_syspipe(SYSPIPE *p, int *val);
|
int kpop_syspipe(SYSPIPE *p, char *val);
|
|
int kpop_short_syspipe(SYSPIPE *p, unsigned short *val);
|
extern int num_avail_syspipe(SYSPIPE *p);
|
extern int num_avail_syspipe(SYSPIPE *p);
|
extern int len_syspipe(SYSPIPE *p);
|
extern int len_syspipe(SYSPIPE *p);
|
|
|
#define INTERRUPT_READ_TASK ((TASKP)((unsigned)-1))
|
#define INTERRUPT_READ_TASK ((TASKP)((unsigned)-1))
|
// #define INTERRUPT_WRITE_TASK ((TASKP)((unsigned)-1))
|
// #define INTERRUPT_WRITE_TASK ((TASKP)((unsigned)-1))
|
|
|
#endif
|
#endif
|
|
|