Mobil_surveillance_system 1
Defines | Typedefs | Functions | Variables
UART1.h File Reference

UART1 functions header file. More...

#include <string.h>
#include <stdlib.h>
#include "msp430f2617.h"
#include "Bitmanip.h"
#include "FIFO.h"
#include "Interrupts.h"

Go to the source code of this file.

Defines

#define UART1_RX_BUFFER_SIZE   16
#define UART1_TX_BUFFER_SIZE   16
#define DEFINE_TBOOLEAN
#define UART1_TX_BUFFER_USED
#define UART1_TX_BUFFER_FREE   (UART1_TX_BUFFER_SIZE - UART1_TX_BUFFER_USED)
#define UART1_TX_BUFFER_EMPTY
#define UART1_TX_BUFFER_FULL
#define UART1_ADVANCE_TX_BUFFER_INDEX(Index)   ((Index) = ((Index) + 1) % UART1_TX_BUFFER_SIZE)
#define UART1_RX_BUFFER_USED
#define UART1_RX_BUFFER_FREE   (UART1_RX_BUFFER_SIZE - UART1_RX_BUFFER_USED)
#define UART1_RX_BUFFER_EMPTY
#define UART1_RX_BUFFER_FULL
#define UART1_ADVANCE_RX_BUFFER_INDEX(Index)   ((Index) = ((Index) + 1) % UART1_RX_BUFFER_SIZE)

Typedefs

typedef unsigned char tBoolean
typedef void(* tpfUART1AppendResponseCallbackFunction )(const char *)

Functions

void UART1_rxHandler (void)
void UART1_txHandler (void)
void UART1_initUART1 (void)
int UART1_read (void)
int UART1_write (char *pcBuffer, unsigned int uiLength)
void UART1_sendChar (void)
tBoolean UART1_isWritingDone (void)
void UART1_primeTransmit (void)
void UART1_flushRx (void)
void UART1_flushTx (void)
void UART1_setAppendResponseCallbackFunction (tpfUART1AppendResponseCallbackFunction pfCallbackAppendResponse)

Variables

tBoolean ge_tbUART1RXITFLAG
 This flag inicates if any character has been received.
tBoolean ge_tbUART1TXITFLAG
 This flag inicates if any character has been sent.

Detailed Description

UART1 functions header file.

This file contains functions prototypes reltad to the UART1 pertiferia.

Definition in file UART1.h.


Define Documentation

#define UART1_ADVANCE_RX_BUFFER_INDEX (   Index)    ((Index) = ((Index) + 1) % UART1_RX_BUFFER_SIZE)

This macro can be used to increase the either the read or write index of the rx fifo.

Definition at line 123 of file UART1.h.

#define UART1_ADVANCE_TX_BUFFER_INDEX (   Index)    ((Index) = ((Index) + 1) % UART1_TX_BUFFER_SIZE)

This macro can de used to increase the either the read or write index of the tx fifo.

Definition at line 95 of file UART1.h.

#define UART1_RX_BUFFER_EMPTY
Value:

This macro can be used to decide if the rx fifo is free.

Definition at line 114 of file UART1.h.

#define UART1_RX_BUFFER_FREE   (UART1_RX_BUFFER_SIZE - UART1_RX_BUFFER_USED)

This macro can be used to decide if we have place in the rx fifo.

Definition at line 110 of file UART1.h.

#define UART1_RX_BUFFER_FULL
Value:

This macro can de used to decide if the rx fifo is full.

Definition at line 118 of file UART1.h.

#define UART1_RX_BUFFER_USED
Value:

This macro can be used to determine the current elements in the rx fifo.

Definition at line 105 of file UART1.h.

#define UART1_TX_BUFFER_EMPTY
Value:

This macro can be used to decide if the tx fifo is free.

Definition at line 86 of file UART1.h.

#define UART1_TX_BUFFER_FREE   (UART1_TX_BUFFER_SIZE - UART1_TX_BUFFER_USED)

This macro can be used to decide if we have place in the tx fifo.

Definition at line 82 of file UART1.h.

#define UART1_TX_BUFFER_FULL
Value:

This macro can de used to decide if the tx fifo is full.

Definition at line 90 of file UART1.h.

#define UART1_TX_BUFFER_USED
Value:

This macro can be used to determine the current elements in the tx fifo.

Definition at line 77 of file UART1.h.


Typedef Documentation

typedef unsigned char tBoolean

bool type defination

Definition at line 49 of file UART1.h.

typedef void(* tpfUART1AppendResponseCallbackFunction)(const char *)

Callback functions functionpointer declarations

Definition at line 56 of file UART1.h.


Function Documentation

void UART1_initUART1 ( void  )

proba

Definition at line 118 of file UART1.c.

{
    P3OUT &= ~(BIT6+BIT7);
    // P3.6,7 = USCI_A1 TXD/RXD
    P3SEL = 0xC0;
    // CLK = ACLK
    UCA1CTL1 |= UCSSEL_1; 
    // 9600
    UCA1BR0 = 0x03;      // 32kHz/9600 = 3.41  
    // 9600                       
    UCA1BR1 = 0x00;
    // Modulation UCBRSx = 5
    UCA1MCTL = UCBRS1 + UCBRS0; // 
    // **Initialize USCI state machine**              
    UCA1CTL1 &= ~UCSWRST; 
    // Enable USCI_A1 RX interrupt                    
    UC1IE |= UCA1RXIE;
    // Enable USCI_A1 TX interrupt     
    UC1IE |= UCA1TXIE;  
    // Enable global interrupt
    _bis_SR_register(LPM3_bits + GIE);
    // set RX ISR callback function
    Interrupts_setUSCI1RX_ISRCallbackFunction(&UART1_rxHandler);
    // set TX ISR callback function;    
    Interrupts_setUSCI1TX_ISRCallbackFunction(&UART1_txHandler);              
}
void UART1_setAppendResponseCallbackFunction ( tpfUART1AppendResponseCallbackFunction  pfCallbackAppendResponse)
Parameters:
pfCallbackAppendResponse

Definition at line 169 of file UART1.c.

{
    g_pfOnCallbackGPSAppendResponse = pfCallbackAppendResponse;
}
int UART1_write ( char *  pcBuffer,
unsigned int  uiLength 
)
Parameters:
pcBuffer
uiLength

Definition at line 206 of file UART1.c.

{
    unsigned int uiIdx;
    for( uiIdx = 0; uiIdx < uiLength; uiIdx++ ){
        if(!UART1_TX_BUFFER_FULL){
            g_pcUart1TxBuffer[g_uiUart1TxWriteIndex] = pcBuffer[uiIdx];
            UART1_ADVANCE_TX_BUFFER_INDEX(g_uiUart1TxWriteIndex);
        }
        else{
            // TODO if the tx buffer is full
        }
    }
    if(!UART1_TX_BUFFER_EMPTY){
        // send as many characters to the uart buffer as many can
        UART1_primeTransmit();
    }
    // return the number of the character written into the buffer
    return uiIdx;
}
 All Data Structures Files Functions Variables Typedefs Enumerations Defines