rs232.c File Reference

#include "error_management.h"

Go to the source code of this file.

Functions

int rs232_close ()
int rs232_open (char *_port, int baud_rate, int byte_size, int parity, int stop_bits)
int rs232_read (void *buffer, int size, int *_read_bytes)
int rs232_write (void *buffer, int size, int *_written_bytes)

Variables

static COMMTIMEOUTS g_cto
static DCB g_dcb
static HANDLE handle_com = NULL


Function Documentation

int rs232_close (  ) 

Definition at line 121 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00122 {
00123   CloseHandle(handle_com);
00124   return 1;
00125 }

int rs232_open ( char *  _port,
int  baud_rate,
int  byte_size,
int  parity,
int  stop_bits 
)

Definition at line 79 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00080 {
00081     // Make sure another port is not already opened
00082     ASSERT(!handle_com);
00083 
00084     // Open the existing COMX file to open the port
00085   handle_com = CreateFile(
00086                       _port,
00087                       GENERIC_READ | GENERIC_WRITE,
00088                       0,
00089                       NULL,
00090                       OPEN_EXISTING,
00091                       FILE_ATTRIBUTE_SYSTEM,
00092                       NULL);
00093  
00094     // Make sure it is opened
00095     if (handle_com == INVALID_HANDLE_VALUE)
00096        return 0;
00097 
00098     // buffer size for emission and reception
00099   SetupComm(handle_com, RS232_RX_SIZE, RS232_TX_SIZE);
00100 
00101     // COM port configuration
00102   g_dcb.BaudRate = baud_rate;
00103   g_dcb.ByteSize = byte_size;
00104   g_dcb.Parity = parity;
00105   g_dcb.StopBits = stop_bits;
00106   if(!SetCommTimeouts(handle_com, &g_cto) || !SetCommState(handle_com, &g_dcb))
00107     {
00108       CloseHandle(handle_com);
00109       return 0;
00110     }
00111 
00112     // Flush buffers for emission and reception
00113     // DTR = 1
00114   PurgeComm(handle_com, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
00115   EscapeCommFunction(handle_com, SETDTR);
00116 
00117   return 1;
00118 }

int rs232_read ( void *  buffer,
int  size,
int *  _read_bytes 
)

Definition at line 128 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00129 {
00130   return ReadFile(handle_com, buffer, size, (DWORD *) _read_bytes, (LPOVERLAPPED) NULL);
00131 }

int rs232_write ( void *  buffer,
int  size,
int *  _written_bytes 
)

Definition at line 134 of file ADPCM_STREAMING/rs232.c.

Referenced by main().

00135 {
00136   return WriteFile(handle_com, buffer, size, (DWORD *) _written_bytes, (LPOVERLAPPED) NULL);
00137 }


Variable Documentation

COMMTIMEOUTS g_cto [static]

Initial value:

Definition at line 37 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_open().

DCB g_dcb [static]

Initial value:

{
  sizeof(DCB),          
  9600,                 
  TRUE,                 
  FALSE,                
  FALSE,                
  FALSE,                
  DTR_CONTROL_ENABLE,   
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  RTS_CONTROL_ENABLE,   
  FALSE,                
  0,                    
  0,                    
  0x100,                
  0x100,                
  8,                    
  NOPARITY,             
  ONESTOPBIT,           
  0x11,                 
  0x13,                 
    '?',                  
  0x1A,                 
  0x10                
}

Definition at line 47 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_open().

HANDLE handle_com = NULL [static]

Definition at line 34 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_close(), rs232_open(), rs232_read(), and rs232_write().


Generated on Thu Dec 17 19:57:24 2009 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5