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