KL25 driver for Tango Control System

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.h Source File

main.h

Go to the documentation of this file.
00001 /** @file main.cpp   */
00002 /** @file main.h 
00003 *   
00004 *   \brief 
00005 * Program main features:
00006 *    - enables communication via ethernet
00007 *    - reads data from GY-80 sensor
00008 *    - reads data from built-in touch sensor
00009 *    - enables configuration of Wiz550io ethernet card via PC serial port
00010 *  
00011 * 
00012 * Peripherals connection details:
00013 *
00014 * WIZ550io pins are connected to:
00015 *    - MOSI  ->  PTD2
00016 *    - MISO  ->  PTD3
00017 *    - SCLK  ->  PTD1
00018 *    - CS    ->  PTD0
00019 *    - RST   ->  PTA20
00020 *    - VCC   ->  +3.3V
00021 *    - GND   ->  GND
00022 *    
00023 * IMU GY-80 pins:
00024 *    - VCC   ->  +5V
00025 *    - GND   ->  GND
00026 *    - SDA   ->  PTC9
00027 *    - SCL   ->  PTC8
00028 *    - Connection to other I2C port may not work!!!
00029 *    
00030 * Serial port communication is available via virtual OpenSDA COM port.
00031 * Detailed description about configuring OpenSDA available here: https://mbed.org/handbook/Windows-serial-configuration .
00032 *
00033 * Digital I/O ports pins and names:
00034 *   - PTE20  ->  P1
00035 *   - PTE21  ->  P2
00036 *   - PTE22  ->  P3
00037 *   - PTE23  ->  P4
00038 *   - PTE29  ->  P5
00039 *   - PTE30  ->  P6
00040 *
00041 * Ethernet commands:
00042 * Available commands:
00043 *   - "read_sensor" - reads all sensor data - Reply form: "Sensor data: magnX, magnY, magnZ, accelX, accelY, accelZ, gyroX, gyroY, gyroZ, TSIposition"
00044 *   - "check_ports" - reads ports P1 to P6 status - Reply form: "Port values: P1: %d, P2: %d, P3: %d, P4: %d, P5: %d, P6: %d"
00045 * Single port commands:
00046 *   - "set_P$_i" - sets port as input    - Reply: "P1 is now set as input"
00047 *   - "set_P$_o" - sets port as output   - Reply: "P1 is now set as output"
00048 *   - "set_P$_1" - sets port as 1 (High) - Reply: "P1 value is now: %d "
00049 *   - "set_P$_0" - sets port as 0 (low)  - Reply: "P1 value is now: %d " 
00050 *   - "get_P$"   - gets port value       - Reply: "P1 value: %d"
00051 *   -  $ mark is port number from 1-6 
00052 *
00053 *   @author Mateusz Jaskula
00054 *
00055 */
00056 
00057 
00058 
00059 // Set server communication port to 22
00060 #define ECHO_SERVER_PORT   22
00061 
00062 
00063 /// SPI communication with WIZ550io initialization
00064 SPI spi(PTD2, PTD3, PTD1); /// mosi, miso, sclk
00065 
00066 /// Ethernet communication via WIZ550io
00067 WIZnetInterface eth(&spi, PTD0, PTA20); /// spi, cs, reset
00068 
00069 /// Serial communication init
00070 Serial pc(USBTX,USBRX);
00071 
00072 /// TSI Electrodes definition:
00073 #define ELEC0 9
00074 /// TSI Electrodes definition:
00075 #define ELEC1 10
00076 
00077 
00078 /// port P1 is connected to PTE20 pin
00079 DigitalInOut P1(PTE20);                         
00080 /// port P1 is connected to PTE21 pin
00081 DigitalInOut P2(PTE21);                         
00082 /// port P2 is connected to PTE22 pin
00083 DigitalInOut P3(PTE22);                         
00084 /// port P3 is connected to PTE23 pin
00085 DigitalInOut P4(PTE23);                         
00086 /// port P4 is connected to PTE29 pin
00087 DigitalInOut P5(PTE29);                         
00088 /// port P5 is connected to PTE30 pin
00089 DigitalInOut P6(PTE30);                         
00090 
00091 
00092 /// Defines use of DHCP protocol or Static IP Configuration
00093 bool USE_DHCP = true;
00094 
00095 // Static IP setting. Using MAC stored in WIZ550io
00096  char IP_Addr[16] = "192.168.133.015";          /// IP
00097  char IP_Subnet[16]  = "255.255.255.000";       /// Subnet Mask
00098  char IP_Gateway[16] = "192.168.133.001";       /// Gateway
00099 
00100 /// MAC Adress global variable
00101 uint8_t mac[6];
00102 
00103 /// GY80 IMU sensor Object
00104 GY80 sensor;
00105 
00106 // GY80 Data is being hold here
00107 float  magn[3];     /// Current magnitude
00108 float accel[3];     /// Current acceleration
00109 float  gyro[3];     /// current gyroscope
00110 
00111 /// TSI Slider object:
00112 TSIAnalogSlider tsi(ELEC0, ELEC1, 100);
00113 
00114 /// TSI Slider position:
00115 float TSI_pos;
00116 
00117 /// Ticker generates time based interrups to read data from sensors in 10ms intervals.
00118 Ticker tick1;
00119 
00120 
00121 //Functions declaration:
00122 // Initializes eth communication with MAC, IP, Subnet Mask asd Gateway
00123 int init_eth ();
00124 // Handles ethernet communication
00125 void eth_comm ();
00126 // Reads data from sensor with 1ms freq
00127 void read_data ();
00128 // Reads commands and takes action
00129 void comm_handler (char* command);
00130 // Enables configuration mode
00131 void SerialInterHandler ();
00132 // 5 sec serial menu with info how to enter configuration mode
00133 void menu_prop ();