RC

Dependents:   WizFi250_AP_HelloWorld

Fork of WizFi250Interface by DongEun Koak

Committer:
kaizen8501
Date:
Fri Jun 19 15:34:40 2015 +0900
Revision:
9:12ecb377f63f
Parent:
6:e149bf87a1bd
Child:
10:187e3fd24123
Fixed Bug when using TCP Server, TCP Client

Who changed what in which revision?

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