ThingPlug Test

Dependents:   WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P

Fork of WizFi310Interface by WIZnet

Committer:
jehoon
Date:
Mon Jun 26 00:17:10 2017 +0000
Revision:
5:72212beb817c
Parent:
0:df571f8f8c03
modify message parsing in isr

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jehoon 0:df571f8f8c03 1 /*
jehoon 0:df571f8f8c03 2 * Copyright (C) 2013 gsfan, MIT License
jehoon 0:df571f8f8c03 3 *
jehoon 0:df571f8f8c03 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
jehoon 0:df571f8f8c03 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
jehoon 0:df571f8f8c03 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
jehoon 0:df571f8f8c03 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
jehoon 0:df571f8f8c03 8 * furnished to do so, subject to the following conditions:
jehoon 0:df571f8f8c03 9 *
jehoon 0:df571f8f8c03 10 * The above copyright notice and this permission notice shall be included in all copies or
jehoon 0:df571f8f8c03 11 * substantial portions of the Software.
jehoon 0:df571f8f8c03 12 *
jehoon 0:df571f8f8c03 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
jehoon 0:df571f8f8c03 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
jehoon 0:df571f8f8c03 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
jehoon 0:df571f8f8c03 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jehoon 0:df571f8f8c03 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
jehoon 0:df571f8f8c03 18 */
jehoon 0:df571f8f8c03 19 /* Copyright (C) 2014 Wiznet, MIT License
jehoon 0:df571f8f8c03 20 * port to the Wiznet Module WizFi310
jehoon 0:df571f8f8c03 21 */
jehoon 0:df571f8f8c03 22
jehoon 0:df571f8f8c03 23 #include "WizFi310.h"
jehoon 0:df571f8f8c03 24
jehoon 0:df571f8f8c03 25 void WizFi310::setReset(bool flg)
jehoon 0:df571f8f8c03 26 {
jehoon 0:df571f8f8c03 27 if( flg )
jehoon 0:df571f8f8c03 28 {
jehoon 0:df571f8f8c03 29 // low
jehoon 0:df571f8f8c03 30 _reset.output();
jehoon 0:df571f8f8c03 31 _reset = 0;
jehoon 0:df571f8f8c03 32 }
jehoon 0:df571f8f8c03 33 else
jehoon 0:df571f8f8c03 34 {
jehoon 0:df571f8f8c03 35 // high z
jehoon 0:df571f8f8c03 36 _reset.input();
jehoon 0:df571f8f8c03 37 _reset.mode(PullNone);
jehoon 0:df571f8f8c03 38 }
jehoon 0:df571f8f8c03 39 }
jehoon 0:df571f8f8c03 40
jehoon 0:df571f8f8c03 41 void WizFi310::isrUart()
jehoon 0:df571f8f8c03 42 {
jehoon 0:df571f8f8c03 43 char c;
jehoon 0:df571f8f8c03 44
jehoon 0:df571f8f8c03 45 c = getUart();
jehoon 5:72212beb817c 46
jehoon 0:df571f8f8c03 47 recvData(c);
jehoon 0:df571f8f8c03 48 }
jehoon 0:df571f8f8c03 49
jehoon 0:df571f8f8c03 50 int WizFi310::getUart()
jehoon 0:df571f8f8c03 51 {
jehoon 0:df571f8f8c03 52 return _wizfi.getc();
jehoon 0:df571f8f8c03 53 }
jehoon 0:df571f8f8c03 54
jehoon 0:df571f8f8c03 55 void WizFi310::putUart (char c)
jehoon 0:df571f8f8c03 56 {
jehoon 0:df571f8f8c03 57 _wizfi.putc(c);
jehoon 0:df571f8f8c03 58 }
jehoon 0:df571f8f8c03 59
jehoon 0:df571f8f8c03 60 void WizFi310::setRts (bool flg)
jehoon 0:df571f8f8c03 61 {
jehoon 0:df571f8f8c03 62 if (flg)
jehoon 0:df571f8f8c03 63 {
jehoon 0:df571f8f8c03 64 if(_flow == 2)
jehoon 0:df571f8f8c03 65 {
jehoon 0:df571f8f8c03 66 if(_rts)
jehoon 0:df571f8f8c03 67 {
jehoon 0:df571f8f8c03 68 _rts->write(0); // low
jehoon 0:df571f8f8c03 69 }
jehoon 0:df571f8f8c03 70 }
jehoon 0:df571f8f8c03 71 }
jehoon 0:df571f8f8c03 72 else
jehoon 0:df571f8f8c03 73 {
jehoon 0:df571f8f8c03 74 if(_flow == 2)
jehoon 0:df571f8f8c03 75 {
jehoon 0:df571f8f8c03 76 if(_rts)
jehoon 0:df571f8f8c03 77 {
jehoon 0:df571f8f8c03 78 _rts->write(1); // high
jehoon 0:df571f8f8c03 79 }
jehoon 0:df571f8f8c03 80 }
jehoon 0:df571f8f8c03 81 }
jehoon 0:df571f8f8c03 82 }
jehoon 0:df571f8f8c03 83
jehoon 0:df571f8f8c03 84 int WizFi310::lockUart (int ms)
jehoon 0:df571f8f8c03 85 {
jehoon 0:df571f8f8c03 86 Timer t;
jehoon 0:df571f8f8c03 87
jehoon 0:df571f8f8c03 88 if(_state.mode != MODE_COMMAND)
jehoon 0:df571f8f8c03 89 {
jehoon 0:df571f8f8c03 90 t.start();
jehoon 0:df571f8f8c03 91 while(_state.mode != MODE_COMMAND)
jehoon 0:df571f8f8c03 92 {
jehoon 0:df571f8f8c03 93 if(t.read_ms() >= ms)
jehoon 0:df571f8f8c03 94 {
jehoon 0:df571f8f8c03 95 WIZ_WARN("lock timeout (%d)\r\n", _state.mode);
jehoon 0:df571f8f8c03 96 return -1;
jehoon 0:df571f8f8c03 97 }
jehoon 0:df571f8f8c03 98 }
jehoon 0:df571f8f8c03 99 }
jehoon 0:df571f8f8c03 100
jehoon 0:df571f8f8c03 101 #ifdef CFG_ENABLE_RTOS
jehoon 0:df571f8f8c03 102 if (_mutexUart.lock(ms) != osOK) return -1;
jehoon 0:df571f8f8c03 103 #endif
jehoon 0:df571f8f8c03 104
jehoon 0:df571f8f8c03 105 if(_flow == 2)
jehoon 0:df571f8f8c03 106 {
jehoon 0:df571f8f8c03 107 if(_cts && _cts->read())
jehoon 0:df571f8f8c03 108 {
jehoon 0:df571f8f8c03 109 // CTS check
jehoon 0:df571f8f8c03 110 t.start();
jehoon 0:df571f8f8c03 111 while (_cts->read())
jehoon 0:df571f8f8c03 112 {
jehoon 0:df571f8f8c03 113 if(t.read_ms() >= ms)
jehoon 0:df571f8f8c03 114 {
jehoon 0:df571f8f8c03 115 WIZ_DBG("cts timeout\r\n");
jehoon 0:df571f8f8c03 116 return -1;
jehoon 0:df571f8f8c03 117 }
jehoon 0:df571f8f8c03 118 }
jehoon 0:df571f8f8c03 119 }
jehoon 0:df571f8f8c03 120 }
jehoon 0:df571f8f8c03 121
jehoon 0:df571f8f8c03 122 setRts(false); // blcok
jehoon 0:df571f8f8c03 123 return 0;
jehoon 0:df571f8f8c03 124 }
jehoon 0:df571f8f8c03 125
jehoon 0:df571f8f8c03 126 void WizFi310::unlockUart()
jehoon 0:df571f8f8c03 127 {
jehoon 0:df571f8f8c03 128 setRts(true); // release
jehoon 0:df571f8f8c03 129 #ifdef CFG_ENABLE_RTOS
jehoon 0:df571f8f8c03 130 _mutexUart.unlock();
jehoon 0:df571f8f8c03 131 #endif
jehoon 0:df571f8f8c03 132 }
jehoon 0:df571f8f8c03 133
jehoon 0:df571f8f8c03 134 void WizFi310::initUart (PinName cts, PinName rts, PinName alarm, int baud)
jehoon 0:df571f8f8c03 135 {
jehoon 0:df571f8f8c03 136 _baud = baud;
jehoon 0:df571f8f8c03 137 if (_baud) _wizfi.baud(_baud);
jehoon 0:df571f8f8c03 138
jehoon 0:df571f8f8c03 139 _wizfi.attach(this, &WizFi310::isrUart, Serial::RxIrq);
jehoon 0:df571f8f8c03 140
jehoon 0:df571f8f8c03 141 _cts = NULL;
jehoon 0:df571f8f8c03 142 _rts = NULL;
jehoon 0:df571f8f8c03 143 _flow = 0;
jehoon 0:df571f8f8c03 144
jehoon 0:df571f8f8c03 145 if(cts != NC)
jehoon 0:df571f8f8c03 146 {
jehoon 0:df571f8f8c03 147 _cts = new DigitalIn(cts);
jehoon 0:df571f8f8c03 148 }
jehoon 0:df571f8f8c03 149 if(rts != NC)
jehoon 0:df571f8f8c03 150 {
jehoon 0:df571f8f8c03 151 _rts = new DigitalOut(rts);
jehoon 0:df571f8f8c03 152 _flow = 2;
jehoon 0:df571f8f8c03 153 }
jehoon 0:df571f8f8c03 154 }