1 //==========================================================================
3 // devs/i2c/m68k/mcf52xx/current/src/i2c_mcf52xx.h
5 // I2C driver for Motorola coldfire processors
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2005, 2006 eCosCentric Ltd.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 // -------------------------------------------
36 //####ECOSGPLCOPYRIGHTEND####
37 //==========================================================================
38 //#####DESCRIPTIONBEGIN####
40 // Author(s): Bart Veer
43 // Description: I2C driver for motorola coldfire processor
44 //####DESCRIPTIONEND####
45 //==========================================================================
47 #include <pkgconf/devs_i2c_mcf52xx.h>
48 #include <cyg/infra/cyg_type.h>
49 #include <cyg/hal/drv_api.h>
51 typedef enum cyg_mcf52xx_i2c_xfer_mode {
52 CYG_MCF52xx_I2C_XFER_MODE_INVALID = 0x00,
53 CYG_MCF52xx_I2C_XFER_MODE_TX = 0x01,
54 CYG_MCF52xx_I2C_XFER_MODE_RX = 0x02,
55 CYG_MCF52xx_I2C_XFER_MODE_STARTRX = 0x03
56 } cyg_mcf52xx_i2c_xfer_mode;
58 typedef struct cyg_mcf52xx_i2c_extra {
59 #ifdef CYGHWR_DEVS_I2C_MCF52xx_MULTIPLE_BUSES
60 // Put statically initialized fields first.
61 cyg_uint8* i2c_base; // Per-bus h/w details
62 cyg_vector_t i2c_isrvec;
67 cyg_uint8 i2c_owner; // We have bus ownership
68 cyg_uint8 i2c_lost_arb; // Error condition leading to loss of bus ownership
69 cyg_uint8 i2c_send_nack; // As per rx send_nack argument
70 cyg_uint8 i2c_got_nack; // The last tx resulted in a nack
71 cyg_uint8 i2c_completed; // Set by DSR, checked by thread
74 const cyg_uint8* i2c_tx_data;
75 cyg_uint8* i2c_rx_data;
76 } i2c_data; // The current buffer for rx or tx
77 cyg_uint32 i2c_count; // Number of bytes left in buffer
78 cyg_mcf52xx_i2c_xfer_mode i2c_mode; // TX, RX, ...
81 cyg_drv_mutex_t i2c_lock; // For synchronizing between DSR and foreground
82 cyg_drv_cond_t i2c_wait;
83 cyg_handle_t i2c_interrupt_handle; // For initializing the interrupt
84 cyg_interrupt i2c_interrupt_data;
85 } cyg_mcf52xx_i2c_extra;
87 externC void cyg_mcf52xx_i2c_init(struct cyg_i2c_bus*);
88 externC cyg_uint32 cyg_mcf52xx_i2c_tx(const cyg_i2c_device*, cyg_bool, const cyg_uint8*, cyg_uint32, cyg_bool);
89 externC cyg_uint32 cyg_mcf52xx_i2c_rx(const cyg_i2c_device*, cyg_bool, cyg_uint8*, cyg_uint32, cyg_bool, cyg_bool);
90 externC void cyg_mcf52xx_i2c_stop(const cyg_i2c_device*);
92 #ifdef CYGHWR_DEVS_I2C_MCF52xx_MULTIPLE_BUSES
93 # define CYG_MCF52xx_I2C_BUS(_name_, _init_fn_, _base_, _isr_vec_, _isr_pri_, _fdr_) \
94 static cyg_mcf52xx_i2c_extra _name_ ## _extra = { \
100 CYG_I2C_BUS(_name_, \
102 &cyg_mcf52xx_i2c_tx, \
103 &cyg_mcf52xx_i2c_rx, \
104 &cyg_mcf52xx_i2c_stop, \
105 (void*) & ( _name_ ## _extra)) ;
108 # define CYG_MCF52xx_I2C_BUS(_name_, _init_fn_, _base_, _isr_vec_, _isr_pri_, _fdr_) \
109 static cyg_mcf52xx_i2c_extra _name_ ## _extra; \
110 CYG_I2C_BUS(_name_, \
112 cyg_mcf52xx_i2c_tx, \
113 cyg_mcf52xx_i2c_rx, \
114 cyg_mcf52xx_i2c_stop, \
115 (void*) & ( _name_ ## _extra)) ;