Subversion Repositories NaviCtrl

Rev

Rev 464 | Rev 470 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 464 Rev 465
Line 169... Line 169...
169
#define MK3MAG_CMD_VERSION              0x01
169
#define MK3MAG_CMD_VERSION              0x01
170
#define MK3MAG_CMD_READ_MAGVECT         0x02
170
#define MK3MAG_CMD_READ_MAGVECT         0x02
171
#define MK3MAG_CMD_WRITE_CAL            0x04
171
#define MK3MAG_CMD_WRITE_CAL            0x04
Line 172... Line 172...
172
 
172
 
173
// use I2C1 for communication
173
// use I2C1 for communication
174
void MK3MAG_SendCommandI2C1(u8 command)
174
void MK3MAG_SendCommand(u8 command)
175
{
175
{
176
        // try to catch the I2C buffer
176
        // try to catch the I2C buffer
177
        if(I2C_LockBuffer(0))
177
        if(I2C_LockBuffer(0))
178
        {
178
        {
Line 211... Line 211...
211
                // initiate I2C transmission
211
                // initiate I2C transmission
212
                I2C_Transmission(MK3MAG_SLAVE_ADDRESS, TxBytes, pRxHandlerFunc, RxBytes);
212
                I2C_Transmission(MK3MAG_SLAVE_ADDRESS, TxBytes, pRxHandlerFunc, RxBytes);
213
        } // EOF I2C_State == I2C_IDLE  
213
        } // EOF I2C_State == I2C_IDLE  
214
}
214
}
Line 215... Line -...
215
 
-
 
216
// use I2C0 for communication
-
 
217
void MK3MAG_SendCommandI2C0(u8 command)
-
 
218
{
-
 
219
        // try to catch the I2C buffer
-
 
220
        if(I2C0_LockBuffer(0))
-
 
221
        {
-
 
222
                u16 TxBytes = 0;
-
 
223
                u16 RxBytes = 0;
-
 
224
                I2C_pRxHandler_t pRxHandlerFunc = NULL;
-
 
225
               
-
 
226
                // update current command id
-
 
227
                I2C0_Buffer[TxBytes++] = command;
-
 
228
 
-
 
229
                // set pointers to data area with respect to the command id
-
 
230
                switch (command)
-
 
231
                {
-
 
232
                        case MK3MAG_CMD_VERSION:
-
 
233
                                RxBytes = sizeof(MK3MAG_Version)+1;
-
 
234
                                pRxHandlerFunc = &MK3MAG_UpdateVersion;
-
 
235
                                break;
-
 
236
                        case MK3MAG_CMD_WRITE_CAL:
-
 
237
                                RxBytes = sizeof(MK3MAG_ReadCal)+1;
-
 
238
                                pRxHandlerFunc = &MK3MAG_UpdateCalibration;
-
 
239
                                memcpy((u8*)I2C0_Buffer+1, (u8*)&MK3MAG_WriteCal, sizeof(MK3MAG_WriteCal));
-
 
240
                                TxBytes += sizeof(MK3MAG_WriteCal);
-
 
241
                                break;
-
 
242
                        case MK3MAG_CMD_READ_MAGVECT:
-
 
243
                                RxBytes = sizeof(MagVector)+1;
-
 
244
                                pRxHandlerFunc = &MK3MAG_UpdateMagVector;
-
 
245
                                break;
-
 
246
                        default: // unknown command id
-
 
247
                                RxBytes = 0;
-
 
248
                                pRxHandlerFunc = NULL;
-
 
249
                                break;
-
 
250
                }
-
 
251
                // update packet checksum
-
 
252
                I2C0_Buffer[TxBytes] = MK3MAG_CalcCRC((u8*)I2C0_Buffer, TxBytes);
-
 
253
                TxBytes++;
-
 
254
                // initiate I2C transmission
-
 
255
                I2C0_Transmission(MK3MAG_SLAVE_ADDRESS, TxBytes, pRxHandlerFunc, RxBytes);
-
 
256
        } // EOF I2C_State == I2C_IDLE  
-
 
257
}
-
 
258
 
-
 
259
void MK3MAG_SendCommand(u8 command)
-
 
260
{
-
 
261
 // MK3MAG_SendCommandI2C1(command);
-
 
262
  MK3MAG_SendCommandI2C0(command);
-
 
Line 263... Line 215...
263
}
215
 
264
 
216
 
265
//----------------------------------------------------------------
217
//----------------------------------------------------------------
266
u8 MK3MAG_Init(void)
218
u8 MK3MAG_Init(void)