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