⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printf.c

📁 uCos2在ARM的移植方法
💻 C
字号:

//********************************************************************
//OSPrintf post message to UartQ
//TaskUart send message to Uart from UartQ
//tangxiaofeng xidian 503
//********************************************************************

#include "2440lib.h"
#include   "config.h" 
#include <stdarg.h>
#include "ucos_ii.h"
#include <stdio.h>
#include "app_cfg.h"


#define UartMsgNum  25
#define UartMsgBufLengh 100

OS_STK	TaskUartStk [TaskUartStkLengh];       // Define the TaskUart stack 

static OS_MEM *pUartMem;
static INT8U  UartBuf[UartMsgNum][UartMsgBufLengh];
static OS_EVENT *pUart_Q;
static void *MsgUart[UartMsgNum];


void OSPrintfInit(void)
{   
	INT8U err;
	pUartMem=OSMemCreate(UartBuf,UartMsgNum,UartMsgBufLengh,&err);//Create a mem for Uart post Msg
	
	pUart_Q=OSQCreate(&MsgUart[0],UartMsgNum);//Create a Quen for Uart
	
	OSTaskCreate(TaskUart,(void*)0,&TaskUartStk[TaskUartStkLengh-1],TaskUartPrio);//Creat a Task to sent Msg to Uart
}

void OSPrintf(const char *fmt,...)//post massage to UartQ
{
    
    INT8U *pUartBuf;
    INT8U err;
    va_list ap;
    
    pUartBuf=OSMemGet(pUartMem,&err);//Reqire a Mem for Msg
    va_start(ap,fmt);
    vsprintf(pUartBuf,fmt,ap);//Msg formate
    va_end(ap);
    //Uart_SendString(string);
    OSQPost(pUart_Q,pUartBuf);//Post Msg
}
void TaskUart(void *pdata) //send message to uart from uartQ
{
  
	INT8U *pUartMsg;
	INT8U err;
	pdata=pdata;
	
	
	
	while(1)
	{
	    pUartMsg=OSQAccept(pUart_Q,&err);//Accept the Msg from Qene; no wait 
		while(pUartMsg)
			{
				Uart_SendString(pUartMsg);//seng str to Uart
				OSMemPut(pUartMem,pUartMsg);
				pUartMsg=OSQAccept(pUart_Q,&err);//free Mem
			}
		
		
		OSTimeDly(OS_TICKS_PER_SEC/5);

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -