📄 as1.c
字号:
/** ###################################################################
** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : AS1.C
** Project : NODE_A
** Processor : MC9S12C64CFA16
** Beantype : AsynchroSerial
** Version : Bean 02.363, Driver 01.14.01, CPU db: 2.87.339
** Compiler : Metrowerks HC12 C Compiler
** Date/Time : 2006-11-11, 14:37
** Abstract :
** This bean "AsynchroSerial" implements an asynchronous serial
** communication. The bean supports different settings of
** parity, word width, stop-bit and communication speed,
** user can select interrupt or polling handler.
** Communication speed can be changed also in runtime.
** The bean requires one on-chip asynchronous serial channel.
** Settings :
** Serial channel : SCI
**
** Protocol
** Init baud rate : 9600baud
** Width : 8 bits
** Stop bits : 1
** Parity : none
** Breaks : Disabled
**
** Registers
** Input buffer : SCIDRL [207]
** Output buffer : SCIDRL [207]
** Control register : SCICR1 [202]
** Mode register : SCICR2 [203]
** Baud setting reg. : SCIBD [200]
** Special register : SCISR1 [204]
**
** Input interrupt
** Vector name : Vsci
** Priority : 1
**
** Output interrupt
** Vector name : Vsci
** Priority : 1
**
** Used pins:
** ----------------------------------------------------------
** Function | On package | Name
** ----------------------------------------------------------
** Input | 38 | PS0_RxD
** Output | 39 | PS1_TxD
** ----------------------------------------------------------
**
**
**
** Contents :
** RecvChar - byte AS1_RecvChar(AS1_TComData *Chr);
** SendChar - byte AS1_SendChar(AS1_TComData Chr);
** GetCharsInRxBuf - word AS1_GetCharsInRxBuf(void);
** GetCharsInTxBuf - word AS1_GetCharsInTxBuf(void);
** GetRxIdle - bool AS1_GetRxIdle(void);
** GetTxComplete - bool AS1_GetTxComplete(void);
**
** (c) Copyright UNIS, spol. s r.o. 1997-2005
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE AS1. */
#pragma MESSAGE DISABLE C4002 /* WARNING C4002: Result not used is ignored */
#pragma MESSAGE DISABLE C4301 /* INFORMATION C4301: Inline expansion done for function call */
#include "AS1.h"
#include "TI1.h"
#include "PWM6.h"
#include "CAN1.h"
#include "Bits1.h"
#include "TO1.h"
#include "Events.h"
#pragma DATA_SEG AS1_DATA
#pragma CODE_SEG AS1_CODE
#define OVERRUN_ERR 1 /* Overrun error flag bit */
#define COMMON_ERR 2 /* Common error of RX */
#define CHAR_IN_RX 4 /* Char is in the RX buffer */
#define FULL_TX 8 /* Full transmit buffer */
#define IDLE_ERR 16 /* Idle character flag bit */
static byte SerFlag; /* Flags for serial communication */
/* Bit 0 - Overrun error */
/* Bit 1 - Common error of RX */
/* Bit 2 - Char in the RX buffer */
/* Bit 3 - Full TX buffer */
/* Bit 4 - Idle detected */
static AS1_TComData BufferRead; /* Input char for SCI commmunication */
/*
** ===================================================================
** Method : AS1_RecvChar (bean AsynchroSerial)
**
** Description :
** If any data is received, this method returns one
** character, otherwise it returns an error code (it does
** not wait for data). This method is enabled only if the
** receiver property is enabled.
** DMA mode:
** If DMA controller is available on the selected CPU and
** the receiver is configured to use DMA controller then
** this method only sets the selected DMA channel. Then the
** status of the DMA transfer can be checked using
** GetCharsInRxBuf method. See an example of a typical usage
** for details about the communication using DMA.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to a received character
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_RXEMPTY - No data in receiver
** ERR_BREAK - Break character is detected
** (only when the <Interrupt service>
** property is disabled and the <Break
** signal> property is enabled)
** ERR_COMMON - common error occurred (the
** GetError method can be used for error
** specification)
** DMA mode:
** If DMA controller is available on the
** selected CPU and the receiver is
** configured to use DMA controller then
** only ERR_OK, ERR_RXEMPTY, and ERR_SPEED
** error code can be returned from this
** method.
** ===================================================================
*/
byte AS1_RecvChar(AS1_TComData *Chr)
{
byte Result = ERR_OK; /* Return error code */
if(!(SerFlag & CHAR_IN_RX)) { /* Is any char in the RX buffer? */
return ERR_RXEMPTY; /* If no then error */
}
EnterCritical(); /* Save the PS register */
*Chr = BufferRead; /* Received char */
Result = (byte)((SerFlag & (OVERRUN_ERR|COMMON_ERR))?ERR_COMMON:ERR_OK);
SerFlag &= ~(OVERRUN_ERR|COMMON_ERR|CHAR_IN_RX); /* Clear all errors in the status variable */
ExitCritical(); /* Restore the PS register */
return Result; /* Return error code */
}
/*
** ===================================================================
** Method : AS1_SendChar (bean AsynchroSerial)
**
** Description :
** Sends one character to the channel. If the bean is
** temporarily disabled (Disable method) SendChar method
** only stores data into an output buffer. In case of a zero
** output buffer size, only one character can be stored.
** Enabling the bean (Enable method) starts the transmission
** of the stored data. This method is available only if the
** transmitter property is enabled.
** DMA mode:
** If DMA controller is available on the selected CPU and
** the transmitter is configured to use DMA controller then
** this method only sets selected DMA channel. Then the
** status of the DMA transfer can be checked using
** GetCharsInTxBuf method. See an example of a typical usage
** for details about communication using DMA.
** Parameters :
** NAME - DESCRIPTION
** Chr - Character to send
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_TXFULL - Transmitter is full
** ===================================================================
*/
byte AS1_SendChar(AS1_TComData Chr)
{
if(SerFlag & FULL_TX) { /* Is any char in the TX buffer */
return ERR_TXFULL; /* If yes then error */
}
EnterCritical(); /* Save the PS register */
(void) SCISR1; /* Reset interrupt request flag */
SCIDRL = (byte)Chr; /* Store char to transmitter register */
SCICR2_SCTIE = 1; /* Enable transmit interrupt */
SerFlag |= FULL_TX; /* Set the flag "full TX buffer" */
ExitCritical(); /* Restore the PS register */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : AS1_GetCharsInRxBuf (bean AsynchroSerial)
**
** Description :
** Returns the number of characters in the input buffer.
** This method is available only if the receiver property is
** enabled.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -