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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [spi/] [current/] [include/] [spi.h] - Blame information for rev 825

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

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_IO_SPI_H
2
#define CYGONCE_IO_SPI_H
3
 
4
//=============================================================================
5
//
6
//      spi.h
7
//
8
//      Generic API for accessing devices on an SPI bus
9
//
10
//=============================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
12
// -------------------------------------------                              
13
// This file is part of eCos, the Embedded Configurable Operating System.   
14
// Copyright (C) 2004 Free Software Foundation, Inc.                        
15
//
16
// eCos is free software; you can redistribute it and/or modify it under    
17
// the terms of the GNU General Public License as published by the Free     
18
// Software Foundation; either version 2 or (at your option) any later      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//=============================================================================
43
//####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   bartv
46
// Date:            2004-04-23
47
//####DESCRIPTIONEND####
48
//=============================================================================
49
 
50
#include <pkgconf/infra.h>
51
#include <cyg/infra/cyg_type.h>
52
#include <cyg/hal/drv_api.h>
53
#include <cyg/hal/hal_tables.h>
54
#include <cyg/hal/hal_io.h>
55
 
56
typedef struct cyg_spi_device {
57
    struct cyg_spi_bus*     spi_bus;
58
} cyg_spi_device;
59
 
60
typedef struct cyg_spi_bus {
61
    cyg_drv_mutex_t         spi_lock;
62
#ifdef CYGDBG_USE_ASSERTS    
63
    cyg_spi_device*         spi_current_device;
64
#endif
65
    void                    (*spi_transaction_begin)(cyg_spi_device*);
66
    void                    (*spi_transaction_transfer)(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*, cyg_bool);
67
    void                    (*spi_transaction_tick)(cyg_spi_device*, cyg_bool, cyg_uint32);
68
    void                    (*spi_transaction_end)(cyg_spi_device*);
69
    int                     (*spi_get_config)(cyg_spi_device*, cyg_uint32, void*, cyg_uint32*);
70
    int                     (*spi_set_config)(cyg_spi_device*, cyg_uint32, const void*, cyg_uint32*);
71
} cyg_spi_bus;
72
 
73
#ifdef CYGDBG_USE_ASSERTS
74
# define CYG_SPI_BUS_COMMON_INIT(_bus_)                                 \
75
    CYG_MACRO_START                                                     \
76
    cyg_drv_mutex_init( & ((_bus_)->spi_lock));                         \
77
    (_bus_)->spi_current_device = (cyg_spi_device*)0;                   \
78
    CYG_MACRO_END
79
#else
80
# define CYG_SPI_BUS_COMMON_INIT(_bus_)                                 \
81
    CYG_MACRO_START                                                     \
82
    cyg_drv_mutex_init( & ((_bus_)->spi_lock));                         \
83
    CYG_MACRO_END
84
#endif
85
 
86
// All devices should be in a per-bus table
87
#define CYG_SPI_DEFINE_BUS_TABLE(_type_, _which_)                                       \
88
    CYG_HAL_TABLE_BEGIN(cyg_spi_bus_ ## _which_ ## _devs, spibus_ ## _which_);          \
89
    CYG_HAL_TABLE_END(cyg_spi_bus_ ## _which_ ## _devs_end, spibus_ ## _which_);        \
90
    extern _type_ cyg_spi_bus_## _which_ ## _devs[], cyg_spi_bus_## _which_ ## _devs_end
91
 
92
#define CYG_SPI_DEVICE_ON_BUS(_which_)  CYG_HAL_TABLE_ENTRY( spibus_ ## _which_)
93
 
94
// Keys for use with the get_config() and set_config() operations.
95
#define CYG_IO_GET_CONFIG_SPI_CLOCKRATE     0x00000800
96
#define CYG_IO_SET_CONFIG_SPI_CLOCKRATE     0x00000880
97
 
98
// The simple I/O operations.
99
externC void        cyg_spi_transfer(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*);
100
externC void        cyg_spi_tick(cyg_spi_device*, cyg_bool, cyg_uint32);
101
externC int         cyg_spi_get_config(cyg_spi_device*, cyg_uint32, void*, cyg_uint32*);
102
externC int         cyg_spi_set_config(cyg_spi_device*, cyg_uint32, const void*, cyg_uint32*);
103
 
104
// Support for more complicated transactions.
105
externC void        cyg_spi_transaction_begin(cyg_spi_device*);
106
externC cyg_bool    cyg_spi_transaction_begin_nb(cyg_spi_device*);
107
externC void        cyg_spi_transaction_transfer(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*, cyg_bool);
108
externC void        cyg_spi_transaction_tick(cyg_spi_device*, cyg_bool, cyg_uint32);
109
externC void        cyg_spi_transaction_end(cyg_spi_device*);
110
 
111
// Allow the HAL to export named devices, without introducing circular
112
// dependencies in the header files.
113
#ifdef HAL_SPI_EXPORTED_DEVICES
114
  HAL_SPI_EXPORTED_DEVICES
115
#endif
116
 
117
//-----------------------------------------------------------------------------
118
#endif // ifndef CYGONCE_IO_SPI_H
119
// End of spi.h

powered by: WebSVN 2.1.0

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