亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serial.c

?? 最新版FreeRTOS, 包擴多種開發平臺的移植
?? C
字號:
/*
	FreeRTOS.org V4.1.1 - Copyright (C) 2003-2006 Richard Barry.

	This file is part of the FreeRTOS.org distribution.

	FreeRTOS.org is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	FreeRTOS.org is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with FreeRTOS.org; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

	A special exception to the GPL can be applied should you wish to distribute
	a combined work that includes FreeRTOS.org, without being obliged to provide
	the source code for any proprietary components.  See the licensing section 
	of http://www.FreeRTOS.org for full details of how and when the exception
	can be applied.

	***************************************************************************
	See http://www.FreeRTOS.org for documentation, latest information, license 
	and contact details.  Please ensure to read the configuration and relevant 
	port sections of the online documentation.
	***************************************************************************
*/

/*
Changes from V1.00:
	
	+ Call to the more efficient portSWITCH_CONTEXT() replaces the call to 
	  taskYIELD() in the ISR.

Changes from V1.01:

	+ The semaphore task is not operational.  This does nothing but check
	  the semaphore from ISR functionality.
	+ ISR modified slightly so only Rx or Tx is serviced per ISR - not both.

Changes from V1.2.0:

	+ Change so Tx uses a DMA channel, and Rx uses an interrupt.

Changes from V1.2.3

	+ The function xPortInitMinimal() has been renamed to 
	  xSerialPortInitMinimal() and the function xPortInit() has been renamed
	  to xSerialPortInit().

Changes from V1.2.5

	+ Reverted back to the non-DMA serial port driver, with a slightly modified
	  ISR.  This is a better test of the scheduler mechanisms.
	+ A critical section is now used in vInterruptOn().
	+ Flag sTxInterruptOn has been added to the port structure.  This allows
	  checking of the interrupt enable status without performing any IO.

Changes from V2.0.0

	+ Use portTickType in place of unsigned pdLONG for delay periods.
	+ Slightly more efficient vSerialSendString() implementation.
	+ cQueueReieveFromISR() used in place of xQueueReceive() in ISR.
*/

#include <stdlib.h>
#include <dos.h>
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
#include "portasm.h"
#include "semphr.h"

#define serMAX_PORTS			( ( unsigned portSHORT ) 2 )

#define serPORT_0_INT_REG		( 0xff44 )
#define serPORT_0_BAUD_REG		( 0xff88 )
#define serPORT_0_RX_REG		( 0xff86 )
#define serPORT_0_TX_REG		( 0xff84 )
#define serPORT_0_STATUS_REG	( 0xff82 )
#define serPORT_0_CTRL_REG		( 0xff80 )
#define serPORT_0_IRQ			( 0x14 )

#define serPORT_1_INT_REG		( 0xff42 )
#define serPORT_1_BAUD_REG		( 0xff18 )
#define serPORT_1_RX_REG		( 0xff16 )
#define serPORT_1_TX_REG		( 0xff14 )
#define serPORT_1_STATUS_REG	( 0xff12 )
#define serPORT_1_CTRL_REG		( 0xff10 )
#define serPORT_1_IRQ			( 0x11 )

#define serTX_EMPTY				( ( unsigned portSHORT ) 0x40 )
#define serRX_READY				( ( unsigned portSHORT ) 0x80 )

#define serRESET_PIC( usEOI_TYPE )	portOUTPUT_WORD( ( unsigned portSHORT ) 0xff22, usEOI_TYPE )
#define serTX_HOLD_EMPTY_INT		( ( unsigned portSHORT ) 0x100 )

#define serENABLE_INTERRUPTS		( ( unsigned portSHORT ) 0x80 )
#define serMODE						( ( unsigned portSHORT ) 0x01 )
#define serENABLE_TX_MACHINES		( ( unsigned portSHORT ) 0x40 )
#define serENABLE_RX_MACHINES		( ( unsigned portSHORT ) 0x20 )
#define serINTERRUPT_MASK			( ( unsigned portSHORT ) 0x08 )
#define serCLEAR_ALL_STATUS_BITS	( ( unsigned portSHORT ) 0x00 )
#define serINTERRUPT_PRIORITY		( ( unsigned portSHORT ) 0x01 ) /*< Just below the scheduler priority. */

#define serDONT_BLOCK				( ( portTickType ) 0 )

typedef enum
{ 
	serCOM1 = 0, 
	serCOM2, 
	serCOM3, 
	serCOM4, 
	serCOM5, 
	serCOM6, 
	serCOM7, 
	serCOM8 
} eCOMPort;

