Main Page | Data Structures | File List | Data Fields | Globals

AVRGSM_FILES/AVRGSM_com.c File Reference


Detailed Description

Atmel Corporation

Revision
1.2
Date
Wednesday, January 26, 2005 10:43:44 UTC

Definition in file AVRGSM_com.c.

#include <ioavr.h>
#include <inavr.h>
#include "AVRGSM_com.h"

Include dependency graph for AVRGSM_com.c:

Include dependency graph

Go to the source code of this file.

Functions

unsigned char * COM_gets (void)
 Return pointer to receive buffer.

void COM_init (unsigned int baudrate)
 USART0 initialization.

void COM_put_integer (int i)
 This method will print an integer in the range +-(10^5 - 1 ).

int COM_putchar (unsigned char data)
 Adapted putchar method...no need for interrup driven tx-isr.

void COM_puts (unsigned char *str)
 Print unsigned char string.

void COM_putsf (const unsigned char __flash *fstr)
 Print const unsigned char __flash string.

void COM_rx_off (void)
 RX interrupt disable.

void COM_rx_on (void)
 RX interrupt enable.

void COM_rx_reset (void)
 Reset receive interrupt.

void COM_setSearchString (unsigned char Response)
 Set desired search string.

int COM_trim (void)
 Remove trailing O, K, and
.

__interrupt void USART0_RX_interrupt (void)
 Receive interrupt routine.


Variables

const unsigned char __flash CMTI [] = "+CMTI: "
 New Message arrived.

const unsigned char __flash CR_LF [] = "\r\n"
 Carrige Return Line Feed.

const unsigned char __flash OK [] = "OK\r\n"
 "OK"

const unsigned char __flash READY [] = "> "
 Phone ready to receive text message.

int rx_ack
 Extern flag from AVRSMS_com.c.

unsigned char rx_buffer [RX_BUFFER_SIZE]
 private buffer

int rx_i
 Buffer counter.

int rx_overflow
 Overflow and acknowledge flag.

int rx_wr_i
 Buffer write index.

const unsigned char __flash * searchFor
 Flash pointer.

unsigned char searchStr
 Private pointer.

const unsigned char __flash * searchStrings [4] = {OK, CMTI, READY, CR_LF}
 Initialize pointer.


Function Documentation

unsigned char* COM_gets void   ) 
 

Return pointer to receive buffer.

Parameters:
void 
Return values:
rx_buffer Pointer to receive buffer

Definition at line 317 of file AVRGSM_com.c.

References rx_buffer.

Referenced by TOOLS__decodeCMGR(), and TOOLS_decodeCMTI().

00318 { 00319 return rx_buffer; 00320 }

void COM_init unsigned int  baudrate  ) 
 

USART0 initialization.

This function set correct baurate and functionality of the USART0. See data sheet for more details.

Parameters:
input Desired baudrate...see datasheet
Return values:
void 

Definition at line 66 of file AVRGSM_com.c.

References COM_rx_reset().

Referenced by Initialization().

00067 { 00068 00069 UBRR0H = (unsigned char) (baudrate>>8); //Setting baudrate 00070 UBRR0L = (unsigned char) baudrate; //Setting baudrate 00071 00072 UCSR0B = ( 1 << RXEN0 ) | ( 1 << TXEN0 ); //Enable receiver and transmitter 00073 UCSR0C = ( 1 << USBS0 ) | ( 1 << UCSZ01 ) | ( 1 << UCSZ00 ); //8N1...see Datasheet for more information 00074 00075 COM_rx_reset(); //Reset buffers etc. 00076 }

Here is the call graph for this function:

void COM_put_integer int  i  ) 
 

This method will print an integer in the range +-(10^5 - 1 ).

Parameters:
i integer to be printed
Return values:
void 

Local variables

Definition at line 224 of file AVRGSM_com.c.

References COM_putchar().

Referenced by API_deletemsg(), API_readmsg(), and API_sendmsg().

00225 { 00226 00228 int ii; 00229 unsigned char int_buf[5]; 00230 00231 if (i < 0) //Integer is negative 00232 { 00233 i = -i; //Convert to positive Integer 00234 COM_putchar('-'); //Print - sign 00235 } 00236 00237 for (ii=0; ii < 5; ) //Convert Integer to char array 00238 { 00239 int_buf[ii++] = '0'+ i % 10; //Find carry using modulo operation 00240 i = i / 10; //Move towards MSB 00241 } 00242 do{ ii--; }while( (int_buf[ii] == '0') && (ii != 0) ); //Remove leading 0's 00243 do{ COM_putchar( int_buf[ii--] ); }while (ii >= 0); //Print int->char array convertion 00244 00245 }

Here is the call graph for this function:

int COM_putchar unsigned char  data  ) 
 

