Firmware for the controller of the JRO Radar Controller.

Dependencies:   CR2 EthernetInterface FreescaleIAP I2CLCD SerialDriver jro k64f_EthLink mbed-rtos mbed

Fork of JRO_DDSv2 by Miguel Urco

Committer:
joaquinbvw
Date:
Mon Mar 14 19:52:12 2016 +0000
Revision:
6:20e6ba387783
Parent:
5:12b90c023958
First attempt for the JRO Radar Controller firmware.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miguelcordero191 0:c9bdd57867af 1 /*
miguelcordero191 0:c9bdd57867af 2 * Author: MIGUEL URCO
miguelcordero191 0:c9bdd57867af 3 * Date: 10/11/2014
miguelcordero191 0:c9bdd57867af 4 * Notes: Checks the Ethernet cable connection
miguelcordero191 0:c9bdd57867af 5 */
miguelcordero191 0:c9bdd57867af 6 #if 1
miguelcordero191 0:c9bdd57867af 7
miguelcordero191 0:c9bdd57867af 8 #include "mbed.h"
miguelcordero191 0:c9bdd57867af 9 #include "rtos.h"
miguelcordero191 1:072a0ab47d9c 10 #include "EthernetInterface.h"
miguelcordero191 0:c9bdd57867af 11 #include "SerialDriver.h"
miguelcordero191 3:f84802422619 12 #include "I2CLCD.h"
miguelcordero191 0:c9bdd57867af 13
miguelcordero191 3:f84802422619 14 #include "k64f_EthLink.h"
miguelcordero191 3:f84802422619 15 #include "EthUtils.h"
miguelcordero191 3:f84802422619 16 #include "JroIpdata.h"
miguelcordero191 3:f84802422619 17 #include "JroSIR.h"
joaquinbvw 5:12b90c023958 18 #include "CR2.h"
miguelcordero191 3:f84802422619 19
miguelcordero191 3:f84802422619 20 #define mbed_reset NVIC_SystemReset
miguelcordero191 1:072a0ab47d9c 21
miguelcordero191 0:c9bdd57867af 22 #define BUFFER_SIZE 256
miguelcordero191 0:c9bdd57867af 23 static char rx_buffer[BUFFER_SIZE];
miguelcordero191 0:c9bdd57867af 24 static char tx_buffer[BUFFER_SIZE];
miguelcordero191 0:c9bdd57867af 25
miguelcordero191 3:f84802422619 26 //THREADS
miguelcordero191 3:f84802422619 27 Thread *ser_thread_ptr;
miguelcordero191 3:f84802422619 28 Thread *eth_thread_ptr;
miguelcordero191 3:f84802422619 29 Thread *lcd_thread_ptr;
joaquinbvw 5:12b90c023958 30 Mutex cr2_mutex;
miguelcordero191 3:f84802422619 31 Mutex eth_mutex;
miguelcordero191 3:f84802422619 32 Mutex lcd_mutex;
miguelcordero191 3:f84802422619 33
miguelcordero191 0:c9bdd57867af 34 //SERIAL
miguelcordero191 1:072a0ab47d9c 35 #define SERIAL_BAUDRATE 1000000
joaquinbvw 5:12b90c023958 36 const char* UART_MSG_OK = "CR2 Successful";
joaquinbvw 5:12b90c023958 37 const char* UART_MSG_KO = "CR2 Unsuccessful";
joaquinbvw 5:12b90c023958 38 const char* UART_MSG_NC = "CR2 Not connected";
miguelcordero191 3:f84802422619 39
miguelcordero191 3:f84802422619 40 Serial screen(USBTX, USBRX);
miguelcordero191 3:f84802422619 41 SerialDriver uart(D1, D0);
miguelcordero191 3:f84802422619 42
miguelcordero191 1:072a0ab47d9c 43
miguelcordero191 3:f84802422619 44 //LCD
miguelcordero191 3:f84802422619 45 I2C i2c_device(I2C_SDA, I2C_SCL);
miguelcordero191 3:f84802422619 46 I2CLCD lcd(i2c_device, 0x78, LCD20x2);
miguelcordero191 3:f84802422619 47
joaquinbvw 5:12b90c023958 48 //const char LCD_WELCOME[] = " JICAMARCA - CR2 ";
miguelcordero191 3:f84802422619 49 const char LCD_IP_INI[] = "IP : checking... ";
miguelcordero191 3:f84802422619 50 const char LCD_IP_NC[] = "IP : Not connected ";
miguelcordero191 3:f84802422619 51 //const char LCD_IP_NI[] = "IP : Not initialized";
miguelcordero191 3:f84802422619 52
joaquinbvw 5:12b90c023958 53 const char LCD_CR2_INI[] = "CR2: checking... ";
joaquinbvw 5:12b90c023958 54 const char LCD_CR2_NC[] = "CR2: Not detected ";
joaquinbvw 5:12b90c023958 55 const char LCD_CR2_ENA[] = " Outputs Enabled ";
joaquinbvw 5:12b90c023958 56 const char LCD_CR2_DIS[] = " Otuputs Disabled ";
miguelcordero191 0:c9bdd57867af 57
miguelcordero191 0:c9bdd57867af 58 //ETHERNET
miguelcordero191 1:072a0ab47d9c 59 #define ECHO_SERVER_PORT 2000
miguelcordero191 3:f84802422619 60 const char DEVICE_NAME[] = "jrodds";
miguelcordero191 1:072a0ab47d9c 61
miguelcordero191 0:c9bdd57867af 62 IpData ipData(tx_buffer);
miguelcordero191 3:f84802422619 63
miguelcordero191 3:f84802422619 64 k64fEthLink eth_link;
miguelcordero191 0:c9bdd57867af 65 EthernetInterface eth;
miguelcordero191 0:c9bdd57867af 66 TCPSocketServer server;
miguelcordero191 0:c9bdd57867af 67
joaquinbvw 5:12b90c023958 68 //CR2
miguelcordero191 0:c9bdd57867af 69 SPI spi_device(D11, D12, D13);
miguelcordero191 0:c9bdd57867af 70
joaquinbvw 5:12b90c023958 71 DigitalOut cr2_mreset(D4);
joaquinbvw 5:12b90c023958 72 DigitalOut cr2_outramp(D5);
joaquinbvw 5:12b90c023958 73 DigitalOut cr2_sp_mode(D6);
joaquinbvw 5:12b90c023958 74 DigitalOut cr2_cs(D7);
joaquinbvw 5:12b90c023958 75 DigitalOut cr2_io_reset(D9);
joaquinbvw 5:12b90c023958 76 DigitalInOut cr2_updclk(D10);
miguelcordero191 0:c9bdd57867af 77
joaquinbvw 5:12b90c023958 78 CR2 cr2_device(&spi_device, &cr2_mreset, &cr2_outramp, &cr2_sp_mode, &cr2_cs, &cr2_io_reset, &cr2_updclk);
miguelcordero191 0:c9bdd57867af 79
miguelcordero191 0:c9bdd57867af 80 //LEDS
miguelcordero191 0:c9bdd57867af 81 DigitalOut LedR(LED1);
miguelcordero191 0:c9bdd57867af 82 DigitalOut LedG(LED2);
miguelcordero191 0:c9bdd57867af 83 DigitalOut LedB(LED3);
miguelcordero191 0:c9bdd57867af 84
miguelcordero191 3:f84802422619 85 DigitalIn IPResetButton(PTB2, PullUp);
miguelcordero191 3:f84802422619 86
miguelcordero191 3:f84802422619 87 int printAddr(char *_ip, char *_mask, char *_gateway){
miguelcordero191 3:f84802422619 88 lcd.printf(_ip, 0, 0);
miguelcordero191 3:f84802422619 89 lcd.printf(_mask, 0, 1);
miguelcordero191 3:f84802422619 90
miguelcordero191 3:f84802422619 91 screen.putc(0x0A);
miguelcordero191 3:f84802422619 92 screen.putc(0x0D);
miguelcordero191 3:f84802422619 93
miguelcordero191 3:f84802422619 94 for (int i=0; i<20; i++){
miguelcordero191 3:f84802422619 95 screen.putc(_ip[i]);
miguelcordero191 3:f84802422619 96 }
miguelcordero191 3:f84802422619 97 screen.putc(0x0A);
miguelcordero191 3:f84802422619 98 screen.putc(0x0D);
miguelcordero191 3:f84802422619 99
miguelcordero191 3:f84802422619 100 for (int i=0; i<20; i++){
miguelcordero191 3:f84802422619 101 screen.putc(_mask[i]);
miguelcordero191 3:f84802422619 102 }
miguelcordero191 3:f84802422619 103
miguelcordero191 3:f84802422619 104 screen.putc(0x0A);
miguelcordero191 3:f84802422619 105 screen.putc(0x0D);
miguelcordero191 3:f84802422619 106
miguelcordero191 3:f84802422619 107 for (int i=0; i<20; i++){
miguelcordero191 3:f84802422619 108 screen.putc(_gateway[i]);
miguelcordero191 3:f84802422619 109 }
miguelcordero191 3:f84802422619 110
miguelcordero191 3:f84802422619 111 screen.putc(0x0A);
miguelcordero191 3:f84802422619 112 screen.putc(0x0D);
miguelcordero191 3:f84802422619 113
miguelcordero191 3:f84802422619 114 return 1;
miguelcordero191 3:f84802422619 115 }
miguelcordero191 3:f84802422619 116
miguelcordero191 3:f84802422619 117 int wasIPResetPressed(){
miguelcordero191 3:f84802422619 118
miguelcordero191 3:f84802422619 119 if (IPResetButton)
miguelcordero191 3:f84802422619 120 return 0;
miguelcordero191 3:f84802422619 121
miguelcordero191 3:f84802422619 122 //Wait until button will be released
miguelcordero191 3:f84802422619 123 while(!IPResetButton){
miguelcordero191 3:f84802422619 124 Thread::wait(50);
miguelcordero191 3:f84802422619 125 }
miguelcordero191 3:f84802422619 126
miguelcordero191 3:f84802422619 127 return 1;
miguelcordero191 3:f84802422619 128 }
miguelcordero191 3:f84802422619 129
miguelcordero191 3:f84802422619 130
miguelcordero191 0:c9bdd57867af 131 void waitSerialData_thread(void const *args){
miguelcordero191 0:c9bdd57867af 132
miguelcordero191 0:c9bdd57867af 133 int n;
miguelcordero191 1:072a0ab47d9c 134 bool successful;
miguelcordero191 0:c9bdd57867af 135
miguelcordero191 1:072a0ab47d9c 136 //Thread::signal_wait(0x1);
miguelcordero191 1:072a0ab47d9c 137
miguelcordero191 2:f9e1bcb3409a 138 LedG = 1;
miguelcordero191 0:c9bdd57867af 139
miguelcordero191 2:f9e1bcb3409a 140 uart.baud(SERIAL_BAUDRATE);
miguelcordero191 0:c9bdd57867af 141
miguelcordero191 0:c9bdd57867af 142 while(1){
miguelcordero191 2:f9e1bcb3409a 143 LedG = 0;
miguelcordero191 1:072a0ab47d9c 144 successful = false;
miguelcordero191 0:c9bdd57867af 145
miguelcordero191 0:c9bdd57867af 146 if (uart.isRxBufferEmpty()){
miguelcordero191 3:f84802422619 147 Thread::wait(100);
miguelcordero191 0:c9bdd57867af 148 continue;
miguelcordero191 0:c9bdd57867af 149 }
miguelcordero191 0:c9bdd57867af 150
miguelcordero191 2:f9e1bcb3409a 151 Thread::wait(10);
miguelcordero191 1:072a0ab47d9c 152 n = uart.read(rx_buffer, 255, false);
miguelcordero191 2:f9e1bcb3409a 153
miguelcordero191 2:f9e1bcb3409a 154 //******************** BLINK LED *****************************
miguelcordero191 2:f9e1bcb3409a 155 for (int i=0; i<n; i++){
miguelcordero191 2:f9e1bcb3409a 156 LedG = !LedG;
miguelcordero191 2:f9e1bcb3409a 157 Thread::wait(10);
miguelcordero191 2:f9e1bcb3409a 158 }
miguelcordero191 3:f84802422619 159 lcd.printf("Serial command received", 0, 1);
joaquinbvw 5:12b90c023958 160 //******************** CR2 NOT INITIALIZED *******************
joaquinbvw 5:12b90c023958 161 if (!cr2_device.wasInitialized()){
miguelcordero191 3:f84802422619 162 for (int i=0; i<strlen(UART_MSG_NC); i++){
miguelcordero191 3:f84802422619 163 uart.putc(UART_MSG_NC[i]);
miguelcordero191 2:f9e1bcb3409a 164 }
miguelcordero191 2:f9e1bcb3409a 165 continue;
miguelcordero191 2:f9e1bcb3409a 166 }
joaquinbvw 5:12b90c023958 167 //Lock cr2_device before execute any command
joaquinbvw 5:12b90c023958 168 cr2_mutex.lock();
miguelcordero191 2:f9e1bcb3409a 169
miguelcordero191 2:f9e1bcb3409a 170 //********************* SUCCESSFUL DATA **********************
joaquinbvw 5:12b90c023958 171 //if (n == 40)
joaquinbvw 5:12b90c023958 172 //if (cr2_device.setAllDevice(rx_buffer) == 1)
joaquinbvw 5:12b90c023958 173 //successful = true;
miguelcordero191 0:c9bdd57867af 174
miguelcordero191 2:f9e1bcb3409a 175 //******************** REPLY UART*****************************
miguelcordero191 3:f84802422619 176 if (successful)
miguelcordero191 3:f84802422619 177 //for (int i=0; i<strlen(UART_MSG_OK); i++)
miguelcordero191 3:f84802422619 178 uart.printf(UART_MSG_OK);
miguelcordero191 3:f84802422619 179
miguelcordero191 3:f84802422619 180 else
miguelcordero191 3:f84802422619 181 uart.printf(UART_MSG_KO);
miguelcordero191 3:f84802422619 182
joaquinbvw 5:12b90c023958 183 cr2_mutex.unlock();
miguelcordero191 0:c9bdd57867af 184
miguelcordero191 0:c9bdd57867af 185 }
miguelcordero191 0:c9bdd57867af 186
miguelcordero191 0:c9bdd57867af 187 }
miguelcordero191 0:c9bdd57867af 188
miguelcordero191 0:c9bdd57867af 189 void waitEthData_thread(void const *args){
miguelcordero191 0:c9bdd57867af 190
miguelcordero191 1:072a0ab47d9c 191 TCPSocketConnection client;
miguelcordero191 3:f84802422619 192 //int status;
miguelcordero191 1:072a0ab47d9c 193 int n, totalSize=0;
miguelcordero191 3:f84802422619 194 char _ip[MAX_IP_LEN], _mask[MAX_IP_LEN], _gateway[MAX_IP_LEN];
miguelcordero191 0:c9bdd57867af 195
miguelcordero191 3:f84802422619 196 //Lock ethernet resource until initial configuration will be loaded
miguelcordero191 3:f84802422619 197 eth_mutex.lock();
miguelcordero191 3:f84802422619 198
miguelcordero191 3:f84802422619 199 readIpConfig(_ip, _mask, _gateway);
miguelcordero191 0:c9bdd57867af 200
miguelcordero191 2:f9e1bcb3409a 201 LedB = 1;
miguelcordero191 0:c9bdd57867af 202
miguelcordero191 3:f84802422619 203 if (eth.init(_ip, _mask, _gateway) != 0){
miguelcordero191 3:f84802422619 204 //mbed_reset();
miguelcordero191 3:f84802422619 205 }
miguelcordero191 3:f84802422619 206
miguelcordero191 1:072a0ab47d9c 207 eth.setName(DEVICE_NAME);
miguelcordero191 3:f84802422619 208 eth.connect();
miguelcordero191 3:f84802422619 209 Thread::wait(200);
miguelcordero191 3:f84802422619 210 eth_mutex.unlock();
miguelcordero191 3:f84802422619 211
miguelcordero191 3:f84802422619 212 //If ethernet connection fails then try again
miguelcordero191 3:f84802422619 213 while(eth_link.GetELink() != 0){
miguelcordero191 3:f84802422619 214 eth.connect();
miguelcordero191 3:f84802422619 215 Thread::wait(200);
miguelcordero191 3:f84802422619 216 }
miguelcordero191 0:c9bdd57867af 217
miguelcordero191 1:072a0ab47d9c 218 server.bind(ECHO_SERVER_PORT);
miguelcordero191 1:072a0ab47d9c 219 server.listen(1);
miguelcordero191 0:c9bdd57867af 220
miguelcordero191 2:f9e1bcb3409a 221 LedB = 0;
miguelcordero191 0:c9bdd57867af 222
miguelcordero191 1:072a0ab47d9c 223 while(1)
miguelcordero191 1:072a0ab47d9c 224 {
miguelcordero191 0:c9bdd57867af 225 LedB = 0;
miguelcordero191 1:072a0ab47d9c 226 n = 0;
miguelcordero191 1:072a0ab47d9c 227 totalSize = 0;
miguelcordero191 2:f9e1bcb3409a 228
miguelcordero191 1:072a0ab47d9c 229 server.accept(client);
miguelcordero191 1:072a0ab47d9c 230
miguelcordero191 2:f9e1bcb3409a 231 client.set_blocking(false, 500); // Timeout after (0.5)s
miguelcordero191 0:c9bdd57867af 232
miguelcordero191 1:072a0ab47d9c 233 while (true) {
miguelcordero191 2:f9e1bcb3409a 234 LedR = !LedR;
miguelcordero191 1:072a0ab47d9c 235 n = client.receive(rx_buffer, sizeof(rx_buffer));
miguelcordero191 1:072a0ab47d9c 236 if (n <= 0) break;
miguelcordero191 1:072a0ab47d9c 237 totalSize += n;
miguelcordero191 2:f9e1bcb3409a 238 Thread::wait(10);
miguelcordero191 2:f9e1bcb3409a 239 }
miguelcordero191 2:f9e1bcb3409a 240
miguelcordero191 2:f9e1bcb3409a 241 LedB = 1;
miguelcordero191 2:f9e1bcb3409a 242
miguelcordero191 2:f9e1bcb3409a 243 if (totalSize < 1){
miguelcordero191 2:f9e1bcb3409a 244 client.close();
miguelcordero191 2:f9e1bcb3409a 245 continue;
miguelcordero191 1:072a0ab47d9c 246 }
miguelcordero191 1:072a0ab47d9c 247
miguelcordero191 2:f9e1bcb3409a 248 if (ipData.decode(rx_buffer, totalSize) == 0){
miguelcordero191 3:f84802422619 249 client.send(ipData.getKOData(0x00), ipData.getKODataLen());
miguelcordero191 2:f9e1bcb3409a 250 client.close();
miguelcordero191 0:c9bdd57867af 251 continue;
miguelcordero191 2:f9e1bcb3409a 252 }
miguelcordero191 3:f84802422619 253 lcd.printf("Eth command received", 0, 1);
joaquinbvw 5:12b90c023958 254 //******************** CR2 NOT INITIALIZED *******************
joaquinbvw 5:12b90c023958 255 if (!cr2_device.wasInitialized()){
miguelcordero191 2:f9e1bcb3409a 256 client.send(ipData.getNIData(ipData.getCmd()), ipData.getNIDataLen());
miguelcordero191 2:f9e1bcb3409a 257 client.close();
miguelcordero191 0:c9bdd57867af 258 continue;
miguelcordero191 2:f9e1bcb3409a 259 }
miguelcordero191 0:c9bdd57867af 260
miguelcordero191 2:f9e1bcb3409a 261 //******************** REPLY REQ *****************************
miguelcordero191 3:f84802422619 262
miguelcordero191 3:f84802422619 263 //********* IP CONFIG ****
miguelcordero191 0:c9bdd57867af 264 if (ipData.getCmd() == CMD_CHANGE_IP){
miguelcordero191 3:f84802422619 265
miguelcordero191 3:f84802422619 266 if ( splitIpConf(ipData.getPayload(), _ip, _mask, _gateway) ){
miguelcordero191 3:f84802422619 267 //changing ip and reseting device
miguelcordero191 3:f84802422619 268 client.send(ipData.getOKData(ipData.getCmd()), ipData.getOKDataLen());
miguelcordero191 3:f84802422619 269 Thread::wait(200);
miguelcordero191 3:f84802422619 270 client.close();
miguelcordero191 3:f84802422619 271
miguelcordero191 3:f84802422619 272 saveIpConfig(_ip, _mask, _gateway);
miguelcordero191 3:f84802422619 273 eth.setNewAddr(_ip, _mask, _gateway);
miguelcordero191 3:f84802422619 274 Thread::wait(500);
miguelcordero191 3:f84802422619 275 //mbed_reset();
miguelcordero191 3:f84802422619 276 continue;
miguelcordero191 3:f84802422619 277 }
miguelcordero191 3:f84802422619 278 else{
miguelcordero191 3:f84802422619 279 client.send(ipData.getKOData(ipData.getCmd()), ipData.getKODataLen());
miguelcordero191 3:f84802422619 280 Thread::wait(200);
miguelcordero191 3:f84802422619 281 client.close();
miguelcordero191 3:f84802422619 282 continue;
miguelcordero191 3:f84802422619 283 }
miguelcordero191 0:c9bdd57867af 284 }
miguelcordero191 0:c9bdd57867af 285
joaquinbvw 5:12b90c023958 286 //Lock cr2_device before execute any command
joaquinbvw 5:12b90c023958 287 cr2_mutex.lock();
miguelcordero191 3:f84802422619 288
miguelcordero191 3:f84802422619 289 // ********** OTHER COMMANDS
joaquinbvw 5:12b90c023958 290 cr2_device.writeBlock(ipData.getPayloadLen(),ipData.getPayload());
joaquinbvw 5:12b90c023958 291 //cr2_device.setCommand(ipData.getCmd(), ipData.getPayload(), ipData.getPayloadLen());
joaquinbvw 5:12b90c023958 292 ipData.encode(ipData.getCmd(), cr2_device.getCmdAnswer(), cr2_device.getCmdAnswerLen());
miguelcordero191 0:c9bdd57867af 293
miguelcordero191 1:072a0ab47d9c 294 client.send(ipData.getTxData(), ipData.getTxDataLen());
miguelcordero191 3:f84802422619 295 Thread::wait(10);
miguelcordero191 1:072a0ab47d9c 296 client.close();
miguelcordero191 0:c9bdd57867af 297
joaquinbvw 5:12b90c023958 298 cr2_mutex.unlock();
miguelcordero191 0:c9bdd57867af 299 }
miguelcordero191 0:c9bdd57867af 300 }
miguelcordero191 0:c9bdd57867af 301
miguelcordero191 3:f84802422619 302 void lcdView_thread(void const *args){
miguelcordero191 3:f84802422619 303
miguelcordero191 3:f84802422619 304 char c=0;
miguelcordero191 3:f84802422619 305 char lcd_status[2]="\xF7";
miguelcordero191 3:f84802422619 306
joaquinbvw 5:12b90c023958 307 lcd.printf(LCD_CR2_INI, 0, 0);
miguelcordero191 3:f84802422619 308 lcd.printf(LCD_IP_INI, 0, 1);
miguelcordero191 3:f84802422619 309 Thread::wait(2000);
miguelcordero191 3:f84802422619 310
miguelcordero191 3:f84802422619 311 while(1){
miguelcordero191 3:f84802422619 312 /*
miguelcordero191 3:f84802422619 313 if (lcd_mutex.trylock()==false){
miguelcordero191 3:f84802422619 314 Thread::wait(1000);
miguelcordero191 3:f84802422619 315 continue;
miguelcordero191 3:f84802422619 316 }
miguelcordero191 3:f84802422619 317 */
miguelcordero191 3:f84802422619 318
joaquinbvw 5:12b90c023958 319 if (cr2_device.wasInitialized()){
miguelcordero191 3:f84802422619 320
miguelcordero191 3:f84802422619 321 //RF ENABLED OR DISABLED
miguelcordero191 3:f84802422619 322 if (c==1){
joaquinbvw 5:12b90c023958 323 //if(cr2_device.isRFEnabled()){
joaquinbvw 5:12b90c023958 324 //lcd.printf(LCD_CR2_ENA, 0, 0);
joaquinbvw 5:12b90c023958 325 //}
joaquinbvw 5:12b90c023958 326 //else{
joaquinbvw 5:12b90c023958 327 lcd.printf(LCD_CR2_DIS, 0, 0);
joaquinbvw 5:12b90c023958 328 //}
miguelcordero191 3:f84802422619 329 lcd_status[0] = 0x01;
miguelcordero191 3:f84802422619 330 lcd.printf(lcd_status, 19, 0);
miguelcordero191 3:f84802422619 331
miguelcordero191 3:f84802422619 332 }
miguelcordero191 3:f84802422619 333 //FREQUENCY
miguelcordero191 3:f84802422619 334 if (c==3){
miguelcordero191 3:f84802422619 335 char tmp[21];
joaquinbvw 5:12b90c023958 336 sprintf(tmp, "Fout = %7.5f*Clk", cr2_device.getFreqFactor1());
miguelcordero191 3:f84802422619 337 lcd.printf(tmp, 0, 0);
miguelcordero191 3:f84802422619 338 }
miguelcordero191 3:f84802422619 339 if (c==5){
miguelcordero191 3:f84802422619 340 char tmp[21];
joaquinbvw 5:12b90c023958 341 sprintf(tmp, "Modulation = %s", cr2_device.getModeStr() );
miguelcordero191 3:f84802422619 342 lcd.printf(tmp, 0, 0);
miguelcordero191 3:f84802422619 343 }
miguelcordero191 3:f84802422619 344 }
miguelcordero191 3:f84802422619 345 else{
joaquinbvw 5:12b90c023958 346 lcd.printf(LCD_CR2_NC, 0, 0);
miguelcordero191 3:f84802422619 347 lcd_status[0] = lcd_status[0] ^ 0xFF;
miguelcordero191 3:f84802422619 348 lcd.printf(lcd_status, 19, 0);
miguelcordero191 3:f84802422619 349 }
miguelcordero191 3:f84802422619 350
miguelcordero191 3:f84802422619 351 //Verify if ethernet resource is free
miguelcordero191 3:f84802422619 352 if (eth_mutex.trylock()){
miguelcordero191 3:f84802422619 353 if (eth_link.GetELink() == 0){
miguelcordero191 3:f84802422619 354 if (c==0){
miguelcordero191 3:f84802422619 355 lcd.printf("IP : ", 0, 1);
miguelcordero191 3:f84802422619 356 lcd.printf(eth.getIPAddress(), 5, 1);
miguelcordero191 3:f84802422619 357 }
miguelcordero191 3:f84802422619 358 if (c==2){
miguelcordero191 3:f84802422619 359 lcd.printf("MSK: ", 0, 1);
miguelcordero191 3:f84802422619 360 lcd.printf(eth.getNetworkMask(), 5, 1);
miguelcordero191 3:f84802422619 361 }
miguelcordero191 3:f84802422619 362 if (c==4){
miguelcordero191 3:f84802422619 363 lcd.printf("GW : ", 0, 1);
miguelcordero191 3:f84802422619 364 lcd.printf(eth.getGateway(), 5, 1);
miguelcordero191 3:f84802422619 365 }
miguelcordero191 3:f84802422619 366 }
miguelcordero191 3:f84802422619 367 else{
miguelcordero191 3:f84802422619 368 lcd.printf(LCD_IP_NC, 0, 1);
miguelcordero191 3:f84802422619 369 }
miguelcordero191 3:f84802422619 370 eth_mutex.unlock();
miguelcordero191 3:f84802422619 371 }
miguelcordero191 3:f84802422619 372 else{
miguelcordero191 3:f84802422619 373 lcd.printf(LCD_IP_INI, 0, 1);
miguelcordero191 3:f84802422619 374 }
miguelcordero191 3:f84802422619 375 c++;
miguelcordero191 3:f84802422619 376 if (c>5) c=0;
miguelcordero191 3:f84802422619 377 //lcd_mutex.unlock();
miguelcordero191 3:f84802422619 378 Thread::wait(1000);
miguelcordero191 3:f84802422619 379 }
miguelcordero191 3:f84802422619 380
miguelcordero191 3:f84802422619 381 }
miguelcordero191 3:f84802422619 382
miguelcordero191 0:c9bdd57867af 383 int main()
miguelcordero191 3:f84802422619 384 {
miguelcordero191 0:c9bdd57867af 385 screen.baud(9600);
miguelcordero191 1:072a0ab47d9c 386
miguelcordero191 0:c9bdd57867af 387 screen.putc(0x0A);
miguelcordero191 0:c9bdd57867af 388 screen.putc(0x0D);
miguelcordero191 0:c9bdd57867af 389 screen.putc(0x33);
miguelcordero191 2:f9e1bcb3409a 390 screen.putc(0x33);
miguelcordero191 0:c9bdd57867af 391
miguelcordero191 1:072a0ab47d9c 392 ser_thread_ptr = new Thread(&waitSerialData_thread);
miguelcordero191 0:c9bdd57867af 393 eth_thread_ptr = new Thread(&waitEthData_thread);
miguelcordero191 3:f84802422619 394 lcd_thread_ptr = new Thread(&lcdView_thread);
miguelcordero191 0:c9bdd57867af 395
miguelcordero191 2:f9e1bcb3409a 396 LedR = 1;
miguelcordero191 0:c9bdd57867af 397
miguelcordero191 0:c9bdd57867af 398 screen.putc(0x33);
miguelcordero191 2:f9e1bcb3409a 399 screen.putc(0x32);
miguelcordero191 0:c9bdd57867af 400
miguelcordero191 0:c9bdd57867af 401 while(true){
joaquinbvw 5:12b90c023958 402 if (cr2_device.init())
miguelcordero191 0:c9bdd57867af 403 break;
miguelcordero191 3:f84802422619 404
miguelcordero191 2:f9e1bcb3409a 405 LedR = !LedR;
miguelcordero191 0:c9bdd57867af 406 Thread::wait(250);
miguelcordero191 3:f84802422619 407
miguelcordero191 3:f84802422619 408 if (wasIPResetPressed()){
miguelcordero191 3:f84802422619 409 eraseIpConfig();
miguelcordero191 3:f84802422619 410 mbed_reset();
miguelcordero191 3:f84802422619 411 }
miguelcordero191 0:c9bdd57867af 412 }
miguelcordero191 0:c9bdd57867af 413
miguelcordero191 2:f9e1bcb3409a 414 LedR = 0;
miguelcordero191 3:f84802422619 415 /*
miguelcordero191 0:c9bdd57867af 416 screen.putc(0x33);
miguelcordero191 2:f9e1bcb3409a 417 screen.putc(0x31);
miguelcordero191 3:f84802422619 418 */
miguelcordero191 2:f9e1bcb3409a 419 LedR = 1;
miguelcordero191 2:f9e1bcb3409a 420
joaquinbvw 5:12b90c023958 421 //cr2_device.defaultSettings();
miguelcordero191 2:f9e1bcb3409a 422 LedR = 0;
miguelcordero191 3:f84802422619 423 /*
miguelcordero191 0:c9bdd57867af 424 screen.putc(0x33);
miguelcordero191 2:f9e1bcb3409a 425 screen.putc(0x30);
miguelcordero191 3:f84802422619 426 */
miguelcordero191 3:f84802422619 427 Thread::wait(1000);
miguelcordero191 2:f9e1bcb3409a 428
miguelcordero191 1:072a0ab47d9c 429 //int c=0;
miguelcordero191 1:072a0ab47d9c 430 while(true){
miguelcordero191 3:f84802422619 431
joaquinbvw 5:12b90c023958 432 //if (cr2_device.isRFEnabled()){
joaquinbvw 5:12b90c023958 433 //LedR = 0;
joaquinbvw 5:12b90c023958 434 //}
joaquinbvw 5:12b90c023958 435 //else{
miguelcordero191 3:f84802422619 436 LedR = 1;
joaquinbvw 5:12b90c023958 437 //}
miguelcordero191 3:f84802422619 438
miguelcordero191 3:f84802422619 439 if (wasIPResetPressed()){
miguelcordero191 3:f84802422619 440 eraseIpConfig();
miguelcordero191 3:f84802422619 441 mbed_reset();
miguelcordero191 3:f84802422619 442 }
miguelcordero191 3:f84802422619 443
miguelcordero191 3:f84802422619 444 Thread::wait(200);
miguelcordero191 0:c9bdd57867af 445 }
miguelcordero191 3:f84802422619 446
miguelcordero191 0:c9bdd57867af 447 }
miguelcordero191 0:c9bdd57867af 448
miguelcordero191 0:c9bdd57867af 449 #endif