typedef enum 
{ 
	serNO_PARITY, 
	serODD_PARITY, 
	serEVEN_PARITY, 
	serMARK_PARITY, 
	serSPACE_PARITY 
} eParity;

typedef enum 
{ 
	serSTOP_1, 
	serSTOP_2 
} eStopBits;

typedef enum 
{ 
	serBITS_5, 
	serBITS_6, 
	serBITS_7, 
	serBITS_8 
} eDataBits;

typedef enum 
{ 
	ser50 = 0,
	ser75,		
	ser110,		
	ser134,		
	ser150,    
	ser200,
	ser300,		
	ser600,		
	ser1200,	
	ser1800,	
	ser2400,   
	ser4800,
	ser9600,		
	ser19200,	
	ser38400,	
	ser57600,	
	ser115200
} eBaud;

/* Must be same order as eBaud definitions. */
static const unsigned portSHORT usBaudRateDivisor[] = 
{
	0, /* Not sure if the first 6 are correct.  First cannot be used. */
	29127,
	19859,
	16302,
	14564,
	10923,	
	6879,
	3437,
	1718,
	1145,
	859,
	429,
	214,
	107,
	54,
	35,
	18
};


typedef struct xCOM_PORT
{
	/* Hardware parameters for this port. */
	portSHORT sTxInterruptOn;
	unsigned portSHORT usIntReg;
	unsigned portSHORT usBaudReg;
	unsigned portSHORT usRxReg;
	unsigned portSHORT usTxReg;
	unsigned portSHORT usStatusReg;
	unsigned portSHORT usCtrlReg;

	unsigned portSHORT usIRQVector;

	/* Queues used for communications with com test task. */
	xQueueHandle xRxedChars; 
	xQueueHandle xCharsForTx;

	/* This semaphore does nothing useful except test a feature of the
	scheduler. */
	xSemaphoreHandle xTestSem;

} xComPort;

static xComPort xPorts[ serMAX_PORTS ] = 
{
	{ pdFALSE, serPORT_0_INT_REG, serPORT_0_BAUD_REG, serPORT_0_RX_REG, serPORT_0_TX_REG, serPORT_0_STATUS_REG, serPORT_0_CTRL_REG, serPORT_0_IRQ, NULL, NULL, NULL },
	{ pdFALSE, serPORT_1_INT_REG, serPORT_1_BAUD_REG, serPORT_1_RX_REG, serPORT_1_TX_REG, serPORT_1_STATUS_REG, serPORT_1_CTRL_REG, serPORT_1_IRQ, NULL, NULL, NULL }
};

typedef xComPort * xComPortHandle;

/* These prototypes are repeated here so we don't have to include the serial header.  This allows
the xComPortHandle structure details to be private to this file. */
xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );
portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime );
portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime );
void vSerialClose( xComPortHandle xPort );
portSHORT sSerialWaitForSemaphore( xComPortHandle xPort );
/*-----------------------------------------------------------*/

static portSHORT xComPortISR( xComPort * const pxPort );

#define vInterruptOn( pxPort, usInterrupt )										\
{																				\
unsigned portSHORT usIn;														\
																				\
	portENTER_CRITICAL();														\
	{																			\
		if( pxPort->sTxInterruptOn == pdFALSE )									\
		{																		\
			usIn = portINPUT_WORD( pxPort->usCtrlReg );							\
			portOUTPUT_WORD( pxPort->usCtrlReg, usIn | usInterrupt );			\
																				\
			pxPort->sTxInterruptOn = pdTRUE;									\
		}																		\
	}																			\
	portEXIT_CRITICAL();															\
}																				
/*-----------------------------------------------------------*/

#define vInterruptOff( pxPort, usInterrupt )									\
{																				\
	unsigned portSHORT usIn = portINPUT_WORD( pxPort->usCtrlReg );				\
	if( usIn & usInterrupt )													\
	{																			\
		portOUTPUT_WORD( pxPort->usCtrlReg, usIn & ~usInterrupt);				\
		pxPort->sTxInterruptOn = pdFALSE;										\
	}																			\
}
/*-----------------------------------------------------------*/