Adapted putchar method...no need for interrup driven tx-isr.

Adpation of ansi c putchar() method

Parameters:
data Character to send
Return values:
data if successful
-1 if timeout

Definition at line 198 of file AVRGSM_com.c.

References RX_WAIT.

Referenced by API_sendmsg(), COM_put_integer(), COM_puts(), and COM_putsf().

00199 { 00200 00201 //Local variables 00202 unsigned int i; 00203 00204 for( i = 0; !( UCSR0A & ( 1 << UDRE0 ) ); i++ ) // Wait for empty transmit buffer 00205 { 00206 if( i > RX_WAIT ) //How long one should wait 00207 { 00208 return -1; //Give feedback to function caller 00209 } 00210 } 00211 00212 UDR0 = data; // Start transmittion 00213 00214 return (int)data; //Cast and return int value 00215 }

void COM_puts unsigned char *  str  ) 
 

Print unsigned char string.

Parameters:
str Pointer to the string
Return values:
void 

Definition at line 254 of file AVRGSM_com.c.

References COM_putchar().

Referenced by API_sendmsg().

00255 { 00256 00257 for( ;*str != '\0'; ) 00258 { 00259 COM_putchar( *str++ ); 00260 } 00261 }

Here is the call graph for this function:

void COM_putsf const unsigned char __flash *  fstr  ) 
 

Print const unsigned char __flash string.

Parameters:
fstr Pointer to the string
Return values:
void 

Definition at line 270 of file AVRGSM_com.c.

References COM_putchar().

Referenced by API_deletemsg(), API_modem_init(), API_readmsg(), and API_sendmsg().

00271 { 00272 00273 for( ;*fstr != '\0'; ) 00274 { 00275 COM_putchar( *fstr++ ); 00276 } 00277 }

Here is the call graph for this function:

void COM_rx_off void   ) 
 

RX interrupt disable.

Parameters:
void 
Return values:
void 

Definition at line 114 of file AVRGSM_com.c.

Referenced by API_check_acknowledge().

00115 { 00116 00117 UCSR0B &= ~( 1 << RXCIE0 ); // Disable RX interrupt 00118 }

void COM_rx_on void   ) 
 

RX interrupt enable.

Parameters:
void 
Return values:
void 

Definition at line 101 of file AVRGSM_com.c.

Referenced by API_deletemsg(), API_modem_init(), API_readmsg(), API_sendmsg(), ST_delete_msg(), ST_init_phone(), and ST_read().

00102 { 00103 00104 UCSR0B |= ( 1 << RXCIE0 ); // Enable RX interrupt 00105 }

void COM_rx_reset void   ) 
 

Reset receive interrupt.

Parameters:
void 
Return values:
void 

Definition at line 85 of file AVRGSM_com.c.

References rx_ack, rx_buffer, rx_i, rx_overflow, and rx_wr_i.

Referenced by API_check_acknowledge(), API_deletemsg(), API_modem_init(), API_readmsg(), API_sendmsg(), COM_init(), ST_delete_msg(), ST_init_phone(), and ST_read().

00086 { 00087 00088 UCSR0B &= ~(1<<RXCIE0); // Disable RX interrupt 00089 rx_i = rx_wr_i = 0; //Init variables 00090 rx_overflow = rx_ack = 0; //Zero overflow flag 00091 rx_buffer[ rx_wr_i ] = '\0'; //Buffer init. 00092 }

void COM_setSearchString unsigned char  Response  ) 
 

Set desired search string.

Parameters:
void 
Return values:
void 

Definition at line 127 of file AVRGSM_com.c.

References rx_i, searchFor, searchStr, and searchStrings.

Referenced by API_deletemsg(), API_modem_init(), API_readmsg(), API_sendmsg(), ST_delete_msg(), ST_init_phone(), and ST_read().

00128 { 00129 00130 UCSR0B &= ~( 1 << RXCIE0 ); // Disable RX interrupt 00131 searchFor = searchStrings[Response]; //Set desired search dtring 00132 searchStr = Response; //Used in rx_isr 00133 rx_i = 0; 00134 }

int COM_trim void   ) 
 

Remove trailing O, K, and
.

If the receive buffer have trailing "OK\r\n" These characters will be deleted.

Parameters:
void 
Return values:
i Length of trimmed buffer

Local variables

Definition at line 289 of file AVRGSM_com.c.

References rx_buffer, and rx_wr_i.

Referenced by TOOLS__decodeCMGR(), and TOOLS_decodeCMTI().

