📄 avrgsm__com_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>AVR323 Interfacing GSM modems: AVRGSM_FILES/AVRGSM_com.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>AVRGSM_FILES/AVRGSM_com.c</h1><a href="AVRGSM__com_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">// This file has been prepared for Doxygen automatic documentation generation.</span>00022 <span class="comment"></span><span class="comment">//Used for SPLINT</span>00023 <span class="preprocessor">#ifdef S_SPLINT_S</span>00024 <span class="preprocessor"></span><span class="preprocessor"> #include"<a class="code" href="splint_8h.html">splint.h</a>"</span>00025 <span class="preprocessor">#endif</span>00026 <span class="preprocessor"></span>00027 00028 <span class="comment">//Includes</span>00029 <span class="preprocessor">#include<ioavr.h></span>00030 <span class="preprocessor">#include<inavr.h></span>00031 <span class="preprocessor">#include"<a class="code" href="AVRGSM__com_8h.html">AVRGSM_com.h</a>"</span>00032 <a name="l00034"></a><a class="code" href="AVRGSM__com_8c.html#a0">00034</a> <span class="keywordtype">int</span> <a class="code" href="AVRGSM__com_8c.html#a0">rx_overflow</a>, <a class="code" href="AVRGSM__api_8c.html#a0">rx_ack</a>;00035 <a name="l00037"></a><a class="code" href="AVRGSM__com_8c.html#a2">00037</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="AVRGSM__com_8c.html#a2">rx_buffer</a>[<a class="code" href="AVRGSM__com_8h.html#a0">RX_BUFFER_SIZE</a>];00038 <a name="l00040"></a><a class="code" href="AVRGSM__com_8c.html#a3">00040</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="AVRGSM__com_8c.html#a3">searchStr</a>;00041 <a name="l00043"></a><a class="code" href="AVRGSM__com_8c.html#a4">00043</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a>;00044 <a name="l00046"></a><a class="code" href="AVRGSM__com_8c.html#a5">00046</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a>;00047 <a name="l00049"></a><a class="code" href="AVRGSM__com_8c.html#a6">00049</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash <a class="code" href="AVRGSM__com_8c.html#a6">OK</a>[] = <span class="stringliteral">"OK\r\n"</span>; <a name="l00050"></a><a class="code" href="AVRGSM__com_8c.html#a7">00050</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash <a class="code" href="AVRGSM__com_8c.html#a7">CMTI</a>[] = <span class="stringliteral">"+CMTI: "</span>; <a name="l00051"></a><a class="code" href="AVRGSM__com_8c.html#a8">00051</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash <a class="code" href="AVRGSM__com_8c.html#a8">READY</a>[] = <span class="stringliteral">"> "</span>; <a name="l00052"></a><a class="code" href="AVRGSM__com_8c.html#a9">00052</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash <a class="code" href="AVRGSM__com_8c.html#a9">CR_LF</a>[] = <span class="stringliteral">"\r\n"</span>; <a name="l00053"></a><a class="code" href="AVRGSM__com_8c.html#a10">00053</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash *<a class="code" href="AVRGSM__com_8c.html#a10">searchFor</a>; <a name="l00054"></a><a class="code" href="AVRGSM__com_8c.html#a11">00054</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> __flash *<a class="code" href="AVRGSM__com_8c.html#a11">searchStrings</a>[4] = {<a class="code" href="AVRGSM__com_8c.html#a6">OK</a>, <a class="code" href="AVRGSM__com_8c.html#a7">CMTI</a>, <a class="code" href="AVRGSM__com_8c.html#a8">READY</a>, <a class="code" href="AVRGSM__com_8c.html#a9">CR_LF</a>}; 00055 00056 <a name="l00066"></a><a class="code" href="AVRGSM__com_8h.html#a7">00066</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8h.html#a7">COM_init</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> baudrate )00067 {00068 00069 UBRR0H = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>) (baudrate>>8); <span class="comment">//Setting baudrate</span>00070 UBRR0L = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>) baudrate; <span class="comment">//Setting baudrate</span>00071 00072 UCSR0B = ( 1 << RXEN0 ) | ( 1 << TXEN0 ); <span class="comment">//Enable receiver and transmitter</span>00073 UCSR0C = ( 1 << USBS0 ) | ( 1 << UCSZ01 ) | ( 1 << UCSZ00 ); <span class="comment">//8N1...see Datasheet for more information</span>00074 00075 <a class="code" href="AVRGSM__com_8c.html#a13">COM_rx_reset</a>(); <span class="comment">//Reset buffers etc.</span>00076 }00077 00078 <a name="l00085"></a><a class="code" href="AVRGSM__com_8h.html#a8">00085</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8c.html#a13">COM_rx_reset</a>( <span class="keywordtype">void</span> )00086 {00087 00088 UCSR0B &= ~(1<<RXCIE0); <span class="comment">// Disable RX interrupt</span>00089 <a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a> = <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a> = 0; <span class="comment">//Init variables</span>00090 <a class="code" href="AVRGSM__com_8c.html#a0">rx_overflow</a> = <a class="code" href="AVRGSM__api_8c.html#a0">rx_ack</a> = 0; <span class="comment">//Zero overflow flag</span>00091 <a class="code" href="AVRGSM__com_8c.html#a2">rx_buffer</a>[ <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a> ] = <span class="charliteral">'\0'</span>; <span class="comment">//Buffer init.</span>00092 }00093 00094 <a name="l00101"></a><a class="code" href="AVRGSM__com_8h.html#a9">00101</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8c.html#a14">COM_rx_on</a>( <span class="keywordtype">void</span> )00102 {00103 00104 UCSR0B |= ( 1 << RXCIE0 ); <span class="comment">// Enable RX interrupt</span>00105 }00106 00107 <a name="l00114"></a><a class="code" href="AVRGSM__com_8h.html#a10">00114</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8c.html#a15">COM_rx_off</a>( <span class="keywordtype">void</span> )00115 {00116 00117 UCSR0B &= ~( 1 << RXCIE0 ); <span class="comment">// Disable RX interrupt</span>00118 }00119 00120 <a name="l00127"></a><a class="code" href="AVRGSM__com_8h.html#a11">00127</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8h.html#a11">COM_setSearchString</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Response )00128 {00129 00130 UCSR0B &= ~( 1 << RXCIE0 ); <span class="comment">// Disable RX interrupt</span>00131 <a class="code" href="AVRGSM__com_8c.html#a10">searchFor</a> = <a class="code" href="AVRGSM__com_8c.html#a11">searchStrings</a>[Response]; <span class="comment">//Set desired search dtring</span>00132 <a class="code" href="AVRGSM__com_8c.html#a3">searchStr</a> = Response; <span class="comment">//Used in rx_isr</span>00133 <a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a> = 0;00134 }00135 00136 00142 <span class="preprocessor">#pragma vector=USART0_RXC_vect</span><a name="l00143"></a><a class="code" href="AVRGSM__com_8c.html#a17">00143</a> <span class="preprocessor"></span><a class="code" href="splint_8h.html#a2">__interrupt</a> <span class="keywordtype">void</span> <a class="code" href="AVRGSM__com_8c.html#a17">USART0_RX_interrupt</a>( <span class="keywordtype">void</span> )00144 {00145 00146 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data; <span class="comment">//Local variable</span>00147 00148 data = UDR0; <span class="comment">//Always read something</span>00149 00150 <a class="code" href="AVRGSM__com_8c.html#a2">rx_buffer</a>[ <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a>++ ] = data; <span class="comment">//Store new data</span>00151 00152 00153 <span class="keywordflow">if</span>( <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a> > <a class="code" href="AVRGSM__com_8h.html#a1">RX_BUFFER_MASK</a> ) <span class="comment">//Check for overflow</span>00154 {00155 <a class="code" href="AVRGSM__com_8c.html#a5">rx_wr_i</a> = 0; <span class="comment">//Reset write index</span>00156 <a class="code" href="AVRGSM__com_8c.html#a0">rx_overflow</a> = 1; <span class="comment">//Set flag high</span>00157 UCSR0B &= ~( 1 << RXCIE0 ); <span class="comment">// Disable RX interrupt</span>00158 }00159 00160 <span class="keywordflow">if</span>( <a class="code" href="AVRGSM__com_8c.html#a10">searchFor</a>[<a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a>] == data ) <span class="comment">//Test response match</span>00161 {00162 <a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a>++;00163 00164 <span class="keywordflow">if</span>( !<a class="code" href="AVRGSM__com_8c.html#a10">searchFor</a>[<a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a>] ) <span class="comment">//End of new_message string...received new message!</span>00165 {00166 <a class="code" href="AVRGSM__com_8c.html#a4">rx_i</a> = 0;00167 00168 <span class="keywordflow">if</span>( <a class="code" href="AVRGSM__com_8c.html#a3">searchStr</a> == <a class="code" href="AVRGSM__com_8h.html#a4">CMTI_</a> ) <span class="comment">//+CMTI:</span>00169 {00170 <a class="code" href="AVRGSM__com_8c.html#a10">searchFor</a> = <a class="code" href="AVRGSM__com_8c.html#a11">searchStrings</a>[ <a class="code" href="AVRGSM__com_8h.html#a6">CRLF_</a> ]; <span class="comment">//Wait for</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -