middleware-i2cのコントローラ使用例。回路図同梱
Revision | b2e10e822a6d1455a8db32407305f316bd943455 (tree) |
---|---|
Time | 2012-07-16 15:26:07 |
Author | takemasa <suikan@sour...> |
Commiter | takemasa |
i2c_subsystemに関するファイルを追加。
@@ -116,10 +116,10 @@ UTASK_CFG = $(UNAME).cfg | ||
116 | 116 | UTASK_DIR = $(SRCDIR)/library |
117 | 117 | UTASK_ASMOBJS = |
118 | 118 | ifdef USE_CXX |
119 | - UTASK_CXXOBJS = $(UNAME).o | |
119 | + UTASK_CXXOBJS = $(UNAME).o i2c_subsystem.o | |
120 | 120 | UTASK_COBJS = |
121 | 121 | else |
122 | - UTASK_COBJS = $(UNAME).o | |
122 | + UTASK_COBJS = $(UNAME).o i2c_subsystem.o | |
123 | 123 | endif |
124 | 124 | UTASK_CFLAGS = |
125 | 125 | UTASK_LIBS = |
@@ -616,6 +616,23 @@ i2c-test.o: kernel/include/kernel.h kernel/include/t_services.h \ | ||
616 | 616 | kernel/include/itron.h \ |
617 | 617 | /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/include/stddef.h \ |
618 | 618 | kernel/include/t_stddef.h |
619 | +i2c_subsystem.o: \ | |
620 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/defBF59x_base.h \ | |
621 | + kernel/include/kernel.h kernel/config/blackfin/cpu_defs.h \ | |
622 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/stdint.h \ | |
623 | + kernel/config/blackfin/_common_bf592/chip_defs.h \ | |
624 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/cdef_LPBlackfin.h \ | |
625 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/defBF592-A.h \ | |
626 | + i2c_subsystem.h i2c_subsystem.c \ | |
627 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/cdefBF59x_base.h \ | |
628 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/cdefBF592-A.h \ | |
629 | + kernel/include/t_stddef.h \ | |
630 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/def_LPBlackfin.h \ | |
631 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/include-fixed/limits.h \ | |
632 | + kernel/config/blackfin/tool_defs.h kernel/include/t_syslog.h \ | |
633 | + kernel/config/blackfin/acb_bf592/sys_defs.h \ | |
634 | + /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/include/stddef.h \ | |
635 | + kernel/include/itron.h | |
619 | 636 | timer.o: \ |
620 | 637 | /opt/uClinux2011R1RC4/bfin-elf/bin/../lib/gcc/bfin-elf/4.3.5/../../../../bfin-elf/include/defBF59x_base.h \ |
621 | 638 | kernel/include/kernel.h kernel/include/timer.h \ |
@@ -0,0 +1 @@ | ||
1 | +kernel/configure -C blackfin -S acb_bf592 -A i2c-test -U "i2c_subsystem.o" |
@@ -6,17 +6,10 @@ | ||
6 | 6 | */ |
7 | 7 | #include "i2c_subsystem.h" |
8 | 8 | |
9 | -extern ID SEM_I2C0_BLOCK_id; | |
10 | -extern ID SEM_I2C0_SIGNAL_id; | |
11 | -extern ID SEM_I2C1_BLOCK_id; | |
12 | -extern ID SEM_I2C1_SIGNAL_id; | |
13 | -extern ID SEM_I2C2_BLOCK_id; | |
14 | -extern ID SEM_I2C2_SIGNAL_id; | |
15 | - | |
16 | 9 | /** |
17 | 10 | * \brief チップ上のI2Cペリフェラルの数 |
18 | 11 | */ |
19 | -#define I2CNUM 3 | |
12 | +#define I2CNUM 0 | |
20 | 13 | |
21 | 14 | /** |
22 | 15 | * \brief I2C管理用構造体 |
@@ -24,8 +17,6 @@ extern ID SEM_I2C2_SIGNAL_id; | ||
24 | 17 | struct I2C_CONTROL_TYPE { |
25 | 18 | ID signal; /**< データの送受信が全部終わったときに割り込みハンドラからタスクに知らせるためのセマフォ */ |
26 | 19 | ID blocking; /**< I2Cペリフェラルへの排他アクセスのためのセマフォ */ |
27 | - LPC_I2C_TypeDef *i2c; /**< I2Cペリフェラルの先頭アドレス。 CMSIS の関数が使用する */ | |
28 | - void (*callback)(void); /* 割り込みハンドラが */ | |
29 | 20 | }; |
30 | 21 | |
31 | 22 | /** |
@@ -49,69 +40,18 @@ int i2c_master_read( int peripheral, int slave, unsigned char read_data[], int r | ||
49 | 40 | |
50 | 41 | int i2c_master_write_read( int peripheral, int slave, unsigned char write_data[], int write_count, unsigned char read_data[], int read_count) |
51 | 42 | { |
52 | - I2C_M_SETUP_Type setup; | |
53 | - | |
54 | - // CMSISが内部で使うコンフィギュレーション変数の設定。こ | |
55 | - setup.sl_addr7bit = slave; | |
56 | - setup.tx_data = write_data; | |
57 | - setup.tx_length = write_count; | |
58 | - setup.rx_data = read_data; | |
59 | - setup.rx_length = read_count; | |
60 | - setup.retransmissions_max = 3; | |
61 | - setup.callback = i2c_control[peripheral].callback; | |
62 | 43 | |
63 | 44 | // peripheral 引数で指定されたi2cペリフェラルを排他的に使うためのPV処理。 |
64 | 45 | // これでスレッドセーフにできる |
65 | 46 | wai_sem(i2c_control[peripheral].blocking); |
66 | 47 | |
67 | - I2C_MasterTransferData( | |
68 | - i2c_control[peripheral].i2c, // どのI2Cペリフェラルを使うか指定する, | |
69 | - &setup, // コンフィギュレーション変数を渡す, | |
70 | - I2C_TRANSFER_INTERRUPT // 割り込みベース | |
71 | - ); | |
72 | 48 | |
73 | 49 | // 割り込みハンドラが送受処理を完了するまで待つ |
74 | 50 | wai_sem(i2c_control[peripheral].signal); |
75 | 51 | // 排他区間の終了 |
76 | 52 | sig_sem(i2c_control[peripheral].blocking); |
77 | 53 | |
78 | - // setup.status には処理の結果の他、I2Cステータスレジスタの最後の値が入っている | |
79 | - // 正常終了なら0を返す | |
80 | - if ( setup.status & I2C_SETUP_STATUS_DONE ) | |
81 | - return 0; | |
82 | - else | |
83 | - return setup.status; | |
84 | -} | |
85 | - | |
86 | -/** | |
87 | - * \brief i2c0 コールバック関数 | |
88 | - * \details | |
89 | - * 割り込みハンドラが、タスクに処理の完了を通知するためのコールバック関数。 | |
90 | - */ | |
91 | -static void i2c0_master_report_complete(void) | |
92 | -{ | |
93 | - /* 通知はセマフォを使う。タスクは i2c_master_write_read()の中で待っている。 */ | |
94 | - isig_sem(i2c_control[0].signal); | |
95 | -} | |
96 | -/** | |
97 | - * \brief i210 コールバック関数 | |
98 | - * \details | |
99 | - * 割り込みハンドラが、タスクに処理の完了を通知するためのコールバック関数。 | |
100 | - */ | |
101 | -static void i2c1_master_report_complete(void) | |
102 | -{ | |
103 | - /* 通知はセマフォを使う。タスクは i2c_master_write_read()の中で待っている。 */ | |
104 | - isig_sem(i2c_control[1].signal); | |
105 | -} | |
106 | -/** | |
107 | - * \brief i2c2 コールバック関数 | |
108 | - * \details | |
109 | - * 割り込みハンドラが、タスクに処理の完了を通知するためのコールバック関数。 | |
110 | - */ | |
111 | -static void i2c2_master_report_complete(void) | |
112 | -{ | |
113 | - /* 通知はセマフォを使う。タスクは i2c_master_write_read()の中で待っている。 */ | |
114 | - isig_sem(i2c_control[2].signal); | |
54 | + return 0; | |
115 | 55 | } |
116 | 56 | |
117 | 57 | /** |
@@ -119,22 +59,10 @@ static void i2c2_master_report_complete(void) | ||
119 | 59 | * \details |
120 | 60 | * ATT_ISRを使って静的コンフィギュレータで宣言する。 |
121 | 61 | */ |
122 | -void i2c_master_isr(intptr_t exinf) | |
62 | +void i2c0_master_handler(void) | |
123 | 63 | { |
124 | - /* 処理はCMSISの割り込みハンドラにすべて任せる。ただし、2011年4月時点で、*/ | |
125 | - /* CMSIS 2.0 のI2C_MasterHandler()には、コールバックを行わないバグがある */ | |
126 | - /* このバグは修正が必要 */ | |
127 | - switch ((int)exinf){ | |
128 | - case 0 : | |
129 | - I2C_MasterHandler (LPC_I2C0); | |
130 | - break; | |
131 | - case 1 : | |
132 | - I2C_MasterHandler (LPC_I2C1); | |
133 | - break; | |
134 | - case 2 : | |
135 | - I2C_MasterHandler (LPC_I2C2); | |
136 | - break; | |
137 | - } | |
64 | + /* 通知はセマフォを使う。タスクは i2c_master_write_read()の中で待っている。 */ | |
65 | + isig_sem(i2c_control[0].signal); | |
138 | 66 | } |
139 | 67 | |
140 | 68 |
@@ -145,16 +73,10 @@ void i2c_master_isr(intptr_t exinf) | ||
145 | 73 | */ |
146 | 74 | void i2c0_master_initialize(intptr_t exinf) |
147 | 75 | { |
148 | - i2c_control[0].blocking = SEM_I2C0_BLOCK_id; | |
149 | - i2c_control[0].signal = SEM_I2C0_SIGNAL_id; | |
150 | - i2c_control[0].i2c = LPC_I2C0; | |
76 | + i2c_control[0].blocking = SEM_I2C0_BLOCK; | |
77 | + i2c_control[0].signal = SEM_I2C0_SIGNAL; | |
151 | 78 | i2c_control[0].callback = i2c0_master_report_complete; |
152 | 79 | |
153 | - // CMSIS内部のクロック変数の設定のための呼び出し | |
154 | - // この関数はシステム初期化時に一度呼べばいいのだが、CMSIS依存関数を | |
155 | - // target_initialize() で呼ぶのはためらわれる。そのため、複数回呼ぶ | |
156 | - // 無駄を承知でここで呼んでいる。 | |
157 | - SystemCoreClockUpdate(); | |
158 | 80 | |
159 | 81 | // I2C のクロックデバイダの設定 |
160 | 82 | I2C_Init(LPC_I2C0, 100000); |
@@ -163,54 +85,4 @@ void i2c0_master_initialize(intptr_t exinf) | ||
163 | 85 | I2C_Cmd(LPC_I2C0, ENABLE); |
164 | 86 | } |
165 | 87 | |
166 | -/** | |
167 | - * \brief i2c1 イニシャライザ | |
168 | - * \details | |
169 | - * I2C0用のコントロールブロックのI2C1相当部分を初期化する。 | |
170 | - */ | |
171 | -void i2c1_master_initialize(intptr_t exinf) | |
172 | -{ | |
173 | - i2c_control[1].blocking = SEM_I2C1_BLOCK_id; | |
174 | - i2c_control[1].signal = SEM_I2C1_SIGNAL_id; | |
175 | - i2c_control[1].i2c = LPC_I2C1; | |
176 | - i2c_control[1].callback = i2c1_master_report_complete; | |
177 | - | |
178 | - // CMSIS内部のクロック変数の設定のための呼び出し | |
179 | - // この関数はシステム初期化時に一度呼べばいいのだが、CMSIS依存関数を | |
180 | - // target_initialize() で呼ぶのはためらわれる。そのため、複数回呼ぶ | |
181 | - // 無駄を承知でここで呼んでいる。 | |
182 | - SystemCoreClockUpdate(); | |
183 | - | |
184 | - // I2C のクロックデバイダの設定 | |
185 | - I2C_Init(LPC_I2C1, 100000); | |
186 | - | |
187 | - /* Enable I2C operation */ | |
188 | - I2C_Cmd(LPC_I2C1, ENABLE); | |
189 | -} | |
190 | - | |
191 | -/** | |
192 | - * \brief i2c2 イニシャライザ | |
193 | - * \details | |
194 | - * I2C用のコントロールブロックのI2C2相当部分を初期化する。 | |
195 | - */ | |
196 | -void i2c2_master_initialize(intptr_t exinf) | |
197 | -{ | |
198 | - i2c_control[2].blocking = SEM_I2C2_BLOCK_id; | |
199 | - i2c_control[2].signal = SEM_I2C2_SIGNAL_id; | |
200 | - i2c_control[2].i2c = LPC_I2C2; | |
201 | - i2c_control[2].callback = i2c2_master_report_complete; | |
202 | - | |
203 | - // CMSIS内部のクロック変数の設定のための呼び出し | |
204 | - // この関数はシステム初期化時に一度呼べばいいのだが、CMSIS依存関数を | |
205 | - // target_initialize() で呼ぶのはためらわれる。そのため、複数回呼ぶ | |
206 | - // 無駄を承知でここで呼んでいる。 | |
207 | - SystemCoreClockUpdate(); | |
208 | - | |
209 | - // I2C のクロックデバイダの設定 | |
210 | - I2C_Init(LPC_I2C2, 100000); | |
211 | - | |
212 | - /* Enable I2C operation */ | |
213 | - I2C_Cmd(LPC_I2C2, ENABLE); | |
214 | -} | |
215 | - | |
216 | 88 |