Subversion Repositories shark

Rev

Rev 715 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
 *   Luca Abeni          <luca@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/**
 ------------
 CVS :        $Id: scom.h,v 1.1 2004-03-29 18:31:42 mauro Exp $

 File:        $File$
 Revision:    $Revision: 1.1 $
 Last update: $Date: 2004-03-29 18:31:42 $
 ------------

**/


/*
 * Copyright (C) 2000 Gerardo Lamastra
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


/* Project:     HARTIK 3.0                                      */
/* Description: Hard Real TIme Kernel for 386 & higher machines */
/* Author:      Gerardo Lamastra                                */
/* Date:        9/5/96                                          */

/* File:        SCOM.H                                          */
/* Revision:    2.0                                             */

#ifndef __SCOM_H__
#define __SCOM_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <modules/sem.h>

/* Number of available COM links */
#define COM_LINKS       4

#define COM1            0
#define COM2            1
#define COM3            2
#define COM4            3

/* These values identify interrupt type */
#define RX_FULL         1
#define TX_EMPTY        2
#define LS_CHANGED      4
#define MS_CHANGED      8

/* This is set when the channel is open */
#define LINK_BUSY       128
/* This is set if the fast handler is installed */
#define FAST_INSTALLED  64

/* Register displacements */
#define THR     0
#define RBR     0
#define IER     1
#define FCR     2
#define IIR     2
#define LCR     3
#define MCR     4
#define LSR     5
#define MSR     6
#define SPad    7

/* Parity value */
#define NONE    0
#define ODD     1
#define EVEN    3

/* Used for decoding the IIR status */
extern const int IIRbits[];
#define DECODE(v)       IIRbits[((v >> 1) & 3)]
#define PENDIRQ(v)      !((v) & 1)

/* Bit setting macros */
#define bit_on(v,b)     v |= (b)
#define bit_off(v,b)    v &= (~(b))

/* The descriptor of a serial link                               */
/* Each array entry is associated to a COM port                  */
/* The control field is used to specify which kind of interrupts */
/* are going to be served; the status field tracks if the entry  */
/* is curretly used & if the shared fast handler is linked       */
/* The semaphores are opened if you use an asyncronous server    */
/* with the link                                                 */

extern struct COM_LINK {
    /* These fields are for general use */
    BYTE status;
    BYTE control;
    BYTE request;
    BYTE msk;
    PID server;
    sem_t mutex;
    sem_t tx_sem;
    sem_t rx_sem;
    BYTE *tx_buf;
    BYTE *rx_buf;
    unsigned tx_len,rx_len;
    unsigned tx_cnt,rx_cnt;
} com_link[COM_LINKS];

/* Available servers */
TASK duplexServer(int port);
TASK rxServer(int port);

int com_open(unsigned int port,DWORD speed,BYTE parity,BYTE len,BYTE stop);
int com_server(unsigned int port,unsigned int control,PID server);
int com_close(unsigned int port);
unsigned com_read(unsigned int port,unsigned int reg);
unsigned com_receive(unsigned int port);
void com_write(unsigned int port,unsigned int reg,unsigned int value);
void com_send(unsigned int port,BYTE b);
void com_AsyncSend(int port,void *buf,unsigned int len);
void com_AsyncReceive(int port,void *buf,unsigned int len);

#ifdef __cplusplus
};
#endif

#endif