예제 #1
0
파일: cmd_mmc.c 프로젝트: josh64x2/apc-rock
int do_mmc_wait_insert(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    SD_Controller_Powerup();
	int insert = simple_strtoul(argv[1], NULL, 10);
	if(insert){
		printf("waiting insert SD card\n");
		while(SD_card_inserted()!=1){
			if( sd_check_ctrlc())
                    return -1;
		}
		return 0;

	}else{
		printf("wainting remove SD card\n");
		while(SD_card_inserted()!=0){
			if( sd_check_ctrlc())
                    return -1;
            udelay(500000);//delay 500ms
		}
		
		return 0;
	}
}
예제 #2
0
파일: Toplevel.c 프로젝트: mtwieg/NMR
uint8_t check_SD(void)
{
	if(SD_card_inserted()==false)
	{
		return SD_card_not_inserted;	
	}
	spi_options_t SD_spiOptions =
	  {
		.reg          = SD_MMC_SPI_NPCS,
		.baudrate     = SD_SPI_SPEED,  // Defined in conf_sd_mmc_spi.h.
		.bits         = 8,          // Defined in conf_sd_mmc_spi.h.
		.spck_delay   = 0,
		.trans_delay  = 0,
		.stay_act     = 1,
		.spi_mode     = 0,
		.modfdis      = 1
	  };
  
	if(sd_mmc_spi_init(SD_spiOptions, PBA_SPEED)==false)
	{
		return SD_card_init_failed;
	}
  
	if(card_type!=SD_CARD_2_SDHC)
	{
		return SD_card_invalid;
	}
	return SD_card_valid;
}

bool SD_card_inserted(void)
{
	if(gpio_get_pin_value(SD_detect_pin)==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

uint8_t hostmode_run(void)
{
	//first receive and verify full experiment
	//set USB PDCA to store experiment
	USB_USART->rtor=0;	//disable timeout
	pdca_disable(USB_USART_RX_PDCA_CHANNEL);
	my_pdca_init_channel(USB_USART_RX_PDCA_CHANNEL, (uint32_t)(&experiment.MODE),(uint32_t)(sizeof(experiment)), USB_USART_RX_PDCA_PID,   0,  0, PDCA_TRANSFER_SIZE_BYTE);
	pdca_enable(USB_USART_RX_PDCA_CHANNEL);
	
	while(!(pdca_get_transfer_status(USB_USART_RX_PDCA_CHANNEL) & AVR32_PDCA_TRC_MASK)); //wait until transfer is done
	
	if(validate_sequences()==false)
	{
		usart_write_line(USB_USART, "badexp\n");
		
		usart_putchar(USB_USART,(uint8_t)(get_experiment_problem()));
		
		my_pdca_init_channel(USB_USART_RX_PDCA_CHANNEL, (uint32_t)(&host_USART_buffer),(uint32_t)(sizeof(host_USART_buffer)),USB_USART_RX_PDCA_PID,0,0, PDCA_TRANSFER_SIZE_BYTE);
		pdca_enable(USB_USART_RX_PDCA_CHANNEL);
		USB_USART->cr|=AVR32_USART_CR_STTTO_MASK; //set timeout to stop until new character is received
		USB_USART->rtor=15000;	//set to timeout in 1ms
		
		return 0;
	}
	
	usart_write_line(USB_USART, "goodexp\n");
	pdca_disable(USB_USART_TX_PDCA_CHANNEL);
	gettruesequence();
	my_pdca_init_channel(USB_USART_TX_PDCA_CHANNEL, (uint32_t)(&experiment.MODE),(uint32_t)(sizeof(experiment)), USB_USART_TX_PDCA_PID,   0,  0, PDCA_TRANSFER_SIZE_BYTE);
	pdca_enable(USB_USART_TX_PDCA_CHANNEL);
	while(!(pdca_get_transfer_status(USB_USART_TX_PDCA_CHANNEL) & AVR32_PDCA_TRC_MASK)); //wait until transfer is done
	pdca_disable(USB_USART_TX_PDCA_CHANNEL);
	
	//change back USB USART to accept command tokens
	my_pdca_init_channel(USB_USART_RX_PDCA_CHANNEL, (uint32_t)(&host_USART_buffer),(uint32_t)(sizeof(host_USART_buffer)),USB_USART_RX_PDCA_PID,0,0, PDCA_TRANSFER_SIZE_BYTE);
	pdca_enable(USB_USART_RX_PDCA_CHANNEL);
	
	for(uint8_t i=0;i<Nsequences_max;i++)
	{
		usart_putchar(USB_USART,(uint8_t)(t_experiment.t_sequence[i].clusters_per_sequence));
	}
	
	USB_USART->cr|=AVR32_USART_CR_STTTO_MASK; //set timeout to stop until new character is received
	USB_USART->rtor=15000;	//set to timeout in 1ms
	
	reset_SD_sink_ptr();
	uint32_t SD_read_ptr=data_base_address;
	
	DAC1->dr0=t_experiment.t_Vgain; //set gain of RF amp
	
	while(1)	//once in host mode, this will run until a restart command is received
	{
		char *HOSTCMD="false";
		while(strcmp(HOSTCMD,"false")==0)
		{
			HOSTCMD=get_HOST_cmd();
			if(strcmp((HOSTCMD+1),"sequencetoken")==0)
			{
				uint8_t sequenceindex=*HOSTCMD;
				t_currentsequence=t_experiment.t_sequence[sequenceindex];
				
				executesequence_SDstorage_multiprep_combined();
				
				if(did_data_fail())
				{
					usart_write_line(USB_USART, "fail\n");
					usart_putchar(USB_USART,(uint8_t)(get_failure_cause()));
					usart_putchar(USB_USART,(uint8_t)(get_saved_r1()));
				}					
				else
				{
					usart_write_line(USB_USART, "good\n");
					send_data_to_host(SD_read_ptr,t_currentsequence.clusters_per_sequence);
				}	
				
				
				SD_read_ptr+=t_currentsequence.clusters_per_sequence*blocks_per_cluster*bytes_per_block;
				//set back to command mode
				pdca_disable(USB_USART_RX_PDCA_CHANNEL);
				my_pdca_init_channel(USB_USART_RX_PDCA_CHANNEL, (uint32_t)(&host_USART_buffer),(uint32_t)(sizeof(host_USART_buffer)),USB_USART_RX_PDCA_PID,0,0, PDCA_TRANSFER_SIZE_BYTE);
				pdca_enable(USB_USART_RX_PDCA_CHANNEL);
				USB_USART->cr|=AVR32_USART_CR_STTTO_MASK; //set timeout to stop until new character is received
				USB_USART->rtor=15000;	//set to timeout in 1ms
			}
			else if(strcmp((HOSTCMD),"RESTART\n")==0)
			{	//want to handle start of new host mode experiment
				return 1;
			}
		}
			
	}
	return 1;	
}