Beispiel #1
0
void ADT_shutdown()
{
	uint8_t i;
	//shutdown
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT shutdown:");
		uart_num(i,1);
		uart_nl();
		#endif		
		if(bit_get(ADT_status,BIT(i)))
		{
			#ifdef debug
			uart_println("SKIP");
			#endif
			continue;
		}

		i2c_start(ADT_addr_base|i,I2C_WRITE);
		i2c_write(0x03);//config reg
		i2c_write(0b11100000);//7: 16bit res, 6~5: shutdown mode
		i2c_stop();
	}
		#ifdef debug
		uart_println("ADTs off");
		#endif

}
void flashtest(){
	int i;
	short *flash = (short*)FLASH_TEST_BASE;
	short status;
	uart_print("Try to write in Flash at the address ");
	uart_printhex(flash);
	uart_skipline();

	uart_println("Unlock the block");
	unlock_block(flash);

	uart_println("Write memory");
	for(i=0; i<FLASHTEST_SIZE; i++){
		status = flash_write(FLASH_TEST_BASE+i*2, i+0x0);
		uart_print("write status = ");
		uart_printhex(status);
		uart_skipline();
	}
	//flash_erase_block(flash);

	uart_println("Try to dump memory, it should return the numbers from 0 to 9");
	for(i=0; i<FLASHTEST_SIZE; i++){
		uart_printhex(flash_read(flash++));	
		uart_skipline();
	}
}
Beispiel #3
0
void ADT_wake()
{
	uint8_t i;
	//power on sensors
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT wake:");
		uart_num(i,1);
		uart_nl();
		#endif		
		if(bit_get(ADT_status,BIT(i)))
		{
			#ifdef debug
			uart_println("SKIP");
			#endif		
			continue;//jump to next sensor, this one is broken
		}

		i2c_start(ADT_addr_base|i,I2C_WRITE);
		i2c_write(0x03);//config reg
		i2c_write(0b10000000);
		i2c_stop();
	}
	
}
void vga_black(){
	int i;
	short *vram = (short*) 0x40800000;
	uart_println("Write memory");
	for(i=0; i<800*300; i++){
		vram[i] = 0x0000;
	}
}
Beispiel #5
0
uint8_t ADT_check()
{
	uint8_t i;
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT chk: ");
		uart_num(i,1);
		#endif	
		if(i2c_start(ADT_addr_base|i,I2C_READ))
		{
			bit_set(ADT_status,BIT(i));//set Ith bit as sign of sensor error
			#ifdef debug
				uart_println(" FAIL");
			#endif
		}
		else
		{
			i2c_read(0);
			bit_clr(ADT_status,BIT(i));//set as working
			#ifdef debug
			uart_println(" OK");
			#endif
		}
		i2c_stop();
		
	}

	if(ADT_minimum_working > ADT_get_working_count())
	{
		error_flags.ADT=1;
		return 1;
	}
	else
	{	
		error_flags.ADT=0;
		return 0;
	}
}
void help(){
	uart_println("INSoC bootloader helper");
	uart_skipline();
	uart_println("help\t\t\tdiplays this help");
	uart_println("reboot\t\t\treboots the system");
	uart_println("kernel\t\t\tjumps to kernel");
	uart_println("ramtest\t\t\tperforms a memory test with the RAM memory");
	uart_println("flashtest\t\tperforms a memory test with the Flash memory");
}
void ramtest(){
	int i;
	char *ram = (char *)0x40004000;
	uart_print("Try to write in RAM at the address ");
	uart_printhex((int) ram);
	uart_skipline();
	for(i=0; i<RAMTEST_SIZE; i++){
		ram[i] = i;	
	}
	uart_println("Try to dump memory, it should return the numbers from 0 to 9");
	for(i=0; i<RAMTEST_SIZE; i++){
		uart_printhex(ram[i]);	
		uart_skipline();
	}
}
void vga_white(){
	int x, y;
	char *vram = (char*) 0x40800000;
	uart_println("Write memory");
	for(y=0; y<600; y++){
		for(x=0; x<800; x++){
			if(x>=0 && x<268)
				vram[y*800+x] = 0xFF & 0x01;
			if(x >=268 && x <532)
				vram[y*800+x] = 0xFF & 0x07;
			if(x >=532 && x <800)
				vram[y*800+x] = 0xFF & 0x04;
		}
	}
}
Beispiel #9
0
uint8_t ADT_measure(int16_t *storage, uint8_t samples,uint16_t sample_pause_ms)
{
	ADT_wake();

	int32_t temp=0;
	
	uint8_t sensor_num,sample_num;
	
	int8_t Htemp;
	int16_t Ltemp;

	
	//delay fow proper wakeup
	
	delay_ms(300);//because 1st conversion after wake is fast and inaccurate,
	//nomal conversion tooks 240ms
	
	for(sample_num=0;sample_num<samples;sample_num++)//take N samples
	{
	
		
		for(sensor_num=0;sensor_num<ADT_sensor_count;sensor_num++)
		{

			#ifdef debug
			uart_print("ADT measure:");
			uart_num(sensor_num,1);
			uart_nl();
			#endif	

			if(!bit_get(ADT_status,BIT(sensor_num)))
			{
				if(i2c_start(ADT_addr_base|sensor_num,I2C_READ))//start reading
					return 1;
				Htemp=i2c_readAck();//recieve degrees
				Ltemp=i2c_readNak();//recieve decimals (hexadecimals correctly), align them on lower bits
				i2c_stop();

				temp+=(Htemp<<8)+Ltemp;
				
				#ifdef debug
				uart_num((Htemp<<8)+Ltemp,4);
				uart_putc('\n');
				#endif
			}
			#ifdef debug
			else
				uart_println("SKIP");
			#endif

		}
		delay_ms(sample_pause_ms); //wait for another conversion, tooks 240ms at minimum
	}
	
	

	temp=temp/(samples*ADT_get_working_count());//calculate average value (still not converted)
	//there is now sth. like 3089 (24.1°C)

	temp*=10;//without this, we will lose decimal information in next step
	temp/=128;//convert into value
	//now it is 241

	ADT_shutdown();
	
	*storage=temp;

	//all measurements done
	
	return 0;
}
void jump_to_kernel(){
	uart_println("Jump to kernel");
	jump(KERNEL_BASE);
	while(1);
}
Beispiel #11
0
int main(void)
{	
	//PMIC.CTRL = PMIC_HILVLEN_bm | */PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm;
	//sei();
	
	
	LED_Init();
	LED_On(Red);
	//LED_On(Orange);
	
	#ifdef DEBUG
    uart_init();
	LED_On(Orange);
	uart_println("UART ready.");
	LED_Off(Red);
	#endif
	
	USB_Init();
	#ifdef DEBUG
	uart_println("Attaching USB lines");
	#endif
	USB_Attach();
	
	#ifdef DEBUG
	uart_println("Init done. BL waiting...");
	#endif
	LED_Off(Red);
	LED_On(Orange);
	
	// wait for USB to come up within 7 secs. If it does not => jump to the application directly
	// if it does: check reset status. EXT = wait another 7 seconds in BL before jumping to the app itself for any programming stuff
	// if PO/WD/BOD = wait only 2 seconds before jumping to the app.
	
	char Keep = 1;
	
	OVFCounter = 0;
	
	TCD0.CTRLA = TC_CLKSEL_DIV64_gc; // 125ms or thereabouts
	TCD0.INTCTRLA = TC_OVFINTLVL_MED_gc;
	
	while(Keep) // wait for USB
	{
		if(OVFCounter >= 7*8) // 7 seconds
			Keep = 0; 
		if(USB_State == Configured)
			Keep = 0;
			
		if(OVFCounter & 1)
			LED_On(Red);
		else
			LED_Off(Red);
	}
	
	
	#ifdef DEBUG
	u8 DelayTime = 2*8; // 2 seconds just for the lulz. Will be set to 0 for production code.
	#else
	u8 DelayTime = 0;
	#endif
	
	Keep = 1;
	
	u8 rst = RST.STATUS;
	RST.STATUS = 0xFF; // clear the flags
	
	if(rst & RST_EXTRF_bm) // external reset -- stay in bootloader!
	{
		DelayTime = 7*8; // 7 seconds
	}
	
	if(USB_State == Configured)
	{
		LED_On(Red);
	}
	
	else if (rst & RST_PORF_bm) // power on -- jump to app
	{
		LED_Off(Orange);
		uart_println("DBG: Jumping to application.");
		
		//__asm__ ("jmp 0");
	}
	
	u8 GoToBL = 0;
	OVFCounter = 0;
	
	while(Keep)
	{
		if(OVFCounter >= DelayTime)
			Keep = 0;
			
		if(USB_Serial_Pending() > 0)
		{
			Keep = 0;
			GoToBL = 1;
		}
		
		if(OVFCounter & 1)
			LED_On(Orange);
		else
			LED_Off(Orange);
	}
	
	if(GoToBL && USB_State == Configured)
	{
		#ifdef DEBUG
		uart_println("Going to bootloader...");
		#endif
		
		LED_On(Orange);
		LED_On(Red);
			
		LaunchBootloader();
		
		while (1)
		{
		}
	}
	
	#ifdef DEBUG
	uart_println("Going to application...");
	#endif
		
	LED_Off(Orange);
	
	while(1)
	{
		
	}
}