📄 mc13191.c
字号:
/** ###################################################################
** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : MC13191.C
** Project : RTOSDemo
** Processor : MC9S08GT60CFB
** Beantype : SynchroMaster
** Version : Bean 02.213, Driver 01.10, CPU db: 2.87.086
** Compiler : Metrowerks HCS08 C Compiler
** Date/Time : 3/10/2006, 2:35 PM
** Abstract :
** This bean "SynchroMaster" implements MASTER part of synchronous
** serial master-slave communication.
** Settings :
** Synchro type : MASTER
**
** Serial channel : SPI1
**
** Protocol
** Init baud rate : 9_998MHz
** Clock edge : rising
** Width : 8 bits (always)
** Empty character : 0
** Empty char. on input : RECEIVED
**
** Registers
** Input buffer : SPI1D [002D]
** Output buffer : SPI1D [002D]
** Control register : SPI1C1 [0028]
** Mode register : SPI1C2 [0029]
** Baud setting reg. : SPI1BR [002A]
**
**
**
** Used pins :
** ----------------------------------------------------------
** Function | On package | Name
** ----------------------------------------------------------
** Input | 13 | PTE3_MISO1
** Output | 14 | PTE4_MOSI1
** Clock | 15 | PTE5_SPSCK1
** ----------------------------------------------------------
**
** Contents :
** RecvChar - byte MC13191_RecvChar(MC13191_TComData *Chr);
** SendChar - byte MC13191_SendChar(MC13191_TComData Chr);
** CharsInRxBuf - byte MC13191_CharsInRxBuf(word *Chr);
** GetCharsInRxBuf - word MC13191_GetCharsInRxBuf(void);
** SetShiftClockPolarity - byte MC13191_SetShiftClockPolarity(byte Edge);
** SetIdleClockPolarity - byte MC13191_SetIdleClockPolarity(byte Level);
**
** (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 MC13191. */
#include "MC13191.h"
#include "TickTimer.h"
#include "SW1Int.h"
#include "SW2.h"
#include "SW3.h"
#include "SW4.h"
#include "LED1.h"
#include "LED2.h"
#include "LED3.h"
#include "LED4.h"
#include "UART.h"
#include "SWI.h"
#define OVERRUN_ERR 0x01 /* Overrun error flag bit */
#define CHAR_IN_RX 0x08 /* Char is in RX buffer */
#define FULL_TX 0x10 /* Full transmit buffer */
#define RUNINT_FROM_TX 0x20 /* Interrupt is in progress */
#define FULL_RX 0x40 /* Full receive buffer */
static bool EnUser; /* Enable/Disable SPI */
static bool EnMode; /* Enable/Disable SPI in speed mode */
static byte SerFlag; /* Flags for serial communication */
/* Bits: 0 - OverRun error */
/* 1 - Unused */
/* 2 - Unused */
/* 3 - Char in RX buffer */
/* 4 - Full TX buffer */
/* 5 - Running int from TX */
/* 6 - Full RX buffer */
/* 7 - Unused */
static MC13191_TComData BufferWrite; /* Output char SPI commmunication */
/*
** ===================================================================
** Method : HWEnDi (bean SynchroMaster)
**
** Description :
** Enables or disables the peripheral(s) associated with the bean.
** The method is called automatically as a part of the Enable and
** Disable methods and several internal methods.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void HWEnDi(void)
{
if (EnMode && EnUser) { /* Enable device? */
SPI1C1_SPE = 1; /* Enable device */
if (SerFlag & FULL_TX) { /* Is any char in transmit buffer? */
SPI1D = BufferWrite; /* Store char to transmitter register */
SerFlag &= ~FULL_TX; /* Zeroize FULL_TX flag */
}
}
else {
SPI1C1_SPE = 0; /* Disable device */
}
}
/*
** ===================================================================
** Method : MC13191_RecvChar (bean SynchroMaster)
**
** Description :
** If any data is received, this method returns one
** character, otherwise it returns an error code (it does
** not wait for data).
** DMA mode:
** If DMA controller is available on selected CPU and
** receiver is configured to use DMA controller then this
** method only sets the selected DMA channel. Status of the
** DMA transfer can then be checked using method
** GetCharsInRxBuf. See typical usage for details about
** communication using DMA.
** Parameters :
** NAME - DESCRIPTION
** * Chr - A pointer to the 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_OVERRUN - Overrun error was detected
** from the last char or block received
** ERR_FAULT - Fault error was detected
** from the last char or block received.
** This error may not be supported on some
** CPUs (see generated code).
** ===================================================================
*/
byte MC13191_RecvChar(MC13191_TComData *Chr)
{
byte Status;
if (!EnMode) /* Is the device disabled in the actual speed CPU mode? */
return ERR_SPEED; /* If yes then error */
Status = SPI1S; /* Read the device error register */
*Chr = SPI1D; /* Read data from receiver */
if (!(Status & 0x80)) /* Is not received char? */
return ERR_RXEMPTY; /* If yes then error is returned */
return ERR_OK;
}
/*
** ===================================================================
** Method : MC13191_SendChar (bean SynchroMaster)
**
** Description :
** Sends one character to the channel.
** 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 the selected DMA channel. The
** status of the DMA transfer can then be checked using
** GetCharsInTxBuf method. See the 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_DISABLED - Device is disabled (only
** if output DMA is supported and enabled)
** ERR_TXFULL - Transmitter is full
** ===================================================================
*/
byte MC13191_SendChar(MC13191_TComData Chr)
{
if (!EnMode) /* Is the device disabled in the actual speed CPU mode? */
return ERR_SPEED; /* If yes then error */
if ((!SPI1S_SPTEF)||(SerFlag&FULL_TX)) { /* Is last character send? */
return ERR_TXFULL; /* If no then return error */
}
if(EnUser) { /* Is device enabled? */
SPI1D = Chr; /* If yes, send character */
}
else {
BufferWrite = Chr; /* If no, save character */
SerFlag |= FULL_TX; /* ...and set flag */
}
return ERR_OK; /* OK */
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -