Freedman v2
Fork of WizFi250Interface by
WizFi250/WizFi250_hal.cpp@4:085e7efeae47, 2014-11-14 (annotated)
- Committer:
- DongEun Koak
- Date:
- Fri Nov 14 15:10:33 2014 +0900
- Revision:
- 4:085e7efeae47
- Parent:
- 0:f2039204c8f6
- Child:
- 5:8a0702aa91e3
Modified source code for removing warning message from compiler.
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(); |
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 | #ifdef CFG_UART_DIRECT |
kaizen | 0:f2039204c8f6 | 53 | return _uart->RBR; |
kaizen | 0:f2039204c8f6 | 54 | #else |
kaizen | 0:f2039204c8f6 | 55 | return _wizfi.getc(); |
kaizen | 0:f2039204c8f6 | 56 | #endif |
kaizen | 0:f2039204c8f6 | 57 | } |
kaizen | 0:f2039204c8f6 | 58 | |
kaizen | 0:f2039204c8f6 | 59 | void WizFi250::putUart (char c) |
kaizen | 0:f2039204c8f6 | 60 | { |
kaizen | 0:f2039204c8f6 | 61 | #ifdef CFG_UART_DIRECT |
kaizen | 0:f2039204c8f6 | 62 | while(!(_uart->LSR & (1<<5))); |
kaizen | 0:f2039204c8f6 | 63 | _uart->THR = c; |
kaizen | 0:f2039204c8f6 | 64 | #else |
kaizen | 0:f2039204c8f6 | 65 | _wizfi.putc(c); |
kaizen | 0:f2039204c8f6 | 66 | #endif |
kaizen | 0:f2039204c8f6 | 67 | } |
kaizen | 0:f2039204c8f6 | 68 | |
kaizen | 0:f2039204c8f6 | 69 | void WizFi250::setRts (bool flg) |
kaizen | 0:f2039204c8f6 | 70 | { |
kaizen | 0:f2039204c8f6 | 71 | if (flg) |
kaizen | 0:f2039204c8f6 | 72 | { |
kaizen | 0:f2039204c8f6 | 73 | if(_flow == 2) |
kaizen | 0:f2039204c8f6 | 74 | { |
kaizen | 0:f2039204c8f6 | 75 | if(_rts) |
kaizen | 0:f2039204c8f6 | 76 | { |
kaizen | 0:f2039204c8f6 | 77 | _rts->write(0); // low |
kaizen | 0:f2039204c8f6 | 78 | } |
kaizen | 0:f2039204c8f6 | 79 | } |
kaizen | 0:f2039204c8f6 | 80 | } |
kaizen | 0:f2039204c8f6 | 81 | else |
kaizen | 0:f2039204c8f6 | 82 | { |
kaizen | 0:f2039204c8f6 | 83 | if(_flow == 2) |
kaizen | 0:f2039204c8f6 | 84 | { |
kaizen | 0:f2039204c8f6 | 85 | if(_rts) |
kaizen | 0:f2039204c8f6 | 86 | { |
kaizen | 0:f2039204c8f6 | 87 | _rts->write(1); // high |
kaizen | 0:f2039204c8f6 | 88 | } |
kaizen | 0:f2039204c8f6 | 89 | } |
kaizen | 0:f2039204c8f6 | 90 | } |
kaizen | 0:f2039204c8f6 | 91 | } |
kaizen | 0:f2039204c8f6 | 92 | |
kaizen | 0:f2039204c8f6 | 93 | int WizFi250::lockUart (int ms) |
kaizen | 0:f2039204c8f6 | 94 | { |
kaizen | 0:f2039204c8f6 | 95 | Timer t; |
kaizen | 0:f2039204c8f6 | 96 | |
kaizen | 0:f2039204c8f6 | 97 | if(_state.mode != MODE_COMMAND) |
kaizen | 0:f2039204c8f6 | 98 | { |
kaizen | 0:f2039204c8f6 | 99 | t.start(); |
kaizen | 0:f2039204c8f6 | 100 | while(_state.mode != MODE_COMMAND) |
kaizen | 0:f2039204c8f6 | 101 | { |
kaizen | 0:f2039204c8f6 | 102 | if(t.read_ms() >= ms) |
kaizen | 0:f2039204c8f6 | 103 | { |
kaizen | 0:f2039204c8f6 | 104 | WARN("lock timeout (%d)\r\n", _state.mode); |
kaizen | 0:f2039204c8f6 | 105 | return -1; |
kaizen | 0:f2039204c8f6 | 106 | } |
kaizen | 0:f2039204c8f6 | 107 | } |
kaizen | 0:f2039204c8f6 | 108 | } |
kaizen | 0:f2039204c8f6 | 109 | |
kaizen | 0:f2039204c8f6 | 110 | #ifdef CFG_ENABLE_RTOS |
kaizen | 0:f2039204c8f6 | 111 | if (_mutexUart.lock(ms) != osOK) return -1; |
kaizen | 0:f2039204c8f6 | 112 | #endif |
kaizen | 0:f2039204c8f6 | 113 | |
kaizen | 0:f2039204c8f6 | 114 | if(_flow == 2) |
kaizen | 0:f2039204c8f6 | 115 | { |
kaizen | 0:f2039204c8f6 | 116 | if(_cts && _cts->read()) |
kaizen | 0:f2039204c8f6 | 117 | { |
kaizen | 0:f2039204c8f6 | 118 | // CTS check |
kaizen | 0:f2039204c8f6 | 119 | t.start(); |
kaizen | 0:f2039204c8f6 | 120 | while (_cts->read()) |
kaizen | 0:f2039204c8f6 | 121 | { |
kaizen | 0:f2039204c8f6 | 122 | if(t.read_ms() >= ms) |
kaizen | 0:f2039204c8f6 | 123 | { |
kaizen | 0:f2039204c8f6 | 124 | DBG("cts timeout\r\n"); |
kaizen | 0:f2039204c8f6 | 125 | return -1; |
kaizen | 0:f2039204c8f6 | 126 | } |
kaizen | 0:f2039204c8f6 | 127 | } |
kaizen | 0:f2039204c8f6 | 128 | } |
kaizen | 0:f2039204c8f6 | 129 | } |
kaizen | 0:f2039204c8f6 | 130 | |
kaizen | 0:f2039204c8f6 | 131 | setRts(false); // blcok |
kaizen | 0:f2039204c8f6 | 132 | return 0; |
kaizen | 0:f2039204c8f6 | 133 | } |
kaizen | 0:f2039204c8f6 | 134 | |
kaizen | 0:f2039204c8f6 | 135 | void WizFi250::unlockUart() |
kaizen | 0:f2039204c8f6 | 136 | { |
kaizen | 0:f2039204c8f6 | 137 | setRts(true); // release |
kaizen | 0:f2039204c8f6 | 138 | #ifdef CFG_ENABLE_RTOS |
kaizen | 0:f2039204c8f6 | 139 | _mutexUart.unlock(); |
kaizen | 0:f2039204c8f6 | 140 | #endif |
kaizen | 0:f2039204c8f6 | 141 | } |
kaizen | 0:f2039204c8f6 | 142 | |
kaizen | 0:f2039204c8f6 | 143 | void WizFi250::initUart (PinName cts, PinName rts, PinName alarm, int baud) |
kaizen | 0:f2039204c8f6 | 144 | { |
kaizen | 0:f2039204c8f6 | 145 | _baud = baud; |
kaizen | 0:f2039204c8f6 | 146 | if (_baud) _wizfi.baud(_baud); |
kaizen | 0:f2039204c8f6 | 147 | |
kaizen | 0:f2039204c8f6 | 148 | _wizfi.attach(this, &WizFi250::isrUart, Serial::RxIrq); |
kaizen | 0:f2039204c8f6 | 149 | |
kaizen | 0:f2039204c8f6 | 150 | _cts = NULL; |
kaizen | 0:f2039204c8f6 | 151 | _rts = NULL; |
kaizen | 0:f2039204c8f6 | 152 | _flow = 0; |
kaizen | 0:f2039204c8f6 | 153 | |
kaizen | 0:f2039204c8f6 | 154 | #if defined(TARGET_FRDM_KL25Z) |
kaizen | 0:f2039204c8f6 | 155 | _uart = UART1; |
kaizen | 0:f2039204c8f6 | 156 | #endif |
kaizen | 0:f2039204c8f6 | 157 | |
kaizen | 0:f2039204c8f6 | 158 | if(cts != NC) |
kaizen | 0:f2039204c8f6 | 159 | { |
kaizen | 0:f2039204c8f6 | 160 | _cts = new DigitalIn(cts); |
kaizen | 0:f2039204c8f6 | 161 | } |
kaizen | 0:f2039204c8f6 | 162 | if(rts != NC) |
kaizen | 0:f2039204c8f6 | 163 | { |
kaizen | 0:f2039204c8f6 | 164 | _rts = new DigitalOut(rts); |
kaizen | 0:f2039204c8f6 | 165 | _flow = 2; |
kaizen | 0:f2039204c8f6 | 166 | } |
kaizen | 0:f2039204c8f6 | 167 | } |