Please Do Not This File From Project
This File is created to Maintain Project Revision and changes
Project Rev 1.0
Used for Testing Teridian Daughter Card
RTC is not used on Teridian board.
Pin Definition
P06 ----> SCK
P04 ----> MOSI
P01 ----> CS_N
P20 ----> MISO
Hold - Pulled up
WP pin not available on board
For testing nvSRAM the same setup can be used 
P31 ----> configured as Interrupt pin to interrupt from display contineous clock on LCD.
P21 ----> RX - UART
P13 ----> TX -UART

void nvSRAMCompleteTest(void)

{
  int i;
  BYTE readdata, readdata1, readdata2, readdata3, readdata4, readdata5, readdata6;
  
  
  
  
  
  
//nvSRAM write 5 locations	
	nvSRAMWRITE(0xaa, 0x01, 0x80, 0x00); 			//write AA to protected block starting array address
    nvSRAMWRITE(0xbb, 0x01, 0x80, 0x01); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xcc, 0x01, 0x80, 0x02); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xdd, 0x01, 0x80, 0x03); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xee, 0x01, 0x80, 0x04); 			//write AA to protected block starting array address
	
	//nvSRAM read 5 locations
	UART_CPutString("\r\n nvSRAM Read 5 locations expected aa bb cc dd ee\r\n");  
	readdata=nvSRAMREAD(0x01, 0x80, 0x00); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x01); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x02); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x03); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x04); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
		
	//nvSRAM write on different locations	
	nvSRAMWRITE(0xa5, 0x01, 0xa0, 0x00); 			//write AA to protected block starting array address
    nvSRAMWRITE(0x5a, 0x01, 0xa0, 0x01); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xa5, 0x01, 0xa0, 0x02); 			//write AA to protected block starting array address
	nvSRAMWRITE(0x5a, 0x01, 0xa0, 0x03); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xa5, 0x01, 0xa0, 0x04); 			//write AA to protected block starting array address
	
	//nvSRAM read 5 locations
	UART_CPutString("\r\n nvSRAM Read 5 locations exp a5,5a,a5,5a,a5\r\n");  
	readdata=nvSRAMREAD(0x01, 0xa0, 0x00); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0xa0, 0x01); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0xa0, 0x02); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0xa0, 0x03); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0xa0, 0x04); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	
	//nvSRAM Readback first 5 locations
	UART_CPutString("\r\n nvSRAM Readback 5 locations exp aa,bb,cc,dd,ee\r\n");  
	readdata=nvSRAMREAD(0x01, 0x80, 0x00); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x01); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x02); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x03); 		// read from memory location 0x01222
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	readdata=nvSRAMREAD(0x01, 0x80, 0x04); 		// read from memory location 0x01222 
	UART_PutSHexByte(readdata); // read status register, it should read back 0x04
	
	/*************Burst read/write operation**********************/

