这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » ZLGSmartARM2200,UCOSII 请教ZLGSmartARM2200

共2条 1/1 1 跳转至

ZLGSmartARM2200,UCOSII 请教ZLGSmartARM2200的基于UCOSII串口附带实验问题

院士
2006-09-17 18:14:16     打赏
ZLGSmartARM2200,UCOSII 请教ZLGSmartARM2200的基于UCOSII串口附带实验问题



关键词: ZLGSmartARM2200     UCOSII     请教    

院士
2006-12-22 22:43:00     打赏
2楼
问 实验光盘的基于UCOS的串口接收程序,为什么只能一次接收16个字节以内的数据。如果一次从PC串口发送超过16个字节,16个之后的数据就丢掉了,谁知道为什么?我是在任务中循环调用函数:uint8 UART0Getch(void);附带光盘上的串口部分程序,文件uart0.c  :
#define IN_UART0
#include "config.h"

static int UART0SendBuf[(UART0_SEND_QUEUE_LENGTH + sizeof(int) - 1) / sizeof(int)];

static OS_EVENT *Uart0Sem;
uint8 UART0Init(uint32 bps)
{
    uint16 Fdiv;   
    PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05;    /* 选择管脚为UART0 */
    U0LCR = 0x80;                   /* 允许访问分频因子寄存器 */
    Fdiv = (Fpclk / 16) / bps;                  /* 设置波特率 */
    U0DLM = Fdiv / 256;                    
    U0DLL = Fdiv % 256;                    
    U0LCR = 0x03;                  /* 禁止访问分频因子寄存器 */
                                        /* 且设置为8,1,n */
    U0IER = 0x05;                      /* 允许接收和发送中断 */
    U0FCR = 0x87;                               /* 初始化FIFO */
    if (QueueCreate((void *)UART0SendBuf,
                     sizeof(UART0SendBuf),
                     NULL,
                     (uint8 (*)())Uart0WriteFull)
                     == NOT_OK)
    {
        return FALSE;
    }
    Uart0Sem = OSSemCreate(0);
    if (Uart0Sem != NULL)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }

}
uint8 UART0Getch(void)
{
    uint8 err;
    OS_ENTER_CRITICAL();
    while ((U0LSR & 0x00000001) == 0)
    {                                           /* 没有收到数据 */
        U0IER = U0IER | 0x01;                   /* 允许接收中断 */
        OSSemPend(Uart0Sem, 0, &err);           /* 等待接收数据 */
    }
    err = U0RBR;                                /* 读取收到的数据 */
    OS_EXIT_CRITICAL();
    return err;
}
void UART0_Exception(void)
{
    uint8 IIR, temp, i;
    
    OS_ENTER_CRITICAL();

    while(((IIR = U0IIR) & 0x01) == 0)
    {                                                   /* 有中断未处理完 */
        switch (IIR & 0x0e)
        {
            case 0x02:                                  /* THRE中断    */
                for (i = 0; i < UART0_FIFO_LENGTH; i++) /* 向发送FIFO填充数据 */
                {
                    if (QueueRead(&temp, UART0SendBuf) == QUEUE_OK)
                    {
                        U0THR = temp;
                    }
                    else
                    {
                        U0IER = U0IER & (~0x02);        /* 队列空,则禁止发送中断 */
                    }
                }
                break;
            case 0x04:                                  /* 接收数据可用 */
                OSSemPost(Uart0Sem);                    /* 通知接收任务 */
                U0IER = U0IER & (~0x01);                /* 禁止接收及字符超时中断 */
                break;
            case 0x06:                                  /* 接收线状态   */
                temp = U0LSR;
                break;
            case 0x0c:                                  /* 字符超时指示 */
                OSSemPost(Uart0Sem);                    /* 通知接收任务 */
                U0IER = U0IER & (~0x01);                /* 禁止接收及字符超时中断 */
                break;
            default :
                break;
        }
    }
    VICVectAddr = 0;            // 通知中断控制器中断结束
    OS_EXIT_CRITICAL();
} 1: 请加我为好友,QQ9009617,因为我要向你学习UCos 2: 看缓冲区的定义阿#define UART0_FIFO_LENGTH         16 3: ucos2感觉不大好用了功能API太少了,

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]