查看: 3681|回复: 3

[已解决] KE06串口中断的例程没看懂

[复制链接]

该用户从未签到

15

主题

40

帖子

0

中级会员

Rank: 3Rank: 3

积分
202
最后登录
2020-7-2
发表于 2017-11-24 21:41:41 | 显示全部楼层 |阅读模式
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2013 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED 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 FREESCALE OR ITS 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.
*
***************************************************************************//*!
*
* @file uart.c
*
* @author Freescale
*
* @version 0.0.1
*
* @date June-6-2013
*
* @brief providing common UART API.
*
******************************************************************************/
#include "UART_app.h"

static uint8_t *pUART_TxBuff[MAX_UART_NO] = {NULL};           /* pointer to RxBuf */
static uint8_t *pUART_RxBuff[MAX_UART_NO] = {NULL};           /* pointer to TxBuf */
static uint16_t gu16UART_TxBuffPos[MAX_UART_NO] = {0};        /* write position to RxBuf */
static uint16_t gu16UART_RxBuffPos[MAX_UART_NO] = {0};        /* read position to TxBuf */
static uint32_t gu32UART_BuffSize[MAX_UART_NO] = {0};         /* buffer size*/

UART_TxDoneCallbackType UART_TxDoneCallback[MAX_UART_NO] = {NULL};
UART_RxDoneCallbackType UART_RxDoneCallback[MAX_UART_NO] = {NULL};
/*****************************************************************************//*!
*
* @brief send a series of charecters using interrupt mode.
*        
* @param[in] pUART      base of UART port
* @param[in] pSendBuff  pointer of charecters to send
* @param[in] u32Length  number of charecters
*
* @return       none
*
* @ Pass/ Fail criteria:
*****************************************************************************/
void UART_SendInt(UART_Type *pUART, uint8_t *pSendBuff, uint32_t u32Length)
{
    uint8_t u8Port = ((uint32_t)pUART-(uint32_t)UART0)>>12;

    /* save user defined send buffer pointers and size */
    pUART_TxBuff[u8Port]        = pSendBuff;
    gu32UART_BuffSize[u8Port]   = u32Length;
    gu16UART_TxBuffPos[u8Port]  = 0;

    UART_EnableTxBuffEmptyInt(pUART);   /* enable tx interrupt */
}
/*****************************************************************************//*!
*
* @brief receive a series of charecters using interrupt mode.
*        
* @param[in] pUART      base of UART port
* @param[in] pSendBuff  pointer of charecters to send
* @param[in] u32Length  number of charecters
*
* @return       none
*
* @ Pass/ Fail criteria:
*****************************************************************************/
void UART_ReceiveInt(UART_Type *pUART, uint8_t *pReceiveBuff, uint32_t u32Length)
{
    uint8_t u8Port = ((uint32_t)pUART-(uint32_t)UART0)>>12;

    /* save user defined read buffer pointers and size */
    pUART_RxBuff[u8Port]        = pReceiveBuff;
    gu32UART_BuffSize[u8Port]   = u32Length;
    gu16UART_RxBuffPos[u8Port]  = 0;

    UART_EnableRxBuffFullInt(pUART);   /* enable rx interrupt */
}
void UART_HandleInt(UART_Type *pUART)
{
    uint8_t   u8Port;
    uint8_t   *pRdBuff;
    uint8_t   *pWrBuff;  
    volatile uint8_t read_temp = 0;

    u8Port = ((uint32_t)pUART-(uint32_t)UART0)>>12;

    /* check overrun flag */
    if(UART_CheckFlag(pUART,UART_FlagOR))
    {
        read_temp = UART_ReadDataReg(pUART);     
    }

    /* check receiver */
    else if(UART_IsRxBuffFull(pUART))      
    {
        /* there's data received in rx buffer */
       pRdBuff = pUART_RxBuff[u8Port];                     /* get user read buffer */
        read_temp = UART_ReadDataReg(pUART);
        pRdBuff[gu16UART_RxBuffPos[u8Port]++]= read_temp;   /* save received data */
        //pRdBuff[gu16UART_RxBuffPos[u8Port]++] = UART_ReadDataReg(pUART);
        if(gu16UART_RxBuffPos[u8Port] == gu32UART_BuffSize[u8Port])
        {   
            /* User read buffer is full, end receive */
            UART_DisableRxBuffFullInt(pUART);
            if (UART_RxDoneCallback[u8Port])
                        {
                            /* call back function to tell user that rx is done */
                            UART_RxDoneCallback[u8Port]();
                        }
        }   
    }
    /* check transmitter */
                        else if(UART_IsTxBuffEmpty(pUART))
    {
        if(gu16UART_TxBuffPos[u8Port] != gu32UART_BuffSize[u8Port])
        {
            /* user tx buffer not empty */
            pWrBuff = pUART_TxBuff[u8Port];
            UART_WriteDataReg(pUART, pWrBuff[gu16UART_TxBuffPos[u8Port]++]);     
        }  
        else
        {
                        UART_DisableTxBuffEmptyInt(pUART);
                        if (UART_TxDoneCallback[u8Port])
                        {
                            /* call back function to tell user that tx is done */
                            UART_TxDoneCallback[u8Port]();
                        }
        }
    }
    else
    {
        /* default interrupt */
    }
}

