1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC5200 BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | File: mpc5200mbus.h |
---|
5 | +-----------------------------------------------------------------+ |
---|
6 | | Copyright (c) 2005 | |
---|
7 | | Embedded Brains GmbH | |
---|
8 | | Obere Lagerstr. 30 | |
---|
9 | | D-82178 Puchheim | |
---|
10 | | Germany | |
---|
11 | | rtems@embedded-brains.de | |
---|
12 | +-----------------------------------------------------------------+ |
---|
13 | | The license and distribution terms for this file may be | |
---|
14 | | found in the file LICENSE in this distribution or at | |
---|
15 | | | |
---|
16 | | http://www.rtems.com/license/LICENSE. | |
---|
17 | | | |
---|
18 | +-----------------------------------------------------------------+ |
---|
19 | | MBUS module (I2C bus) definitions | |
---|
20 | +-----------------------------------------------------------------+ |
---|
21 | | This file has been adapted from an existing source code file, | |
---|
22 | | see the original file header below for reference | |
---|
23 | +-----------------------------------------------------------------+ |
---|
24 | | date history ID | |
---|
25 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
---|
26 | | 01.12.05 creation doe | |
---|
27 | |*****************************************************************| |
---|
28 | |*CVS information: | |
---|
29 | |*(the following information is created automatically, | |
---|
30 | |*do not edit here) | |
---|
31 | |*****************************************************************| |
---|
32 | |* $Log$ |
---|
33 | |* Revision 1.5 2005/12/09 08:57:03 thomas |
---|
34 | |* added/modifed file headers |
---|
35 | |* |
---|
36 | |* Revision 1.4 2005/12/06 14:11:11 thomas |
---|
37 | |* added EB file headers |
---|
38 | |* |
---|
39 | * |
---|
40 | |*****************************************************************| |
---|
41 | \*===============================================================*/ |
---|
42 | /* |
---|
43 | * MCF5206e MBUS module (I2C bus) driver header file |
---|
44 | * |
---|
45 | * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia |
---|
46 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
47 | * |
---|
48 | * The license and distribution terms for this file may be |
---|
49 | * found in the file LICENSE in this distribution or at |
---|
50 | * |
---|
51 | * http://www.rtems.com/license/LICENSE. |
---|
52 | * |
---|
53 | * @(#) mcfmbus.h,v 1.3 2004/03/31 01:59:32 ralf Exp |
---|
54 | */ |
---|
55 | |
---|
56 | #ifndef __MPC5200BSP_MPC5200MBUS_H__ |
---|
57 | #define __MPC5200BSP_MPC5200MBUS_H__ |
---|
58 | |
---|
59 | #include "../include/mpc5200.h" |
---|
60 | #include "../include/i2c.h" |
---|
61 | |
---|
62 | /* States of I2C machine */ |
---|
63 | typedef enum mpc5200mbus_i2c_state { |
---|
64 | STATE_UNINITIALIZED, |
---|
65 | STATE_IDLE, |
---|
66 | STATE_ADDR_7, |
---|
67 | STATE_ADDR_1_W, |
---|
68 | STATE_ADDR_1_R, |
---|
69 | STATE_SENDING, |
---|
70 | STATE_RECEIVING |
---|
71 | } mpc5200mbus_i2c_state; |
---|
72 | |
---|
73 | typedef struct mpc5200_mbus { |
---|
74 | enum mpc5200mbus_i2c_state state;/* State of I2C machine */ |
---|
75 | i2c_message *msg; /* Pointer to the first message in transfer */ |
---|
76 | int nmsg; /* Number of messages in transfer */ |
---|
77 | i2c_message *cmsg; /* Current message */ |
---|
78 | int byte; /* Byte number in current message */ |
---|
79 | rtems_id sema; /* MBUS semaphore */ |
---|
80 | i2c_transfer_done done; /* Transfer done function */ |
---|
81 | uint32_t done_arg; /* Done function argument */ |
---|
82 | int bus_idx; /* bus index: 0 or 1 */ |
---|
83 | } mpc5200mbus; |
---|
84 | |
---|
85 | /* mpc5200mbus_initialize -- |
---|
86 | * Initialize ColdFire MBUS I2C bus controller. |
---|
87 | * |
---|
88 | * PARAMETERS: |
---|
89 | * i2c_bus - pointer to the bus descriptor structure |
---|
90 | * |
---|
91 | * RETURNS: |
---|
92 | * RTEMS_SUCCESSFUL, or RTEMS error code when initialization failed. |
---|
93 | */ |
---|
94 | rtems_status_code |
---|
95 | mpc5200mbus_initialize(mpc5200mbus *i2c_bus); |
---|
96 | |
---|
97 | /* mpc5200mbus_select_clock_divider -- |
---|
98 | * Select divider for system clock which is used for I2C bus clock |
---|
99 | * generation. Not each divider can be selected for I2C bus; this |
---|
100 | * function select nearest larger or equal divider, or maximum |
---|
101 | * possible divider, if passed value greater. |
---|
102 | * |
---|
103 | * PARAMETERS: |
---|
104 | * i2c_bus - pointer to the bus descriptor structure |
---|
105 | * divider - system frequency divider for I2C serial clock. |
---|
106 | * |
---|
107 | * RETURNS: |
---|
108 | * RTEMS_SUCCESSFUL, if operation performed successfully, or |
---|
109 | * RTEMS error code when failed. |
---|
110 | */ |
---|
111 | rtems_status_code |
---|
112 | mpc5200mbus_select_clock_divider(mpc5200mbus *i2c_bus, int divider); |
---|
113 | |
---|
114 | /* mpc5200mbus_i2c_transfer -- |
---|
115 | * Initiate multiple-messages transfer over I2C bus via ColdFire MBUS |
---|
116 | * controller. |
---|
117 | * |
---|
118 | * PARAMETERS: |
---|
119 | * bus - pointer to MBUS controller descriptor |
---|
120 | * nmsg - number of messages |
---|
121 | * msg - pointer to messages array |
---|
122 | * done - function which is called when transfer is finished |
---|
123 | * done_arg - arbitrary argument passed to done funciton |
---|
124 | * |
---|
125 | * RETURNS: |
---|
126 | * RTEMS_SUCCESSFUL if transfer initiated successfully, or error |
---|
127 | * code when failed. |
---|
128 | */ |
---|
129 | rtems_status_code |
---|
130 | mpc5200mbus_i2c_transfer(mpc5200mbus *bus, int nmsg, i2c_message *msg, |
---|
131 | i2c_transfer_done done, uint32_t done_arg); |
---|
132 | |
---|
133 | /* mpc5200mbus_i2c_done -- |
---|
134 | * Close ColdFire MBUS I2C bus controller and release all resources. |
---|
135 | * |
---|
136 | * PARAMETERS: |
---|
137 | * bus - pointer to MBUS controller descriptor |
---|
138 | * |
---|
139 | * RETURNS: |
---|
140 | * RTEMS_SUCCESSFUL, if transfer initiated successfully, or error |
---|
141 | * code when failed. |
---|
142 | */ |
---|
143 | rtems_status_code |
---|
144 | mpc5200mbus_i2c_done(mpc5200mbus *i2c_bus); |
---|
145 | |
---|
146 | /* mpc5200mbus_i2c_interrupt_handler -- |
---|
147 | * ColdFire MBUS I2C bus controller interrupt handler. This function |
---|
148 | * called from real interrupt handler, and pointer to MBUS descriptor |
---|
149 | * structure passed to this function. |
---|
150 | * |
---|
151 | * PARAMETERS: |
---|
152 | * bus - pointert to the bus descriptor structure |
---|
153 | * |
---|
154 | * RETURNS: |
---|
155 | * none |
---|
156 | */ |
---|
157 | void mpc5200mbus_i2c_interrupt_handler(mpc5200mbus *bus); |
---|
158 | |
---|
159 | /* mpc5200mbus_poll -- |
---|
160 | * MBUS module poll routine; used to poll events when I2C driver |
---|
161 | * operates in poll-driven mode. |
---|
162 | * |
---|
163 | * PARAMETERS: |
---|
164 | * none |
---|
165 | * |
---|
166 | * RETURNS: |
---|
167 | * none |
---|
168 | */ |
---|
169 | void mpc5200mbus_poll(mpc5200mbus *bus); |
---|
170 | |
---|
171 | #endif /* __MPC5200BSP_MPC5200MBUS_H__ */ |
---|