|
本帖最后由 FSL_TICS_ZP 于 2014-10-8 16:01 编辑
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : UART2.h
** Project : KL16_T
** Processor : MKL16Z128VLH4
** Component : Serial_LDD
** Version : Component 01.188, Driver 01.12, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2014-09-24, 01:35, # CodeGen: 71
** Abstract :
** This component "Serial_LDD" implements an asynchronous serial
** communication. The component 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 component requires one on-chip asynchronous serial communication channel.
** Settings :
** Component name : UART2
** Device : UART2
** Interrupt service/event : Enabled
** Interrupt RxD : INT_UART2
** Interrupt RxD priority : medium priority
** Interrupt TxD : INT_UART2
** Interrupt TxD priority : medium priority
** Interrupt Error : INT_UART2
** Interrupt Error priority : medium priority
** Settings :
** Data width : 8 bits
** Parity : None
** Stop bits : 1
** Loop mode : Normal
** Baud rate : 9600 baud
** Wakeup condition : Idle line wakeup
** Stop in wait mode : no
** Idle line mode : Starts after start bit
** Transmitter output : Not inverted
** Receiver input : Not inverted
** Break generation length : 10/11 bits
** Receiver : Enabled
** RxD : ADC0_DM3/ADC0_SE7a/PTE23/TPM2_CH1/UART2_RX
** RxD pin signal :
** Transmitter : Enabled
** TxD : ADC0_DP3/ADC0_SE3/PTE22/TPM2_CH0/UART2_TX
** TxD pin signal :
** Flow control : None
** Initialization :
** Enabled in init. code : yes
** Auto initialization : yes
** Event mask :
** OnBlockSent : Enabled
** OnBlockReceived : Enabled
** OnTxComplete : Disabled
** OnError : Disabled
** OnBreak : Disabled
** CPU clock/configuration selection :
** Clock configuration 0 : This component enabled
** Clock configuration 1 : This component disabled
** Clock configuration 2 : This component disabled
** Clock configuration 3 : This component disabled
** Clock configuration 4 : This component disabled
** Clock configuration 5 : This component disabled
** Clock configuration 6 : This component disabled
** Clock configuration 7 : This component disabled
** Contents :
** Init - LDD_TDeviceData* UART2_Init(LDD_TUserData *UserDataPtr);
** SendBlock - LDD_TError UART2_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData...
** ReceiveBlock - LDD_TError UART2_ReceiveBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData...
** CancelBlockTransmission - LDD_TError UART2_CancelBlockTransmission(LDD_TDeviceData *DeviceDataPtr);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file UART2.h
** @version 01.12
** @brief
** This component "Serial_LDD" implements an asynchronous serial
** communication. The component 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 component requires one on-chip asynchronous serial communication channel.
*/
/*!
** @addtogroup UART2_module UART2 module documentation
** @{
*/
#ifndef __UART2_H
#define __UART2_H
/* MODULE UART2. */
#include "Cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
/*! Peripheral base address of a device allocated by the component. This constant can be used directly in PDD macros. */
#define UART2_PRPH_BASE_ADDRESS 0x4006C000U
/*! Device data structure pointer used when auto initialization property is enabled. This constant can be passed as a first parameter to all component's methods. */
#define UART2_DeviceData ((LDD_TDeviceData *)PE_LDD_GetDeviceStructure(PE_LDD_COMPONENT_UART2_ID))
/* Methods configuration constants - generated for all enabled component's methods */
#define UART2_Init_METHOD_ENABLED /*!< Init method of the component UART2 is enabled (generated) */
#define UART2_SendBlock_METHOD_ENABLED /*!< SendBlock method of the component UART2 is enabled (generated) */
#define UART2_ReceiveBlock_METHOD_ENABLED /*!< ReceiveBlock method of the component UART2 is enabled (generated) */
#define UART2_CancelBlockTransmission_METHOD_ENABLED /*!< CancelBlockTransmission method of the component UART2 is enabled (generated) */
/* Events configuration constants - generated for all enabled component's events */
#define UART2_OnBlockReceived_EVENT_ENABLED /*!< OnBlockReceived event of the component UART2 is enabled (generated) */
#define UART2_OnBlockSent_EVENT_ENABLED /*!< OnBlockSent event of the component UART2 is enabled (generated) */
#define ENABLED_TX_INT 0x01U /*!< TX interrupt enabled */
#define BREAK_DETECTED 0x02U /*!< Break detected */
#define TX_COMPLETED 0x04U /*!< Transmission completed */
#define ENABLE_TX_COMPLETE 0x10U /*!< Enable/Disable of TX complete detection. Used in the polling mode only */
/*! Device data structure type */
typedef struct {
uint16_t SerFlag; /*!< Flags for serial communication */
uint16_t InpRecvDataNum; /*!< The counter of received characters */
uint8_t *InpDataPtr; /*!< The buffer pointer for received characters */
uint16_t InpDataNumReq; /*!< The counter of characters to receive by ReceiveBlock() */
uint16_t OutSentDataNum; /*!< The counter of sent characters */
uint8_t *OutDataPtr; /*!< The buffer pointer for data to be transmitted */
uint16_t OutDataNumReq; /*!< The counter of characters to be send by SendBlock() */
LDD_TUserData *UserDataPtr; /*!< Pointer to user data */
} UART2_TDeviceData;
typedef UART2_TDeviceData *UART2_TDeviceDataPtr ; /*!< Pointer to the device data structure. */
/*
** ===================================================================
** Method : UART2_Init (component Serial_LDD)
*/
/*!
** @brief
** Initializes the device. Allocates memory for the device data
** structure, allocates interrupt vectors and sets interrupt
** priority, sets pin routing, sets timing, etc. If the "Enable
** in init. code" is set to "yes" value then the device is also
** enabled(see the description of the Enable() method). In this
** case the Enable() method is not necessary and needn't to be
** generated.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer will be
** passed as an event or callback parameter.
** @return
** - Device data structure pointer.
*/
/* ===================================================================*/
LDD_TDeviceData* UART2_Init(LDD_TUserData *UserDataPtr);
/*
** ===================================================================
** Method : UART2_ReceiveBlock (component Serial_LDD)
*/
/*!
** @brief
** Specifies the number of data to receive. The method returns
** ERR_BUSY until the specified number of characters is
** received. Method [CancelBlockReception] can be used to
** cancel a running receive operation. If a receive operation
** is not in progress (the method was not called or a previous
** operation has already finished) all received characters will
** be lost without any notification. To prevent the loss of
** data call the method immediately after the last receive
** operation has finished (e.g. from the [OnBlockReceived]
** event). This method finishes immediately after calling it -
** it doesn't wait the end of data reception. Use event
** [OnBlockReceived] to check the end of data reception.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @param
** BufferPtr - Pointer to a buffer where
** received characters will be stored. In case
** of 8bit character width each character in
** buffer occupies 1 byte. In case of 9 and
** more bit long character width each
** character in buffer occupies 2 bytes.
** @param
** Size - Number of characters to receive
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_PARAM_SIZE - Parameter Size is out of
** expected range.
** ERR_DISABLED - The component or device is
** disabled.
** ERR_BUSY - The previous receive request is
** pending.
*/
/* ===================================================================*/
LDD_TError UART2_ReceiveBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size);
/*
** ===================================================================
** Method : UART2_SendBlock (component Serial_LDD)
*/
/*!
** @brief
** Sends a block of characters. The method returns ERR_BUSY
** when the previous block transmission is not completed.
** Method [CancelBlockTransmission] can be used to cancel a
** transmit operation. This method is available only if the
** transmitter property is enabled. This method finishes
** immediately after calling it - it doesn't wait the end of
** data transmission. Use event [OnBlockSent] to check the end
** of data transmission.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @param
** BufferPtr - Pointer to a buffer from where
** data will be sent. In case of 8bit
** character width each character in buffer
** occupies 1 byte. In case of 9 and more bit
** long character width each character in
** buffer occupies 2 bytes.
** @param
** Size - Number of characters in the buffer.
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_PARAM_SIZE - Parameter Size is out of
** expected range.
** ERR_DISABLED - The component or device is
** disabled.
** ERR_BUSY - The previous transmit request is
** pending.
*/
/* ===================================================================*/
LDD_TError UART2_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size);
/*
** ===================================================================
** Method : UART2_CancelBlockTransmission (component Serial_LDD)
*/
/*!
** @brief
** Immediately cancels the running transmit process started by
** method [SendBlock]. Characters already stored in the
** transmit shift register will be sent.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_DISABLED - The component or device is
** disabled.
*/
/* ===================================================================*/
LDD_TError UART2_CancelBlockTransmission(LDD_TDeviceData *DeviceDataPtr);
/*
** ===================================================================
** Method : UART2_Interrupt (component Serial_LDD)
**
** Description :
** The ISR function handling the device receive/transmit
** interrupt. Calls InterruptTX/InterruptRX methods.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/* {Default RTOS Adapter} ISR function prototype */
PE_ISR(UART2_Interrupt);
/* END UART2. */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
/* ifndef __UART2_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.10]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : UART2.c
** Project : KL16_T
** Processor : MKL16Z128VLH4
** Component : Serial_LDD
** Version : Component 01.188, Driver 01.12, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2014-09-24, 01:35, # CodeGen: 71
** Abstract :
** This component "Serial_LDD" implements an asynchronous serial
** communication. The component 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 component requires one on-chip asynchronous serial communication channel.
** Settings :
** Component name : UART2
** Device : UART2
** Interrupt service/event : Enabled
** Interrupt RxD : INT_UART2
** Interrupt RxD priority : medium priority
** Interrupt TxD : INT_UART2
** Interrupt TxD priority : medium priority
** Interrupt Error : INT_UART2
** Interrupt Error priority : medium priority
** Settings :
** Data width : 8 bits
** Parity : None
** Stop bits : 1
** Loop mode : Normal
** Baud rate : 9600 baud
** Wakeup condition : Idle line wakeup
** Stop in wait mode : no
** Idle line mode : Starts after start bit
** Transmitter output : Not inverted
** Receiver input : Not inverted
** Break generation length : 10/11 bits
** Receiver : Enabled
** RxD : ADC0_DM3/ADC0_SE7a/PTE23/TPM2_CH1/UART2_RX
** RxD pin signal :
** Transmitter : Enabled
** TxD : ADC0_DP3/ADC0_SE3/PTE22/TPM2_CH0/UART2_TX
** TxD pin signal :
** Flow control : None
** Initialization :
** Enabled in init. code : yes
** Auto initialization : yes
** Event mask :
** OnBlockSent : Enabled
** OnBlockReceived : Enabled
** OnTxComplete : Disabled
** OnError : Disabled
** OnBreak : Disabled
** CPU clock/configuration selection :
** Clock configuration 0 : This component enabled
** Clock configuration 1 : This component disabled
** Clock configuration 2 : This component disabled
** Clock configuration 3 : This component disabled
** Clock configuration 4 : This component disabled
** Clock configuration 5 : This component disabled
** Clock configuration 6 : This component disabled
** Clock configuration 7 : This component disabled
** Contents :
** Init - LDD_TDeviceData* UART2_Init(LDD_TUserData *UserDataPtr);
** SendBlock - LDD_TError UART2_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData...
** ReceiveBlock - LDD_TError UART2_ReceiveBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData...
** CancelBlockTransmission - LDD_TError UART2_CancelBlockTransmission(LDD_TDeviceData *DeviceDataPtr);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file UART2.c
** @version 01.12
** @brief
** This component "Serial_LDD" implements an asynchronous serial
** communication. The component 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 component requires one on-chip asynchronous serial communication channel.
*/
/*!
** @addtogroup UART2_module UART2 module documentation
** @{
*/
/* MODULE UART2. */
/*lint -save -e926 -e927 -e928 -e929 -e572 Disable MISRA rule (11.4,12.8) checking. */
/* {Default RTOS Adapter} No RTOS includes */
#include "UART2.h"
#include "Events.h"
#include "UART_PDD.h"
#include "SIM_PDD.h"
#ifdef __cplusplus
extern "C" {
#endif
/*! The mask of available events used to enable/disable events during runtime. */
#define AVAILABLE_EVENTS_MASK (LDD_SERIAL_ON_BLOCK_RECEIVED | LDD_SERIAL_ON_BLOCK_SENT)
/* {Default RTOS Adapter} Static object used for simulation of dynamic driver memory allocation */
static UART2_TDeviceData DeviceDataPrv__DEFAULT_RTOS_ALLOC;
/* {Default RTOS Adapter} Global variable used for passing a parameter into ISR */
static UART2_TDeviceDataPtr INT_UART2__DEFAULT_RTOS_ISRPARAM;
/*
** ===================================================================
** Method : UART2_Init (component Serial_LDD)
*/
/*!
** @brief
** Initializes the device. Allocates memory for the device data
** structure, allocates interrupt vectors and sets interrupt
** priority, sets pin routing, sets timing, etc. If the "Enable
** in init. code" is set to "yes" value then the device is also
** enabled(see the description of the Enable() method). In this
** case the Enable() method is not necessary and needn't to be
** generated.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer will be
** passed as an event or callback parameter.
** @return
** - Device data structure pointer.
*/
/* ===================================================================*/
LDD_TDeviceData* UART2_Init(LDD_TUserData *UserDataPtr)
{
/* Allocate device structure */
UART2_TDeviceDataPtr DeviceDataPrv;
/* {Default RTOS Adapter} Driver memory allocation: Dynamic allocation is simulated by a pointer to the static object */
DeviceDataPrv = &DeviceDataPrv__DEFAULT_RTOS_ALLOC;
/* Clear the receive counters and pointer */
DeviceDataPrv->InpRecvDataNum = 0x00U; /* Clear the counter of received characters */
DeviceDataPrv->InpDataNumReq = 0x00U; /* Clear the counter of characters to receive by ReceiveBlock() */
DeviceDataPrv->InpDataPtr = NULL; /* Clear the buffer pointer for received characters */
/* Clear the transmit counters and pointer */
DeviceDataPrv->OutSentDataNum = 0x00U; /* Clear the counter of sent characters */
DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of characters to be send by SendBlock() */
DeviceDataPrv->OutDataPtr = NULL; /* Clear the buffer pointer for data to be transmitted */
DeviceDataPrv->UserDataPtr = UserDataPtr; /* Store the RTOS device structure */
/* Allocate interrupt vectors */
/* {Default RTOS Adapter} Set interrupt vector: IVT is static, ISR parameter is passed by the global variable */
INT_UART2__DEFAULT_RTOS_ISRPARAM = DeviceDataPrv;
/* SIM_SCGC4: UART2=1 */
SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;
/* PORTE_PCR23: ISF=0,MUX=4 */
PORTE_PCR23 = (uint32_t)((PORTE_PCR23 & (uint32_t)~(uint32_t)(
PORT_PCR_ISF_MASK |
PORT_PCR_MUX(0x03)
)) | (uint32_t)(
PORT_PCR_MUX(0x04)
));
/* PORTE_PCR22: ISF=0,MUX=4 */
PORTE_PCR22 = (uint32_t)((PORTE_PCR22 & (uint32_t)~(uint32_t)(
PORT_PCR_ISF_MASK |
PORT_PCR_MUX(0x03)
)) | (uint32_t)(
PORT_PCR_MUX(0x04)
));
/* NVIC_IPR3: PRI_14=0x80 */
NVIC_IPR3 = (uint32_t)((NVIC_IPR3 & (uint32_t)~(uint32_t)(
NVIC_IP_PRI_14(0x7F)
)) | (uint32_t)(
NVIC_IP_PRI_14(0x80)
));
/* NVIC_ISER: SETENA|=0x4000 */
NVIC_ISER |= NVIC_ISER_SETENA(0x4000);
UART_PDD_EnableTransmitter(UART2_BASE_PTR, PDD_DISABLE); /* Disable transmitter. */
UART_PDD_EnableReceiver(UART2_BASE_PTR, PDD_DISABLE); /* Disable receiver. */
DeviceDataPrv->SerFlag = 0x00U; /* Reset flags */
/* UART2_C1: LOOPS=0,UARTSWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */
UART2_C1 = 0x00U; /* Set the C1 register */
/* UART2_C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
UART2_C3 = 0x00U; /* Set the C3 register */
/* UART2_S2: LBKDIF=0,RXEDGIF=0,??=0,RXINV=0,RWUID=0,BRK13=0,LBKDE=0,RAF=0 */
UART2_S2 = 0x00U; /* Set the S2 register */
UART_PDD_SetBaudRate(UART2_BASE_PTR, 156U); /* Set the baud rate register. */
UART_PDD_EnableTransmitter(UART2_BASE_PTR, PDD_ENABLE); /* Enable transmitter */
UART_PDD_EnableReceiver(UART2_BASE_PTR, PDD_ENABLE); /* Enable receiver */
UART_PDD_EnableInterrupt(UART2_BASE_PTR, ( UART_PDD_INTERRUPT_RECEIVER )); /* Enable interrupts */
/* Registration of the device structure */
PE_LDD_RegisterDeviceStructure(PE_LDD_COMPONENT_UART2_ID,DeviceDataPrv);
return ((LDD_TDeviceData *)DeviceDataPrv);
}
/*
** ===================================================================
** Method : UART2_ReceiveBlock (component Serial_LDD)
*/
/*!
** @brief
** Specifies the number of data to receive. The method returns
** ERR_BUSY until the specified number of characters is
** received. Method [CancelBlockReception] can be used to
** cancel a running receive operation. If a receive operation
** is not in progress (the method was not called or a previous
** operation has already finished) all received characters will
** be lost without any notification. To prevent the loss of
** data call the method immediately after the last receive
** operation has finished (e.g. from the [OnBlockReceived]
** event). This method finishes immediately after calling it -
** it doesn't wait the end of data reception. Use event
** [OnBlockReceived] to check the end of data reception.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @param
** BufferPtr - Pointer to a buffer where
** received characters will be stored. In case
** of 8bit character width each character in
** buffer occupies 1 byte. In case of 9 and
** more bit long character width each
** character in buffer occupies 2 bytes.
** @param
** Size - Number of characters to receive
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_PARAM_SIZE - Parameter Size is out of
** expected range.
** ERR_DISABLED - The component or device is
** disabled.
** ERR_BUSY - The previous receive request is
** pending.
*/
/* ===================================================================*/
LDD_TError UART2_ReceiveBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size)
{
UART2_TDeviceDataPtr DeviceDataPrv = (UART2_TDeviceDataPtr)DeviceDataPtr;
if (Size == 0U) { /* Is the parameter Size within an expected range? */
return ERR_PARAM_SIZE; /* If no then error */
}
if (DeviceDataPrv->InpDataNumReq != 0x00U) { /* Is the previous receive operation pending? */
return ERR_BUSY; /* If yes then error */
}
/* {Default RTOS Adapter} Critical section begin, general PE function is used */
EnterCritical();
DeviceDataPrv->InpDataPtr = (uint8_t*)BufferPtr; /* Store a pointer to the input data. */
DeviceDataPrv->InpDataNumReq = Size; /* Store a number of characters to be received. */
DeviceDataPrv->InpRecvDataNum = 0x00U; /* Set number of received characters to zero. */
/* {Default RTOS Adapter} Critical section end, general PE function is used */
ExitCritical();
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : UART2_SendBlock (component Serial_LDD)
*/
/*!
** @brief
** Sends a block of characters. The method returns ERR_BUSY
** when the previous block transmission is not completed.
** Method [CancelBlockTransmission] can be used to cancel a
** transmit operation. This method is available only if the
** transmitter property is enabled. This method finishes
** immediately after calling it - it doesn't wait the end of
** data transmission. Use event [OnBlockSent] to check the end
** of data transmission.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @param
** BufferPtr - Pointer to a buffer from where
** data will be sent. In case of 8bit
** character width each character in buffer
** occupies 1 byte. In case of 9 and more bit
** long character width each character in
** buffer occupies 2 bytes.
** @param
** Size - Number of characters in the buffer.
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_PARAM_SIZE - Parameter Size is out of
** expected range.
** ERR_DISABLED - The component or device is
** disabled.
** ERR_BUSY - The previous transmit request is
** pending.
*/
/* ===================================================================*/
LDD_TError UART2_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size)
{
UART2_TDeviceDataPtr DeviceDataPrv = (UART2_TDeviceDataPtr)DeviceDataPtr;
if (Size == 0U) { /* Is the parameter Size within an expected range? */
return ERR_PARAM_SIZE; /* If no then error */
}
if (DeviceDataPrv->OutDataNumReq != 0x00U) { /* Is the previous transmit operation pending? */
return ERR_BUSY; /* If yes then error */
}
/* {Default RTOS Adapter} Critical section begin, general PE function is used */
EnterCritical();
DeviceDataPrv->OutDataPtr = (uint8_t*)BufferPtr; /* Set a pointer to the output data. */
DeviceDataPrv->OutDataNumReq = Size; /* Set the counter of characters to be sent. */
DeviceDataPrv->OutSentDataNum = 0x00U; /* Clear the counter of sent characters. */
DeviceDataPrv->SerFlag |= ENABLED_TX_INT; /* Set the flag ENABLED_TX_INT */
UART_PDD_EnableInterrupt(UART2_BASE_PTR, UART_PDD_INTERRUPT_TRANSMITTER); /* Enable TX interrupt */
/* {Default RTOS Adapter} Critical section end, general PE function is used */
ExitCritical();
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : UART2_CancelBlockTransmission (component Serial_LDD)
*/
/*!
** @brief
** Immediately cancels the running transmit process started by
** method [SendBlock]. Characters already stored in the
** transmit shift register will be sent.
** @param
** DeviceDataPtr - Device data structure
** pointer returned by [Init] method.
** @return
** - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - The component does not work in
** the active clock configuration.
** ERR_DISABLED - The component or device is
** disabled.
*/
/* ===================================================================*/
LDD_TError UART2_CancelBlockTransmission(LDD_TDeviceData *DeviceDataPtr)
{
UART2_TDeviceDataPtr DeviceDataPrv = (UART2_TDeviceDataPtr)DeviceDataPtr;
/* {Default RTOS Adapter} Critical section begin, general PE function is used */
EnterCritical();
DeviceDataPrv->SerFlag &= (uint16_t)(~(uint16_t)ENABLED_TX_INT); /* Clear the flag ENABLED_TX_INT */
DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of requested outgoing characters. */
DeviceDataPrv->OutSentDataNum = 0x00U; /* Clear the counter of sent characters. */
UART_PDD_DisableInterrupt(UART2_BASE_PTR, (UART_PDD_INTERRUPT_TRANSMITTER | UART_PDD_INTERRUPT_TRANSMITTER_COMPLETE)); /* Disable TX interrupt */
/* {Default RTOS Adapter} Critical section end, general PE function is used */
ExitCritical();
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : InterruptRx (component Serial_LDD)
**
** Description :
** The method services the receive interrupt of the selected
** peripheral(s) and eventually invokes the bean's event(s).
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void InterruptRx(UART2_TDeviceDataPtr DeviceDataPrv)
{
register uint16_t Data; /* Temporary variable for data */
Data = (uint16_t)UART_PDD_GetChar8(UART2_BASE_PTR); /* Read an 8-bit character from the receiver */
if (DeviceDataPrv->InpDataNumReq != 0x00U) { /* Is the receive block operation pending? */
*(DeviceDataPrv->InpDataPtr++) = (uint8_t)Data; /* Put an 8-bit character to the receive buffer */
DeviceDataPrv->InpRecvDataNum++; /* Increment received char. counter */
if (DeviceDataPrv->InpRecvDataNum == DeviceDataPrv->InpDataNumReq) { /* Is the requested number of characters received? */
DeviceDataPrv->InpDataNumReq = 0x00U; /* If yes then clear number of requested characters to be received. */
UART2_OnBlockReceived(DeviceDataPrv->UserDataPtr);
}
}
}
/*
** ===================================================================
** Method : InterruptTx (component Serial_LDD)
**
** Description :
** The method services the receive interrupt of the selected
** peripheral(s) and eventually invokes the bean's event(s).
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void InterruptTx(UART2_TDeviceDataPtr DeviceDataPrv)
{
if (DeviceDataPrv->OutSentDataNum < DeviceDataPrv->OutDataNumReq) { /* Is number of sent characters less than the number of requested incoming characters? */
UART_PDD_PutChar8(UART2_BASE_PTR, *(DeviceDataPrv->OutDataPtr++)); /* Put a 8-bit character to the transmit register */
DeviceDataPrv->OutSentDataNum++; /* Increment the counter of sent characters. */
if (DeviceDataPrv->OutSentDataNum == DeviceDataPrv->OutDataNumReq) {
DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of characters to be send by SendBlock() */
UART2_OnBlockSent(DeviceDataPrv->UserDataPtr);
}
} else {
UART_PDD_DisableInterrupt(UART2_BASE_PTR, UART_PDD_INTERRUPT_TRANSMITTER); /* Disable TX interrupt */
DeviceDataPrv->SerFlag &= (uint16_t)(~(uint16_t)ENABLED_TX_INT); /* Clear the flag ENABLED_TX_INT */
}
}
/*
** ===================================================================
** Method : UART2_Interrupt (component Serial_LDD)
**
** Description :
** The ISR function handling the device receive/transmit
** interrupt. Calls InterruptTX/InterruptRX methods.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
PE_ISR(UART2_Interrupt)
{
/* {Default RTOS Adapter} ISR parameter is passed through the global variable */
UART2_TDeviceDataPtr DeviceDataPrv = INT_UART2__DEFAULT_RTOS_ISRPARAM;
register uint32_t StatReg = UART_PDD_ReadInterruptStatusReg(UART2_BASE_PTR); /* Read status register */
if (StatReg & (UART_S1_NF_MASK | UART_S1_OR_MASK | UART_S1_FE_MASK | UART_S1_PF_MASK)) { /* Is any error flag set? */
(void)UART_PDD_GetChar8(UART2_BASE_PTR); /* Dummy read 8-bit character from receiver */
StatReg &= (uint32_t)(~(uint32_t)UART_S1_RDRF_MASK); /* Clear the receive data flag to discard the errorneous data */
}
if (StatReg & UART_S1_RDRF_MASK) { /* Is the receiver's interrupt flag set? */
InterruptRx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */
}
if (DeviceDataPrv->SerFlag & ENABLED_TX_INT) { /* Is the transmitter interrupt enabled? */
if (StatReg & UART_S1_TDRE_MASK) { /* Is the transmitter empty? */
InterruptTx(DeviceDataPrv); /* If yes, then invoke the internal service routine. This routine is inlined. */
}
}
}
/*lint -restore Enable MISRA rule (11.4,12.8) checking. */
/* END UART2. */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.10]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
/* ###################################################################
** Filename : Events.c
** Project : KL16_T
** Processor : MKL16Z128VLH4
** Component : Events
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2014-09-04, 15:13, # CodeGen: 0
** Abstract :
** This is user's event module.
** Put your event handler code here.
** Settings :
** Contents :
** Cpu_OnNMIINT - void Cpu_OnNMIINT(void);
**
** ###################################################################*/
/*!
** @file Events.c
** @version 01.00
** @brief
** This is user's event module.
** Put your event handler code here.
*/
/*!
** @addtogroup Events_module Events module documentation
** @{
*/
/* MODULE Events */
#include "Cpu.h"
#include "Events.h"
#ifdef __cplusplus
extern "C" {
#endif
/* User includes (#include below this line is not maintained by Processor Expert) */
/*
** ===================================================================
** Event : Cpu_OnNMIINT (module Events)
**
** Component : Cpu [MKL16Z256LH4]
*/
/*!
** @brief
** This event is called when the Non maskable interrupt had
** occurred. This event is automatically enabled when the [NMI
** interrupt] property is set to 'Enabled'.
*/
/* ===================================================================*/
void Cpu_OnNMIINT(void)
{
/* Write your code here ... */
}
/*
** ===================================================================
** Event : UART2_OnBlockReceived (module Events)
**
** Component : UART2 [Serial_LDD]
*/
/*!
** @brief
** This event is called when the requested number of data is
** moved to the input buffer.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer is passed
** as the parameter of Init method.
*/
/* ===================================================================*/
//串口2
extern volatile bool Uart2DataReceivedFlg;
extern char Uart2OutData[20];
extern char Uart2InpData[10];
extern LDD_TError UART2_Error;
extern LDD_TDeviceData *Uart2SerialPtr;
void UART2_OnBlockReceived(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
Uart2DataReceivedFlg = TRUE; /* Set DataReceivedFlg flag */
// if (UART2_Error == ERR_OK)
// {
// if (Uart2InpData[0] == 'e') //接收地址码:01 -06 SystemAddress = 2;//本机地址
// {
// Uart2Status = 20;
// UART2_RD_SetVal(); //RS485设为发送
// }
// Uart2Status = 20;
// UART2_RD_SetVal(); //RS485设为发送
// }
}
/*
** ===================================================================
** Event : UART0_OnBlockReceived (module Events)
**
** Component : UART0 [Serial_LDD]
*/
/*!
** @brief
** This event is called when the requested number of data is
** moved to the input buffer.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer is passed
** as the parameter of Init method.
*/
/* ===================================================================*/
extern volatile bool Uart0DataReceivedFlg;
void UART0_OnBlockReceived(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
Uart0DataReceivedFlg = TRUE; /* Set DataReceivedFlg flag */
}
/*
** ===================================================================
** Event : Timer1_OnCounterRestart (module Events)
**
** Component : Timer1 [TimerUnit_LDD]
*/
/*!
** @brief
** Called if counter overflow/underflow or counter is
** reinitialized by modulo or compare register matching.
** OnCounterRestart event and Timer unit must be enabled. See
** [SetEventMask] and [GetEventMask] methods. This event is
** available only if a [Interrupt] is enabled.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. The pointer passed as
** the parameter of Init method.
*/
/* ===================================================================*/
extern volatile uint32_t EventCount;
extern LDD_TDeviceData *MyTU1Ptr;
extern LDD_TError Error;
void Timer1_OnCounterRestart(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
EventCount++; /* Increment counter of events */
}
/*
** ===================================================================
** Event : Timer0_OnCounterRestart (module Events)
**
** Component : Timer0 [TimerUnit_LDD]
*/
/*!
** @brief
** Called if counter overflow/underflow or counter is
** reinitialized by modulo or compare register matching.
** OnCounterRestart event and Timer unit must be enabled. See
** [SetEventMask] and [GetEventMask] methods. This event is
** available only if a [Interrupt] is enabled.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. The pointer passed as
** the parameter of Init method.
*/
/* ===================================================================*/
void Timer0_OnCounterRestart(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
rxi();
//ALARM_LED_NegVal(NULL);
}
/*
** ===================================================================
** Event : UART2_OnBlockSent (module Events)
**
** Component : UART2 [Serial_LDD]
*/
/*!
** @brief
** This event is called after the last character from the
** output buffer is moved to the transmitter.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer is passed
** as the parameter of Init method.
*/
/* ===================================================================*/
void UART2_OnBlockSent(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
}
/*
** ===================================================================
** Event : UART0_OnBlockSent (module Events)
**
** Component : UART0 [Serial_LDD]
*/
/*!
** @brief
** This event is called after the last character from the
** output buffer is moved to the transmitter.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer is passed
** as the parameter of Init method.
*/
/* ===================================================================*/
void UART0_OnBlockSent(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
}
/*
** ===================================================================
** Event : FLASH1_OnOperationComplete (module Events)
**
** Component : FLASH1 [FLASH_LDD]
*/
/*!
** @brief
** Called at the end of the whole write / erase operation. if
** the event is enabled. See SetEventMask() and GetEventMask()
** methods.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. This pointer is passed
** as the parameter of Init method.
*/
/* ===================================================================*/
extern volatile bool DataWrittenFlg;
void FLASH1_OnOperationComplete(LDD_TUserData *UserDataPtr)
{
/* Write your code here ... */
DataWrittenFlg = TRUE; /* Set DataWrittenFlg flag */
}
/* END Events */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.10]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
以上是KDS生的MKL16Z128VLH4 代码
请高手指导用法
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|