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

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

?? i2cisr.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.
	***************************************************************************
*/


/* Standard includes. */
#include <stdlib.h>

/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

/* Application includes. */
#include "i2c.h"

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

/* Bit definitions within the I2CONCLR register. */
#define i2cSTA_BIT		( ( unsigned portCHAR ) 0x20 )
#define i2cSI_BIT		( ( unsigned portCHAR ) 0x08 )
#define i2cSTO_BIT		( ( unsigned portCHAR ) 0x10 )
#define i2cAA_BIT		( ( unsigned portCHAR ) 0x04 )

/* Status codes for the I2STAT register. */
#define i2cSTATUS_START_TXED			( 0x08 )
#define i2cSTATUS_REP_START_TXED		( 0x10 )
#define i2cSTATUS_TX_ADDR_ACKED			( 0x18 )
#define i2cSTATUS_DATA_TXED				( 0x28 )
#define i2cSTATUS_RX_ADDR_ACKED			( 0x40 )
#define i2cSTATUS_DATA_RXED				( 0x50 )
#define i2cSTATUS_LAST_BYTE_RXED		( 0x58 )

/* Constants for operation of the VIC. */
#define i2cCLEAR_VIC_INTERRUPT	( 0 )

/* Misc constants. */
#define i2cJUST_ONE_BYTE_TO_RX	( 1 )
#define i2cBUFFER_ADDRESS_BYTES	( 2 )

/* End the current transmission and free the bus. */
#define i2cEND_TRANSMISSION( lStatus )					\
{														\
	I2C_I2CONCLR = i2cAA_BIT;							\
	I2C_I2CONSET = i2cSTO_BIT;							\
	eCurrentState = eSentStart;							\
	lTransactionCompleted = lStatus;					\
}
/*-----------------------------------------------------------*/

/* Valid i2c communication states. */
typedef enum
{
	eSentStart,				/*<< Last action was the transmission of a start bit. */
	eSentAddressForWrite,	/*<< Last action was the transmission of the slave address we are to write to. */
	eSentAddressForRead,	/*<< Last action was the transmission of the slave address we are to read from. */
	eSentData,				/*<< Last action was the transmission of a data byte. */
	eReceiveData			/*<< We expected data to be received. */
} I2C_STATE;
/*-----------------------------------------------------------*/

/* Points to the message currently being sent. */
volatile xI2CMessage *pxCurrentMessage = NULL;	

/* The queue of messages waiting to be transmitted. */
static xQueueHandle xMessagesForTx;

/* Flag used to indicate whether or not the ISR is amid sending a message. */
unsigned portLONG ulBusFree = ( unsigned portLONG ) pdTRUE;

/* Setting this to true will cause the TCP task to think a message is 
complete and thus restart.  It can therefore be used under error states
to force a restart. */
volatile portLONG lTransactionCompleted = pdTRUE;

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

void vI2CISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxTxMessages, unsigned portLONG **ppulBusFree )
{
	/* Create the queues used to hold Rx and Tx characters. */
	xMessagesForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( xI2CMessage * ) );

	/* Pass back a reference to the queue and bus free flag so the I2C API file 
	can post messages. */
	*pxTxMessages = xMessagesForTx;
	*ppulBusFree = &ulBusFree;
}
/*-----------------------------------------------------------*/

