-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParTest.c
18029 lines (17895 loc) · 635 KB
/
ParTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
***************************************************************************
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
***************************************************************************
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available on the following
link: http://www.freertos.org/a00114.html
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that is more than just the market leader, it *
* is the industry's de facto standard. *
* *
* Help yourself get started quickly while simultaneously helping *
* to support the FreeRTOS project by purchasing a FreeRTOS *
* tutorial book, reference manual, or both: *
* http://www.FreeRTOS.org/Documentation *
* *
***************************************************************************
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
the FAQ page "My application does not run, what could be wrong?". Have you
defined configASSERT()?
http://www.FreeRTOS.org/support - In return for receiving this top quality
embedded software for free we request you assist our global community by
participating in the support forum.
http://www.FreeRTOS.org/training - Investing in training allows your team to
be as productive as possible as early as possible. Now you can receive
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
Ltd, and the world's leading authority on the world's leading RTOS.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and commercial middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
/*-----------------------------------------------------------
* Simple IO routines to control the LEDs.
* This file is called ParTest.c for historic reasons. Originally it stood for
* PARallel port TEST.
*-----------------------------------------------------------*/
#include "stdio.h"
#include "xil_printf.h"
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Demo includes. */
#include "partest.h"
/* Xilinx includes. */
#include "xgpiops.h"
#include "xgpio.h"
#include "xspips.h"
#include "xparameters.h"
#include "sleep.h"
#include "assert.h"
/* bno055 includes. */
//#include "bno055.h"
//#include "bno055_support.h"
#define AXI_COM_PORT ( 0x0 )
#define partstNUM_LEDS ( 1 )
#define partstDIRECTION_OUTPUT ( 0 )
#define partstOUTPUT_ENABLED ( 1 )
#define partsMOTORoutput ( 1 )
#define gpioCtlPwm ( 1 )
#define gpio2BtnSw ( 2 )
/*-----------------------------------------------------------*/
static XGpioPs xGpio;
static XGpio xGpioHC;
static struct bno055_t bno055;
static struct bno055_euler_t hpr;
/*-----------------------------------------------------------*/
void initI2C(void)
{
XGpioPs_Config *pxConfigPtr;
XGpio_Config *configPtr;
BaseType_t xStatus;
/* Initialize the GPIO driver. */
pxConfigPtr = XGpioPs_LookupConfig( XPAR_XGPIOPS_0_DEVICE_ID );
xStatus = XGpioPs_CfgInitialize( &xGpio, pxConfigPtr, pxConfigPtr->BaseAddr );
configASSERT( xStatus == XST_SUCCESS );
( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
/* Enable outputs and set low. */
XGpioPs_SetDirectionPin( &xGpio, AXI_COM_PORT, partstDIRECTION_OUTPUT );
XGpioPs_SetOutputEnablePin( &xGpio, AXI_COM_PORT, partstOUTPUT_ENABLED );
XGpioPs_WritePin( &xGpio, AXI_COM_PORT, 0x000F );
I2C_routine( XPAR_XGPIOPS_0_DEVICE_ID );
bno055_init(&bno055);
/* Initialise the GPIO driver. */
configPtr = XGpio_LookupConfig( XPAR_AXI_GPIO_0_DEVICE_ID );
configPtr->IsDual = 1; // Tell the Config Driver to have dual channels
xStatus = XGpio_CfgInitialize( &xGpioHC, configPtr, configPtr->BaseAddress );
configASSERT( xStatus == XST_SUCCESS );
( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
/* Enable outputs and set low. */
XGpio_SetDataDirection(&xGpioHC, gpio2BtnSw, 0x00);
XGpio_SetDataDirection(&xGpioHC, gpioCtlPwm, 0x00);
XGpio_DiscreteClear(&xGpioHC, gpioCtlPwm, 0xFFFF);
XGpio_DiscreteClear(&xGpioHC, gpio2BtnSw, 0x00);
}
void vParTestInitialise( void )
{
// u8 val;
// initGPIO();
initI2C();
// initSPI();
// val = initRF24();
// (void)val;
}
/*-----------------------------------------------------------*/
void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue )
{
( void ) uxLED;
( void ) xValue;
}
/*-----------------------------------------------------------*/
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
( void ) uxLED;
}
s16 normalize(s16 speed) {
s16 max = 10;
s16 min = 2;
if (speed > max)
speed = max;
else if (speed < min && speed > -min) {
speed = 0;
}
else if (speed < -max) {
speed = -max;
}
return speed;
}
// H - heading, Roll, Pitch
// Z, X, Y?
void readIMU ()
{
bno055_read_euler_hrp(&hpr);
fprintf(stdout, "%i, %i, %i\n", hpr.h, hpr.r, hpr.p);
xil_printf("%i, %i, %i\n", hpr.h, hpr.r, hpr.p);
}
void writePWM ()
{
u32 motorData = 0;
u32 sw = 0;
motorData = sw = XGpio_DiscreteRead(&xGpioHC, gpio2BtnSw);
sw = (sw & 15) << 3; // Increase Switch capability
motorData = motorData << 8; //Push BTN to the end
uint8_t x = normalize(hpr.r);
uint8_t y = normalize(hpr.p);
motorData = x;
motorData = motorData << 8;
motorData |= y;
motorData = motorData << 8;
motorData |= sw;
XGpio_DiscreteClear(&xGpioHC, gpioCtlPwm, motorData);
}
/********************************** bno055_support.c ********************************/
/*
****************************************************************************
* Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
*
* bno055_support.c
* Date: 2016/03/14
* Revision: 1.0.4 $
*
* Usage: Sensor Driver support file for BNO055 sensor
*
****************************************************************************
* License:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
**************************************************************************/
/*---------------------------------------------------------------------------*
Includes
*---------------------------------------------------------------------------*/
//#include "bno055.h"
//#include "bno055_support.h"
/***************************** Include Files **********************************/
#include "xparameters.h"
#include "xiicps.h"
#include "xil_printf.h"
/************************** Constant Definitions ******************************/
/*
* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are defined here such that a user can easily
* change all the needed parameters in one place.
*/
#define IIC_DEVICE_ID XPAR_XIICPS_0_DEVICE_ID
#define IIC_SLAVE_ADDR 0x55
#define IIC_SCLK_RATE 100000
#define TEST_BUFFER_SIZE 256
/************************** Function Prototypes *******************************/
int IicPsMasterPolledExample(u16 DeviceId);
/************************** Variable Definitions ******************************/
XIicPs Iic; /**< Instance of the IIC Device */
u8 SendBuffer[TEST_BUFFER_SIZE]; /**< Buffer for Transmitting Data */
u8 RecvBuffer[TEST_BUFFER_SIZE]; /**< Buffer for Receiving Data */
static struct bno055_t bno055;
/*--------------------------------------------------------------------------*
* The following API is used to map the I2C bus read, write, delay and
* device address with global structure bno055_t
*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*
* By using bno055 the following structure parameter can be accessed
* Bus write function pointer: BNO055_WR_FUNC_PTR
* Bus read function pointer: BNO055_RD_FUNC_PTR
* Delay function pointer: delay_msec
* I2C address: dev_addr
*--------------------------------------------------------------------------*/
s8 I2C_routine(u16 DeviceId)
{
XIicPs_Config *Config;
int Status;
bno055.bus_write = BNO055_I2C_bus_write;
bno055.bus_read = BNO055_I2C_bus_read;
bno055.delay_msec = BNO055_delay_msek;
bno055.dev_addr = BNO055_I2C_ADDR1;
/*
* Initialize the IIC driver so that it's ready to use
* Look up the configuration in the config table,
* then initialize it.
*/
Config = XIicPs_LookupConfig(DeviceId);
if (NULL == Config) {
return XST_FAILURE;
}
Status = XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
Status = XIicPs_SelfTest(&Iic);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/*
* Set the IIC serial clock rate.
*/
XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);
return BNO055_INIT_VALUE;
}
/*-------------------------------------------------------------------*
*
* This is a sample code for read and write the data by using I2C
* Use either I2C based on your need
* The device address defined in the bno055.h file
*
*--------------------------------------------------------------------*/
/* \Brief: The API is used as I2C bus write
* \Return : Status of the I2C write
* \param dev_addr : The device address of the sensor
* \param reg_addr : Address of the first register,
* will data is going to be written
* \param reg_data : It is a value hold in the array,
* will be used for write the value into the register
* \param cnt : The no of byte of data to be write
*/
s8 BNO055_I2C_bus_write(u8 *SendBuffer, u8 cnt)
{
/*
* Please take the below APIs as your reference for
* write the data using I2C communication
* "BNO055_iERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)"
* add your I2C write APIs here
* BNO055_iERROR is an return value of I2C read API
* Please select your valid return value
* In the driver BNO055_SUCCESS defined as 0
* and FAILURE defined as -1
* Note :
* This is a full duplex operation,
* The first read data is discarded, for that extra write operation
* have to be initiated. For that cnt+1 operation done
* in the I2C write string function
* For more information please refer data sheet SPI communication:
*/
return (s8)XIicPs_MasterSendPolled(&Iic, SendBuffer, cnt, IIC_SLAVE_ADDR);
}
/* \Brief: The API is used as I2C bus read
* \Return : Status of the I2C read
* \param dev_addr : The device address of the sensor
* \param reg_addr : Address of the first register,
* will data is going to be read
* \param reg_data : This data read from the sensor,
* which is hold in an array
* \param cnt : The no of byte of data to be read
*/
s8 BNO055_I2C_bus_read(u8 *RecvBuffer, u8 cnt)
{
/* Please take the below API as your reference
* for read the data using I2C communication
* add your I2C read API here.
* "BNO055_iERROR = I2C_WRITE_READ_STRING(DEV_ADDR,
* ARRAY, ARRAY, 1, CNT)"
* BNO055_iERROR is an return value of SPI write API
* Please select your valid return value
* In the driver BNO055_SUCCESS defined as 0
* and FAILURE defined as -1
*/
return (s8)XIicPs_MasterRecvPolled(&Iic, RecvBuffer, cnt, IIC_SLAVE_ADDR);
}
/* Brief : The delay routine
* \param : delay in ms
*/
void BNO055_delay_msek(u32 msek)
{
u32 i;
for (i = 0; i < msek; i++);
}
/****** bno055.c **********************************************/
/*
*
****************************************************************************
* Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
*
* File : bno055.c
*
* Date : 2016/03/14
*
* Revision : 3 $
*
* Usage: Sensor Driver file for BNO055 sensor for use with ZYBO board
*
* Revision Author: Darius Holmgren
*
****************************************************************************
* \section License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
**************************************************************************/
/*********************************************************/
/* INCLUDES */
/*******************************************************/
//#include "bno055.h"
/*! file <BNO055 >
brief <Sensor driver for BNO055> */
/* STRUCTURE DEFINITIONS */
static struct bno055_t *p_bno055;
/* LOCAL FUNCTIONS */
/*!
* @brief
* This API is used for initialize
* bus read, bus write function pointers,device
* address,accel revision id, gyro revision id
* mag revision id, software revision id, boot loader
* revision id and page id
*
* @param bno055 - structure pointer
*
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
* @note While changing the parameter of the bno055_t
* consider the following point:
* Changing the reference value of the parameter
* will changes the local copy or local reference
* make sure your changes will not
* affect the reference value of the parameter
* (Better case don't change the reference value of the parameter)
*/
BNO055_RETURN_FUNCTION_TYPE bno055_init(struct bno055_t *bno055)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
u8 bno055_page_zero_u8 = BNO055_PAGE_ZERO;
/* Array holding the Software revision id
*/
u8 a_SW_ID_u8[BNO055_REV_ID_SIZE] = {
BNO055_INIT_VALUE, BNO055_INIT_VALUE};
/* stuct parameters are assign to bno055*/
p_bno055 = bno055;
/* Write the default page as zero*/
com_rslt = p_bno055->BNO055_BUS_WRITE_FUNC
(p_bno055->dev_addr,
BNO055_PAGE_ID_REG, &bno055_page_zero_u8, BNO055_GEN_READ_WRITE_LENGTH);
/* Read the chip id of the sensor from page
zero 0x00 register*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_CHIP_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->chip_id = data_u8;
/* Read the accel revision id from page
zero 0x01 register*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_ACCEL_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->accel_rev_id = data_u8;
/* Read the mag revision id from page
zero 0x02 register*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_MAG_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->mag_rev_id = data_u8;
/* Read the gyro revision id from page
zero 0x02 register*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_GYRO_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->gyro_rev_id = data_u8;
/* Read the boot loader revision from page
zero 0x06 register*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_BL_REV_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->bl_rev_id = data_u8;
/* Read the software revision id from page
zero 0x04 and 0x05 register( 2 bytes of data)*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC(p_bno055->dev_addr,
BNO055_SW_REV_ID_LSB_REG,
a_SW_ID_u8, BNO055_LSB_MSB_READ_LENGTH);
a_SW_ID_u8[BNO055_SW_ID_LSB] = BNO055_GET_BITSLICE(
a_SW_ID_u8[BNO055_SW_ID_LSB],
BNO055_SW_REV_ID_LSB);
p_bno055->sw_rev_id = (u16)
((((u32)((u8)a_SW_ID_u8[BNO055_SW_ID_MSB])) <<
BNO055_SHIFT_EIGHT_BITS) | (a_SW_ID_u8[BNO055_SW_ID_LSB]));
/* Read the page id from the register 0x07*/
com_rslt += p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_PAGE_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
p_bno055->page_id = data_u8;
return com_rslt;
}
/*!
* @brief
* This API gives data to the given register and
* the data is written in the corresponding register address
*
* @param addr_u8 : Address of the register
* @param data_u8 : Data to be written to the register
* @param len_u8 : Length of the Data
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_write_register(u8 addr_u8,
u8 *data_u8, u8 len_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/* Write the values of respective given register */
com_rslt = p_bno055->BNO055_BUS_WRITE_FUNC
(p_bno055->dev_addr, addr_u8, data_u8, len_u8);
}
return com_rslt;
}
/*!
* @brief This API reads the data from
* the given register address
*
* @param addr_u8 : Address of the register
* @param data_u8 : address of the variable,
* read value will be kept
* @param len_u8 : Length of the data
*
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_register(u8 addr_u8,
u8 *data_u8, u8 len_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/* Read the value from given register*/
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr, addr_u8, data_u8, len_u8);
}
return com_rslt;
}
/*!
* @brief This API reads chip id
* from register 0x00 it is a byte of data
*
*
* @param chip_id_u8 : The chip id value 0xA0
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_chip_id(u8 *chip_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the chip id*/
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_CHIP_ID_REG, &data_u8,
BNO055_GEN_READ_WRITE_LENGTH);
*chip_id_u8 = data_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API reads software revision id
* from register 0x04 and 0x05 it is a two byte of data
*
* @param sw_id_u8 : The SW revision id
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_sw_rev_id(u16 *sw_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
/* array having the software revision id
data_u8[0] - LSB
data_u8[1] - MSB*/
u8 data_u8[BNO055_REV_ID_SIZE] = {BNO055_INIT_VALUE,
BNO055_INIT_VALUE};
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty*/
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the two byte value of software
revision id*/
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_SW_REV_ID_LSB_REG,
data_u8, BNO055_LSB_MSB_READ_LENGTH);
data_u8[BNO055_SW_ID_LSB] =
BNO055_GET_BITSLICE(data_u8[BNO055_SW_ID_LSB],
BNO055_SW_REV_ID_LSB);
*sw_id_u8 = (u16)
((((u32)((u8)data_u8[BNO055_SW_ID_MSB])) <<
BNO055_SHIFT_EIGHT_BITS)
| (data_u8[BNO055_SW_ID_LSB]));
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API reads page id
* from register 0x07 it is a byte of data
*
*
* @param page_id_u8 : The value of page id
*
* BNO055_PAGE_ZERO -> 0x00
* BNO055_PAGE_ONE -> 0x01
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_page_id(u8 *page_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/* Read the page id form 0x07*/
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_PAGE_ID_REG, &data_u8, BNO055_GEN_READ_WRITE_LENGTH);
if (com_rslt == BNO055_SUCCESS) {
data_u8 = BNO055_GET_BITSLICE(data_u8,
BNO055_PAGE_ID);
*page_id_u8 = data_u8;
p_bno055->page_id = data_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API used to write
* the page id register 0x07
*
* @param page_id_u8 : The value of page id
*
* BNO055_PAGE_ZERO -> 0x00
* BNO055_PAGE_ONE -> 0x01
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_write_page_id(u8 page_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8r = BNO055_INIT_VALUE;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/* Read the current page*/
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_PAGE_ID_REG, &data_u8r,
BNO055_GEN_READ_WRITE_LENGTH);
/* Check condition for communication BNO055_SUCCESS*/
if (com_rslt == BNO055_SUCCESS) {
data_u8r = BNO055_SET_BITSLICE(data_u8r,
BNO055_PAGE_ID, page_id_u8);
/* Write the page id*/
com_rslt += p_bno055->BNO055_BUS_WRITE_FUNC
(p_bno055->dev_addr,
BNO055_PAGE_ID_REG,
&data_u8r, BNO055_GEN_READ_WRITE_LENGTH);
if (com_rslt == BNO055_SUCCESS)
p_bno055->page_id = page_id_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API reads accel revision id
* from register 0x01 it is a byte of value
*
* @param accel_rev_id_u8 : The accel revision id 0xFB
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_accel_rev_id(
u8 *accel_rev_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the accel revision id */
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_ACCEL_REV_ID_REG,
&data_u8, BNO055_GEN_READ_WRITE_LENGTH);
*accel_rev_id_u8 = data_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API reads mag revision id
* from register 0x02 it is a byte of value
*
* @param mag_rev_id_u8 : The mag revision id 0x32
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_mag_rev_id(
u8 *mag_rev_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the mag revision id */
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_MAG_REV_ID_REG,
&data_u8, BNO055_GEN_READ_WRITE_LENGTH);
*mag_rev_id_u8 = data_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API reads gyro revision id
* from register 0x03 it is a byte of value
*
* @param gyro_rev_id_u8 : The gyro revision id 0xF0
*
*
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_gyro_rev_id(
u8 *gyro_rev_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the gyro revision id */
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_GYRO_REV_ID_REG,
&data_u8, BNO055_GEN_READ_WRITE_LENGTH);
*gyro_rev_id_u8 = data_u8;
} else {
com_rslt = BNO055_ERROR;
}
}
return com_rslt;
}
/*!
* @brief This API used to read boot loader revision id
* from register 0x06 it is a byte of value
*
* @param bl_rev_id_u8 : The boot loader revision id
*
*
* @return results of bus communication function
* @retval 0 -> BNO055_SUCCESS
* @retval 1 -> BNO055_ERROR
*
*
*/
BNO055_RETURN_FUNCTION_TYPE bno055_read_bl_rev_id(
u8 *bl_rev_id_u8)
{
/* Variable used to return value of
communication routine*/
BNO055_RETURN_FUNCTION_TYPE com_rslt = BNO055_ERROR;
u8 data_u8 = BNO055_INIT_VALUE;
s8 stat_s8 = BNO055_ERROR;
/* Check the struct p_bno055 is empty */
if (p_bno055 == BNO055_INIT_VALUE) {
return BNO055_E_NULL_PTR;
} else {
/*condition check for page, chip id is
available in the page zero*/
if (p_bno055->page_id != BNO055_PAGE_ZERO)
/* Write the page zero*/
stat_s8 = bno055_write_page_id(BNO055_PAGE_ZERO);
if ((stat_s8 == BNO055_SUCCESS) ||
(p_bno055->page_id == BNO055_PAGE_ZERO)) {
/* Read the boot loader revision id */
com_rslt = p_bno055->BNO055_BUS_READ_FUNC
(p_bno055->dev_addr,
BNO055_BL_REV_ID_REG,
&data_u8, BNO055_GEN_READ_WRITE_LENGTH);
*bl_rev_id_u8 = data_u8;
} else {
com_rslt = BNO055_ERROR;
}