/* Define an interrupt handler for each port */
#define COM_IRQ_WRAPPER(N)										\
	static void __interrupt COM_IRQ##N##_WRAPPER( void )		\
	{															\
        if( xComPortISR( &( xPorts[##N##] ) ) )                 \
        {                                                       \
			portSWITCH_CONTEXT();                             \
		}                                                       \
	}

  

COM_IRQ_WRAPPER( 0 )
COM_IRQ_WRAPPER( 1 )

static pxISR xISRs[ serMAX_PORTS ] = 
{
	COM_IRQ0_WRAPPER, 
	COM_IRQ1_WRAPPER
};

/*-----------------------------------------------------------*/

xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength )
{
unsigned portSHORT usPort;
xComPortHandle pxPort = NULL;

/* BAUDDIV = ( Microprocessor Clock / Baud Rate ) / 16 */

	/* Only n, 8, 1 is supported so these parameters are not required for this
	port. */
	( void ) eWantedParity;
	( void ) eWantedDataBits;
    ( void ) eWantedStopBits;

	/* Currently only n,8,1 is supported. */

	usPort = ( unsigned portSHORT ) ePort;
	
	if( usPort < serMAX_PORTS )
	{
		pxPort = &( xPorts[ usPort ] );

		portENTER_CRITICAL();
		{
			unsigned portSHORT usInWord;

			/* Create the queues used by the com test task. */
			pxPort->xRxedChars = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );
			pxPort->xCharsForTx = xQueueCreate( uxBufferLength, ( unsigned portBASE_TYPE ) sizeof( portCHAR ) );

			/* Create the test semaphore.  This does nothing useful except test a feature of the scheduler. */
			vSemaphoreCreateBinary( pxPort->xTestSem );

			/* There is no ISR here already to restore later. */
			_dos_setvect( ( portSHORT ) pxPort->usIRQVector, xISRs[ usPort ] );

			usInWord = portINPUT_WORD( pxPort->usIntReg );
			usInWord &= ~serINTERRUPT_MASK;
			usInWord |= serINTERRUPT_PRIORITY;
			portOUTPUT_WORD( pxPort->usIntReg, usInWord );

			portOUTPUT_WORD( pxPort->usBaudReg, usBaudRateDivisor[ eWantedBaud ] );
			portOUTPUT_WORD( pxPort->usCtrlReg, serENABLE_INTERRUPTS | serMODE | serENABLE_TX_MACHINES | serENABLE_RX_MACHINES );

			portOUTPUT_WORD( pxPort->usStatusReg, serCLEAR_ALL_STATUS_BITS );
		}
		portEXIT_CRITICAL();
	}

	return pxPort;
} /*lint !e715 Some parameters are not used as only a subset of the serial port functionality is currently implemented. */
/*-----------------------------------------------------------*/

void vSerialPutString( xComPortHandle pxPort, const portCHAR * const pcString, unsigned portSHORT usStringLength )
{
unsigned portSHORT usByte;
portCHAR *pcNextChar;

	pcNextChar = ( portCHAR * ) pcString;

	for( usByte = 0; usByte < usStringLength; usByte++ )
	{
		xQueueSend( pxPort->xCharsForTx, pcNextChar, serDONT_BLOCK );
		pcNextChar++;
	}

	vInterruptOn( pxPort, serTX_HOLD_EMPTY_INT );
}
/*-----------------------------------------------------------*/

portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, portCHAR *pcRxedChar, portTickType xBlockTime )
{
	/* Get the next character from the buffer, note that this routine is only 
	called having checked that the is (at least) one to get */
	if( xQueueReceive( pxPort->xRxedChars, pcRxedChar, xBlockTime ) )
	{
		return pdTRUE;
	}
	else
	{
		return pdFALSE;
	}
}
/*-----------------------------------------------------------*/

portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, portCHAR cOutChar, portTickType xBlockTime )
{
	if( xQueueSend( pxPort->xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
	{
		return pdFAIL;
	}

	vInterruptOn( pxPort, serTX_HOLD_EMPTY_INT );

	return pdPASS;
}
/*-----------------------------------------------------------*/

portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort )
{
const portTickType xBlockTime = ( portTickType ) 0xffff;

	/* This function does nothing interesting, but test the 
	semaphore from ISR mechanism. */
	return xSemaphoreTake( xPort->xTestSem, xBlockTime );
}
/*-----------------------------------------------------------*/

void vSerialClose( xComPortHandle xPort )
{
unsigned portSHORT usOutput;

	/* Turn off the interrupts.  We may also want to delete the queues and/or
	re-install the original ISR. */

	portENTER_CRITICAL();
	{
		usOutput = portINPUT_WORD( xPort->usCtrlReg );

		usOutput &= ~serENABLE_INTERRUPTS;
		usOutput &= ~serENABLE_TX_MACHINES;
		usOutput &= ~serENABLE_RX_MACHINES;
		portOUTPUT_WORD( xPort->usCtrlReg, usOutput );

		usOutput = portINPUT_WORD( xPort->usIntReg );
		usOutput |= serINTERRUPT_MASK;
		portOUTPUT_WORD( xPort->usIntReg, usOutput );
	}
	portEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/

static portBASE_TYPE xComPortISR( xComPort * const pxPort )
{
unsigned portSHORT usStatusRegister;
portCHAR cChar;
portBASE_TYPE xTaskWokenByPost = pdFALSE, xAnotherTaskWokenByPost = pdFALSE, xTaskWokenByTx = pdFALSE, xContinue = pdTRUE;

	/* NOTE:  THIS IS NOT AN EFFICIENT ISR AS IT IS DESIGNED SOLELY TO TEST
	THE SCHEDULER FUNCTIONALITY.  REAL APPLICATIONS SHOULD NOT USE THIS
	FUNCTION. */


	while( xContinue == pdTRUE )
	{
		xContinue = pdFALSE;
		usStatusRegister = portINPUT_WORD( pxPort->usStatusReg );

		if( usStatusRegister & serRX_READY )
		{
			cChar = ( portCHAR ) portINPUT_WORD( pxPort->usRxReg );
			xTaskWokenByPost = xQueueSendFromISR( pxPort->xRxedChars, &cChar, xTaskWokenByPost );

			/* Also release the semaphore - this does nothing interesting and is just a test. */
			xAnotherTaskWokenByPost = xSemaphoreGiveFromISR( pxPort->xTestSem, xAnotherTaskWokenByPost );

			/* We have performed an action this cycle - there may be other to perform. */
			xContinue = pdTRUE;
		}

		if( pxPort->sTxInterruptOn && ( usStatusRegister & serTX_EMPTY ) )
		{
			if( xQueueReceiveFromISR( pxPort->xCharsForTx, &cChar, &xTaskWokenByTx ) == pdTRUE )
			{
				portOUTPUT_WORD( pxPort->usTxReg, ( unsigned portSHORT ) cChar );

				/* We have performed an action this cycle - there may be others to perform. */
				xContinue = pdTRUE;
			}
			else
			{
				/* Queue empty, nothing to send */
				vInterruptOff( pxPort, serTX_HOLD_EMPTY_INT );
			}
		}
	}

	serRESET_PIC( pxPort->usIRQVector );

	/* If posting to the queue woke a task that was blocked on the queue we may
	want to switch to the woken task - depending on its priority relative to
	the task interrupted by this ISR. */
	if( xTaskWokenByPost || xAnotherTaskWokenByPost || xTaskWokenByTx)
	{
		return pdTRUE;
	}
	else
	{
		return pdFALSE;
	}
}





?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本美女一区二区三区| 日韩久久一区二区| 亚洲免费观看高清| 国产精品成人一区二区三区夜夜夜 | 国产毛片精品视频| 亚洲欧美在线另类| 欧美经典三级视频一区二区三区| 欧美亚州韩日在线看免费版国语版| 岛国一区二区三区| 激情综合色综合久久| 五月天丁香久久| 亚洲电影第三页| 亚洲综合自拍偷拍| 一区二区三区高清在线| 亚洲欧洲av一区二区三区久久| 久久综合色天天久久综合图片| 欧美高清一级片在线| 欧美综合天天夜夜久久| 在线亚洲一区观看| 99精品热视频| 99视频超级精品| 久久99国产精品尤物| 日韩精品每日更新| 日本三级韩国三级欧美三级| 日本伊人色综合网| 九九热在线视频观看这里只有精品| 日本aⅴ精品一区二区三区| 美女视频黄a大片欧美| 精品一二三四区| 国产成人综合在线观看| 处破女av一区二区| 色94色欧美sute亚洲线路一ni| 在线观看国产91| 日韩一级欧美一级| 欧美精品一区二区三区蜜臀| 中文字幕精品一区二区精品绿巨人| 国产精品久久久久9999吃药| 亚洲美女电影在线| 日韩精品亚洲专区| 国产一区二区免费在线| 91蝌蚪国产九色| 欧美三级一区二区| 欧美精品一区二| 最新热久久免费视频| 亚洲午夜精品在线| 欧美日韩一区二区三区不卡| 亚洲男帅同性gay1069| 欧美怡红院视频| 一区二区三区中文在线观看| 成人丝袜高跟foot| 欧美日韩免费不卡视频一区二区三区| 欧美精品一区二区精品网| 亚洲综合色区另类av| 麻豆视频一区二区| 日韩欧美高清一区| 国产麻豆精品久久一二三| 日韩一区欧美二区| 国产精品99久久久| 欧美精品在线观看一区二区| 91精品国产免费久久综合| 亚洲精品国产a久久久久久| 精品一区二区三区在线播放视频| 在线观看免费亚洲| 国产精品久久久久毛片软件| 日韩不卡手机在线v区| 欧美精品第一页| 17c精品麻豆一区二区免费| 国产一区二三区好的| 欧美日韩国产欧美日美国产精品| 日韩欧美二区三区| 韩国三级中文字幕hd久久精品| 欧美天天综合网| 亚洲国产精品自拍| 色婷婷久久综合| 日本一二三四高清不卡| 国产综合色在线视频区| 欧美一区二区在线视频| 免费看日韩a级影片| 欧美人与性动xxxx| 日本成人在线电影网| 欧美人与禽zozo性伦| 亚洲欧美日韩国产一区二区三区| 99视频热这里只有精品免费| 国产欧美1区2区3区| 国产成人精品亚洲777人妖| 亚洲精品一区二区三区福利| 国产日韩欧美综合在线| 国产成人久久精品77777最新版本| 日韩欧美视频一区| 国产白丝精品91爽爽久久| 欧美精品一区二区三区在线| 日本人妖一区二区| 91精品国产免费久久综合| 午夜欧美2019年伦理| 欧美v亚洲v综合ⅴ国产v| 久久精品国产秦先生| 国产女同性恋一区二区| 国产精品一二三区| 色8久久精品久久久久久蜜| 五月婷婷另类国产| 日韩精品影音先锋| 99久久精品免费看国产| 亚洲欧洲在线观看av| 欧美日韩视频在线观看一区二区三区| 亚洲成在人线在线播放| 在线成人免费观看| 国产999精品久久| 中文字幕亚洲一区二区av在线| 国产一区二区女| 中文字幕五月欧美| 99re在线精品| 日韩欧美亚洲国产精品字幕久久久| 欧美精品高清视频| 国产精品亚洲一区二区三区妖精 | 欧美日韩一本到| 欧美日韩电影在线播放| 国产亚洲视频系列| 精品成人免费观看| 亚洲欧美视频在线观看视频| 亚洲国产成人高清精品| 欧美一区二区三区的| 欧美日韩精品三区| 久久综合九色综合欧美98| 一本色道综合亚洲| 日本不卡免费在线视频| 亚洲三级在线看| 欧美一级片在线看| 福利一区在线观看| 美女精品自拍一二三四| 中文字幕一区二区三区四区| 欧美精品一区男女天堂| 在线观看国产精品网站| 欧美午夜精品久久久久久孕妇 | 亚洲免费观看高清在线观看| 欧美成人vps| 一本色道久久综合亚洲91| 成人激情小说网站| 欧美aaaaa成人免费观看视频| 国产精品高清亚洲| 国产欧美日韩综合| 日韩欧美国产午夜精品| 日韩三级在线观看| 在线精品视频免费观看| 成人自拍视频在线| 久99久精品视频免费观看| 一区二区三区电影在线播| 亚洲欧洲精品一区二区三区| 精品处破学生在线二十三| 欧美一区二区精品在线| 精品视频123区在线观看| 国产成人福利片| www.亚洲色图.com| 国产99久久久国产精品潘金| 久久成人羞羞网站| 美女视频网站黄色亚洲| 午夜欧美大尺度福利影院在线看| 国产日韩欧美一区二区三区乱码 | 成人av集中营| 精品午夜久久福利影院| 亚洲中国最大av网站| 亚洲成a人v欧美综合天堂| 一区二区三区在线视频免费观看| 亚洲欧美另类综合偷拍| 自拍偷自拍亚洲精品播放| 精品久久一区二区| 久久久综合精品| 久久久国产午夜精品| 国产精品免费视频一区| 国产精品乱码一区二区三区软件 | 99久久99久久精品免费观看| 国产成人在线视频网址| 午夜国产精品一区| 91亚洲大成网污www| 欧美一个色资源| 欧美一二三四在线| 6080国产精品一区二区| 成人国产亚洲欧美成人综合网| 午夜欧美电影在线观看| 亚欧色一区w666天堂| 国产免费观看久久| 国产女主播视频一区二区| 日韩亚洲国产中文字幕欧美| 93久久精品日日躁夜夜躁欧美| 色综合久久久久久久| 高清成人在线观看| 99久久精品国产一区| 日本高清免费不卡视频| 欧美一区二区三区免费视频 | 亚洲欧洲韩国日本视频| 国产精品久久久久久久久图文区| 亚洲欧美日韩一区二区| 亚洲伊人伊色伊影伊综合网| 成人黄色一级视频| 欧美怡红院视频| 91精品国产色综合久久ai换脸| 中文字幕制服丝袜一区二区三区 | 成人午夜精品一区二区三区| 99r国产精品| 精品国产乱码久久久久久免费 | 国产乱码字幕精品高清av|