/*******************************************************************************
*
* Copyright 2004-2016 NXP Semiconductor, Inc.
*
* This software is owned or controlled by NXP Semiconductor.
* Use of this software is governed by the NXP FreeMASTER License
* distributed with this Material.
* See the LICENSE file distributed for more details.
*
****************************************************************************//*!
*
* @brief FreeMASTER serial communication routines
*
*******************************************************************************/
#include "freemaster.h"
#include "freemaster_private.h"
#include "freemaster_protocol.h"
#if !(FMSTR_DISABLE)
#if FMSTR_USE_SERIAL
/***********************************
* local variables
***********************************/
/* Runtime base address used when constant address is not specified */
#if FMSTR_SCI_BASE_DYNAMIC
static FMSTR_ADDR pcm_pSciBaseAddr;
#define FMSTR_SCI_BASE pcm_pSciBaseAddr
#endif
#if FMSTR_USE_MBED
#include "serial_api.h"
serial_t* pSerialObj;
#endif
/* FreeMASTER communication buffer (in/out) plus the STS and LEN bytes */
static FMSTR_BCHR pcm_pCommBuffer[FMSTR_COMM_BUFFER_SIZE+3];
/* FreeMASTER runtime flags */
/*lint -e{960} using union */
typedef volatile union
{
FMSTR_FLAGS all;
struct
{
unsigned bTxActive : 1; /* response is being transmitted */
#if (FMSTR_USE_SCI) || (FMSTR_USE_ESCI) || (FMSTR_USE_LPUART)
unsigned bTxWaitTC : 1; /* response sent, wait for transmission complete */
#endif
unsigned bTxLastCharSOB : 1; /* last transmitted char was equal to SOB */
unsigned bRxLastCharSOB : 1; /* last received character was SOB */
unsigned bRxMsgLengthNext : 1; /* expect the length byte next time */
#if FMSTR_USE_JTAG
unsigned bJtagRIEPending : 1; /* JTAG RIE bit failed to be set, try again later */
#endif
#if (FMSTR_USE_USB_CDC) || (FMSTR_USE_MQX_IO) || (FMSTR_USE_JTAG)
unsigned bTxFirstSobSend : 1; /* to send SOB char at the begin of the packet */
#endif
#if FMSTR_USE_MQX_IO
unsigned bMqxReadyToSend : 1; /* to send next character in transmit routine */
#endif
#if FMSTR_USE_USB_CDC
unsigned bUsbCdcStartApp : 1; /* FreeMASTER USB CDC Application start Init Flag */
unsigned bUsbCdcStartTrans : 1; /* FreeMASTER USB CDC Application Carrier Activate Flag */
unsigned bUsbReadyToDecode : 1; /* FreeMASTER packet is received, ready to decode in Poll function in Short Interrupt mode */
#endif
} flg;
} FMSTR_SERIAL_FLAGS;
static FMSTR_SERIAL_FLAGS pcm_wFlags;
/* receive and transmit buffers and counters */
static FMSTR_SIZE8 pcm_nTxTodo; /* transmission to-do counter (0 when tx is idle) */
static FMSTR_SIZE8 pcm_nRxTodo; /* reception to-do counter (0 when rx is idle) */
static FMSTR_BPTR pcm_pTxBuff; /* pointer to next byte to transmit */
static FMSTR_BPTR pcm_pRxBuff; /* pointer to next free place in RX buffer */
static FMSTR_BCHR pcm_nRxCheckSum; /* checksum of data being received */
/* in older versions, the SCI flags were tested directly, new version is more general,
* but it remains backward compatible. If SCI flag test macros are not defined, use
* the equivalent of the old functionality. */
#ifndef FMSTR_SCI_TXFULL
#define FMSTR_SCI_TXFULL(wSciSR) (!((wSciSR) & FMSTR_SCISR_TDRE))
#endif
#ifndef FMSTR_SCI_TXEMPTY
#define FMSTR_SCI_TXEMPTY(wSciSR) ((wSciSR) & FMSTR_SCISR_TC)
#endif
#ifndef FMSTR_SCI_RXREADY
/* when overrun flag is defined, use it also to detect incoming character (and to
* make sure the OR flag is cleared in modules where RDRF and OR are independent */
#ifdef FMSTR_SCISR_OR
#define FMSTR_SCI_RXREADY(wSciSR) ((wSciSR) & (FMSTR_SCISR_RDRF | FMSTR_SCISR_OR))
#else
#define FMSTR_SCI_RXREADY(wSciSR) ((wSciSR) & (FMSTR_SCISR_RDRF))
#endif
#endif
#if FMSTR_DEBUG_TX
/* The poll counter is used to roughly measure duration of test frame transmission.
* The test frame will be sent once per N.times this measured period. */
static FMSTR_S32 pcm_nDebugTxPollCount;
/* the N factor for multiplying the transmission time to get the wait time */
#define FMSTR_DEBUG_TX_POLLCNT_XFACTOR 32
#define FMSTR_DEBUG_TX_POLLCNT_MIN (-1*0x4000000L)
#endif
/***********************************
* local function prototypes
***********************************/
static void FMSTR_Listen(void);
static void FMSTR_SendError(FMSTR_BCHR nErrCode);
#else /* FMSTR_USE_SERIAL */
/*lint -efile(766, freemaster_protocol.h) include file is not used in this case */
#endif /* FMSTR_USE_SERIAL */
#if (FMSTR_USE_SCI) || (FMSTR_USE_ESCI) || (FMSTR_USE_LPUART) || (FMSTR_USE_JTAG)
/***********************************
* local variables
***********************************/
/* SHORT_INTR receive queue (circular buffer) */
#if FMSTR_SHORT_INTR
static FMSTR_BCHR pcm_pRQueueBuffer[FMSTR_COMM_RQUEUE_SIZE];
static FMSTR_BPTR pcm_pRQueueRP; /* SHORT_INTR queue read-pointer */
static FMSTR_BPTR pcm_pRQueueWP; /* SHORT_INTR queue write-pointer */
#endif
/***********************************
* local function prototypes
***********************************/
#if FMSTR_SHORT_INTR
static void FMSTR_RxQueue(FMSTR_BCHR nRxChar);
static void FMSTR_RxDequeue(void);
#endif
/*lint -esym(752,FMSTR_RxQueue) this may be unreferenced in some cases */
/*lint -esym(752,FMSTR_RxDequeue) this may be unreferenced in some cases */
/*******************************************************************************
*
* @brief Routine to quick-receive a character (put to a queue only)
*
* This function puts received character into a queue and exits as soon as possible.
*
*******************************************************************************/
#if FMSTR_SHORT_INTR
static void FMSTR_RxQueue(FMSTR_BCHR nRxChar)
{
/* future value of write pointer */
FMSTR_BPTR wpnext = pcm_pRQueueWP + 1;
/*lint -e{946} pointer arithmetic is okay here (same array) */
if(wpnext >= (pcm_pRQueueBuffer + FMSTR_COMM_RQUEUE_SIZE))
{
wpnext = pcm_pRQueueBuffer;
}
/* any space in queue? */
if(wpnext != pcm_pRQueueRP)
{
*pcm_pRQueueWP = (FMSTR_U8) nRxChar;
pcm_pRQueueWP = wpnext;
}
}
#endif /* FMSTR_SHORT_INTR */
/*******************************************************************************
*
* @brief Late processing of queued characters
*
* This function takes the queued characters and calls FMSTR_Rx() for each of them,
* just like as the characters would be received from SCI one by one.
*
*******************************************************************************/
#if FMSTR_SHORT_INTR
static void FMSTR_RxDequeue(void)
{
FMSTR_BCHR nChar = 0U;
/* get all queued characters */
while(pcm_pRQueueRP != pcm_pRQueueWP)
{
nChar = *pcm_pRQueueRP++;
/*lint -e{946} pointer arithmetic is okay here (same array) */
if(pcm_pRQueueRP >= (pcm_pRQueueBuffer + FMSTR_COMM_RQUEUE_SIZE))
{
pcm_pRQueueRP = pcm_pRQueueBuffer;
}
/* emulate the SCI receive event */
if(!pcm_wFlags.flg.bTxActive)
{
(void)FMSTR_Rx(nChar);
}
}
}
#endif /* FMSTR_SHORT_INTR */
#endif /* (FMSTR_USE_SCI) || (FMSTR_USE_ESCI) || (FMSTR_USE_LPUART) || (FMSTR_USE_JTAG) */
#if (FMSTR_USE_SCI) || (FMSTR_USE_LPUART) || (FMSTR_USE_ESCI)
/**************************************************************************//*!
*
* @brief Handle SCI communication (both TX and RX)
*
* This function checks the SCI flags and calls the Rx and/or Tx functions
*
* @note This function can be called either from SCI ISR or from the polling routine
*
********************
没有合适的资源?快使用搜索试试~ 我知道了~
MPC5744P FreeMaster下位机示例
共124个文件
args:25个
o:21个
c:19个
需积分: 50 28 下载量 183 浏览量
2018-12-05
08:11:11
上传
评论 6
收藏 407KB 7Z 举报
温馨提示
MPC5744P FreeMaster下位机示例,可以使用PEMicro作为通信接口,详细请参考文章:https://blog.csdn.net/u010875635/article/details/84789579
资源推荐
资源详情
资源评论
收起资源包目录
MPC5744P FreeMaster下位机示例 (124个子文件)
FreeMaster.args 1KB
freemaster_example.args 753B
MPC57xx__Interrupt_Init.args 753B
freemaster_bdm.args 753B
freemaster_lin.args 753B
freemaster_appcmd.args 753B
freemaster_protocol.args 753B
freemaster_can.args 753B
freemaster_scope.args 753B
data_img_logo.args 753B
intc_SW_mode_isr_vectors_MPC5744P.args 753B
freemaster_MPC57xx.args 753B
main.args 753B
freemaster_rec.args 753B
data_img_tower.args 753B
periphinit.args 753B
freemaster_pipes.args 753B
Vector.args 753B
freemaster_serial.args 753B
freemaster_sfio.args 753B
freemaster_tsa.args 753B
data_demo_pmp.args 753B
flashrchw.args 753B
intc_sw_handlers.args 439B
startup.args 439B
freemaster_serial.c 52KB
freemaster_pipes.c 49KB
intc_SW_mode_isr_vectors_MPC5744P.c 48KB
freemaster_can.c 28KB
freemaster_rec.c 26KB
freemaster_protocol.c 25KB
freemaster_example.c 23KB
freemaster_tsa.c 14KB
freemaster_appcmd.c 14KB
MPC57xx__Interrupt_Init.c 11KB
freemaster_lin.c 9KB
periphinit.c 7KB
freemaster_MPC57xx.c 7KB
freemaster_sfio.c 6KB
freemaster_scope.c 5KB
freemaster_bdm.c 3KB
Vector.c 3KB
flashrchw.c 2KB
main.c 550B
.cproject 68KB
periphinit.d 4KB
main.d 4KB
freemaster_example.d 4KB
freemaster_pipes.d 4KB
MPC57xx__Interrupt_Init.d 3KB
intc_SW_mode_isr_vectors_MPC5744P.d 3KB
flashrchw.d 2KB
freemaster_rec.d 2KB
freemaster_MPC57xx.d 2KB
freemaster_protocol.d 2KB
freemaster_serial.d 2KB
freemaster_appcmd.d 2KB
freemaster_scope.d 2KB
freemaster_sfio.d 2KB
freemaster_bdm.d 2KB
freemaster_tsa.d 2KB
freemaster_can.d 2KB
freemaster_lin.d 2KB
Vector.d 779B
FreeMaster.elf 582KB
MPC5744P.h 1.02MB
freemaster_MPC57xx.h 30KB
freemaster_private.h 19KB
freemaster_defcfg.h 16KB
freemaster_tsa.h 12KB
freemaster_protocol.h 9KB
freemaster.h 7KB
freemaster_cfg.h 6KB
typedefs.h 4KB
freemaster_rec.h 3KB
freemaster_example.h 2KB
compiler_api.h 1KB
periphinit.h 678B
derivative.h 204B
FreeMaster_Debug.launch 17KB
FreeMaster_Debug_RAM.launch 16KB
57xx_flash.ld 4KB
57xx_ram.ld 4KB
libs.ld 88B
makefile.local 379B
makefile 2KB
FreeMaster.map 137KB
subdir.mk 9KB
subdir.mk 4KB
sources.mk 1KB
subdir.mk 1KB
subdir.mk 1KB
subdir.mk 1KB
subdir.mk 633B
objects.mk 276B
periphinit.o 427KB
main.o 367KB
MPC57xx__Interrupt_Init.o 360KB
freemaster_pipes.o 87KB
freemaster_example.o 71KB
共 124 条
- 1
- 2
资源评论
Beatfan_N
- 粉丝: 698
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Quartz框架的定时任务调度系统.zip
- (源码)基于Spring Boot和Spring Security的安全管理系统.zip
- (源码)基于Spring Boot的家庭智能助理系统.zip
- Marki_20241121_192504660.jpg
- (源码)基于Spring Boot框架的仓库管理系统.zip
- (源码)基于Spring、Dubbo和MyBatis的跨境支付系统.zip
- (源码)基于Python的Excel数据处理系统.zip
- (源码)基于Python和ESP8266的物联网按钮通知系统.zip
- (源码)基于C++的多态职工管理系统.zip
- (源码)基于C++的小型便利店管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功