void vI2C_ISR( void ) __attribute__ (( naked ));
void vI2C_ISR( void )
{
	portENTER_SWITCHING_ISR();

	/* Holds the current transmission state. */							
	static I2C_STATE eCurrentState = eSentStart;
	static portLONG lMessageIndex = -i2cBUFFER_ADDRESS_BYTES; /* There are two address bytes to send prior to the data. */
	portBASE_TYPE xTaskWokenByTx = pdFALSE;
	portLONG lBytesLeft;

	/* The action taken for this interrupt depends on our current state. */
	switch( eCurrentState )
	{
		case eSentStart	:	

				/* We sent a start bit, if it was successful we can
				go on to send the slave address. */
				if( ( I2C_I2STAT == i2cSTATUS_START_TXED ) || ( I2C_I2STAT == i2cSTATUS_REP_START_TXED ) )
				{
					/* Send the slave address. */
					I2C_I2DAT = pxCurrentMessage->ucSlaveAddress;

					if( pxCurrentMessage->ucSlaveAddress & i2cREAD )
					{
						/* We are then going to read bytes back from the 
						slave. */
						eCurrentState = eSentAddressForRead;
						
						/* Initialise the buffer index so the first byte goes
						into the first buffer position. */
						lMessageIndex = 0;
					}
					else
					{
						/* We are then going to write some data to the slave. */
						eCurrentState = eSentAddressForWrite;

						/* When writing bytes we first have to send the two
						byte buffer address so lMessageIndex is set negative,
						when it reaches 0 it is time to send the actual data. */
						lMessageIndex = -i2cBUFFER_ADDRESS_BYTES;
					}
				}
				else
				{
					/* Could not send the start bit so give up. */
					i2cEND_TRANSMISSION( pdFAIL );					
				}

				I2C_I2CONCLR = i2cSTA_BIT;				

				break;

		case eSentAddressForWrite :

				/* We sent the address of the slave we are going to write to.
				If this was acknowledged we	can go on to send the data. */
				if( I2C_I2STAT == i2cSTATUS_TX_ADDR_ACKED )
				{
					/* Start the first byte transmitting which is the 
					first byte of the buffer address to which the data will 
					be sent. */
					I2C_I2DAT = pxCurrentMessage->ucBufferAddressHighByte;
					eCurrentState = eSentData;
				}
				else
				{
					/* Address was not acknowledged so give up. */
					i2cEND_TRANSMISSION( pdFAIL );					
				}					
				break;

		case eSentAddressForRead :

				/* We sent the address of the slave we are going to read from.
				If this was acknowledged we can go on to read the data. */
				if( I2C_I2STAT == i2cSTATUS_RX_ADDR_ACKED )
				{
					eCurrentState = eReceiveData;
					if( pxCurrentMessage->lMessageLength > i2cJUST_ONE_BYTE_TO_RX )
					{
						/* Don't ack the last byte of the message. */
						I2C_I2CONSET = i2cAA_BIT;
					}					
				}
				else
				{
					/* Something unexpected happened - give up. */
					i2cEND_TRANSMISSION( pdFAIL );					
				}
				break;

		case eReceiveData :
				
				/* We have just received a byte from the slave. */
				if( ( I2C_I2STAT == i2cSTATUS_DATA_RXED ) || ( I2C_I2STAT == i2cSTATUS_LAST_BYTE_RXED ) )
				{
					/* Buffer the byte just received then increment the index 
					so it points to the next free space. */
					pxCurrentMessage->pucBuffer[ lMessageIndex ] = I2C_I2DAT;
					lMessageIndex++;

					/* How many more bytes are we expecting to receive? */
					lBytesLeft = pxCurrentMessage->lMessageLength - lMessageIndex;
					if( lBytesLeft == ( unsigned portLONG ) 0 )
					{
						/* This was the last byte in the message. */
						i2cEND_TRANSMISSION( pdPASS );

						/* If xMessageCompleteSemaphore is not null then there
						is a task waiting for this message to complete and we
						must 'give' the semaphore so the task is woken.*/
						if( pxCurrentMessage->xMessageCompleteSemaphore )
						{
							xTaskWokenByTx = xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, xTaskWokenByTx );
						}

						/* Are there any other messages to transact? */
						if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xTaskWokenByTx ) == pdTRUE )
						{
							/* Start the next message - which was
							retrieved from the queue. */
							I2C_I2CONSET = i2cSTA_BIT;
						}
						else
						{
							/* No more messages were found to be waiting for
							transaction so the bus is free. */
							ulBusFree = ( unsigned portLONG ) pdTRUE;			
						}						
					}
					else
					{
						/* There are more bytes to receive but don't ack the 
						last byte. */
						if( lBytesLeft <= i2cJUST_ONE_BYTE_TO_RX )
						{
							I2C_I2CONCLR = i2cAA_BIT;
						}							 
					}
				}
				else
				{
					/* Something unexpected happened - give up. */
					i2cEND_TRANSMISSION( pdFAIL );					
				}

				break;
				
		case eSentData	:	

				/* We sent a data byte, if successful send the	next byte in 
				the message. */
				if( I2C_I2STAT == i2cSTATUS_DATA_TXED )
				{
					/* Index to the next byte to send. */
					lMessageIndex++;
					if( lMessageIndex < 0 )
					{
						/* lMessage index is still negative so we have so far 
						only sent the first byte of the buffer address.  Send 
						the second byte now, then initialise the buffer index
						to zero so the next byte sent comes from the actual 
						data buffer. */
						I2C_I2DAT = pxCurrentMessage->ucBufferAddressLowByte;
					}
					else if( lMessageIndex < pxCurrentMessage->lMessageLength )
					{
						/* Simply send the next byte in the tx buffer. */
						I2C_I2DAT = pxCurrentMessage->pucBuffer[ lMessageIndex ];										
					}
					else
					{
						/* No more bytes in this message to be send.  Finished 
						sending message - send a stop bit. */
						i2cEND_TRANSMISSION( pdPASS );

						/* If xMessageCompleteSemaphore is not null then there
						is a task waiting for this message to be sent and the
						semaphore must be 'given' to wake the task. */
						if( pxCurrentMessage->xMessageCompleteSemaphore )
						{
							xTaskWokenByTx = xSemaphoreGiveFromISR( pxCurrentMessage->xMessageCompleteSemaphore, xTaskWokenByTx );
						}

						/* Are there any other messages to transact? */
						if( xQueueReceiveFromISR( xMessagesForTx, &pxCurrentMessage, &xTaskWokenByTx ) == pdTRUE )
						{
							/* Start the next message from the Tx queue. */
							I2C_I2CONSET = i2cSTA_BIT;
						}
						else
						{
							/* No more message were queues for transaction so 
							the bus is free. */
							ulBusFree = ( unsigned portLONG ) pdTRUE;			
						}
					}
				}
				else
				{
					/* Something unexpected happened, give up. */
					i2cEND_TRANSMISSION( pdFAIL );					
				}
				break;

		default	:	
		
				/* Should never get here. */
				eCurrentState = eSentStart;
				break;
	}	

	/* Clear the interrupt. */
	I2C_I2CONCLR = i2cSI_BIT;
	VICVectAddr = i2cCLEAR_VIC_INTERRUPT;

	portEXIT_SWITCHING_ISR( ( xTaskWokenByTx ) );
}
/*-----------------------------------------------------------*/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99综合影院在线| 亚洲欧洲成人自拍| 99精品偷自拍| www.亚洲色图.com| 一本一道久久a久久精品综合蜜臀| 美腿丝袜亚洲色图| 奇米影视一区二区三区| 久久成人免费网| 激情五月激情综合网| 狠狠色丁香久久婷婷综| av电影在线观看一区| 99久久精品免费观看| 欧美影院午夜播放| 欧美一级xxx| 久久在线免费观看| 国产精品久久99| 国产制服丝袜一区| 久久国产精品区| 国产偷国产偷精品高清尤物| 一区二区免费看| 99久久精品国产毛片| 色狠狠av一区二区三区| av亚洲精华国产精华精| 亚洲一区二区三区国产| 国产精品天美传媒沈樵| 亚洲欧美激情视频在线观看一区二区三区| 亚洲精品视频在线观看免费| 欧美性大战xxxxx久久久| 99精品黄色片免费大全| 国产精品传媒在线| 欧美日韩中文国产| 一本大道久久精品懂色aⅴ| 日本成人中文字幕| 中文字幕欧美三区| 欧美男人的天堂一二区| 国产成a人亚洲| 午夜影院在线观看欧美| 91小宝寻花一区二区三区| 欧美国产1区2区| 韩国在线一区二区| 91精品国产一区二区三区| 亚洲国产电影在线观看| 国产一区中文字幕| 欧美大度的电影原声| 亚洲国产精品一区二区久久恐怖片| 91免费版在线| 日韩欧美你懂的| 免费成人美女在线观看| 欧美久久久久久蜜桃| 亚洲成人手机在线| 欧美在线高清视频| 中文字幕一区av| 色婷婷国产精品综合在线观看| 日韩一区在线看| 色猫猫国产区一区二在线视频| 亚洲欧美日韩在线| 欧美色网站导航| 奇米777欧美一区二区| 精品久久久久香蕉网| 国产成人综合视频| 一色屋精品亚洲香蕉网站| 欧美最猛黑人xxxxx猛交| 久久精品国产精品青草| 国产精品国产三级国产普通话三级| 欧美成人精品3d动漫h| 91丝袜呻吟高潮美腿白嫩在线观看| 国产精品一二三| 国产精品人人做人人爽人人添 | 国产不卡视频在线播放| 国产区在线观看成人精品| 91精品午夜视频| 国产日产欧美一区二区三区| 欧美三级一区二区| 狠狠色丁香婷综合久久| 精品一区二区免费看| 99久久精品国产精品久久| 国产盗摄一区二区| 国产一区二区三区免费观看| 韩国精品在线观看| 国产成人免费视频网站| 国产精品综合二区| 国产成人精品aa毛片| 亚洲成人先锋电影| 图片区小说区区亚洲影院| 亚洲精品一线二线三线无人区| 91欧美一区二区| 丁香婷婷深情五月亚洲| 日本成人在线看| 亚洲情趣在线观看| 国产精品理论在线观看| 久久日一线二线三线suv| 91福利小视频| 一道本成人在线| 成人福利在线看| 丁香天五香天堂综合| 免费成人在线影院| 蜜桃91丨九色丨蝌蚪91桃色| 图片区小说区国产精品视频| 一区二区三区四区中文字幕| 亚洲欧美日韩国产综合| 专区另类欧美日韩| 一区二区欧美在线观看| 一区二区久久久久久| 亚洲成va人在线观看| 日韩成人免费电影| 日韩制服丝袜先锋影音| 亚洲1区2区3区4区| 日日欢夜夜爽一区| 色狠狠一区二区| 岛国av在线一区| 日韩一区二区三区四区| 日韩和的一区二区| 欧美午夜精品一区二区蜜桃| 精品成人在线观看| 性久久久久久久久久久久| 国产精品视频一区二区三区不卡| 欧美mv和日韩mv的网站| 久久精品欧美一区二区三区不卡| 国产嫩草影院久久久久| 国产一区二区成人久久免费影院 | 欧美精品在线观看播放| 久久久国产精华| 精品一区二区在线看| 色网站国产精品| 日韩欧美第一区| 一区二区三区四区不卡在线| 久久国产精品99精品国产| 91亚洲永久精品| 26uuu久久天堂性欧美| 亚洲免费av观看| 国产真实乱子伦精品视频| 欧美三级电影精品| 国产日韩欧美综合在线| 视频一区视频二区中文字幕| av在线播放不卡| 欧美mv日韩mv| 日本最新不卡在线| 色综合色狠狠天天综合色| 久久综合久色欧美综合狠狠| 亚洲第一久久影院| 9久草视频在线视频精品| 久久影院午夜片一区| 亚洲电影你懂得| 色综合天天综合在线视频| 久久久亚洲高清| 久久不见久久见免费视频1| 欧美亚洲另类激情小说| 国产精品精品国产色婷婷| 久久99国产精品免费网站| 欧美精品在欧美一区二区少妇| 亚洲欧美色综合| av影院午夜一区| 中文字幕电影一区| 国产成人免费视频一区| 精品国产91洋老外米糕| 日韩成人免费在线| 欧美剧情电影在线观看完整版免费励志电影 | 岛国一区二区在线观看| 久久综合色8888| 国产在线一区观看| 精品久久久三级丝袜| 久久疯狂做爰流白浆xx| 91精品国产综合久久福利软件| 亚洲一区二区视频在线观看| 色综合久久久久久久| 亚洲视频一二三| 91在线播放网址| 一区二区三区久久久| 欧美性受极品xxxx喷水| 亚洲一区二区偷拍精品| 欧美日韩国产乱码电影| 午夜精品久久久久久| 日韩一区二区三区精品视频| 蜜臀久久99精品久久久画质超高清 | 91国内精品野花午夜精品| 日韩理论片中文av| 色婷婷综合久久久中文字幕| 亚洲免费伊人电影| 欧美在线free| 日韩vs国产vs欧美| 日韩免费看网站| 国产精品88av| 中文字幕一区在线观看| 欧美亚一区二区| 日本成人中文字幕在线视频| 久久综合精品国产一区二区三区 | 久久精品免视看| 国产精品一区二区三区网站| 国产欧美精品一区二区三区四区| 久久99精品国产91久久来源| 欧美剧在线免费观看网站| 亚洲va天堂va国产va久| 日韩精品一区二区三区在线| av毛片久久久久**hd| 亚洲欧美日韩一区| 国产毛片一区二区| 亚洲女同一区二区| 欧美日韩精品高清| 久久99精品久久久久久国产越南| 久久九九久久九九|