Beispiel #1
0
signed char fReadByteLoop(void)
{
	bTargetAddress = 0;
	bTargetDataPtr = 0;

	while (bTargetDataPtr < TARGET_DATABUFF_LEN) {
		//Send Read Byte vector and then get a byte from Target
		SendVector(read_byte_v, 4);
		// Set the drive here because SendByte() does not
		SetSDATAStrong();
		SendByte(bTargetAddress, 7);

		RunClock(2);	// Run two SCLK cycles between writing and reading
		SetSDATAHiZ();	// Set to HiZ so Target can drive SDATA
		bTargetDataIN = bReceiveByte();

		RunClock(1);
		SendVector(read_byte_v + 1, 1);	// Send the ReadByte Vector End

		// Test the Byte that was read from the Target against the original
		// value (already in the 128-Byte array "abTargetDataOUT[]"). If it
		// matches, then bump the address & pointer,loop-back and continue.
		// If it does NOT match abort the loop and return and error.
		if (bTargetDataIN != abTargetDataOUT[bTargetDataPtr]) {
#ifdef TX_ON
			UART_PutCRLF();
			UART_CPutString("bTargetDataIN : ");
			UART_PutHexByte(bTargetDataIN);
			UART_CPutString(" abTargetDataOUT : ");
			UART_PutHexByte(abTargetDataOUT[bTargetDataPtr]);
#endif
			return (BLOCK_ERROR);
		}

		bTargetDataPtr++;
		// Increment the address by 2 to accomodate 7-Bit addressing
		// (puts the 7-bit address into MSBit locations for "SendByte()").
		bTargetAddress += 2;

	}

	return (PASS);
}
Beispiel #2
0
// This function gets a line of text. It writes data into buffer with a maximum size of bufferLen. The function returns number of bytes written
// when enter is pressed
void GetLine(char *buffer, char bufferLen)
{
	char c;
	char strPos = 0; // Current position in the string
	
	UART_PutChar('>'); // Print line pointer
	
	while (1)
	{
		c = UART_cReadChar(); // Use UART module to read the character user enters
		
		if (c == 0x08 || c == 0x7F) // Delete or backspace pressed
		{
			if (strPos > 0) // Only delete if there are characters to delete
			{
				strPos--; // Set the position back one
				UART_PutString(rubout); // Sends the rubout sequence to the serial.
			}
		}
		else if (c == 0x0D) // Newline enter is pressed
		{
			buffer[strPos] = 0x00; // put the null character at the current strPos
			UART_PutCRLF(); // Go to another line
			break;
		}
		else if (c >= 0x20 && c < 0x7F) // only valid characters to the string. These are any alphabet, numeric, or symbols
		{
			if (strPos < bufferLen) // If there is space in the buffer
			{
				buffer[strPos++] = c; // Set the current character in buffer to c and then increment strPos
				UART_PutChar(c); // Send the character to the computer
			}
			else
				UART_PutChar(0x07); // Send BEL key because there is no more space left to add to the string
		}
	}
	
	return;
}
Beispiel #3
0
void main(void)
{	
	M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
	
	// Start the UART(with no parity), and Counter16
	UART_Start(UART_PARITY_NONE);
	// clock for moving serial
	Counter16_Start();
	
	// Start I2CHW
	I2CHW_Start();
	I2CHW_EnableMstr();
	I2CHW_EnableInt();
	
	// This is the command usage string
	UART_CPutString("########################## I2C External SRAM ########################\r\n\
#	W # XX T [Data]\r\n\
#		W    - Write command\r\n\
#		#    - Group Address (0 - 7)\r\n\
#		XX   - Memory Location in hex (00 - FF)\r\n\
#		T    - Data Type, either A for ASCII or H for Hexadecimal\r\n\
#		Data - Either ASCII string or Hexadecimal separates by spaces\r\n\
#\t\t\tA - Mary had a little lamb\r\n\
#\t\t\tH - 01 FF A0 0F D8 C3\r\n\
#\r\n\
#	R # XX T NN\r\n\
#		R    - Read command\r\n\
#		#    - Group Address (0 - 7)\r\n\
#		XX   - Memory Location in hex (00 - FF)\r\n\
#		T    - Data Type, either A for ASCII or H for Hexadecimal\r\n\
#		NN	 - Number of bytes to read in hexadecimal\r\n\
#####################################################################\r\n");
	while (1)
	{
		char *cmd;
		char *params;
		char slaveAddress = 0x50;		// 010100000 R/W shifted to front
		
		GetLine(buf, 79); // Retrieves a line with a maximum length of 70 characters and put it in buf.
		
		memset(data, 0x00, 256);	// Initialize all the set {data} to NULL bytes
		cmd = Lowercase(cstrtok(buf, " ")); // Get the first word from the entered string and lowercase it.
		if (strlen(cmd) == 1 && cmd[0] == 'w') // If the command is one letter and it is w, then write command
		{	
			int groupAddress; // only 1 and 2 actually go to SRAM
			int memLoc;
			char dataType;
			
			int len;

			params = cstrtok(0x00, " ");  // 0x00 indicates it will continue from last cstrtok command and get next word. This gets the next parameter
			
			// csscanf if used to parse the string into values such as hexadecimal or integers
			// It returns the number of parameters it parsed which should be one
			// If the length of the params is not right or it does not parse the right amount, it returns an error
			// %d gets an integer, this is the groupAddress
			if (strlen(params) != 1 || csscanf(params, "%d", &groupAddress) != 1) goto error;
			
			// %x gets a hexadecimal value, this can read capital or lowercase letters, this is the memory location
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &memLoc) != 1) goto error;
			
			// %c gets a character, the data type character
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%c", &dataType) != 1) goto error;
			
			// This reads the rest of the string and stores it in params. 
			// If the length is zero or if cstrtok returns 0, this means that there was no valid string/hex entered
			params = cstrtok(0x00, "\0");
			if (strlen(params) == 0 || params == 0x00) goto error;	// They did all the params but didn't write anything
			
			dataType = tolower(dataType); // Lowercase the data type
			if (groupAddress < 0 || groupAddress > 7)
				goto error; // groupAddress was not in range
			
			data[0] = memLoc;	// First byte needs to be the memory location according to PCF8570 datasheet
			slaveAddress |= groupAddress;	// ORs the group 2 address to the group 1 address to get slaveAddress
			
			if (dataType == 'a') // If the data type is ASCII
			{
				strcpy((data + 1), params); // Copy the string from params and put it right after the data[0] byte
				len = strlen((data + 1)) + 1; // len is the number of bytes to write, it is the length of the string and then +1 because of the memLoc byte
				// Cant just do strlen(data) because data[0] could be 0x00 and it would return 0 as the string length
			}
			else if (dataType == 'h') // If the data type is hex
			{
				// Take ASCII encoded hex data params and put it after data[0], returns number of bytes converted
				if ((len = HexConversion(params, (data + 1))) == -1)
					goto error;
				len++; // Add one to the length because of the memLoc byte at data[0]
			}
			else
				goto error;
			
			I2CHW_bWriteBytes(slaveAddress, data, len, I2CHW_CompleteXfer); // Write len bytes from data 
			while (!(I2CHW_bReadI2CStatus() & I2CHW_WR_COMPLETE)); // Wait while it is writing
			I2CHW_ClrWrStatus(); // Clear the write bit

			csprintf(data, "%x bytes were written", len); // csprintf takes the string and substitutes %x for len, puts into data str
			UART_PutString(data); // Print the string to UART
			UART_PutCRLF();
		}
		else if (strlen(cmd) == 1 && cmd[0] == 'r') // If the command is one letter and it is r, then read command
		{
			int groupAddress;
			int memLoc;
			char dataType;
			int numBytes;
			
			char hexStr[4];
			int i;

			// csscanf if used to parse the string into values such as hexadecimal or integers
			// It returns the number of parameters it parsed which should be one
			// If the length of the params is not right or it does not parse the right amount, it returns an error
			// %d gets an integer, this is the groupAddress
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%d", &groupAddress) != 1) goto error;
	
			// %x gets a hexadecimal value, this can read capital or lowercase letters, this is the memory location
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &memLoc) != 1) goto error;
			
			// %c gets a character, the data type character
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%c", &dataType) != 1) goto error;
			
			// %x gets a hexadecimal value, number of bytes to read
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &numBytes) != 1) goto error;
			
			// If there is any data after the number of bytes, then the format is invalid and it should return an error
			if (cstrtok(0x00, " ") != 0x00) goto error;
			
			dataType = tolower(dataType); // Lowercase the data type
			if (groupAddress < 0 || groupAddress > 7)
				goto error; // groupAddress was not in range
			
			data[0] = memLoc;	// First byte needs to be the memory location according to PCF8570 datasheet
			slaveAddress |= groupAddress;	// ORs the group 2 address to the group 1 address to get slaveAddress
			
			I2CHW_bWriteBytes(slaveAddress, data, 1, I2CHW_NoStop); // Write one byte to the RAM, the slaveAddress so it knows who were talking to
			while (!(I2CHW_bReadI2CStatus() & I2CHW_WR_COMPLETE)); // Wait while it is writing
			I2CHW_ClrWrStatus(); // Clear the write bit
			
			I2CHW_fReadBytes(slaveAddress, data, numBytes, I2CHW_CompleteXfer); // Read numBytes from the RAM, put it in data
			while(!(I2CHW_bReadI2CStatus() & I2CHW_RD_COMPLETE)); // Wait while it is reading
			I2CHW_ClrRdStatus(); // Clear the read bit
			
			if (dataType == 'a') // If the data type is ASCII
			{
				for (i = 0; i < numBytes; ++i) // Loop through each byte
					UART_PutChar(data[i]); // Put the character in PuTTy
				UART_PutCRLF();
			}
			else if (dataType == 'h') // If the data type is Hex
			{
				for (i = 0; i < numBytes; ++i) // Loop through each byte
				{
					csprintf(hexStr, "%X ", data[i]); // csprintf prints into hexStr a hexadecimal with a space
					UART_PutString(hexStr); // Print hexStr
				}
				UART_PutCRLF();
			}
			else
				goto error;
		}
		else 
			goto error;
		
		continue; // This is so that the error is skipped when everything goes right
		error: // This outputs an invalid format message and continues on to read another line
			UART_CPutString("Invalid format entered. Valid formats are:\r\n\tW [GroupAddress] [MemoryLocation] [h|a] Hex/ASCII\r\n\tR [GroupAddress] [MemoryLocation] [h|a] [NumBytes]\r\n");
	}
}
int cypress_update( int HW_ver )
{
	// -- This example section of commands show the high-level calls to -------
	// -- perform Target Initialization, SilcionID Test, Bulk-Erase, Target ---
	// -- RAM Load, FLASH-Block Program, and Target Checksum Verification. ----
	unsigned char fIsError = 0;
	//	unsigned char bTry=0;

	// >>>> ISSP Programming Starts Here <<<<

	//    ioctl(touch_fd, DEV_CTRL_TOUCH_INT_DISABLE,NULL);
	//    ioctl(touch_fd, DEV_CTRL_TOUCH_SET_FLAG,NULL);
	printk(KERN_INFO "[TSP] %s, %d, HW ver=%d\n", __func__, __LINE__,HW_ver);
#if defined(CONFIG_MACH_GIO)
	if( HW_ver == 1)
		pSocData = Firmware_Data_HW1;
	else if ( HW_ver == 2 )
		pSocData = Firmware_Data_HW2;
	else if ( HW_ver == 3 || HW_ver == 0 )
		pSocData = Firmware_Data_HW3;
	else if ( HW_ver == 17 )
		pSocData = Firmware_Data_HW11;
	else if ( HW_ver == 33 )
		pSocData = Firmware_Data_HW21;
	else if ( HW_ver == 34)
		pSocData = Firmware_Data_HW22;
	else if ( HW_ver == 35)
		pSocData = Firmware_Data_HW23;	
#elif defined(CONFIG_MACH_COOPER) 
	if( HW_ver == 4 || HW_ver == 3 || HW_ver == 0 )
		pSocData = Firmware_Data_HW3;
#else
	if( HW_ver == 1 )
		pSocData = Firmware_Data_HW1;
	else if( HW_ver == 2 )
		pSocData = Firmware_Data_HW2;
	else if( HW_ver == 3 )
		pSocData = Firmware_Data_HW3;
	else if( HW_ver == 4 )
		pSocData = Firmware_Data_HW4;
#endif
	else
	{
		printk(KERN_INFO "[TSP] %s, %d, HW ver is wrong!!\n", __func__, __LINE__);
		goto update_err;
	}
#ifdef TX_ON
	UART_Start();
	UART_CPutString("Start HSSP - Ovation");
	UART_PutCRLF();
#endif
	// >>>> ISSP Programming Starts Here <<<<

	// Acquire the device through reset or power cycle
#ifdef RESET_MODE
	UART_CPutString("Reset Mode activated");
#else
	//    UART_CPutString("Power Cycle Mode activated");
	// Initialize the Host & Target for ISSP operations
	fIsError = fPowerCycleInitializeTargetForISSP();
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify SiliconID");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

	// Run the SiliconID Verification, and proceed according to result.
#if !defined(CONFIG_MACH_TASS) && !defined(CONFIG_MACH_TASSDT) && !defined(CONFIG_MACH_GIO)
	fIsError = fVerifySiliconID();
#endif
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End VerifySiliconID");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

#if 1
	// Bulk-Erase the Device.
	fIsError = fEraseTarget();
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End EraseTarget");
	UART_PutCRLF();
	UART_CPutString("Program Flash Blocks Start");
	UART_PutCRLF();
#endif

#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#if 1   // program flash block
	//LCD_Char_Position(1, 0);
	//LCD_Char_PrintString("Program Flash Blocks Start");

	//==============================================================//
	// Program Flash blocks with predetermined data. In the final application
	// this data should come from the HEX output of PSoC Designer.

	iChecksumData = 0;     // Calculte the device checksum as you go
	for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
	{
		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		//LoadProgramData(bBankCounter, (unsigned char)iBlockCounter);
		iChecksumData += iLoadTarget(iBlockCounter);

		fIsError = fProgramTargetBlock(bBankCounter,(unsigned char)iBlockCounter);
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadStatus();
		if (fIsError)
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

#ifdef TX_ON
		UART_PutChar('#');
#endif

	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Program Flash Blocks End");
#endif

#endif


#if 1  // verify
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify Start");
	UART_PutCRLF();
#endif

	//=======================================================//
	//PTJ: Doing Verify
	//PTJ: this code isnt needed in the program flow because we use PROGRAM-AND-VERIFY (ProgramAndVerify SROM Func)
	//PTJ: which has Verify built into it.
	// Verify included for completeness in case host desires to do a stand-alone verify at a later date.

	for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
	{
		//LoadProgramData(bBankCounter, (unsigned char) iBlockCounter);

		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fVerifySetup(bBankCounter,(unsigned char)iBlockCounter);
		if (fIsError)
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadStatus();
		if (fIsError ) {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadWriteSetup();
		if (fIsError)  {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadByteLoop(iBlockCounter);
		if (fIsError ) {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

#ifdef TX_ON
		UART_PutChar('.');
#endif

	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify End");
#endif

#endif // end verify

#if 1
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Security Start");
#endif


	//=======================================================//
	// Program security data into target PSoC. In the final application this
	// data should come from the HEX output of PSoC Designer.
	for (bBankCounter=0; (bBankCounter<NUM_BANKS) ; bBankCounter++)
	{
		//PTJ: READ-WRITE-SETUP used here to select SRAM Bank 1

		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
		// Load one bank of security data from hex file into buffer
   		fIsError = fLoadSecurityData(bBankCounter);
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
		// Secure one bank of the target flash
		fIsError = fSecureTargetFlash();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End Security data");
#endif

#endif


#if 1   // checksum
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("CheckSum Start");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
	//PTJ: Doing Checksum
	iChecksumTarget = 0;
	fIsError = fAccTargetBankChecksum(&iChecksumTarget);
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Checksum : iChecksumTarget (0x");
	UART_PutHexWord(iChecksumTarget);
	UART_CPutString("), iChecksumData (0x");
	UART_PutHexWord(iChecksumData);
	UART_CPutString(")");
#endif

	iChecksumTarget = iChecksumTarget & 0xFFFF;
	iChecksumData = iChecksumData & 0xFFFF;

	if (iChecksumTarget != iChecksumData)
	{
		printk(KERN_INFO "[TSP] %s, %d, iChecksumTarget=%d, iChecksumData=%d\n", __func__, __LINE__,iChecksumTarget, iChecksumData );
		ErrorTrap(CHECKSUM_ERROR);
		goto update_err;
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End Checksum");
#endif

#endif

	// *** SUCCESS ***
	// At this point, the Target has been successfully Initialize, ID-Checked,
	// Bulk-Erased, Block-Loaded, Block-Programmed, Block-Verified, and Device-
	// Checksum Verified.

	// You may want to restart Your Target PSoC Here.
	ReStartTarget();
//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

	return 1;

update_err:
	return 0;
}
Beispiel #5
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*   This is the main entry point for this application. This function initializes all the 
*	components used in the project. It computes the frequency whenever a capture event is 
*
* Parameters:  
*   None
*
* Return:
*   None
*
*******************************************************************************/
int main()
{
	#if(UART_DEBUG_ENABLE)
		/* Variable to store the loop number */
		uint8 loopNo = 0;
	#endif
	/* Enable global interrupt mask */
	CyGlobalIntEnable;	
	
	/* Disable ILO as it is not used */
	CySysClkIloStop();
	
	/* Initialize components related to BLE communication */
	InitializeBLESystem();
	
	/* Initialize components related to frequency counting */
	Initialize_Freq_Meas_System();
	
	/* Start UART component if UART debug is enabled */
	#if(UART_DEBUG_ENABLE)
		/* Start UART component and send welcome string to hyper terminal on PC */
		UART_Start();
		UART_UartPutString("Welcome to Frequency Measurement Using PSoC 4 BLE\n");
		UART_PutCRLF();
	#endif
	
    while(1)
    {
		/* Compute frequency once in every PWM interval(2s) */
		if(Calculate_Frequency == TRUE)
		{
			/* Check if valid capture event is detected */
			if((Input_Sig_Ctr_Capture == 1) && (Ref_Clk_Ctr_Capture == 1))
			{
				/* Compute frequency using the latched count value, computed frequency 
				will be stored in ASCII format in a global array */
				Compute_Frequency();
				
				#if(UART_DEBUG_ENABLE)
					/* Print input signal counter value in hexadecimal */
					UART_UartPutString("Input Signal Counter Value: ");
					UART_SendDebugData(Input_Signal_Count);
					UART_UartPutString("      ");
					
					/* Print input signal counter value in ASCII format */	
					/* Reset the array before storing the ASCII character */
					Reset_Array(InputCounter_ASCII, DATA_END);
					
					Convert_HextoDec(Input_Signal_Count, InputCounter_ASCII);
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(InputCounter_ASCII[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();	

					/* Print reference clock counter value */
					UART_UartPutString("Reference Clock Counter Value: ");
					UART_SendDebugData(Ref_Clock_Count);
					UART_UartPutString("      ");
					
					/* Print input signal counter value in ASCII format */	
					/* Reset the array before storing the ASCII character */				
					Reset_Array(RefCounter_ASCII, DATA_END);
					Convert_HextoDec(Ref_Clock_Count, RefCounter_ASCII);
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(RefCounter_ASCII[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();
					
					/* Print Input Signal Frequency in decimal format */
					UART_UartPutString("Input Frequency: ");
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(Input_Frequency[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();			
				#endif
				/* Reset the capture flag after computing the frequency */
				Input_Sig_Ctr_Capture = 0;
				Ref_Clk_Ctr_Capture = 0;
			} 
			/* If valid capture event is not registered, set the value of frequency to 
			   zero */
			else
			{
				/* Reset the input_frequency array before storing the frequency value */
				Reset_Array(Input_Frequency, DATA_END);

				/* If no capture event is detected in the 1s interval, set the frequency to zero */
				FormatFrequencyData(ZERO_HZ);
				
				#if(UART_DEBUG_ENABLE)
					/* Print Input Signal Frequency in decimal format */
					UART_UartPutString("Input Frequency: ");
					for(loopNo = 0; loopNo < DATA_END; loopNo++)
					{
						UART_UartPutChar(Input_Frequency[DATA_END - loopNo -1]);
					}
					UART_PutCRLF();	
				#endif
			}
			/* Reset the 2s interval flag for computing the frequency in the next interval */
			Calculate_Frequency = 0;
			/* Send frequency value only if BLE device is connected */
			if(TRUE == deviceConnected) 
			{
				/* Send frequency value when notifications are enabled */
				if((startNotification & CCCD_NTF_BIT_MASK))
				{

					/* Send the frequency value to BLE central device by notifications */
					SendDataOverFreqCounterNotification(Input_Frequency);
				}
			}
		}

		
		/* Function to handle LED status depending on BLE state */
		HandleStatusLED();
		
		/* Handle CCCD value update only if BLE device is connected */
		if(TRUE == deviceConnected) 
		{
	
			/* When the Client Characteristic Configuration descriptor (CCCD) is written
			* by Central device for enabling/disabling notifications, then the same
			* descriptor value has to be explicitly updated in application so that
			* it reflects the correct value when the descriptor is read */
			UpdateNotificationCCCD();	
		}		
		if(restartAdvertisement)
		{
			/* Reset 'restartAdvertisement' flag*/
			restartAdvertisement = FALSE;
			
			/* Start Advertisement and enter Discoverable mode*/
			CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);	
		}
		/*Process Event callback to handle BLE events. The events generated and 
		* used for this application are inside the 'CustomEventHandler' routine*/
		CyBle_ProcessEvents();
		
		/* Put CPU to sleep */
		CySysPmSleep();
    }
}
Beispiel #6
0
// ============================================================================
// fVerifySiliconID()
// Returns:
//     0 if successful
//     Si_ID_ERROR if timed out on handshake to the device.
// ============================================================================
signed char fVerifySiliconID(void)
{
	SendVector(id_setup_2, num_bits_id_setup_2);

	fIsError = fDetectHiLoTransition();
	if (fIsError)
	{
#ifdef TX_ON
		UART_PutCRLF();
		UART_CPutString("fDetectHiLoTransition Error");
#endif
		return(SiID_ERROR);
	}
	SendVector(wait_and_poll_end, num_bits_wait_and_poll_end);

	SendVector(tsync_enable, num_bits_tsync_enable);

	//Send Read ID vector and get Target ID
	SendVector(read_id_v, 11);      // Read-MSB Vector is the first 11-Bits
	RunClock(2);                    // Two SCLK cycles between write & read
	bTargetID[0] = bReceiveByte();
	RunClock(1);
	SendVector(read_id_v+2, 12);    // 1+11 bits starting from the 3rd byte

	RunClock(2);                    // Read-LSB Command
	bTargetID[1] = bReceiveByte();

	RunClock(1);
	SendVector(read_id_v+4, 1);     // 1 bit starting from the 5th byte

	//read Revision ID from Accumulator A and Accumulator X
	//SendVector(read_id_v+5, 11);	//11 bits starting from the 6th byte
	//RunClock(2);
	//bTargetID[2] = bReceiveByte();	//Read from Acc.X
	//RunClock(1);
	//SendVector(read_id_v+7, 12);    //1+11 bits starting from the 8th byte
	//
	//RunClock(2);
	//bTargetID[3] = bReceiveByte();	//Read from Acc.A
	//
	//RunClock(1);
	//SendVector(read_id_v+4, 1);     //1 bit starting from the 5th byte,

	SendVector(tsync_disable, num_bits_tsync_disable);


#ifdef TX_ON
	// Print READ-ID
	UART_PutCRLF();
	UART_CPutString("Silicon-ID : ");
	UART_PutChar(' ');
	UART_PutHexByte(bTargetID[0]);
	UART_PutChar(' ');
	UART_PutHexByte(bTargetID[1]);
	UART_PutChar(' ');
#endif

#ifdef LCD_ON
	LCD_Char_Position(1, 0);
	LCD_Char_PrintString("ID : ");
	LCD_Char_PrintInt8(bTargetID[0]);
	LCD_Char_PutChar(' ');
	LCD_Char_PrintInt8(bTargetID[1]);
	LCD_Char_PutChar(' ');
#endif

	if (bTargetID[0] == target_id_v[0] && bTargetID[1] == target_id_v[1])
	{
		return(PASS);
	}
	else if (bTargetID[0] == target_id_v2[0] && bTargetID[1] == target_id_v2[1])	
	{
		return(PASS);
	}
	else
	{
		printk("%x %x \n", bTargetID[0], bTargetID[1]);
		return(SiID_ERROR);
	}
}
Beispiel #7
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
int main()
{
    int16 res = 0;
    int32 temperature;
    char  uartLine[250];
    int16 ADCCountsCorrected;

    /* Initialize the UART */
    UART_Start();
    UART_PutCRLF();
    UART_PutCRLF();
    UART_PutString("Starting temperature measurement...");
    UART_PutCRLF();
    
    PWM_Start();
    PWM_TriggerCommand(PWM_MASK, PWM_CMD_START);

    /* Init and start sequencing SAR ADC */
    ADC_SAR_SEQ_Start();
    ADC_SAR_SEQ_StartConvert();
    /* Enable interrupt and set interrupt handler to local routine */
    ADC_SAR_SEQ_IRQ_StartEx(ADC_SAR_SEQ_ISR_LOC);
    
    /* Init interrupt from timer to measure the temperature rarely */
    ISR_TIMER_StartEx(ISR_TIMER_LOC);

    CyGlobalIntEnable;

    for(;;)
    {
        /* When conversion of sequencing channels has completed */
        if((dataReady & ADC_SAR_SEQ_EOS_MASK) != 0u)
        {
            /* Get voltage, measured by ADC */
            dataReady &= ~ADC_SAR_SEQ_EOS_MASK;
            res = ADC_SAR_SEQ_CountsTo_mVolts(CH0_N, result[CH0_N]);
        }    
        
        /* When conversion of the injection channel has completed */
        if((dataReady & ADC_SAR_SEQ_INJ_EOC_MASK) != 0u)
        {
            dataReady &= ~ADC_SAR_SEQ_INJ_EOC_MASK;

            /******************************************************************************
            * Adjust data from ADC with respect to Vref value.
            * This adjustment is to be done if Vref is set to any other than
            * internal 1.024V.
            * For more detailed description see Functional Description section
            * of DieTemp P4 datasheet.
            *******************************************************************************/
            ADCCountsCorrected = result[TEMP_CH]*((int16)((float)ADC_VREF_VALUE_V/1.024));
            
            temperature = DieTemp_CountsTo_Celsius(ADCCountsCorrected);

            /* Print temperature value to UART */
            sprintf(
                    uartLine, "Temperature value: %dC",
                    (int16) temperature
                    );
            
            UART_PutString(uartLine);
            UART_PutCRLF();
            
            /* Print voltage value to UART */
            sprintf(
                uartLine, "ADC measured voltage: %dmV",
                (uint16) res
                );
            
            UART_PutString(uartLine);
            UART_PutCRLF();
        }
    }
}
Beispiel #8
0
int main(){
    CyGlobalIntEnable;
    SPI_Start();
    UART_Start();
    isrIRQ_Start();
    isrBTN_Start();
    ADC_Start();
    CyDelay(100);
    
    UART_PutString("Test TX and Rx Payload\r\n");
    
    NRF_INIT_t tx;
    tx.channel = CHANNEL;
    tx.isTX = true;
    tx.RF_SETUP_DR = NRF_RF_SETUP_RF_DR_1000;
    tx.RF_SETUP_PWR = 0;
    tx.SETUP_RETR_ARC = NRF_SETUP_RETR_ARC_15;
    tx.SETUP_RETR_ARD = NRF_SETUP_RETR_ARD_1500;

    // Test Rx Payload
    NRF_WriteSingleRegister(NRF_DYNPD, 0x01u);
    NRF_WriteSingleRegister(NRF_FEATURE, 0x06u);
    NRF_SetRxPayloadSize(NRF_RX_PW_P0, PAYLOAD_SIZE);
    //
    
    NRF_SetRxAddress(ADDR, sizeof(ADDR));
    NRF_SetTxAddress(ADDR, sizeof(ADDR));
    NRF_Init(&tx);
    
    NRF_TxTransmit(data, sizeof(data));
    CyDelay(4000);
    NRF_GetRetransmissionsCount(&test);
    UART_PutHexByte(test);
    UART_PutCRLF();
    
    for(;;){
        /*
        if(pressCount){
            if(3 == pressCount) pressCount = 0;
            ADCoutput = ADC_Read32();
            data[1] = (ADCoutput & 0xFF00) >> 8;
            data[2] = ADCoutput & 0xFF;
            data[6] = pressCount;
            NRF_TxTransmit(data, sizeof(data));
        }
        */
        
        count++;
        if(12 == count){
            if(250 == pressCount){
                pressCount = 0;
            }
            if(250 == test){
                test = 0;
            }
            count = 0;
            test++;
            data[9] = test;
            data[0] = pressCount;
            ADCoutput = ADC_Read32();
            data[1] = (ADCoutput & 0xFF00) >> 8;
            data[2] = ADCoutput & 0xFF;
            NRF_TxTransmit(data, sizeof(data));
        }
        CyDelay(20);
        
        NRF_GetLostPackets(&test);
        if(0x0F == test){
            NRF_ResetStatusIRQ(NRF_STATUS_MAX_RT);
        }
        UART_PutHexByte(test);
        UART_PutCRLF();
        
        if(isrFlag){
            isrFlag = false;
            if(NRF_GetStatus() & 0x40u){ /* RX_DR: Data Received */
                do{
                    NRF_RxPayload(RXdata, sizeof(RXdata));
                    NRF_ResetStatusIRQ(NRF_STATUS_RX_DR);
                    NRF_ReadSingleRegister(NRF_FIFO_STATUS, &status);
                }while(!(status & 0x01));
                printFlag = true;
            }else if(NRF_GetStatus() & 0x60u){ /* TX_DS: Data Sent */
                LED_Write(~LED_Read());
                NRF_ResetStatusIRQ(NRF_STATUS_TX_DS);
            }else if(NRF_GetStatus() & 0x10u){ /* MAX_RT: Retry Timeout */
                MAX_Write(~MAX_Read());
                NRF_ResetStatusIRQ(NRF_STATUS_MAX_RT);
            }
        }
        
        if(printFlag){
            UART_PutHexByte(RXdata[0]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[1]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[2]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[3]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[4]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[5]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[6]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[7]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[8]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[9]);
            UART_PutString("\r\n");
            printFlag = false;
        }
    }
}
Beispiel #9
0
int main(){

    CyGlobalIntEnable;
    isrSW_Start();
    isr_Timer_Start();
    UART_Start();
    ADC_Start();
    ADC_StartConvert();

    CyDelay(50);
    
    UART_PutString("nRF Tx\r\n");
    
    NRF_INIT_t tx;
    tx.channel = NRF_CHANNEL;
    tx.isTX = true;
    tx.RF_SETUP_DR = NRF_RF_SETUP_RF_DR_1000;
    tx.RF_SETUP_PWR = NRF_RF_SETUP_RF_PWR_18;
    tx.SETUP_RETR_ARC = NRF_SETUP_RETR_ARC_15;
    tx.SETUP_RETR_ARD = NRF_SETUP_RETR_ARD_1500;
    
    /* Start the component before anything else */
    nRF_Tx_Start(&tx);
    
    /* Test Dynamic Payload */
    nRF_Tx_EnableDynamicPayload(NRF_DYNPD_DPL_P0);

    nRF_Tx_SetRxPayloadSize(NRF_RX_PW_P0, PAYLOAD_SIZE);
    
    nRF_Tx_SetRxAddress(ADDR, sizeof(ADDR));
    nRF_Tx_SetTxAddress(ADDR, sizeof(ADDR));
    
    Timer_Start();

    for(;;){
        
        if(true == isrTimerFlag){
            // Stop the Timer just for fun
            Timer_Stop();

            test++;
            data[0] = pressCount;
            data[9] = test;
            ADCoutput = ADC_Read32();
            UART_PutString("Resultado de la conversion del ADC: ");
            UART_PutHexInt((uint16_t)ADCoutput);
            UART_PutCRLF();
            data[1] = (ADCoutput & 0xFF00) >> 8;
            data[2] = ADCoutput & 0xFF;
            nRF_Tx_TxTransmit(data, sizeof(data));
            isrTimerFlag = false;

            // Start the Timer again
            Timer_Start();
        }

        if(isrFlag){
            
            if(nRF_Tx_GetStatus() & NRF_STATUS_RX_DR_MASK){
                UART_PutString("Status: ");
                UART_PutHexByte(nRF_Tx_GetStatus());
                UART_PutCRLF();
                UART_PutString("RX\r\n");
                do{
                    nRF_Tx_RxPayload(RXdata, sizeof(RXdata));
                    nRF_Tx_ResetStatusIRQ(NRF_STATUS_RX_DR);
                    nRF_Tx_ReadSingleRegister(NRF_FIFO_STATUS, &status);
                }while(!(status & NRF_STATUS_TX_FIFO_FULL));
                printFlag = true;
            }else if(nRF_Tx_GetStatus() & NRF_STATUS_TX_DS_MASK){
                UART_PutString("Status: ");
                UART_PutHexByte(nRF_Tx_GetStatus());
                UART_PutCRLF();
                UART_PutString("TX\r\n");
                LED_Write(~LED_Read());
                nRF_Tx_ResetStatusIRQ(NRF_STATUS_TX_DS);
            }else if(nRF_Tx_GetStatus() & NRF_STATUS_MAX_RT_MASK){
                UART_PutString("Status: ");
                UART_PutHexByte(nRF_Tx_GetStatus());
                UART_PutCRLF();
                UART_PutString("Max RT\r\n");
                MAX_Write(~MAX_Read());
                nRF_Tx_ResetStatusIRQ(NRF_STATUS_MAX_RT);
            }

            isrFlag = false;
        }
        
        if(printFlag){
            UART_PutHexByte(RXdata[0]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[1]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[2]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[3]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[4]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[5]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[6]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[7]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[8]);
            UART_PutString("\r\n");
            UART_PutHexByte(RXdata[9]);
            UART_PutString("\r\n");
            printFlag = false;
        }

    }