Dragon / Mbed OS combination

Dependencies:   LAAP AK8963

Files at this revision

API Documentation at this revision

Comitter:
Glaxys_finest1
Date:
Mon Nov 25 10:51:18 2019 +0000
Child:
1:3463231e9c41
Commit message:
hello1

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
AK8963.lib Show annotated file Show diff for this revision Revisions of this file
CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
LAAP.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
stats_report.h Show annotated file Show diff for this revision Revisions of this file
tests/README.md Show annotated file Show diff for this revision Revisions of this file
tests/blinky.log Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AK8963.lib	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/coisme/code/AK8963/#9dff393e5e86
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CONTRIBUTING.md	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,5 @@
+# Contributing to Mbed OS
+
+Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
+
+To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LAAP.lib	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,1 @@
+LAAP#25d32fc1c12e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,152 @@
+# Getting started example for Mbed OS
+
+This guide reviews the steps required to get Blinky with the addition of dynamic OS statistics working on an Mbed OS platform. (Note: To see a rendered example you can import into the Arm Online Compiler, please see our [quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
+
+Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Import the example application
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the Arm Compiler:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the following result:
+
+```
+[snip]
+
+Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your Mbed device to the computer over USB.
+1. Copy the binary file to the Mbed device.
+1. Press the reset button to start the program.
+
+The LED on your platform turns on and off. The main thread will additionally take a snapshot of the device's runtime statistics and display it over serial to your PC. The snapshot includes:
+
+* System Information:
+    * Mbed OS Version: Will currently default to 999999
+    * Compiler ID
+        * ARM = 1
+        * GCC_ARM = 2
+        * IAR = 3
+    * [CPUID Register Information](#cpuid-register-information)
+    * [Compiler Version](#compiler-version)
+* CPU Statistics
+    * Percentage of runtime that the device has spent awake versus in sleep
+* Heap Statistics
+    * Current heap size
+    * Max heap size which refers to the largest the heap has grown to
+* Thread Statistics
+    * Provides information on all running threads in the OS including
+        * Thread ID
+        * Thread Name
+        * Thread State
+        * Thread Priority
+        * Thread Stack Size
+        * Thread Stack Space
+
+#### Compiler Version
+
+| Compiler | Version Layout |
+| -------- | -------------- |
+| ARM      | PVVbbbb (P = Major; VV = Minor; bbbb = build number) |
+| GCC      | VVRRPP  (VV = Version; RR = Revision; PP = Patch)    |
+| IAR      | VRRRPPP (V = Version; RRR = Revision; PPP = Patch)   |
+
+#### CPUID Register Information
+
+| Bit Field | Field Description | Values |
+| --------- | ----------------- | ------ |
+|[31:24]    | Implementer       | 0x41 = ARM |
+|[23:20]    | Variant           | Major revision 0x0  =  Revision 0 |
+|[19:16]    | Architecture      | 0xC  = Baseline Architecture |
+|           |                   | 0xF  = Constant (Mainline Architecture) |
+|[15:4]     | Part Number       | 0xC20 =  Cortex-M0 |
+|           |                   | 0xC60 = Cortex-M0+ |
+|           |                   | 0xC23 = Cortex-M3  |
+|           |                   | 0xC24 = Cortex-M4  |
+|           |                   | 0xC27 = Cortex-M7  |
+|           |                   | 0xD20 = Cortex-M23 |
+|           |                   | 0xD21 = Cortex-M33 |
+|[3:0]      | Revision          | Minor revision: 0x1 = Patch 1 |
+
+
+
+You can view individual examples and additional API information of the statistics collection tools at the bottom of the page in the [related links section](#related-links).
+
+
+### Output
+
+To view the serial output you can use any terminal client of your choosing such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/). Unless otherwise specified, printf defaults to a baud rate of 9600 on Mbed OS.
+
+You can find more information on the Mbed OS configuration tools and serial communication in Mbed OS in the related [related links section](#related-links).
+
+The output should contain the following block transmitted at the blinking LED frequency (actual values may vary depending on your target, build profile, and toolchain):
+
+```
+=============================== SYSTEM INFO  ================================
+Mbed OS Version: 999999
+CPU ID: 0x410fc241
+Compiler ID: 2
+Compiler Version: 60300
+RAM0: Start 0x20000000 Size: 0x30000
+RAM1: Start 0x1fff0000 Size: 0x10000
+ROM0: Start 0x0 Size: 0x100000
+================= CPU STATS =================
+Idle: 98% Usage: 2%
+================ HEAP STATS =================
+Current heap: 1096
+Max heap size: 1096
+================ THREAD STATS ===============
+ID: 0x20001eac
+Name: main_thread
+State: 2
+Priority: 24
+Stack Size: 4096
+Stack Space: 3296
+
+ID: 0x20000f5c
+Name: idle_thread
+State: 1
+Priority: 1
+Stack Size: 512
+Stack Space: 352
+
+ID: 0x20000f18
+Name: timer_thread
+State: 3
+Priority: 40
+Stack Size: 768
+Stack Space: 664
+
+```
+
+## Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
+
+## Related Links
+
+* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html)
+* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html)
+* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html)
+
+### License and contributions
+
+The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
+
+This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,632 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2018 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "ak8963.h"
+#include <stddef.h>
+#include <stdio.h>                // This ert_main.c example uses printf/fflush
+#include "LAAP.h"                      // Model's header file
+#include "rtwtypes.h"
+
+static LAAPModelClass rtObj;           // Instance of model class
+
+void rt_OneStep(void);
+void rt_OneStep(void)
+{
+  static boolean_T OverrunFlag = false;
+
+  // Disable interrupts here
+
+  // Check for overrun
+  if (OverrunFlag) {
+    rtmSetErrorStatus(rtObj.getRTM(), "Overrun");
+    return;
+  }
+
+  OverrunFlag = true;
+
+  // Save FPU context here (if necessary)
+  // Re-enable timer or interrupt here
+  // Set model inputs here
+
+  // Step the model
+  rtObj.step();
+
+  // Get model outputs here
+
+  // Indicate task complete
+  OverrunFlag = false;
+
+  // Disable interrupts here
+  // Restore FPU context here (if necessary)
+  // Enable interrupts here
+}
+/*
+#define AK8963_ADDRESS   0x0C
+#define WHO_AM_I_AK8963  0x00 // should return 0x48
+#define INFO             0x01
+#define AK8963_ST1       0x02  // data ready status bit 0
+#define AK8963_XOUT_L    0x03  // data
+#define AK8963_XOUT_H    0x04
+#define AK8963_YOUT_L    0x05
+#define AK8963_YOUT_H    0x06
+#define AK8963_ZOUT_L    0x07
+#define AK8963_ZOUT_H    0x08
+#define AK8963_ST2       0x09  // Data overflow bit 3 and data read error status bit 2
+#define AK8963_CNTL      0x0A  // Power down (0000), single-measurement (0001), self-test (1000) and Fuse ROM (1111) modes on bits 3:0
+#define AK8963_ASTC      0x0C  // Self test control
+#define AK8963_I2CDIS    0x0F  // I2C disable
+#define AK8963_ASAX      0x10  // Fuse ROM x-axis sensitivity adjustment value
+#define AK8963_ASAY      0x11  // Fuse ROM y-axis sensitivity adjustment value
+#define AK8963_ASAZ      0x12  // Fuse ROM z-axis sensitivity adjustment value
+*/
+#define USER_CTRL        0x6A;
+#define I2C_MST_EN       0x20;
+
+#define MPU6050_ADDR         0xD0
+#define MPU6050_SMPLRT_DIV   0x19
+#define MPU6050_CONFIG       0x1a
+#define MPU6050_GYRO_CONFIG  0x1b
+#define MPU6050_ACCEL_CONFIG 0x1c
+#define MPU6050_WHO_AM_I     0x75
+#define MPU6050_PWR_MGMT_1   0x6b
+#define ACCEL_XOUT_H_REG 0x3B
+#define Alfa_comp 0.96
+
+    double  Ax, Ay, Az, Gx, Gy, Gz,Mx,My,Mz;
+    
+    double   H_senx,H_seny,H_senz;
+    char   name[1];
+     
+    int16_t Mag_X_RAW = 0;
+    int16_t Mag_Y_RAW = 0;
+    int16_t Mag_Z_RAW = 0;
+
+    double avgx,avgy,avgz;
+    double rate,bias=0; 
+    double angle;
+    
+    double pitch_acc=0, roll_acc=0;
+    double pitch_gyro=0, roll_gyro=0;
+    double pitch=0, roll=0,yaw=0;
+    double dtx,dtx1,dtx2,dt=0,dt1,dt2;
+    //global variables for meaured pwm values
+    uint16_t Rip_chnl_n[6],Rip_chnl_p[6];
+    
+    int distx,disty,distz;
+    int distxo,distyo,distzo;
+    int velocityx,velocityy,velocityz;
+    
+//////////////////////To measure pwm using interrupts and timer///////////////////////////////
+InterruptIn ch1(PG_2);
+InterruptIn ch2(PG_3);
+InterruptIn ch3(A4);
+InterruptIn ch4(A5);
+InterruptIn ch5(PG_0);
+InterruptIn ch6(PG_1);
+///////////////////////////////////////////////////////////////////////////////////////////
+//////////////////// pwm out for ESC inputs////////////////////////////////////////////////
+PwmOut u1(PE_9);
+PwmOut u2(PE_11);
+PwmOut u3(PE_12);
+PwmOut u4(PE_14);
+///////////////////////////I2C/////////////////////////////////////////////////////////////
+I2C i2c(PF_15,PF_14);
+//////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////LIDAR serial ports/////////////////////////////////////////
+RawSerial rawz(PD_5,PD_6);
+RawSerial rawx(PC_10,PC_11);
+RawSerial rawy(PC_12,PD_2); 
+//////////////////////////////////////////////////////////////////////////////////////////
+//////////blue light indicator for error in i2c///////////////////////////////////////////
+DigitalOut myled(LED2); 
+//////////////////////////////////////////////////////////////////////////////////////////
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+Timeout onestep;
+
+Timer timer1,timer2;
+////////////////////////////////function initializations/////////////////////////////////
+void stop_counter();
+void start_counter();
+void counters_init();
+
+void dist_x();
+void dist_y();
+void dist_z();
+
+void mpu_init();
+void mpu_read();
+void get_angle();
+void mpu_calibrate();
+void Mag_init();
+void Mag_read();
+
+onestep.attach_us(&rt_OneStep(),100);
+
+int main()
+{   
+    counters_init();
+    
+    pc.baud(115200);
+    
+    rawx.baud(115200);
+    rawy.baud(115200);
+    rawz.baud(115200);
+    
+    rawx.attach(&dist_x);
+    rawy.attach(&dist_y);
+    rawz.attach(&dist_z);
+    
+    mpu_init();
+    //Mag_init();  
+    /*AK8963 mag(&i2c, AK8963::SLAVE_ADDR_1);
+    if(mag.checkConnection() != AK8963::SUCCESS){
+        pc.printf("check connection");
+        
+        }
+    if(mag.setOperationMode(AK8963::MODE_CONTINUOUS_1) != AK8963::SUCCESS){
+        while(1){pc.printf("failed continious mode");}
+        }*/
+    timer1.start(); //////////////timer for channel  
+    timer2.start(); /////////////timer for dt to calculate dt
+   
+    //mpu_calibrate();
+    
+    
+    u1.period_us(20000);
+    u2.period_us(20000);
+    u3.period_us(20000);
+    u4.period_us(20000);
+      
+    
+    while(timer2.read_ms()<5000)
+    {    u1.write((float)rtObj.getu1_());
+        u2.write((float)rtObj.getu2_());
+        u3.write((float)rtObj.getu3 ());
+        u4.write((float)rtObj.getu4 ());
+        
+        }
+     
+    
+
+
+    while (true) 
+    {   int i;
+        //int statusAK8963= AK8963::NOT_DATA_READY;
+    
+         
+        get_angle();
+        
+       /* if(statusAK8963 == AK8963::DATA_READY){
+            AK8963::MagneticVector mag1;
+            mag.getMagneticVector(&mag1);
+            pc.printf("%5.1f,%5.1f,%5.1f\n",mag1.mx,mag1.my,mag1.mz);
+            statusAK8963 = AK8963::NOT_DATA_READY;
+            } else if (statusAK8963 == AK8963::NOT_DATA_READY){
+                }
+        
+        
+        for(int i=1000;i<2000;i++){
+         u1.write((float)i/20000.0);
+        u2.write((float)i/20000.0);
+        u3.write((float)i/20000.0);
+        u4.write((float)i/20000.0);
+        wait(0.0001);}
+        for(int i=2000;i>1000;i--){
+         u1.write((float)i/20000.0);
+        u2.write((float)i/20000.0);
+        u3.write((float)i/20000.0);
+        u4.write((float)i/20000.0);
+        wait(0.0001);}*/
+       // Mag_read();
+       //for(i=0;i<6;i++)
+        //pc.printf("%d\t",Rip_chnl_n[i]);
+      // pc.printf("\n");
+     /*  pc.printf("pitch =  %f\t",pitch);
+       pc.printf("roll =  %f\t",roll);
+       pc.printf("yaw =  %f\t",yaw);
+       */
+       pc.printf("x =  %d\t",distx);
+       pc.printf("y =  %d\t",disty);
+       pc.printf("z =  %d\n",distz);
+       
+       
+       
+       //pc.printf("magx =  %d\t",name[0]);
+       //pc.printf("raw =  %d\t",Mag_X_RAW);
+       //pc.printf("mx =  %f\t",Mx);
+       //wait(0.01);
+      // 
+       }
+}
+
+
+///////////////////////////////////////////////////////////////functions//////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////********************************functions for interrupts*****************************////////////////
+void start_counter_1()
+{
+     Rip_chnl_p[0]=timer1.read_us();
+    }
+void start_counter_2(){
+    Rip_chnl_p[1]=timer1.read_us();
+    }
+void start_counter_3(){
+    Rip_chnl_p[2]=timer1.read_us();
+    }
+void start_counter_4(){
+   Rip_chnl_p[3]=timer1.read_us();
+    }
+void start_counter_5(){
+    Rip_chnl_p[4]=timer1.read_us();
+    }
+void start_counter_6(){
+    Rip_chnl_p[5]=timer1.read_us();
+    }
+void stop_counter_1(){
+   uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[0]=x-Rip_chnl_p[0];
+    }
+void stop_counter_2(){
+    uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[1]=x-Rip_chnl_p[1];
+    }
+void stop_counter_3(){
+   uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[2]=x-Rip_chnl_p[2];
+    }
+void stop_counter_4(){
+    uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[3]=x-Rip_chnl_p[3];
+    }
+void stop_counter_5(){
+    uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[4]=x-Rip_chnl_p[4];
+    }
+void stop_counter_6(){
+    uint32_t x;
+    x=timer1.read_us();
+   Rip_chnl_n[5]=x-Rip_chnl_p[5];
+    }
+
+void counters_init(){
+    ch1.rise(&start_counter_1);
+    ch2.rise(&start_counter_2);
+    ch3.rise(&start_counter_3);
+    ch4.rise(&start_counter_4);
+    ch5.rise(&start_counter_5);
+    ch6.rise(&start_counter_6);
+    ch1.fall(&stop_counter_1);
+    ch2.fall(&stop_counter_2);
+    ch3.fall(&stop_counter_3);
+    ch4.fall(&stop_counter_4);
+    ch5.fall(&stop_counter_5);
+    ch6.fall(&stop_counter_6);
+    }
+    
+
+//////////////////////////////***********************************LIDAR********************************************////////////////
+void dist_x() ///////////*******use this function to get distance it has object of rawserial as argument*******////////////
+    { //int distance;//actual distance measurements of LiDAR
+    int strength;//signal strength of LiDAR
+    int check;//save check value
+    int i;
+    int uartx[9];//save data measured by LiDAR
+    
+        if (rawx.readable())//check if serial port has data input
+    {       
+        if(rawx.getc()==0x59)//assess data package frame header 0x59
+        {
+            uartx[0]=0x59;
+            if(rawx.getc()==0x59)//assess data package frame header 0x59
+                {
+                    uartx[1]=0x59;
+                    for(i=2;i<9;i++)//save data in array
+                        {
+                        uartx[i]=rawx.getc();
+                        }
+                    check=uartx[0]+uartx[1]+uartx[2]+uartx[3]+uartx[4]+uartx[5]+uartx[6]+uartx[7];
+                    if(uartx[8]==(check&0xff))//verify the received data as per protocol
+                        {
+                            
+                            
+                        strength=uartx[4]+uartx[5]*256;//calculate signal strength value
+                        distx=uartx[2]+uartx[3]*256;//calculate distance value in cm
+                        //velocityx = distx - distxo;  ////velocity in meters
+                          //distxo = distx;
+                        }
+                }
+        }
+    } 
+    
+  }
+void dist_y() ///////////*******use this function to get distance it has object of rawserial as argument*******////////////
+    { 
+    int strength;//signal strength of LiDAR
+    int check;//save check value
+    int i;
+    int uarty[9];//save data measured by LiDAR
+    
+        if (rawy.readable())//check if serial port has data input
+    {
+        if(rawy.getc()==0x59)//assess data package frame header 0x59
+        {
+            uarty[0]=0x59;
+            if(rawy.getc()==0x59)//assess data package frame header 0x59
+                {
+                    uarty[1]=0x59;
+                    for(i=2;i<9;i++)//save data in array
+                        {
+                        uarty[i]=rawy.getc();
+                        }
+                    check=uarty[0]+uarty[1]+uarty[2]+uarty[3]+uarty[4]+uarty[5]+uarty[6]+uarty[7];
+                    if(uarty[8]==(check&0xff))//verify the received data as per protocol
+                        {
+                            
+                        strength=uarty[4]+uarty[5]*256;//calculate signal strength value
+                        disty=uarty[2]+uarty[3]*256;//calculate distance value
+                         //velocityy = disty - distyo;  ////velocity in meters
+                          //distyo = disty;
+                        }
+                        
+                }
+        }
+    } 
+    
+  }
+  void dist_z() ///////////*******use this function to get distance it has object of rawserial as argument*******////////////
+    { 
+    int strength;//signal strength of LiDAR
+    int check;//save check value
+    int i;
+    int uartz[9];//save data measured by LiDAR
+    
+        if (rawz.readable())//check if serial port has data input
+    {
+        if(rawz.getc()==0x59)//assess data package frame header 0x59
+        {
+            uartz[0]=0x59;
+            if(rawz.getc()==0x59)//assess data package frame header 0x59
+                {
+                    uartz[1]=0x59;
+                    for(i=2;i<9;i++)//save data in array
+                        {
+                        uartz[i]=rawz.getc();
+                        }
+                    check=uartz[0]+uartz[1]+uartz[2]+uartz[3]+uartz[4]+uartz[5]+uartz[6]+uartz[7];
+                    if(uartz[8]==(check&0xff))//verify the received data as per protocol
+                        { 
+                        strength=uartz[4]+uartz[5]*256;//calculate signal strength value
+                        distz=uartz[2]+uartz[3]*256;//calculate distance value
+                         //velocityz = distz - distzo;  ////velocity in meters
+                          //distzo = distz;
+                        }
+                }
+        }
+    } 
+    
+  }
+  //////////////////////////////////**********velocity**************//////////////////////////////////////
+ 
+
+/////////////////////////////////***********************mpu****************************///////////////////////////////
+
+ void mpu_init()
+ {
+     i2c.frequency(100000);
+    char data_write[2];
+    
+    data_write[0] = MPU6050_PWR_MGMT_1;
+    data_write[1] = 0x00;
+    
+    int status = i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+    if (status != 0)
+     { // Error
+             while (1)
+          {
+            myled = !myled;
+            wait(0.2);
+           }
+    }
+    data_write[0] = USER_CTRL;
+    data_write[1] = I2C_MST_EN;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+     data_write[0] = 0x37;//INT_PIN_CFG;
+    data_write[1] = 0x02;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+    data_write[0] = MPU6050_SMPLRT_DIV;
+    data_write[1] = 0x07;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+    data_write[0] = MPU6050_ACCEL_CONFIG;
+    data_write[1] = 0x00;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    data_write[0] = 0x1d;
+    data_write[1] = 0x06;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    data_write[0] = MPU6050_CONFIG;
+    data_write[1] = 0x00;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+    data_write[0] = MPU6050_GYRO_CONFIG;
+    data_write[1] = 0x00;
+    i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    wait(0.2);
+ }
+
+void mpu_read(){
+    char Rec_Data[14];
+    int16_t Accel_X_RAW = 0;
+    int16_t Accel_Y_RAW = 0;
+    int16_t Accel_Z_RAW = 0;
+    int16_t Temp_raw = 0;
+    int16_t Gyro_X_RAW = 0;
+    int16_t Gyro_Y_RAW = 0;
+    int16_t Gyro_Z_RAW = 0;
+    char data_write[1];
+    
+    // Read 1 BYTES of data starting from ACCEL_XOUT_H register
+    data_write[0] = ACCEL_XOUT_H_REG;
+        i2c.write(MPU6050_ADDR, data_write, 1, 1); // no stop
+        i2c.read(MPU6050_ADDR, Rec_Data, 14);
+    Accel_X_RAW = (int16_t)(Rec_Data[0] << 8 | Rec_Data [1]);
+    Accel_Y_RAW = (int16_t)(Rec_Data[2] << 8 | Rec_Data [3]);
+    Accel_Z_RAW = (int16_t)(Rec_Data[4] << 8 | Rec_Data [5]);
+    
+    Temp_raw = (int16_t)(Rec_Data[6] << 8 | Rec_Data [7]);
+    
+    Gyro_X_RAW = (int16_t)(Rec_Data[8] << 8 | Rec_Data [9]);
+    Gyro_Y_RAW = (int16_t)(Rec_Data[10] << 8 | Rec_Data [11]);
+    Gyro_Z_RAW = (int16_t)(Rec_Data[12] << 8 | Rec_Data [13]);
+    /*** convert the RAW values into acceleration in 'g'
+         we have to divide according to the Full scale value set in FS_SEL
+         I have configured FS_SEL = 0. So I am dividing by 16384.0
+         for more details check ACCEL_CONFIG Register              ****/
+
+    Ax = Accel_X_RAW/16384.0;
+    Ay = Accel_Y_RAW/16384.0;
+    Az = Accel_Z_RAW/16384.0;
+    
+    Gx = Gyro_X_RAW/131.0;
+    Gy = Gyro_Y_RAW/131.0;
+    Gz = Gyro_Z_RAW/131.0;
+    
+    }
+   
+     
+ void get_angle(){
+    
+      mpu_read();
+        dt2=timer2.read_ms();                 ////////****very imp self note check the order of dt1 and dt2*********/////////// 
+        dt=dt2-dt1;
+        dt=dt/1000;
+        
+            roll_acc = (atan2((Ay),sqrt(pow((Ax),2) + pow((Az),2))))*(90*7/11);
+            pitch_acc = ((atan2((-Ax),sqrt(pow((Ay),2) + pow((Az),2))))*(90*7/11));
+       
+              /* COMPLIMENTARY FILTER*/
+            pitch = Alfa_comp*(pitch + Gy*dt) + (1-Alfa_comp)*pitch_acc ;
+            
+            roll = Alfa_comp*(roll + Gx*dt) + (1-Alfa_comp)*roll_acc ;
+            if(abs(Gz)>1)
+           yaw += Gz*dt;
+       dt1=timer2.read_ms();
+         
+         }
+ void mpu_calibrate(void){
+        int i;
+        for(i=0;i<=3000;i++)
+    {
+        //dt2=timer2.read_ms();
+        if(i>0){
+        get_angle();}
+       
+       // dt1=timer2.read_ms();
+        //dt=dt1-dt2;
+        
+        avgx+=roll;
+        avgy+=pitch;
+        //avgz+=yaw;
+     }
+        avgx=avgx/3000;
+        avgy=avgy/3000;
+       // avgz=avgz/2000;
+        }
+ /*void Mag_init(){
+     char raw[3];
+     char data_write[2];
+
+///////////////////////////////////////// Power down magnetometer///////////////////////////////////////////////////////  
+    data_write[0] = AK8963_CNTL;
+    data_write[1] = 0x00;
+    
+      int status = i2c.write(AK8963_ADDRESS, data_write, 2, 0);
+       if (status != 0)
+     { // Error
+             while (1)
+          {
+            myled = !myled;
+            wait(0.2);
+           }
+    }
+    
+    wait(0.01);
+    data_write[0] = 0x6B;                   //////////////////rest magnetometer
+    data_write[1] = 0x80;
+    
+     i2c.write(MPU6050_ADDR, data_write, 2, 0);
+    
+    
+    wait(0.01);
+///////////////////////////////////////// Enter Fuse ROM access mode///////////////////////////////////////////////////  
+  data_write[0] = AK8963_CNTL;
+    data_write[1] = 0x0F;
+    i2c.write(AK8963_ADDRESS, data_write, 2, 0);
+  
+   wait(0.01);
+///////////////////////////////////////// Read the x-, y-, and z-axis calibration values//////////////////////////////   
+   data_write[0] = AK8963_ASAX;
+    i2c.write(AK8963_ADDRESS, data_write, 1, 0);
+    i2c.read(AK8963_ADDRESS, raw, 3);
+// Return x-axis sensitivity adjustment values, etc.    
+  H_senx =  (float)(raw[0] - 128)/256.0f + 1.0f;   
+  H_seny =  (float)(raw[1] - 128)/256.0f + 1.0f;  
+  H_senz =  (float)(raw[2] - 128)/256.0f + 1.0f; 
+   
+    data_write[0] = AK8963_CNTL;
+    data_write[1] = 0x16;
+    i2c.write(AK8963_ADDRESS, data_write, 2, 0);
+    wait(0.01);
+    data_write[0] = 0x0B;
+    data_write[1] = 0x01;
+    i2c.write(AK8963_ADDRESS, data_write, 2, 0);
+    wait(0.01);
+  // Configure the magnetometer for continuous read and highest resolution
+  // set Mscale bit 4 to 1 (0) to enable 16 (14) bit resolution in CNTL register,
+  // and enable continuous mode data acquisition Mmode (bits [3:0]), 0010 for 8 Hz and 0110 for 100 Hz sample rates
+ 
+     }
+void Mag_read(){
+    
+    char data_write[1];
+    char x[1];
+    char rawData[7]; 
+ /////////////read name///////////////////////////////////     
+data_write[0] = WHO_AM_I_AK8963;
+    i2c.write(AK8963_ADDRESS, data_write, 1, 0);
+   i2c.read(AK8963_ADDRESS, name, 1);
+   
+    //////////////////////////////////////
+    data_write[0] = AK8963_ST1;
+    i2c.write(AK8963_ADDRESS, data_write, 1, 0);
+    i2c.read(AK8963_ADDRESS, x, 1);
+    
+   if(x[0] & 0x01) { // wait for magnetometer data ready bit to be set
+    data_write[0] = AK8963_XOUT_L;// Read the six raw data and ST2 registers sequentially into data array
+    i2c.write(AK8963_ADDRESS, data_write, 1, 1);
+    i2c.read(AK8963_ADDRESS, rawData, 7);
+ 
+  uint8_t c = rawData[6]; // End data read by reading ST2 register
+    if(!(c & 0x08)) { // Check if magnetic sensor overflow set, if not then report data
+    Mag_X_RAW = (int16_t)((rawData[1] << 8) | rawData[0]);  // Turn the MSB and LSB into a signed 16-bit value
+    Mag_Y_RAW = (int16_t)((rawData[3] << 8) | rawData[2]) ;  // Data stored as little Endian
+    Mag_Z_RAW = (int16_t)((rawData[5] << 8) | rawData[4]) ; 
+                   }
+          }
+    Mx = Mag_X_RAW*H_senx;
+    My = Mag_Y_RAW*H_seny;
+    Mz = Mag_Z_RAW*H_senz;
+ }*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#679d24833acf0a0b5b0d528576bb37c70863bc4e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,11 @@
+{
+    "target_overrides": {
+        "*": {
+            "platform.stack-stats-enabled": true,
+            "platform.heap-stats-enabled": true,
+            "platform.cpu-stats-enabled": true,
+            "platform.thread-stats-enabled": true,
+            "platform.sys-stats-enabled": true
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stats_report.h	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,133 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2018 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef STATS_REPORT_H
+#define STATS_REPORT_H
+
+#include <inttypes.h>
+#include "mbed.h"
+
+/**
+ *  System Reporting library. Provides runtime information on device:
+ *      - CPU sleep, idle, and wake times
+ *      - Heap and stack usage
+ *      - Thread information
+ *      - Static system information
+ */
+class SystemReport {
+    mbed_stats_heap_t   heap_stats;
+    mbed_stats_cpu_t    cpu_stats;
+    mbed_stats_sys_t    sys_stats;
+
+    mbed_stats_thread_t *thread_stats;
+    uint8_t   thread_count;
+    uint8_t   max_thread_count;
+    uint32_t  sample_time_ms;
+
+public:
+    /**
+     *  SystemReport - Sample rate in ms is required to handle the CPU percent awake logic
+     */
+    SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate)
+    {
+        thread_stats = new mbed_stats_thread_t[max_thread_count];
+
+        // Collect the static system information
+        mbed_stats_sys_get(&sys_stats);
+
+        printf("=============================== SYSTEM INFO  ================================\r\n");
+        printf("Mbed OS Version: %" PRIu32 " \r\n", sys_stats.os_version);
+        printf("CPU ID: 0x%" PRIx32 " \r\n", sys_stats.cpu_id);
+        printf("Compiler ID: %d \r\n", sys_stats.compiler_id);
+        printf("Compiler Version: %" PRIu32 " \r\n", sys_stats.compiler_version);
+
+        for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
+            if (sys_stats.ram_size[i] != 0) {
+                printf("RAM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]);
+            }
+        }
+        for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
+            if (sys_stats.rom_size[i] != 0) {
+                printf("ROM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]);
+            }
+        }
+    }
+
+    ~SystemReport(void)
+    {
+        free(thread_stats);
+    }
+
+    /**
+     *  Report on each Mbed OS Platform stats API
+     */
+    void report_state(void)
+    {
+        report_cpu_stats();
+        report_heap_stats();
+        report_thread_stats();
+
+        // Clear next line to separate subsequent report logs
+        printf("\r\n");
+    }
+
+    /**
+     *  Report CPU idle and awake time in terms of percentage
+     */
+    void report_cpu_stats(void)
+    {
+        static uint64_t prev_idle_time = 0;
+
+        printf("================= CPU STATS =================\r\n");
+
+        // Collect and print cpu stats
+        mbed_stats_cpu_get(&cpu_stats);
+
+        uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
+        uint8_t idle = (diff * 100) / (sample_time_ms * 1000);  // usec;
+        uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000));  // usec;;
+        prev_idle_time = cpu_stats.idle_time;
+
+        printf("Idle: %d%% Usage: %d%% \r\n", idle, usage);
+    }
+
+    /**
+     *  Report current heap stats. Current heap refers to the current amount of
+     *  allocated heap. Max heap refers to the highest amount of heap allocated
+     *  since reset.
+     */
+    void report_heap_stats(void)
+    {
+        printf("================ HEAP STATS =================\r\n");
+
+        // Collect and print heap stats
+        mbed_stats_heap_get(&heap_stats);
+
+        printf("Current heap: %" PRIu32 "\r\n", heap_stats.current_size);
+        printf("Max heap size: %" PRIu32 "\r\n", heap_stats.max_size);
+    }
+
+    /**
+     *  Report active thread stats
+     */
+    void report_thread_stats(void)
+    {
+        printf("================ THREAD STATS ===============\r\n");
+
+        // Collect and print running thread stats
+        int count = mbed_stats_thread_get_each(thread_stats, max_thread_count);
+
+        for (int i = 0; i < count; i++) {
+            printf("ID: 0x%" PRIx32 " \r\n",        thread_stats[i].id);
+            printf("Name: %s \r\n",               thread_stats[i].name);
+            printf("State: %" PRIu32 " \r\n",       thread_stats[i].state);
+            printf("Priority: %" PRIu32 " \r\n",    thread_stats[i].priority);
+            printf("Stack Size: %" PRIu32 " \r\n",  thread_stats[i].stack_size);
+            printf("Stack Space: %" PRIu32 " \r\n", thread_stats[i].stack_space);
+        }
+    }
+};
+
+#endif // STATS_REPORT_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/README.md	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,12 @@
+# Testing examples
+
+Examples are tested using tool [htrun](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests) and templated print log. 
+
+To run the test, use following command after you build the example:
+```
+mbedhtrun -d D: -p COM4 -m K64F -f .\BUILD\K64F\GCC_ARM\blinky.bin --compare-log tests\blinky.log
+```
+
+
+More details about `htrun` are [here](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests#testing-mbed-os-examples).
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/blinky.log	Mon Nov 25 10:51:18 2019 +0000
@@ -0,0 +1,29 @@
+=============================== SYSTEM INFO  ================================
+Mbed OS Version:
+CPU ID: 0x[0-9a-fA-F]+
+Compiler ID: \d+
+Compiler Version:
+================= CPU STATS =================
+Idle: \d+% Usage: \d+%
+================ HEAP STATS =================
+Current heap: \d+
+Max heap size: \d+
+================ THREAD STATS ===============
+ID: 0x[0-9a-fA-F]+
+Name: main
+State: \d+
+Priority: \d+
+Stack Size: \d+
+Stack Space: \d+
+ID: 0x[0-9a-fA-F]+
+Name: rtx_idle
+State: \d+
+Priority: \d+
+Stack Size: \d+
+Stack Space: \d+
+ID: 0x[0-9a-fA-F]+
+Name: rtx_timer
+State: \d+
+Priority: \d+
+Stack Size: \d+
+Stack Space: \d+