⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.h

📁 This network protcol stack,it is very strong and powerful!
💻 H
字号:
/************************************************************************************
* Includes the UART interface.
*
* Author(s): Allan Poulsen, Jakob Koed
*
* (c) Copyright 2004, Freescale Semiconductor, Inc. All rights reserved.
*
* Freescale Confidential Proprietary
* Digianswer Confidential
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
* Last Inspected:
* Last Tested:
*
* Source Safe revision history (Do not edit manually) 
*   $Date: 10-03-04 11:20 $
*   $Author: Allan1 $
*   $Revision: 10 $
*   $Workfile: Uart.h $
************************************************************************************/

#ifndef _UART_H_
#define _UART_H_

#define ENABLE_UART_PRINT

#include "App_Target.h"

// UART interface specific macros
#ifdef SELECT_SCI1
    #define SCIXBDH     SCI1BDH
    #define SCIXBDL     SCI1BDL

    #define SCIXC1  	SCI1C1
    #define SCIXC2      SCI1C2
    #define SCIXC3  	SCI1C3

    #define SCIXS1	    SCI1S1

    #define SCIXD       SCI1D	
#endif SELECT_SCI1

#ifdef SELECT_SCI2
    #define SCIXBDH     SCI2BDH
    #define SCIXBDL     SCI2BDL

    #define SCIXC1  	SCI2C1
    #define SCIXC2      SCI2C2
    #define SCIXC3  	SCI2C3

    #define SCIXS1	    SCI2S1

    #define SCIXD       SCI2D	
#endif SELECT_SCI2

#define RXBUFFERLEN 256   //MUST be 2^x
#define TXBUFFERLEN 256   //MUST be 2^x
#define FULLPACKETLENGTH 80

// Select one - to get correct baud rate
//#define __SYSTEM_BUS_CLOCK_32_78
//#define __SYSTEM_BUS_CLOCK_62_5
#define __USE_BAUD_RATE_FROM_NV_RAM

#ifndef ENABLE_UART_PRINT
#define Uart_Print(str)
#define Uart_PrintHex(hex, len, flags)
#endif



/************************************************************************************
*************************************************************************************
* Public macros
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Public prototypes
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Public type definitions
*************************************************************************************
************************************************************************************/

enum {
  gPrtHexBigEndian_c = 1<<0,
  gPrtHexNewLine_c   = 1<<1,
  gPrtHexCommas_c    = 1<<2,
};

/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/

/************************************************************************************
* Function that copies data received from the UART to the supplied buffer. A timeout
* ensures that this function will return if no data or only a partial buffer is
* available within a short time frame.
*   
* Interface assumptions:
*   None
*   
* Return value:
*   Number of bytes copied to the buffer
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   240504      ALP      Created
* 
************************************************************************************/
uint8_t Uart_Poll
  (
  uint8_t * pBuffer // Data from the UART is copied to this location
  );

/************************************************************************************
* Function that sends data to the UART from the supplied buffer. 
*   
* Interface assumptions:
*   None
*   
* Return value:
*   Number of bytes copied to the buffer
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   081104    BPPED1      Created
* 
************************************************************************************/
void Uart_Tx
  (
  uint8_t * pData, // Buffer with data to be sent to the UART
  uint8_t length   // Number of bytes in data buffer
  );

/************************************************************************************
* This function returns a byte which is incremented each time TIMER1 wraps around.
* Can be used for simple timing.
*   
* Interface assumptions:
*   None
*   
* Return value:
*   Timer value which is incremented on each TIMER1 IRQ. Wraps around after 255.
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   091104    BPPED1      Created
* 
************************************************************************************/
uint8_t Timer_Get
  (
  void
  );

/************************************************************************************
* This function resets the timer value to 0. Can be used for simple timing like:
* // Reset timer
* Timer_Reset();
* // Wait until timer has reached a certain value
* while(Timer_Get() < 20) {}
*   
* Interface assumptions:
*   None
*   
* Return value:
*   None.
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   161104    BPPED1      Created
* 
************************************************************************************/
void Timer_Reset
  (
  void
  );

#ifdef ENABLE_UART_PRINT

/************************************************************************************
* Function that prints out a string on the UART interface. String needs to be 
* 0-terminated
*   
* Interface assumptions:
*   None
*   
* Return value:
*   None
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   240504      ALP      Created
* 
************************************************************************************/
void Uart_Print(uint8_t * pString);

/************************************************************************************
* Function that prints out one byte on the UART interface as a hexdecimal string.
* E.g. the byte 0x5E is printed as the string "5E". It is up to the user to add
* decorations before or after the string is printed. 
* Example:
*   Uart_Print("Number is: 0x");
*   Uart_PrintHex(0x5E);
*   Uart_Print("\r\n");
*   This will result in "Number is 0x5E" being printed over the UART with line shift.
*   
* Interface assumptions:
*   None
*   
* Return value:
*   None
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   240504      ALP      Created
* 
************************************************************************************/
void Uart_PrintHex(uint8_t *hex, uint8_t len, uint8_t bigEndian);

#endif // ENABLE_UART_PRINT

/************************************************************************************
* Function that initializes UART interface (i.e. UART)
*   
* Interface assumptions:
*   None
*   
* Return value:
*   error code
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   160903      JK      Created
* 
************************************************************************************/
void Uart_Init(void);

/************************************************************************************
* SCI1 ISR for the transmit direction. 
*   
* Interface assumptions:
*   None
*   
* Return value:
*   none
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   160903      JK      Created
* 
************************************************************************************/
interrupt void SCIX_tx_ISR(void);


/************************************************************************************
* SCI1 ISR for the receive direction. 
*   
* Interface assumptions:
*   None
*   
* Return value:
*   none
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   160903      JK      Created
* 
************************************************************************************/
interrupt void SCIX_rx_ISR(void);

/************************************************************************************
*  
*   
* Interface assumptions:
*   None
*   
* Return value:
*   none
* 
* Revision history:
*   date      Author    Comments
*   ------    ------    --------
*   071004     ALP      Created
* 
************************************************************************************/
interrupt void UART_TIMER_ISR(void);

/************************************************************************************
*************************************************************************************
* Level 1 block comment
*************************************************************************************
************************************************************************************/

//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
// Level 2 block comment
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------

/* Level 3 block comment */




// Delimiters

/***********************************************************************************/

//-----------------------------------------------------------------------------------

#endif _UART_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -