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

📄 os_viewc.c

📁 ucos内核源代码
💻 C
字号:
/*
 * 版本历史:
 *
 * 版本     作者        日期        修改内容
 * 1.00     王璀        2005-11-28  创建
 * 1.01     王璀        2006-02-24  删除了timer,直接使用uC/OS II的节拍计数
 * 1.02     王璀        2006-03-09  修改了实现的机制
 */

/*
*********************************************************************************************************
*                                               uC/OS-View
*
*                                 (c) Copyright 2005, Micrium, Weston, FL
*                                           All Rights Reserved
*
*                                          Philips LPC2000 (ARM7)
*                                             IAR C Compiler
*
*
* Filename   : OS_VIEWc.C
* Version    : V1.20
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*/
#include <stdio.h>
#include <assert.h>

#include "os_view.h"

#include "system\sys_types.h"

#include "bsp\bsp_sio.h"

/*
*********************************************************************************************************
*                                              CONSTANTS
*********************************************************************************************************
*/
static BOOL sg_virtualTxIntEn = FALSE;
static INT8U sg_charToTx;
static BOOL sg_charPendTx = FALSE;

static SioChan *sg_pOsviewSioChan = NULL;

/*$PAGE*/
/*
*********************************************************************************************************
*                                           EXIT uC/OS-View
*
* Description: This function is called if your target needs to 'uninstall' uC/OS-View.
*
* Note(s)    :
*********************************************************************************************************
*/
/*
void  OSView_Exit (void)
{
}
*/
/*
*********************************************************************************************************
*                                           Obtain CPU name
*********************************************************************************************************
*/
void  OSView_GetCPUName (CHAR *s)
{
    sprintf(s, OS_VIEW_CPU_NAME "(%d Hz)", OS_VIEW_CPU_FOSC);
}

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*********************************************************************************************************
*/

INT32U  OSView_GetIntStkBase (void)
{
    return (0);                                       /* We are not using an ISR stack                 */
}


INT32U  OSView_GetIntStkSize (void)
{
    return (0);                                       /* We are not using an ISR stack                 */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                    INITIALISE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
*              but may have to be tailored a little (regarding the clock frequency). Of course the same
*              holds true if for some reason you choose to use another timer.
*
* Note(s)    : 1) This function assumes that a free running timer has been initialized.  The timer can
*                 either be a 16 bits or 32 bits timer.  Your application needs to provide a function
*                 called OSView_TmrRd() that reads the current counts of this timer.  The free running
*                 timer is initialized by the BSP function OSView_TmrInit().
*********************************************************************************************************
*/
//------------------------------------------------------------------------------
// 函数描述:发送中断的回调函数
STATUS//OK - 取得下个发送的字节
      //ERROR - 数据发送完毕
OSView_GetTxChar
	(
	INT8U *a_txChar//指向将要发送的字节
	)
{
	if (sg_virtualTxIntEn == TRUE)
	{
		if (sg_charPendTx == TRUE)
		{
  		*a_txChar = sg_charToTx;
  		sg_charPendTx = FALSE;
  		
  		// callback to switch OS_VIEW Tx state machine and get next char(if available) to Tx
	    OSView_TxHandler();
	
  		return OK;
		}
		else
		{
		  return ERROR;
		}
	}
	else
	{	
		return ERROR;
	}
}

//------------------------------------------------------------------------------
// 函数描述:接收中断的回调函数
STATUS//总是返回OK
OSView_PutRcvChar
	(
	INT8U *a_rcvChar//指向已接收的字节
	)
{
	OSView_RxHandler(*a_rcvChar);
	
	return OK;
}

//------------------------------------------------------------------------------
// 函数描述:初始化OS_VIEW的硬件相关部分
void  OSView_InitTarget (void)
{
    INT32U baudrate =OS_VIEW_SIO_BAUDRATE;
    INT32U intMode = SIO_MODE_INT;
    STATUS result;


    sg_pOsviewSioChan = BspSioChanGet(OS_VIEW_SIO_CHAN);
    assert(sg_pOsviewSioChan != (SioChan *)(ERROR));
    result = sg_pOsviewSioChan->m_pIoCtl(SIO_BAUD_SET, &baudrate);
    assert(result == OK);
    result = sg_pOsviewSioChan->m_pCallbackInstall(SIO_CALLBACK_GET_TX_CHAR, OSView_GetTxChar);
    assert(result == OK);
    result = sg_pOsviewSioChan->m_pCallbackInstall(SIO_CALLBACK_PUT_RCV_CHAR, OSView_PutRcvChar);
    assert(result == OK);
    result = sg_pOsviewSioChan->m_pIoCtl(SIO_MODE_SET, &intMode);
    assert(result == OK);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Rx Interrupts
*********************************************************************************************************
*/
/*
void  OSView_RxIntDis (void)
{
}
*/
/*
*********************************************************************************************************
*                                       Enable Rx Interrupts
*********************************************************************************************************
*/
/*
void  OSView_RxIntEn (void)
{
}
*/
/*
*********************************************************************************************************
*                                 Rx Communication handler for uC/OS-View
*
* Description: This function is called by OSView_RxISR (see OS_VIEWa.ASM) to process a received
*              character interrupt.
*
* Note(s)    : This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the UART
*              and thus this function is not needed.
*********************************************************************************************************
*/
/*
void  OSView_RxISRHandler (void)
{
}
*/
/*
*********************************************************************************************************
*                                Rx/Tx Communication handler for uC/OS-View
*
* Description: This function is NOT called because the M16C has a separate Rx and Tx ISR.
*********************************************************************************************************
*/
/*
void  OSView_RxTxISRHandler (void)
{
}
*/
/*$PAGE*/
/*
*********************************************************************************************************
*                                      Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*********************************************************************************************************
*/
void  OSView_Tx1 (INT8U c)
{
	sg_charToTx = c;
	sg_charPendTx = TRUE;
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntDis (void)
{
	sg_virtualTxIntEn = FALSE;
}

/*
*********************************************************************************************************
*                                       Enable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntEn (void)
{
	sg_virtualTxIntEn = TRUE;

  (*(sg_pOsviewSioChan->m_pTxStartup))();
}

/*
*********************************************************************************************************
*                                 Tx Communication handler for uC/OS-View
*                                            (PORT SPECIFIC)
*
* Description: Handle transmission of a character
*
* Note(s)    : 1) This function is called by OSView_RxISR (see OS_VIEWa.ASM)
*              2) This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the
*                 UART and thus this function is not needed.
*********************************************************************************************************
*/
/*
void  OSView_TxISRHandler (void)
{
}
*/
/*
*********************************************************************************************************
*                                       Update 32-bits cycles counter
*
* Description: This function must be called by OSTimeTickHook() and is used to maintain a 32 bit counter
*              of clock cycles.
*
* Returns    : None
*
* Note(s)    : Changes the global variable OSViewCyclesCtr
*********************************************************************************************************
*/
void  OSView_TickHook (void)
{
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           Get time [cycles]
*
* Description: This routine is required for task execution time measurement.  This function needs to
*              return time as accurately as possible and in a 32-bit variable.
*
* Returns    : A 32-bit representation of time.
*********************************************************************************************************
*/

INT32U  OSView_TimeGetCycles (void)
{
    OSView_CyclesCtr = OSTime;
    return OSView_CyclesCtr;
}


⌨️ 快捷键说明

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