uart_lib.c File Reference

#include "config.h"
#include "uart/uart_lib.h"

Include dependency graph for uart_lib.c:

Go to the source code of this file.

Defines

#define BITSAMPLING   8
#define Byte_transfer_enable()   { LINCR = (0<<LIN13)|(1<<LENA)|(1<<LCMD2)|(1<<LCMD1)|(1<<LCMD0); }
#define LBT_MASK   ((1<<LBT5)|(1<<LBT4)|(1<<LBT3)|(1<<LBT2)|(1<<LBT1)|(1<<LBT0))
#define Lin_get_data()   ( LINDAT )
#define Lin_rx_response_ready()   ( LINSIR & (1<<LRXOK) )
#define Lin_set_btr_brr(bt, br)
#define Lin_set_data(data)   ( LINDAT = data )
#define Lin_tx_response_ready()   ( LINSIR & (1<<LTXOK) )

Functions

r_uart_gtchar uart_getchar (void)
 This function allows to get a character from the UART.
bit uart_init (void)
 This function configures the UART configuration and timming following the constant definition of BAUDRATE and enables the UART controller.
r_uart_ptchar uart_putchar (p_uart_ptchar ch)
 This function allows to send a character on the UART.
bit uart_test_hit (void)
 This function allows to inform if a character was received.


Define Documentation

#define BITSAMPLING   8

Definition at line 43 of file uart_lib.c.

Referenced by uart_init().

 
#define Byte_transfer_enable (  )     { LINCR = (0<<LIN13)|(1<<LENA)|(1<<LCMD2)|(1<<LCMD1)|(1<<LCMD0); }

Definition at line 28 of file uart_lib.c.

Referenced by uart_init().

#define LBT_MASK   ((1<<LBT5)|(1<<LBT4)|(1<<LBT3)|(1<<LBT2)|(1<<LBT1)|(1<<LBT0))

Definition at line 26 of file uart_lib.c.

 
#define Lin_get_data (  )     ( LINDAT )

Definition at line 40 of file uart_lib.c.

Referenced by uart_getchar().

 
#define Lin_rx_response_ready (  )     ( LINSIR & (1<<LRXOK) )

Definition at line 38 of file uart_lib.c.

Referenced by uart_getchar(), and uart_test_hit().

#define Lin_set_btr_brr ( bt,
br   ) 

Value:

{ U8 __jacq__;                                                            \
                                  __jacq__ = LINCR;                                                       \
                                  LINCR  &= ~(1<<LENA);                                                   \
                                  LINBTR  = ((1<<LDISR) | (LBT_MASK & bt));                               \
                                  LINBRRH = (U8)((((((((U32)FOSC*1000)<<1)/(((U32)br)*bt))+1)>>1)-1)>>8); \
                                  LINBRRL = (U8)(( (((((U32)FOSC*1000)<<1)/(((U32)br)*bt))+1)>>1)-1)    ; \
                                  LINCR = __jacq__;                                                       }

Definition at line 30 of file uart_lib.c.

Referenced by uart_init().

#define Lin_set_data ( data   )     ( LINDAT = data )

Definition at line 41 of file uart_lib.c.

Referenced by uart_init(), and uart_putchar().

 
#define Lin_tx_response_ready (  )     ( LINSIR & (1<<LTXOK) )

Definition at line 39 of file uart_lib.c.

Referenced by uart_putchar().


Function Documentation

r_uart_gtchar uart_getchar ( void   ) 

This function allows to get a character from the UART.

Returns:
character read.

Definition at line 73 of file uart_lib.c.

References Lin_get_data, and Lin_rx_response_ready.

Referenced by build_cmd().

00074 {
00075     while(!Lin_rx_response_ready());
00076     return Lin_get_data();
00077 }

bit uart_init ( void   ) 

This function configures the UART configuration and timming following the constant definition of BAUDRATE and enables the UART controller.

Precondition:
before calling this function some declaration must be define in config.h:
  • FOSC Frequency of crystal in kHz (mandatory)Standard crystals available
  • BAUDRATE Baudrate in bit per second used for UART configuration (mandatory)
  • UART_CONFIG : (by default 8 bits| 1 bit stop |without parity)

Definition at line 54 of file uart_lib.c.

References BAUDRATE, BITSAMPLING, Byte_transfer_enable, Lin_set_btr_brr, Lin_set_data, and TRUE.

Referenced by ushell_task_init().

00055 {
00056    Lin_set_btr_brr(BITSAMPLING,BAUDRATE);
00057    Byte_transfer_enable();
00058    Lin_set_data(0xFF);
00059    return TRUE;
00060 }

r_uart_ptchar uart_putchar ( p_uart_ptchar  uc_wr_byte  ) 

This function allows to send a character on the UART.

Parameters:
uc_wr_byte character to print on UART.
Returns:
character sent.
Note:
the type p_uart_ptchar and r_uart_ptchar can be define to macth with a printf need.

Definition at line 63 of file uart_lib.c.

References Lin_set_data, and Lin_tx_response_ready.

Referenced by build_cmd(), print_hex16(), print_msg(), and ushell_task().

00064 {
00065    while (!Lin_tx_response_ready());
00066    Lin_set_data(ch);
00067    return (ch);
00068 }

bit uart_test_hit ( void   ) 

This function allows to inform if a character was received.

Returns:
True if character received.

Definition at line 48 of file uart_lib.c.

References Lin_rx_response_ready.

Referenced by build_cmd().

00049 {
00050   return (Lin_rx_response_ready());
00051 }


Generated on Wed Oct 22 15:04:00 2008 for AVR172 : Atmel BLDC control on ATAVRMC310 with ATmega32M1 by  doxygen 1.5.7.1