Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libfitkit /

uart.h

   1  /*******************************************************************************
   2     uart.h:
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5  
   6     LICENSE TERMS
   7  
   8     Redistribution and use in source and binary forms, with or without
   9     modification, are permitted provided that the following conditions
  10     are met:
  11     1. Redistributions of source code must retain the above copyright
  12        notice, this list of conditions and the following disclaimer.
  13     2. Redistributions in binary form must reproduce the above copyright
  14        notice, this list of conditions and the following disclaimer in
  15        the documentation and/or other materials provided with the
  16        distribution.
  17     3. All advertising materials mentioning features or use of this software
  18        or firmware must display the following acknowledgement:
  19  
  20          This product includes software developed by the University of
  21          Technology, Faculty of Information Technology, Brno and its
  22          contributors.
  23  
  24     4. Neither the name of the Company nor the names of its contributors
  25        may be used to endorse or promote products derived from this
  26        software without specific prior written permission.
  27  
  28     This software or firmware is provided ``as is'', and any express or implied
  29     warranties, including, but not limited to, the implied warranties of
  30     merchantability and fitness for a particular purpose are disclaimed.
  31     In no event shall the company or contributors be liable for any
  32     direct, indirect, incidental, special, exemplary, or consequential
  33     damages (including, but not limited to, procurement of substitute
  34     goods or services; loss of use, data, or profits; or business
  35     interruption) however caused and on any theory of liability, whether
  36     in contract, strict liability, or tort (including negligence or
  37     otherwise) arising in any way out of the use of this software, even
  38     if advised of the possibility of such damage.
  39  
  40     $Id$
  41  
  42     Popis:
  43       UART0 drive.
  44  *******************************************************************************/
  45  
  46  #ifndef _UART_H_
  47  #define _UART_H_
  48  
  49  
  50  
  51  
  52  
  53  
  54  
  55  #ifdef MSP_16X
  56   #define UART_RX_BUF RXBUF0
  57   #define UART_TX_BUF TXBUF0
  58   #define UART_TX_BUF_FULL ((IFG1 & UTXIFG0) == 0)
  59   #define UART_RX_BUF_EMPTY ((IFG1 & URXIFG0) == 0)
  60  
  61   #define UART_enable_tx_irq() {IE1 |= UTXIE0;}
  62   #define UART_disable_tx_irq() {IE1 &= ~UTXIE0;}
  63  
  64  #endif
  65  #ifdef MSP_261X
  66   #define UART_RX_BUF UCA0RXBUF
  67   #define UART_TX_BUF UCA0TXBUF
  68   #define UART_TX_BUF_FULL ((IFG2 & UCA0TXIFG) == 0)
  69   #define UART_RX_BUF_EMPTY ((IFG2 & UCA0RXIFG) == 0)
  70  
  71   #define UART_enable_tx_irq() {IE2 |= UCA0TXIE;}
  72   #define UART_disable_tx_irq() {IE2 &= ~UCA0TXIE;}
  73  #endif
  74  
  75  #define serial_tx(ach) \
  76   {while (UART_TX_BUF_FULL) WDG_reset(); \
  77   UART_TX_BUF = (ach);}
  78  
  79  #define serial_rx(ach) \
  80   {while (UART_RX_BUF_EMPTY) WDG_reset(); \
  81   ach = UART_RX_BUF; }
  82  
  83  /**
  84  
  85   **/
  86  void serial_init(void);
  87  
  88  /**
  89  
  90   **/
  91  void serial_close(void);
  92  
  93  
  94  /**
  95  
  96  
  97   **/
  98  void term_send_char(char Uchar);
  99  
 100  /**
 101  
 102  
 103   **/
 104  void term_send_char_idle(unsigned char Uchar);
 105  
 106  /**
 107  
 108  
 109   **/
 110  void term_send_char_hex(unsigned char Uchar);
 111  
 112  
 113  #define term_send_bool(cond) term_send_char((cond) ? '1' : '0')
 114  /**
 115  
 116   **/
 117  /*
 118  void term_send_crlf(void);
 119  */
 120  #define term_send_crlf() { term_send_char(CR); term_send_char(LF); }
 121  
 122  /**
 123  
 124  
 125  
 126   **/
 127  void term_send_str(char *ptrStr);
 128  
 129  /**
 130  
 131  
 132  
 133   **/
 134  /*
 135  void term_send_str_crlf(char *ptrStr);
 136  */
 137  #define term_send_str_crlf(ptrStr) { term_send_str(ptrStr); term_send_crlf(); }
 138  
 139  /**
 140  
 141  
 142   **/
 143  void term_send_num(long int iNum);
 144  
 145  /**
 146  
 147  
 148  
 149   **/
 150  /*
 151  void term_snd_real(long intn, long desn);
 152  */
 153  //#define term_snd_real(inum, fnum) { term_send_num(inum); term_send_char('.'); term_send_num(fnum); }
 154  
 155  /**
 156  
 157  
 158   **/
 159  void term_send_hex(long int iNum);
 160  
 161  /**
 162  
 163  
 164   **/
 165  unsigned char term_rcv_char(void);
 166  
 167  /**
 168  
 169  
 170  
 171  
 172  
 173   **/
 174  signed int term_rcv_block(unsigned char *out, int count);
 175  
 176  /**
 177  
 178  
 179  
 180   **/
 181  /*
 182  unsigned char term_snd_flag(void);
 183  */
 184  #define term_snd_flag() (unsigned char)((TXEPT & U0TCTL) ? 0 : 1)
 185  
 186  /**
 187  
 188  
 189   **/
 190  /*
 191  unsigned int term_rcv_flag(void);
 192  */
 193  extern volatile unsigned int ReceiveNum;
 194  #define term_rcv_flag() (unsigned int)(ReceiveNum)
 195  
 196  /**
 197  
 198  
 199  
 200  
 201   **/
 202  int term_rcv_char_t(long int timeout);
 203  
 204  /**
 205  
 206  
 207   **/
 208  /*
 209  unsigned char term_trnsmt_flag(void);
 210  */
 211  extern volatile unsigned char TransmitNum;
 212  #define term_trnsmt_flag() (unsigned char)(LengthBuffers_Tx - TransmitNum)
 213  
 214  /**
 215  
 216   **/
 217  void term_flush_rx_buf(void);
 218  #define term_flush_rx_buf() while (term_rcv_flag() != 0) { term_rcv_char(); }
 219  
 220  /**
 221  
 222   **/
 223  /*
 224  void term_flush_tx_buf(void);
 225  */
 226  extern volatile unsigned char TransmitNum;
 227  #define term_flush_tx_buf() while ((TransmitNum != 0) || ((U0TCTL & TXEPT) == 0));
 228  
 229  /**
 230     \brief Detekce BREAKu.
 231     \return 0 - nenastal BREAK
 232          \n 1 - BREAK nastal
 233   **/
 234  /*
 235  unsigned char term_dtct_break(void);
 236  */
 237  extern volatile unsigned char BreakFlag;
 238  #define term_dtct_break() (unsigned char)(BreakFlag != 0)
 239  
 240  /**
 241  
 242   **/
 243  /*
 244  void term_rst_break_flag(void);
 245  */
 246  extern volatile unsigned char BreakFlag;
 247  #define term_rst_break_flag() { BreakFlag = 0; }
 248  
 249  /**
 250     \brief Detekce ERROR.
 251     \return 0 - nenastal ERROR,
 252          \n 1 - nastal ERROR
 253   **/
 254  /*
 255  unsigned char term_dtct_error(void);
 256  */
 257  // stoji se za to podivat jak to bylo naprogramovane :)
 258  extern volatile unsigned char ErrorFlag;
 259  #define term_dtct_error() (unsigned char)(ErrorFlag ? ((ErrorFlag = 0), 1) : 0)
 260  
 261  /**
 262   \brief Vyslani ESC sekvence.
 263   - Delka retezce nesmi byt vetsi nez velikost vyst. bufferu (LengthBuffers).
 264   \param ptrStr - vysilany retazec
 265   **/
 266  #define term_send_esc_seq(ptrStr) { term_send_char(ESC); term_send_str(ptrStr); }
 267  
 268  #endif   /* _UART_H_ */
 269  
Zobrazeno: 731750x Naposledy: 29.11.2022 05:38:24