Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WizFi310Interface_Legacy by
WizFi310_hal.cpp
00001 /* 00002 * Copyright (C) 2013 gsfan, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 /* Copyright (C) 2014 Wiznet, MIT License 00020 * port to the Wiznet Module WizFi250 00021 */ 00022 /* Copyright (C) 2017 Wiznet, MIT License 00023 * port to the Wiznet Module WizFi310 00024 */ 00025 00026 #include "WizFi310.h" 00027 00028 void WizFi310::setReset(bool flg) 00029 { 00030 if( flg ) 00031 { 00032 // low 00033 _reset.output(); 00034 _reset = 0; 00035 } 00036 else 00037 { 00038 // high z 00039 _reset.input(); 00040 _reset.mode(PullNone); 00041 } 00042 } 00043 00044 void WizFi310::isrUart() 00045 { 00046 char c; 00047 00048 c = getUart(); 00049 00050 recvData(c); 00051 //S_UartPutc(c); 00052 } 00053 00054 int WizFi310::getUart() 00055 { 00056 return _wizfi.getc(); 00057 } 00058 00059 void WizFi310::putUart (char c) 00060 { 00061 _wizfi.putc(c); 00062 } 00063 00064 void WizFi310::setRts (bool flg) 00065 { 00066 if (flg) 00067 { 00068 if(_flow == 2) 00069 { 00070 if(_rts) 00071 { 00072 _rts->write(0); // low 00073 } 00074 } 00075 } 00076 else 00077 { 00078 if(_flow == 2) 00079 { 00080 if(_rts) 00081 { 00082 _rts->write(1); // high 00083 } 00084 } 00085 } 00086 } 00087 00088 int WizFi310::lockUart (int ms) 00089 { 00090 Timer t; 00091 00092 if(_state.mode != MODE_COMMAND) 00093 { 00094 t.start(); 00095 while(_state.mode != MODE_COMMAND) 00096 { 00097 if(t.read_ms() >= ms) 00098 { 00099 WIZ_WARN("lock timeout (%d)\r\n", _state.mode); 00100 return -1; 00101 } 00102 } 00103 } 00104 00105 #ifdef CFG_ENABLE_RTOS 00106 if (_mutexUart.lock(ms) != osOK) return -1; 00107 #endif 00108 00109 if(_flow == 2) 00110 { 00111 if(_cts && _cts->read()) 00112 { 00113 // CTS check 00114 t.start(); 00115 while (_cts->read()) 00116 { 00117 if(t.read_ms() >= ms) 00118 { 00119 WIZ_DBG("cts timeout\r\n"); 00120 return -1; 00121 } 00122 } 00123 } 00124 } 00125 00126 setRts(false); // blcok 00127 return 0; 00128 } 00129 00130 void WizFi310::unlockUart() 00131 { 00132 setRts(true); // release 00133 #ifdef CFG_ENABLE_RTOS 00134 _mutexUart.unlock(); 00135 #endif 00136 } 00137 00138 void WizFi310::initUart (PinName cts, PinName rts, PinName alarm, int baud) 00139 { 00140 _baud = baud; 00141 if (_baud) _wizfi.baud(_baud); 00142 00143 _wizfi.attach(this, &WizFi310::isrUart, Serial::RxIrq); 00144 00145 _cts = NULL; 00146 _rts = NULL; 00147 _flow = 0; 00148 00149 if(cts != NC) 00150 { 00151 _cts = new DigitalIn(cts); 00152 } 00153 if(rts != NC) 00154 { 00155 _rts = new DigitalOut(rts); 00156 _flow = 2; 00157 } 00158 }
Generated on Wed Jul 13 2022 07:09:49 by