00290 { 00291 00293 int i; 00294 unsigned char temp; 00295 00296 for( i = rx_wr_i - 1; i >= 0; i--) //Run through COM_in[] backwards 00297 { 00298 temp = rx_buffer[i]; //rx_buff[i] into temp 00299 if( ( temp != '\r' ) && ( temp != '\n' ) && ( temp != 'O' ) && ( temp != 'K' ) ) //If not equal to 'O', 'K', '\r' or '\n', break 00300 { 00301 break; //Do break 00302 } 00303 } 00304 00305 rx_buffer[ i+1 ] = '\0'; //Terminate trimmed string 00306 00307 return i; //Return new length 00308 }

__interrupt void USART0_RX_interrupt void   ) 
 

Receive interrupt routine.

This receive routine buffer incomming messages from the connected GSM modem But also check if the received string was a acknowledge

Definition at line 143 of file AVRGSM_com.c.

References __interrupt, CMTI_, CRLF_, rx_ack, rx_buffer, RX_BUFFER_MASK, rx_i, rx_overflow, rx_wr_i, searchFor, searchStr, and searchStrings.

00144 { 00145 00146 unsigned char data; //Local variable 00147 00148 data = UDR0; //Always read something 00149 00150 rx_buffer[ rx_wr_i++ ] = data; //Store new data 00151 00152 00153 if( rx_wr_i > RX_BUFFER_MASK ) //Check for overflow 00154 { 00155 rx_wr_i = 0; //Reset write index 00156 rx_overflow = 1; //Set flag high 00157 UCSR0B &= ~( 1 << RXCIE0 ); // Disable RX interrupt 00158 } 00159 00160 if( searchFor[rx_i] == data ) //Test response match 00161 { 00162 rx_i++; 00163 00164 if( !searchFor[rx_i] ) //End of new_message string...received new message! 00165 { 00166 rx_i = 0; 00167 00168 if( searchStr == CMTI_ ) //+CMTI: 00169 { 00170 searchFor = searchStrings[ CRLF_ ]; //Wait for 00171 searchStr = CRLF_; 00172 } 00173 00174 else //Normal acknowledgement 00175 { 00176 rx_ack = 1; //Set new message flag 00177 UCSR0B &= ~( 1 << RXCIE0 ); // Disable RX interrupt 00178 } 00179 } 00180 } 00181 00182 else 00183 { 00184 rx_i = 0; //Not valid search pattern...start again. 00185 } 00186 }


Variable Documentation

const unsigned char __flash CMTI[] = "+CMTI: "
 

New Message arrived.

Definition at line 50 of file AVRGSM_com.c.

const unsigned char __flash CR_LF[] = "\r\n"
 

Carrige Return Line Feed.

Definition at line 52 of file AVRGSM_com.c.

const unsigned char __flash OK[] = "OK\r\n"
 

"OK"

Definition at line 49 of file AVRGSM_com.c.

const unsigned char __flash READY[] = "> "
 

Phone ready to receive text message.

Definition at line 51 of file AVRGSM_com.c.

int rx_ack
 

Extern flag from AVRSMS_com.c.

Definition at line 34 of file AVRGSM_com.c.

unsigned char rx_buffer[RX_BUFFER_SIZE] [static]
 

private buffer

Definition at line 37 of file AVRGSM_com.c.

Referenced by COM_gets(), COM_rx_reset(), COM_trim(), and USART0_RX_interrupt().

int rx_i [static]
 

Buffer counter.

Definition at line 43 of file AVRGSM_com.c.

Referenced by COM_rx_reset(), COM_setSearchString(), and USART0_RX_interrupt().

int rx_overflow
 

Overflow and acknowledge flag.

Definition at line 34 of file AVRGSM_com.c.

Referenced by COM_rx_reset(), and USART0_RX_interrupt().

int rx_wr_i [static]
 

Buffer write index.

Definition at line 46 of file AVRGSM_com.c.

Referenced by COM_rx_reset(), COM_trim(), and USART0_RX_interrupt().

const unsigned char __flash* searchFor
 

Flash pointer.

Definition at line 53 of file AVRGSM_com.c.

Referenced by COM_setSearchString(), and USART0_RX_interrupt().

unsigned char searchStr [static]
 

Private pointer.

Definition at line 40 of file AVRGSM_com.c.

Referenced by COM_setSearchString(), and USART0_RX_interrupt().

const unsigned char __flash* searchStrings[4] = {OK, CMTI, READY, CR_LF}
 

Initialize pointer.

Definition at line 54 of file AVRGSM_com.c.

Referenced by COM_setSearchString(), and USART0_RX_interrupt().


Generated on Tue Nov 1 16:21:41 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7