void UART_SetTxDoneCallback(UART_Type *pUART, UART_TxDoneCallbackType pfnCallback)
{
    uint8_t u8Port = ((uint32_t)pUART-(uint32_t)UART0)>>12;
    UART_TxDoneCallback[u8Port] = pfnCallback;
}

void UART_SetRxDoneCallback(UART_Type *pUART, UART_RxDoneCallbackType pfnCallback)
{
    uint8_t u8Port = ((uint32_t)pUART-(uint32_t)UART0)>>12;
    UART_RxDoneCallback[u8Port] = pfnCallback;
}
不明白红色的什么意思

最佳答案

本帖最后由 okwh 于 2017-11-25 12:19 编辑 有多个串口,每个串口需要一个接缓冲区、一个发缓冲区,每对接和发的缓冲区长度同长,收完或发完后可能需要进一步回调处理 所以 红色 是 需要  1)  设置 ...
回复

使用道具 举报

  • TA的每日心情
    开心
    2017-11-14 10:38
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    10

    主题

    48

    帖子

    1

    中级会员

    Rank: 3Rank: 3

    积分
    301
    最后登录
    2021-3-6
    发表于 2017-11-25 09:40:59 | 显示全部楼层
    函数名已经告诉你什么意思了啊
    自己加油
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    擦汗
    2021-7-5 15:45
  • 签到天数: 664 天

    连续签到: 1 天

    [LV.9]以坛为家II

    42

    主题

    1594

    帖子

    19

    金牌会员

    Rank: 6Rank: 6

    积分
    5618
    最后登录
    2021-12-22
    发表于 2017-11-25 12:17:39 | 显示全部楼层
    本帖最后由 okwh 于 2017-11-25 12:19 编辑

    有多个串口,每个串口需要一个接缓冲区、一个发缓冲区,每对接和发的缓冲区长度同长,收完或发完后可能需要进一步回调处理
    所以 红色 是 需要 
    1)  设置 用数组记下多个接和发的缓冲区指针、用数组记下这多个接和发缓冲区中的读写位置, 以及接和发缓冲区同长长度。
    2)  接收时,/* check receiver */,从端口读取,存入接收缓冲区RxBuff,并记下已用存储的位置,如果存满了,并且需要处理,就调用对应的回调callback函数处理。  发送类似。
    3)  最后两个红色标记,是 设置  收完或发完后需要的回调处理函数指针。

    UART_HandleInt 函数 是用于中断的响应。

    其他都是 事先的初始化设置和准备。
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2024-9-13 10:15
  • 签到天数: 35 天

    连续签到: 1 天

    [LV.5]常住居民I

    13

    主题

    500

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    1183
    最后登录
    2024-12-10
    发表于 2018-6-18 12:15:42 | 显示全部楼层
    楼主搞定了吗?这个驱动根本没法用,希望你已经爬出坑了!
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-21 00:29 , Processed in 0.095554 second(s), 25 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表