Example #1
0
/********************************************************************
函数功能:发送一个字符串。
入口参数:pd:要发送的字符串指针。
返    回:无。
备    注:无。
********************************************************************/
void Prints(uint8 * pd)
{
 while((*pd)!='\0') //发送字符串,直到遇到0才结束
 {
  UartPutChar(*pd); //发送一个字符
  pd++;  //移动到下一个字符
 }
}
Example #2
0
/********************************************************************
函数功能:将整数转按十进制字符串发送。
入口参数:x:待显示的整数。
返    回:无。
备    注:无。
********************************************************************/
void PrintLongInt(uint32 x)
{
 int8 i;
 uint8 display_buffer[10];

 for(i=9;i>=0;i--)
 {
  display_buffer[i]='0'+x%10;
  x/=10;
 }
 for(i=0;i<9;i++)
 {
  if(display_buffer[i]!='0')break;
 }
 for(;i<10;i++)UartPutChar(display_buffer[i]);
}
/*
*********************************************************************************************************
*	函 数 名: ComSend
*	功能说明: 向COM口发送一组数据。数据放到发送缓冲区后立即返回,由中断服务程序在后台完成发送
*	形    参:  	COM_PORT_E : COM号,_ucaBuf:发送的数据指针,_usLen发送数据长度
*	返 回 值: 	1表示发送缓存已满,0表示发送缓存未满,返回0xFF表示不存在的串口
*********************************************************************************************************
*/	
uint8_t ComSend(COM_PORT_E _ucPort, uint8_t *_ucaBuf, uint16_t _usLen)
{
	UART_T *pUart;
	uint8_t _ucFull;
	uint16_t i;
	
	pUart=ComToUart(_ucPort);
	if (pUart == 0)
	{		
		return 0xFF;
	}

	for(i=0;i<_usLen;i++)
	{
		_ucFull=UartPutChar(pUart,_ucaBuf[i]);
		if(_ucFull)
		{
			return 1;
		}
	} 
		
	return 0;
}
Example #4
0
/*
 * Main application entry point.
 */