//	nvSRAMBURSTWRITE(0x00, 0x00, 0x00,0x0a);			//nvSRAM burst write
	nvSRAMBURSTWRITE_DI(0x00, 0x00, 0x00,0x0a,0x05);			//nvSRAM burst write
	UART_CPutString("\r\n nvSRAM burst read 10 locations with 0x05 to 0x0E\r\n"); 
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x0a,0);            //nvSRAM burst read
	
		
	UART_CPutString("\r\n***********\r\n");  
	  
	nvSRAMBURSTWRITE_DI(0x00, 0x10, 0x00,0x0a,0xA0);			//nvSRAM burst write
	UART_CPutString("\r\n nvSRAM burst read 10 locations with A0 to A9\r\n"); 
	nvSRAMBURSTREAD(0x00, 0x10, 0x00, 0x0a,0);            //nvSRAM burst read  
	  
	UART_CPutString("\r\n nvSRAM burst read  earlier 10 locations with 5 to E\r\n");  
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x0a,0);            //nvSRAM burst read  
	  
		UART_CPutString("\r\n nvSRAM burst read  earlier 1 locations with 5 to E\r\n");  
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x01,0);   
	
		UART_CPutString("\r\n nvSRAM burst read  earlier 4 locations with 5 to E\r\n");  
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x04,0);   
	
		UART_CPutString("\r\n nvSRAM burst read  earlier 7 locations with 5 to E\r\n");  
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x07,0);   
	  
	
		
	/*************block protection=none**********************/

    UART_CPutString("\r\n block protection off \r\n");
	nvSRAMWRITE(0xA5, 0x00, 0x12, 0x22);  			// write 0xA5 to memory location 0x01222
	readdata=nvSRAMREAD(0x00, 0x12, 0x22); 		// read from memory location 0x01222 
	
	WRSR(0x00);                                     // Write 0x00 to status register ( block protection is disabled)
	
	nvSRAMWRITE(0x55, 0x00, 0x12, 0x22);            // Write 0x55 to memory location 0x01222
	readdata1=nvSRAMREAD(0x00, 0x12, 0x22); 		//read from memory locaiton 0x01222
	UART_CPutString("\r\n Expected read back data a5, 55 \r\n");
	UART_PutSHexByte(readdata);
	UART_PutSHexByte(readdata1);
	
	
	/*************block protection=0x18000-0x1FFFF(1/4)**********************/

	WRSR(0x00);                                     //Disable block protect
	UART_CPutString("\r\n block protection quarter block \r\n");
	nvSRAMWRITE(0xaa, 0x01, 0x80, 0x00); 			//write AA to protected block starting array address
	nvSRAMWRITE(0xbb, 0x01, 0x7F, 0xFF); 			//write BB to non protected blcok
	nvSRAMWRITE(0xcc, 0x01, 0xFF, 0xFF);			//write CC to protected block ending array address
	UART_CPutString("\r\n Expected read back data aa,bb,cc \r\n");
	readdata1=nvSRAMREAD(0x01, 0x80, 0x00); 	
	readdata2=nvSRAMREAD(0x01, 0x7F, 0xFF);
	readdata3=nvSRAMREAD(0x01, 0xFF, 0xFF); 
	UART_PutSHexByte(readdata1); 
	UART_PutSHexByte(readdata2); 
	UART_PutSHexByte(readdata3); 
		
	
	WRSR(0x04);									// Write 0x04 to status register to enable 1/4 th memory block protection
	
	nvSRAMWRITE(0x55, 0x01, 0x80, 0x00);		//write 55 to protected block starting array address
	nvSRAMWRITE(0x55, 0x01, 0x7F, 0xFF); 		//write 55 to non protected blcok
	nvSRAMWRITE(0x55, 0x01, 0xFF, 0xFF);		//write 55 to protected block ending array address
	UART_CPutString("\r\n Expected read back data aa,55,cc \r\n");
	readdata4=nvSRAMREAD(0x01, 0x80, 0x00); 
	readdata5=nvSRAMREAD(0x01, 0x7F, 0xFF);
	readdata6=nvSRAMREAD(0x01, 0xFF, 0xFF);
	UART_PutSHexByte(readdata4); 
    UART_PutSHexByte(readdata5); 
	UART_PutSHexByte(readdata6); 
	
	
		
	/*************block protection=0x10000-0x1FFFF(1/2)**********************/
	UART_CPutString("\r\n block protection half block \r\n");

	WRSR(0x00);									// Disable block protect
	
	nvSRAMWRITE(0xaa, 0x01, 0x00, 0x00); 		//write AA to protected block starting array address
	nvSRAMWRITE(0xaa, 0x00, 0xFF, 0xFF); 		//write AA to non protected blcok
	nvSRAMWRITE(0xaa, 0x01, 0xFF, 0xFF);		//write AA to protected block ending array address
	
    WRSR(0x08);									//write 0x08 to status register to enable 1/2 block protect
	
	nvSRAMWRITE(0x55, 0x01, 0x00, 0x00);		//write 55 to protected block starting array address
	nvSRAMWRITE(0x55, 0x00, 0xFF, 0xFF); 		//write 55 to non protected blcok
	nvSRAMWRITE(0x55, 0x01, 0xFF, 0xFF);		//write 55 to protected block ending array address
	
	UART_CPutString("\r\n Expected read back data aa,55,aa \r\n");
	readdata1=nvSRAMREAD(0x01, 0x00, 0x00); 
	readdata2=nvSRAMREAD(0x00, 0xFF, 0xFF); 
	readdata3=nvSRAMREAD(0x01, 0xFF, 0xFF); 
	UART_PutSHexByte(readdata1); 
    UART_PutSHexByte(readdata2); 
	UART_PutSHexByte(readdata3); 
    
	/*************block protection=0x00000-0x1FFFF(full)**********************/
	
	WRSR(0x00);								// Disable block protect
	UART_CPutString("\r\n Expected AA \r\n");
	nvSRAMWRITE(0xaa, 0x00, 0x00, 0x00);		//write AA to protected block starting array address
	readdata1=nvSRAMREAD(0x00, 0x00, 0x00); 

	WRSR(0x0C);									// Enable complete memory block protection				
	
	nvSRAMWRITE(0x55, 0x00, 0x00, 0x00);		//write 55 to protected block starting array address
	readdata2=nvSRAMREAD(0x00, 0x00, 0x00); 
    	
	UART_PutSHexByte(readdata1); 
	UART_PutSHexByte(readdata2); 
	
	
	/************ BURST WRITE COMPLETE memory***************/
	WRSR(0x00);
	UART_CPutString("\r\n nvSRAM burst Write ,Read & Verify for the entire memory Array (128K Locations) \r\n"); 
	UART_CPutString("\r\n Waiting...... \r\n"); 
	nvSRAMBURSTWRITE(0x00, 0x00,0x00,0x1FFFF);			//nvSRAM burst write
    nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x1FFFF,1);            //nvSRAM burst read
	
	UART_CPutString("\r\n nvSRAM Software Store/ Recall\r\n"); 
	
	///************Software Store/ Recall************************//
	
	//nvSRAMWRITE(0x12, 0x11, 0x22, 0x33); //call nvSRAM write Function
	nvSRAMSTORE(); 
	for(i=0;i<10000;i++); ///Delay for nvStrore
	nvSRAMBURSTWRITE_DI(0x00, 0x00, 0x00,0x1FFFF,0x00);			//nvSRAM burst write
	//nvSRAMWRITE(0xBB, 0x11, 0x22, 0x33);
	UART_CPutString("\r\n nvSRAM Read To verify new write successful\r\n"); 
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x0A,0);            //nvSRAM burst read
	nvSRAMRECALL();
	for(i=0;i<10000;i++);///Delay for nvRecall	
	nvSRAMBURSTREAD(0x00, 0x00, 0x00, 0x1FFFF,0);            //nvSRAM burst read
	UART_CPutString("\r\n nvSRAM Testing Completed \r\n"); 
}
