Freedman v2

Dependents:   Freedman_v2

Fork of WizFi250Interface by DongEun Koak

Committer:
DongEun Koak
Date:
Fri Nov 14 15:22:27 2014 +0900
Revision:
6:e149bf87a1bd
Parent:
5:8a0702aa91e3
Child:
9:12ecb377f63f
WizFi250 couldn't use usb serial port in application layer.
So I did add function that you can use serial port in application layer.

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();
kaizen 0:f2039204c8f6 46 //_debug.putc(c);
kaizen 0:f2039204c8f6 47 recvData(c);
kaizen 0:f2039204c8f6 48 }
kaizen 0:f2039204c8f6 49
kaizen 0:f2039204c8f6 50 int WizFi250::getUart()
kaizen 0:f2039204c8f6 51 {
kaizen 0:f2039204c8f6 52 return _wizfi.getc();
kaizen 0:f2039204c8f6 53 }
kaizen 0:f2039204c8f6 54
kaizen 0:f2039204c8f6 55 void WizFi250::putUart (char c)
kaizen 0:f2039204c8f6 56 {
kaizen 0:f2039204c8f6 57 _wizfi.putc(c);
kaizen 0:f2039204c8f6 58 }
kaizen 0:f2039204c8f6 59
kaizen 0:f2039204c8f6 60 void WizFi250::setRts (bool flg)
kaizen 0:f2039204c8f6 61 {
kaizen 0:f2039204c8f6 62 if (flg)
kaizen 0:f2039204c8f6 63 {
kaizen 0:f2039204c8f6 64 if(_flow == 2)
kaizen 0:f2039204c8f6 65 {
kaizen 0:f2039204c8f6 66 if(_rts)
kaizen 0:f2039204c8f6 67 {
kaizen 0:f2039204c8f6 68 _rts->write(0); // low
kaizen 0:f2039204c8f6 69 }
kaizen 0:f2039204c8f6 70 }
kaizen 0:f2039204c8f6 71 }
kaizen 0:f2039204c8f6 72 else
kaizen 0:f2039204c8f6 73 {
kaizen 0:f2039204c8f6 74 if(_flow == 2)
kaizen 0:f2039204c8f6 75 {
kaizen 0:f2039204c8f6 76 if(_rts)
kaizen 0:f2039204c8f6 77 {
kaizen 0:f2039204c8f6 78 _rts->write(1); // high
kaizen 0:f2039204c8f6 79 }
kaizen 0:f2039204c8f6 80 }
kaizen 0:f2039204c8f6 81 }
kaizen 0:f2039204c8f6 82 }
kaizen 0:f2039204c8f6 83
kaizen 0:f2039204c8f6 84 int WizFi250::lockUart (int ms)
kaizen 0:f2039204c8f6 85 {
kaizen 0:f2039204c8f6 86 Timer t;
kaizen 0:f2039204c8f6 87
kaizen 0:f2039204c8f6 88 if(_state.mode != MODE_COMMAND)
kaizen 0:f2039204c8f6 89 {
kaizen 0:f2039204c8f6 90 t.start();
kaizen 0:f2039204c8f6 91 while(_state.mode != MODE_COMMAND)
kaizen 0:f2039204c8f6 92 {
kaizen 0:f2039204c8f6 93 if(t.read_ms() >= ms)
kaizen 0:f2039204c8f6 94 {
DongEun Koak 5:8a0702aa91e3 95 WIZ_WARN("lock timeout (%d)\r\n", _state.mode);
kaizen 0:f2039204c8f6 96 return -1;
kaizen 0:f2039204c8f6 97 }
kaizen 0:f2039204c8f6 98 }
kaizen 0:f2039204c8f6 99 }
kaizen 0:f2039204c8f6 100
kaizen 0:f2039204c8f6 101 #ifdef CFG_ENABLE_RTOS
kaizen 0:f2039204c8f6 102 if (_mutexUart.lock(ms) != osOK) return -1;
kaizen 0:f2039204c8f6 103 #endif
kaizen 0:f2039204c8f6 104
kaizen 0:f2039204c8f6 105 if(_flow == 2)
kaizen 0:f2039204c8f6 106 {
kaizen 0:f2039204c8f6 107 if(_cts && _cts->read())
kaizen 0:f2039204c8f6 108 {
kaizen 0:f2039204c8f6 109 // CTS check
kaizen 0:f2039204c8f6 110 t.start();
kaizen 0:f2039204c8f6 111 while (_cts->read())
kaizen 0:f2039204c8f6 112 {
kaizen 0:f2039204c8f6 113 if(t.read_ms() >= ms)
kaizen 0:f2039204c8f6 114 {
DongEun Koak 5:8a0702aa91e3 115 WIZ_DBG("cts timeout\r\n");
kaizen 0:f2039204c8f6 116 return -1;
kaizen 0:f2039204c8f6 117 }
kaizen 0:f2039204c8f6 118 }
kaizen 0:f2039204c8f6 119 }
kaizen 0:f2039204c8f6 120 }
kaizen 0:f2039204c8f6 121
kaizen 0:f2039204c8f6 122 setRts(false); // blcok
kaizen 0:f2039204c8f6 123 return 0;
kaizen 0:f2039204c8f6 124 }
kaizen 0:f2039204c8f6 125
kaizen 0:f2039204c8f6 126 void WizFi250::unlockUart()
kaizen 0:f2039204c8f6 127 {
kaizen 0:f2039204c8f6 128 setRts(true); // release
kaizen 0:f2039204c8f6 129 #ifdef CFG_ENABLE_RTOS
kaizen 0:f2039204c8f6 130 _mutexUart.unlock();
kaizen 0:f2039204c8f6 131 #endif
kaizen 0:f2039204c8f6 132 }
kaizen 0:f2039204c8f6 133
kaizen 0:f2039204c8f6 134 void WizFi250::initUart (PinName cts, PinName rts, PinName alarm, int baud)
kaizen 0:f2039204c8f6 135 {
kaizen 0:f2039204c8f6 136 _baud = baud;
kaizen 0:f2039204c8f6 137 if (_baud) _wizfi.baud(_baud);
kaizen 0:f2039204c8f6 138
kaizen 0:f2039204c8f6 139 _wizfi.attach(this, &WizFi250::isrUart, Serial::RxIrq);
kaizen 0:f2039204c8f6 140
kaizen 0:f2039204c8f6 141 _cts = NULL;
kaizen 0:f2039204c8f6 142 _rts = NULL;
kaizen 0:f2039204c8f6 143 _flow = 0;
kaizen 0:f2039204c8f6 144
kaizen 0:f2039204c8f6 145 if(cts != NC)
kaizen 0:f2039204c8f6 146 {
kaizen 0:f2039204c8f6 147 _cts = new DigitalIn(cts);
kaizen 0:f2039204c8f6 148 }
kaizen 0:f2039204c8f6 149 if(rts != NC)
kaizen 0:f2039204c8f6 150 {
kaizen 0:f2039204c8f6 151 _rts = new DigitalOut(rts);
kaizen 0:f2039204c8f6 152 _flow = 2;
kaizen 0:f2039204c8f6 153 }
kaizen 0:f2039204c8f6 154 }