int main( void )
{
    
    
    Radio = RadioDriverInit( );
    
    Radio->Init( );

    Radio->StartRx( );
    
    while( 1 )
    {
        if( EnableMaster == true )
        {
            OnMaster( );
        }
        else
        {
            OnSlave( );
        }    
#if( PLATFORM == SX12xxEiger ) && ( USE_UART == 1 )

        UartProcess( );
        
        {
            uint8_t data = 0;
            if( UartGetChar( &data ) == UART_OK )
            {
                UartPutChar( data );
            }
        }
#endif        
    }
#ifdef __GNUC__
    return 0;
#endif
}
Example #5
0
/********************************************************************
函数功能:发送一个byte的数据。
入口参数:待发送的数据。
返    回:无。
备    注:无。
********************************************************************/
void Printc(uint8 x)
{
 UartPutChar(x);
}
void main(void)
{

	// WDT ~350ms, ACLK=1.5kHz, interval timer
	WDTCTL = WDT_ADLY_16;

	// Enable WDT interrupt
	IE1 |= WDTIE;

	SLAVE_SELECT_PORT_SET;
	SLAVE_SELECT_HIGH;

	ENABLE_PORT_SET;
	ENABLE_TRF;

	// wait until TRF7970A system clock started
	McuDelayMillisecond(2);

	// settings for communication with TRF7970A
	Trf7970CommunicationSetup();

	// Set Clock Frequency and Modulation
	Trf7970InitialSettings();

	// set the DCO to 8 MHz
	McuOscSel(1);

	// Re-configure the USART with this external clock
	Trf7970ReConfig();

	// Configure UART
	UartSetup();

	/************	Smart Medical NFC Scanner Project	************/
	McuDelayMillisecond(5);
	UartSendCString("[INFO] NFC Reader ENABLED.");
	UartPutCrlf();
	McuDelayMillisecond(2);

	P1SEL &= ~0x08;					// Select Port 1 P1.3 (push button)
	P1DIR &= ~0x08;					// Port 1 P1.3 (push button) as input, 0 is input
	P1REN |= 0x08;					// Enable Port P1.3 (push button) pull-up resistor
	P1IE |= 0x08;					// Port 1 Interrupt Enable P1.3 (push button)
	P1IFG &= ~0x08;					// Clear interrupt flag
	/************	Smart Medical NFC Scanner Project	************/
	
	// General enable interrupts
	__bis_SR_register(GIE);

	// indicates that setting are done
	enable = 1;

	// stand alone mode
	stand_alone_flag = 1;

	// launchpad LED1
	P1DIR |= BIT0;

	//init function for the patient array
	init_patient();

	P1IN&=BIT3;		///< Port 1.3 (left button) as input as mode switch

	while(1)
	{
		Tag_Count = 0;
		IRQ_OFF;
		DISABLE_TRF;

		// Enter LPM3
		__bis_SR_register(LPM3_bits);

		// launchpad LED1 - Toggle (heartbeat)
		P1OUT ^= BIT0;

		// Clear IRQ Flags before enabling TRF7970A
		IRQ_CLR;
		IRQ_ON;

		ENABLE_TRF;

		/************	Smart Medical NFC Scanner Project	************/
		// Must wait at least 4.8 ms to allow TRF7970A to initialize.
		__delay_cycles(40000);
		#ifdef ENABLE15693
				found_tag_ISO15693 = Iso15693FindTag( edit_mode );	///< Scan for 15693 tags
		#endif

		#ifdef ENABLE14443A
				found_tag_ISO14443a = Iso14443aFindTag( edit_mode );	///< Scan for 14443A tags
		#endif
		/*	We are not using 14443B type tag
		#ifdef ENABLE14443B
			  //Iso14443bFindTag();	// Scan for 14443B tags
		#endif
		*/
		
		/**
		 * Write total number of tags read to UART
		 */
		if(Tag_Count > 0){
			Tag_Count = UartNibble2Ascii(Tag_Count & 0x0F);		///< convert to ASCII
			UartSendCString("[INFO] Tags Found: ");
			UartPutChar(Tag_Count);
			UartPutCrlf();
			UartPutCrlf();
		}
		/**
		 * If either type of tag is found:
		 * reset empty scan counter,
		 * reset delay factor,
		 * delay MCU to prevent duplicate scan,
		 * reset tag found counter for both types of tag.
		 * 
		 */
		if( ( found_tag_ISO15693 == 1 ) || ( found_tag_ISO14443a == 1 ) )
		{
			empty_scan_cnt = 0;
			delay_factor = 0;
			McuDelayMillisecond( SCAN_DELAY_INIT_MS );
			found_tag_ISO15693 = 0;
			found_tag_ISO14443a = 0;
		}
		
		/**
		 * If edit mode is disabled:
		 * delay MCU by an increasing amount of time based on 
		 * delay_factor and initial delay,
		 * increase empty scan counter.
		 * 
		 */
		if( edit_mode == 0 )
		{
			//Dynamic delay for power saving
			McuDelayMillisecond( delay_factor*SCAN_DELAY_INIT_MS );

			//increment empty scan counter
			empty_scan_cnt++;
		}

		/**
		 * If debug mode is enabled:
		 * print out empty scan count.
		 * 
		 */
		if( DEBUG_MODE == 1 )
		{
			char buf[20];
			sprintf( buf, "[DEBUG] Scan#%d\r", empty_scan_cnt );
			UartSendCString( buf );
		}


		/**
		 * After 20 consecutive empty scan:
		 * reset empty scan counter,
		 * increment of delay counter if it's under threshold,
		 * print out message for additional delay occurrence.
		 * 
		 */
		if( empty_scan_cnt >= 20 )
		{
			empty_scan_cnt = 0;
			if( delay_factor < 4 )
			{
				delay_factor++;
				UartSendCString( "[DEBUG] No TAG in range, additional 500ms delay added\n" );
			}
		}
		/************	Smart Medical NFC Scanner Project	************/
	}
}
Example #7
0
int UartPrintf(const char *fmt, ...)
{
	int ret = 0;

	va_list args;
	char* ptr = (char*)fmt;

	va_start(args, fmt);
	while (true)
	{
		char c = *ptr++;

		if (c == '\0')
			break;

		if (c == '%')
		{
			// Get the next character to see what type of output is requested
			c = *ptr++;
			switch (c)
			{
				case '%':
					ret++;
					UartPutChar(c);
					break;
				case 's':
				{
					const char *str = va_arg(args, const char *);
					while (str)
					{
						ret++;
						UartPutChar(*str);
						str++;
					}
					break;
				}
				case 'd':
				{
					int i = va_arg(args, int);
					ret += UartPrintInt(i, eBase10);
					break;
				}
				case 'x':
				{
					int i = va_arg(args, int);
					ret += UartPrintInt(i, eBase16);
					break;
				}
				case 'p':
				{
					void* i = va_arg(args, void*);
					ret += UartPrintPtr(i);
					break;
				}
				default:
					ret++;
					UartPutChar(c);
					break;
			}
		}
		else if (c == '\n')
Example #8
0
void
Type2ReadTwoBlocks(u08_t rd2b)
{	
	u08_t i = 0, command[4];
	
	buf[0] = 0x8F; 						// reset FIFO
	buf[1] = 0x91; 						// send with CRC
	buf[2] = 0x3D; 						// write continuous from register 
	buf[3] = 0x00;						// value for register 1D
	buf[4] = 0x20;						// register 1E (# of bytes to be transmitted)
	buf[5] = 0x31;						// RD2B command
	//buf[6+30] = rd2b;						// addressed block
	
	buf[200] = 80;							// tell apart from Ack/Nack
	
	rx_error_flag = 0x00;
	
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] |= BIT2;						// enable 4-bit receive
	
	McuCounterSet();						// TimerA set 
	COUNT_VALUE = COUNT_1ms * 5;			// 5ms 
	IRQ_CLR;								// PORT2 interrupt flag clear 
	IRQ_ON;
	
	Trf797xReset();							// FIFO has to be reset before recieving the next response

	Trf797xRawWrite(&buf[0], 7);			// set Special Function Register
	
	i_reg = 0x01;
	START_COUNTER;							// start timer up mode
	irq_flag = 0x00;
	while(irq_flag == 0x00)					// wait for end of TX interrupt
	{
	}
	
	Trf797xWriteSingle(command, 2);			// enable 4-bit receive
	
	rxtx_state = 1;						// the response will be stored in buf[1] upwards
		
	McuCounterSet();						// TimerA set
	COUNT_VALUE = COUNT_1ms * 10;    
	START_COUNTER;							// start timer up mode
	i_reg = 0x01;
	while(i_reg == 0x01)					// wait for interrupt
	{
	}

	if(rx_error_flag == 0x02)
	{	
		i_reg = 0x02;
	}
	
	if(i_reg == 0xFF)						// recieved response
	{	
		UartPutChar('[');
		for(i = 1; i < rxtx_state; i++)
		{
			UartPutByte(buf[i]);
		}
		UartPutChar(']');
	}
	else if(i_reg == 0x02)
	{	

		if(buf[200] < 0x20)					// not acknowledged
		{	
			UartSendCString("[NACK]");
		}
		else								// collision occured
		{
			UartPutChar('[');
			UartPutChar('z');
			UartPutChar(']');
		}
	}
	else if(i_reg == 0x00)					// no responce
	{	
		UartPutChar('[');
		UartPutChar(']');
	}
	else
	{
	}
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] &= ~BIT2;
	Trf797xWriteSingle(command, 2);			// disable 4-bit receive
}
Example #9
0
void
Type2WriteOneBlock(u08_t wr1b)
{	
	u08_t command[10];
	
	//for(i=10; i>4; i--)						// write parameter in right frameposition
	//{	
	//	buf[i+2] = buf[i];
	//}
	
	buf[0] = 0x8F; 							// reset FIFO
	buf[1] = 0x91; 							// send with CRC
	buf[2] = 0x3D; 							// write continuous from register 
	buf[3] = 0x00;							// value for register 1D
	buf[4] = 0x60;							// register 1E (# of bytes to be transmitted)
	buf[5] = 0xA2;							// WR2B command
	//buf[6] = wr1b;
	
	buf[200] = 80;							// tell apart from Ack/Nack
	
	rx_error_flag = 0x00;
	
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] |= BIT2;
	Trf797xWriteSingle(command, 2);			// enable 4-bit receive
	
	Trf797xRawWrite(&buf[0], 11);
	
	IRQ_CLR;								// PORT2 interrupt flag clear
	IRQ_ON;
	
	i_reg = 0x01;
	rxtx_state = 1;							// the response will be stored in buf[1] upwards
	
	// wait for end of transmit
	while(i_reg == 0x01)
	{	
		McuCounterSet();
		COUNT_VALUE = COUNT_1ms * 5;		// for 10 ms TIMEOUT
		START_COUNTER;						// start timer up mode
		irq_flag = 0x00;
		while(irq_flag == 0x00)				// wait for interrupt
		{
		}
	}
	
	i_reg = 0x01;
	
	McuCounterSet();					// TimerA set 
	COUNT_VALUE = COUNT_1ms * 6;			// 6ms 
	START_COUNTER;
	
	while(i_reg == 0x01)					// wait for RX complete
	{
	}
	
	if(rx_error_flag == 0x02)
	{	
		i_reg = 0x02;
	}

	if(i_reg == 0x02)
	{	
		if(buf[200] < 0x20)					// not acknowledged
		{	
			UartSendCString("[NACK]");
		}
		else if((buf[200] & 0xF0) == 0xA0)	// acknowledged
		{	
			UartSendCString("[ACK]");
		}
		else								// collision occured
		{
			UartPutChar('[');
			UartPutChar('z');
			UartPutChar(']');
		}
	}
	else if(i_reg == 0x00)					// no response
	{		
			UartPutChar('[');
			UartPutChar(']');
	}
	else
	{
	}
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] &= ~BIT2;
	Trf797xWriteSingle(command, 2);			// disable 4-bit receive
}
Example #10
0
void
iso14443bAnticollision(u08_t command, u08_t slots)
{
	u08_t	i = 0, collision = 0x00, j, found = 0;
	u32_t	k = 0;
	#ifdef ENABLE_HOST
		//u08_t rssi[2];
	#endif
	
	rx_error_flag = 0x00;

	buf[0] = 0x8F;
	buf[1] = 0x91;
	buf[2] = 0x3D;
	buf[3] = 0x00;
	buf[4] = 0x30;
	buf[5] = 0x05;
	buf[6] = 0x00;

	if(slots == 0x04)
	{	
		Trf797xEnableSlotCounter();
	}

	buf[7] = slots;

	if(command == 0xB1)
	{	
		buf[7] |= 0x08; 					// WUPB command else REQB command
	}

	i_reg = 0x01;

	Trf797xRawWrite(&buf[0], 8);

	IRQ_CLR;								// PORT2 interrupt flag clear
	IRQ_ON;

	j = 0;
	while((i_reg == 0x01) && (j < 2))
	{
		j++;
		McuCounterSet();			// TimerA set
		COUNT_VALUE = COUNT_1ms * 2;		// 2ms
		START_COUNTER;
		irq_flag = 0x00;
		while(irq_flag == 0x00)
		{
		}
	}										// wait for end of TX

	i_reg = 0x01;
	
	McuCounterSet();				// TimerA set
	COUNT_VALUE = COUNT_1ms * 2;			// 2ms
	START_COUNTER;

	for(i = 1; i < 17; i++)
	{	
		rxtx_state = 1;						// the response will be stored in buf[1] upwards

		while(i_reg == 0x01)				// wait for RX complete
		{	
			k++;
			if(k == 0xFFF0)
			{	
				i_reg = 0x00;
				rx_error_flag = 0x00;
				break;
			}
		}

		if(rx_error_flag == 0x02)
		{	
			i_reg = rx_error_flag;
		}
		
		if(i_reg == 0xFF)					// recieved SID in buffer
		{	
			if(stand_alone_flag == 1)
			{	
				found = 1;
			}
			else
			{	
				#ifdef ENABLE_HOST
				
					UartPutChar('[');
					for(j = 1; j < rxtx_state; j++)
					{	
						UartPutByte(buf[j]);
					}
					UartPutChar(']');

					//UartPutChar('(');
					//UartPutByte(rssi[0]);
					//UartPutChar(')');
					UartPutCrlf();
				#endif
			}
		}
		else if(i_reg == 0x02)				// collision occured
		{	
			if(stand_alone_flag == 0)
			{	
				#ifdef ENABLE_HOST
					UartPutChar('[');
					UartPutChar('z');
					UartPutChar(']');
				#endif
			}
			collision = 0x01;
		}
		else if(i_reg == 0x00)				// slot timeout
		{	
			if(stand_alone_flag == 0)
			{	
				#ifdef ENABLE_HOST
					//UartPutChar('[');
					//UartPutChar(']');
				#endif
			}
		}
		else
		{
		}

		if((slots == 0x00) || (slots == 0x01) || (slots == 0x02) || ((slots == 0x04) && (i == 16)))
		{	
			break;
		}

		iso14443bSlotMarkerCommand(i);

		i_reg = 0x01;

		if(stand_alone_flag == 0)
		{	
			#ifdef ENABLE_HOST
				//UartPutCrlf();
			#endif
		}
	}										// for

	if(slots == 0x04)
	{	
		Trf797xDisableSlotCounter();
	}

	IRQ_OFF;
	
	if(remote_flag == 0)
	{
		if(found == 1)
		{	
			LED_14443B_ON;
		}
		else
		{	
			LED_14443B_OFF;
		}
	}

	if(collision)
	{	
		iso14443bAnticollision(0x20, 0x02);	// Call this function for 16 timeslots
	}
}											// iso14443bAnticollision