Esempio n. 1
0
void
_kernel_call_inirtn(void)
{
	KzAttIni( (VP_INT)(0) );
	timer_initialize( (VP_INT)(0) );
	serial_initialize( (VP_INT)(0) );
}
Esempio n. 2
0
int main(void)
{
    vuint32_t PulseNum = 0;
    
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    light_init();                                        /* LED灯初始化 */
    
    /* 初始化串口 */
    serial_initialize((intptr_t)(NULL));
    
    ftm_decoder_init(PTA8_9);

    printf("%s\n","FTM - PWM test!");
   
    while(1)
    {
        PulseNum = FTM_CNT_REG(FTM1_BASE_PTR); //读FTM1的CNT寄存器的值
        
        if(PulseNum > 5000)
        {
            light_change(LIGHT1);
        }
    }
    return 0;
}
Esempio n. 3
0
int main(void)
{
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    light_init();                                        /* LED灯初始化 */

    /* 初始化串口 */
    serial_initialize((intptr_t)(NULL));
    
    pit_init(PIT0, BUS_CLK_50000*1000); 
    pit_enable(PIT0);  
    
    printf("%s\n","PIT test!");

    /* 主循环 */
    while (1)
    {
        //主循环计数到一定的值,使小灯的亮、暗状态切换
        if (pit_count > 0)
        {
            light_change(LIGHT0);//指示灯的亮、暗状态切换
            pit_count = 0;
        }
        pit_enable(PIT0);
    } //end_while
}
Esempio n. 4
0
int main(int argc, char **argv)
{   
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    sys_timer_init();                                    /* 系统时钟初始化 */
    light_init();                                        /* LED灯初始化 */
    switch_init();                                       /* 开关初始化 */
    speaker_init();                                      /* 蜂鸣器初始化 */
    motor_init();                                        /* 电机初始化 */
    steer_init();                                        /* 舵机初始化 */
    decoder_init();                                      /* 编码器初始化 */
    serial_initialize((intptr_t)(NULL));                 /* 初始化串口 */
    //sd_init(&Fatfs);                                   /* 初始化SD卡,并创建文件 */
    //sd_create_file(&test_data, test_data_name);
    
    /* 命令注册 */
    help_cmd_initialize((intptr_t)(NULL));
    light_cmd_initialize((intptr_t)(NULL));
    switch_cmd_initialize((intptr_t)(NULL));
    speaker_cmd_initialize((intptr_t)(NULL));
    motor_cmd_initialize((intptr_t)(NULL));
    decoder_cmd_initialize((intptr_t)(NULL));
    control_cmd_initialize((intptr_t)(NULL));
    //sd_cmd_initialize((intptr_t)(NULL));

    printf("\n Welcome to k60 software platform!");
    printf("\n Press 'help' to get the help! \n");
    
    //light_open(LIGHT4); 

    /* ntshell测试 */
    task_ntshell((intptr_t)(NULL));
}
Esempio n. 5
0
void firmware_init(){
	// Initialize firmware
	dxl_initialize(0,1);		//initialize dynamixel communication
	serial_initialize(57600);		//initialize serial communication
	
	//initialize sensors
	sensor_init(SENSOR_FRONT,SENSOR_DISTANCE);
	sensor_init(SENSOR_FRONTLEFT,SENSOR_IR);
	sensor_init(SENSOR_FRONTRIGHT,SENSOR_IR);
	sensor_init(SENSOR_BACKLEFT,SENSOR_IR);
	sensor_init(SENSOR_BACKRIGHT,SENSOR_IR);
	
	//initialize I/O
	io_init();
	io_set_interrupt(BTN_START, &reset_state); //assign callback function when start button is pressed 
	
	// Activate general interrupts
	sei();
	
	// Set motors to wheel mode
	motor_set_mode(254, MOTOR_WHEEL_MODE);
	
	// Set serial communication through ZigBee
	serial_set_zigbee();
	
}
Esempio n. 6
0
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
{
    // COM10 以降への対応用
    enum { NameLength = 11 };
    char adjusted_device[NameLength];

    serial_initialize(serial);

    /* COM ポートを開く */
    _snprintf(adjusted_device, NameLength, "\\\\.\\%s", device);
    serial->hCom = CreateFileA(adjusted_device, GENERIC_READ | GENERIC_WRITE,
                               0, NULL, OPEN_EXISTING,
                               FILE_ATTRIBUTE_NORMAL, NULL);

    if (serial->hCom == INVALID_HANDLE_VALUE) {
        // !!! store error_message buffer
        //printf("open failed: %s\n", device);
        return -1;
    }

    /* 通信サイズの更新 */
    SetupComm(serial->hCom, 4096 * 8, 4096);

    /* ボーレートの変更 */
    serial_set_baudrate(serial, baudrate);

    /* シリアル制御構造体の初期化 */
    serial->has_last_ch = False;

    /* タイムアウトの設定 */
    serial->current_timeout = 0;
    set_timeout(serial, serial->current_timeout);

    return 0;
}
Esempio n. 7
0
int serial_connect(serial_t *serial, const char *device, long baudrate)
{

  enum { NameLength = 11 };
  char adjusted_device[NameLength];

  serial_initialize(serial);


  _snprintf(adjusted_device, NameLength, "\\\\.\\%s", device);
  serial->hCom_ = CreateFileA(adjusted_device, GENERIC_READ | GENERIC_WRITE, 0,
                              NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

  if (serial->hCom_ == INVALID_HANDLE_VALUE) {
    printf("open failed: %s\n", device);
    return -1;
  }


  SetupComm(serial->hCom_, 4096 * 8, 4096);


  serial_setBaudrate(serial, baudrate);


  serial->has_last_ch_ = False;


  serial->current_timeout_ = 0;
  setTimeout(serial, serial->current_timeout_);

  return 0;
}
Esempio n. 8
0
void sensorInit(void){
printf( "### sensorInit\n");
	
//	DDRA  = 0xFC;
//	PORTA = 0xFC;
	
	serial_initialize(57600);
	sei();

	ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1); // ADC Enable, Clock 1/64div.
	ADMUX = ADC_PORT_1; // ADC Port X Select
}
Esempio n. 9
0
/* Symbol for common u-boot code to call. */
int serial_init(void)
{
	serial_initialize();
	serial_setbrg();
	uart_lsr_clear();
#ifdef CONFIG_DEBUG_SERIAL
	cache_count = 0;
	memset(cached_lsr, 0x00, sizeof(cached_lsr));
	memset(cached_rbr, 0x00, sizeof(cached_rbr));
#endif
	return 0;
}
Esempio n. 10
0
void
_kernel_call_inirtn(void)
{
	macaddr_init( (VP_INT)(0) );
	application_init( (VP_INT)(0) );
	sdev_init( (VP_INT)(0) );
	stdfile_init( (VP_INT)(0) );
	rtc_init( (VP_INT)(0) );
	mci_init( (VP_INT)(0) );
	dma_init( (VP_INT)(0) );
	timer_initialize( (VP_INT)(0) );
	serial_initialize( (VP_INT)(0) );
}
Esempio n. 11
0
int main(void)
{
	//int Value = 0;
	
	DDRC  = 0x7F;
	PORTC = 0x7D;
	serial_initialize(57600);				// USART Initialize
	//serial_initialize(250000);				// USART Initialize
	dxl_initialize( 0, 7 ); // Not using device index
	sei();
	SetUpServos();
	SetConstants();
	SetKConstants();

	printf("ARMS CONTROL - Left \r" );
	printf("Ver1.0 - Last Moddification 23-03-15\r" );

	while (1)
	{
	
		
	if(cmdReady)
	{
		 if(!execCommand()) printf("Unknown command\r");
	}
	
	
	if(doLoop)
	{
		executeControl();
		count = count + 100;
	}
	
	if(doGripper)
	{
		executeGripper();
	}
		
		_delay_ms(3);
	

	Leds();

	}

	return 1;
}
Esempio n. 12
0
void Fable_init(){
		DDRA=0xFF;//PORTA is output

		//serial_initialize(9600);
		serial_initialize(57600);

		//serial_set_rx_callback(&serial_receive_data);
		//Init Timer
//		TCCR0A = (1<<COM0A1)|(1<<COM0A0);  //Set OC0A on Compare Match
//		TCCR0B = (1<<FOC0A)|(1<<CS01)|(1<<CS00); //Force Output Compare A and 64 prescaler
//		OCR0A = 125;	//1ms according to KAVRCalc (8Mhz, 1msm, 64 prescaler, 0.0% error)
//		TIMSK0 = 1<<OCIE0A; 	// Enable Timer 0 Output Compare A Match Event Interrupt

//		TCCR0A = (1<<WGM01);//Clear on compare |(1<<COM0A0);  //Set OC0A on Compare Match
//		TCCR0B = (1<<CS01)|(1<<CS00); //64 prescaler
//		OCR0A = 125;	//1ms -> 8M/2*64*1000
//		TIMSK0 = 1<<OCIE0A; 	// Enable Timer 0 Output Compare A Match Event Interrupt
		start_system_timer();
		accel_init();
		i2c_init(400);// init i2c 100 khz
		ext_uart_init();
		ir_init(EXT_UART_0);
		ir_init(EXT_UART_1);
		ir_init(EXT_UART_2);
		ir_init(EXT_UART_3);

		gyro_set_mode(GYRO_MODE_ON);

		sei();//enable interrupts
		ase_printf("fw initialized\n");
/*
		//ext_adc_init();//only on new board
		ext_uart_enable_int_rx(1,&ext_uart_receive);


		ir_init(EXT_UART_2);
		ir_init(EXT_UART_3);

		gyro_set_mode(GYRO_MODE_ON);// turn on gyroscope

		//dxl_initialize(0,207); //init dinamixel, baud= 57600 (to check)

		//printf("External UART %s\n",i2c_read_byte(0xd8,0x1c)==1?"OK":"NOT OK");//check communication works
*/
}
Esempio n. 13
0
int main(void)
{
	
	serial_initialize(57600);
	zigbee_initialize();
	sei();
	
	legsInit();
	
	
	while(1)
	{
		move(FRONT_LEFT,300,1,1);
		move(BACK_RIGHT,300,1,1);
	}

	return 0;
}
Esempio n. 14
0
int main(int argc, char* argv[]) {
    util::ParseInputArgs(argc, argv);

    pointVec_t      points;
    pointVec_t      hull;
    util::my_time_t tm_init, tm_start, tm_end;

    std::cout << "Starting serial version of QUICK HULL algorithm" << std::endl;

    tm_init = util::gettime();
    serial_initialize(points);
    tm_start = util::gettime();
    std::cout << "Init time: " << util::time_diff(tm_init, tm_start) << "  Points in input: " << points.size() << "\n";
    tm_start = util::gettime();
    quickhull(points, hull);
    tm_end = util::gettime();
    std::cout << "Serial time: " << util::time_diff(tm_start, tm_end) << "  Points in hull: " << hull.size() << "\n";
}
Esempio n. 15
0
int main(){
	//portInit();
	serial_initialize(57600);
	dxl_initialize( 0, 1 ); // init with baud = 1 Mbps
	ADCInit();
	sei(); //Enables global interrupts

	unsigned int distanceLeft, distanceRight, front, movingLeft, movingRight;
	signed int speedLeft, speedRight;
	while(1) {
		//printf("%d   %d\n\n",getSensorValue(3),getSensorValue(4));
		//_delay_ms(1000);

		// Get sensor reading (in cm)
		front = DMSDistance(getSensorValue(1));
		distanceLeft = IRValue(getSensorValue(3));
		distanceRight = IRValue(getSensorValue(4));

		// Calculating the required speed
		speedRight = (int)((front-40*distanceLeft));
		speedLeft = (int)((front-40*distanceRight));

		movingLeft = dxl_read_byte( 1, 38 );
		movingRight = dxl_read_byte(2,38);

		if(movingLeft < 15 && movingRight < 15){
			wheel(1,0);
			wheel(2,-20);
			_delay_ms(1000);
		}else{
			wheel(1,-speedRight);
			wheel(2,speedLeft);
		}


		printf("%d   %d  -  %d\n\n",speedLeft,speedRight,getSensorValue(1));
		//_delay_ms(1000);
		// Making the wheels spin


	}

	return 0;
}
Esempio n. 16
0
/*
 打开串口
 */
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
{
    int flags = 0;
    int ret = 0;

    serial_initialize(serial);

#ifndef URG_MAC_OS
    enum { O_EXLOCK = 0x0 }; /*  Not used in Linux, used as dummy */
#endif
	/* Linux系统打开一个设备,详细的可以看 UNIX高级环境编程 */
    serial->fd = open(device, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOCTTY);
    if (serial->fd < 0) {
        /*  设备打开失败 */
        //strerror_r(errno, serial->error_string, ERROR_MESSAGE_SIZE);
        return -1;
    }

    flags = fcntl(serial->fd, F_GETFL, 0);
    fcntl(serial->fd, F_SETFL, flags & ~O_NONBLOCK);

    /*  串口初始化部分  */
    tcgetattr(serial->fd, &serial->sio);
    serial->sio.c_iflag = 0;
    serial->sio.c_oflag = 0;
	/* 下面的大写字母表示的都是Linux系统的宏定义,没有必要全部搞懂,看一下了解一下 */
    serial->sio.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
    serial->sio.c_cflag |= CS8 | CREAD | CLOCAL;
    serial->sio.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);

    serial->sio.c_cc[VMIN] = 0;
    serial->sio.c_cc[VTIME] = 0;
	/* 串口设置波特率 */
    ret = serial_set_baudrate(serial, baudrate);
    if (ret < 0) {
        return ret;
    }

    /*  Initializes serial control structures */
    serial->has_last_ch = False;

    return 0;
}
Esempio n. 17
0
static void __init mv_init(void)
{
        /* init the Board environment */
       	mvBoardEnvInit();

        /* init the controller environment */
        if (mvCtrlEnvInit() ) {
            printk( "Controller env initialization failed.\n" );
            return;
        }


	/* Init the CPU windows setting and the access protection windows. */
	if (mvCpuIfInit(mv_sys_map())) {

		printk( "Cpu Interface initialization failed.\n" );
		return;
	}
#if defined (CONFIG_MV78XX0_Z0)
	mvCpuIfBridgeReorderWAInit();
#endif

    	/* Init Tclk & SysClk */
    	mvTclk = mvBoardTclkGet();
   	mvSysclk = mvBoardSysClkGet();
	
        support_wait_for_interrupt = 1;
  
#ifdef CONFIG_JTAG_DEBUG
            support_wait_for_interrupt = 0; /*  for Lauterbach */
#endif
	mv_vfp_init();	
	elf_hwcap &= ~HWCAP_JAVA;

   	serial_initialize();

	/* At this point, the CPU windows are configured according to default definitions in mvSysHwConfig.h */
	/* and cpuAddrWinMap table in mvCpuIf.c. Now it's time to change defaults for each platform.         */
	mvCpuIfAddrDecShow(whoAmI());

    	print_board_info();
}
Esempio n. 18
0
/* �ڑ� */
int serial_connect(serial_t *serial, const char *device, long baudrate)
{
  int flags = 0;
  int ret = 0;

  serial_initialize(serial);

#ifndef MAC_OS
  enum { O_EXLOCK = 0x0 }; /* Linux �ł͎g���Ȃ��̂Ń_�~�[���쐬���Ă��� */
#endif
  serial->fd_ = open(device, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOCTTY);
  if (serial->fd_ < 0) {
    /* �ڑ��Ɏ��s */
    strerror_r(errno, serial->error_string_, SerialErrorStringSize);
    return SerialConnectionFail;
  }

  flags = fcntl(serial->fd_, F_GETFL, 0);
  fcntl(serial->fd_, F_SETFL, flags & ~O_NONBLOCK);

  /* �V���A���ʐM�̏��� */
  tcgetattr(serial->fd_, &serial->sio_);
  serial->sio_.c_iflag = 0;
  serial->sio_.c_oflag = 0;
  serial->sio_.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
  serial->sio_.c_cflag |= CS8 | CREAD | CLOCAL;
  serial->sio_.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);

  serial->sio_.c_cc[VMIN] = 0;
  serial->sio_.c_cc[VTIME] = 0;

  /* �{�[���[�g�̕ύX */
  ret = serial_setBaudrate(serial, baudrate);
  if (ret < 0) {
    return ret;
  }

  /* �V���A������\���̂̏��� */
  serial->has_last_ch_ = False;

  return 0;
}
Esempio n. 19
0
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
{
    int flags = 0;
    int ret = 0;

    serial_initialize(serial);

#ifndef URG_MAC_OS
    enum { O_EXLOCK = 0x0 }; /*  Not used in Linux, used as dummy */
#endif
    serial->fd = open(device, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOCTTY);
    if (serial->fd < 0) {
        /*  Connection failed */
        //strerror_r(errno, serial->error_string, ERROR_MESSAGE_SIZE);
        return -1;
    }

    flags = fcntl(serial->fd, F_GETFL, 0);
    fcntl(serial->fd, F_SETFL, flags & ~O_NONBLOCK);

    /*  Initializes serial communication  */
    tcgetattr(serial->fd, &serial->sio);
    serial->sio.c_iflag = 0;
    serial->sio.c_oflag = 0;
    serial->sio.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
    serial->sio.c_cflag |= CS8 | CREAD | CLOCAL;
    serial->sio.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);

    serial->sio.c_cc[VMIN] = 0;
    serial->sio.c_cc[VTIME] = 0;

    ret = serial_set_baudrate(serial, baudrate);
    if (ret < 0) {
        return ret;
    }

    /*  Initializes serial control structures */
    serial->has_last_ch = False;

    return 0;
}
Esempio n. 20
0
int main(void)
{
	int Value = 0;

	serial_initialize(57600);				// USART Initialize
	sei();

	printf( "\n\nSerial Comm. example for CM-510\n\n" );

	while (1)
	{
		unsigned char ReceivedData = getchar();
		if(ReceivedData == 'u')
			Value++;
		else if(ReceivedData == 'd')
			Value--;

		printf("%d\r\n", Value);
	}
	return 1;
}
Esempio n. 21
0
void urg_initialize(urg_t *urg)
{
  serial_initialize(&urg->serial_);
  urg->errno_ = UrgNoError;
  urg->last_timestamp_ = 0;
}
Esempio n. 22
0
int main(void)
{
	int id[NUM_ACTUATOR];
	float phase[NUM_ACTUATOR];
	float theta = 0;
	int AmpPos = 512;
	//int AmpPos = 2048; // for EX series
	int GoalPos;
	int i;
	int CommStatus;

	serial_initialize(57600);
	dxl_initialize( 0, DEFAULT_BAUDNUM ); // Not using device index
	sei();	// Interrupt Enable	
	
	printf( "\n\nSyncWrite example for CM-700\n\n" );
		
	for( i=0; i<NUM_ACTUATOR; i++ )
	{
		id[i] = i+1;
		phase[i] = 2*PI * (float)i / (float)NUM_ACTUATOR;
	}
	
	// Set goal speed
	dxl_write_word( BROADCAST_ID, P_GOAL_SPEED_L, 0 );
	// Set goal position
	dxl_write_word( BROADCAST_ID, P_GOAL_POSITION_L, AmpPos );
	_delay_ms(1000);
	
	while(1)
	{
		// Make syncwrite packet
		dxl_set_txpacket_id(BROADCAST_ID);
		dxl_set_txpacket_instruction(INST_SYNC_WRITE);
		dxl_set_txpacket_parameter(0, P_GOAL_POSITION_L);
		dxl_set_txpacket_parameter(1, 2);
		for( i=0; i<NUM_ACTUATOR; i++ )
		{
			dxl_set_txpacket_parameter(2+3*i, id[i]);
			GoalPos = (int)((sin(theta+phase[i]) + 1.0) * (float)AmpPos);
			printf( "%d  ", GoalPos );
			dxl_set_txpacket_parameter(2+3*i+1, dxl_get_lowbyte(GoalPos));
			dxl_set_txpacket_parameter(2+3*i+2, dxl_get_highbyte(GoalPos));
		}
		dxl_set_txpacket_length((2+1)*NUM_ACTUATOR+4);
		
		printf( "\n" );
		
		dxl_txrx_packet();
		CommStatus = dxl_get_result();
		if( CommStatus == COMM_RXSUCCESS )
			PrintErrorCode();
		else
			PrintCommStatus(CommStatus);
			
		theta += STEP_THETA;

		if( theta > 2*PI )
			theta -= 2*PI;
		_delay_ms(CONTROL_PERIOD);
	}

	return 0;
}
Esempio n. 23
0
int main(void)
{
#if 0
	int id[NUM_ACTUATOR];
	float phase[NUM_ACTUATOR];
	float theta = 0;
	int AmpPos = 512;
	//int AmpPos = 2048; // for EX series
	int GoalPos;
	int i;
	int CommStatus;
	int isPress = 0;
	int isOn = 0;
	unsigned char ReceivedData;
	int Value;
	mServoList[0] = (stServo *)malloc(sizeof(stServo));
	memset((void *)mServoList[0], 0x00, sizeof(stServo) );
	mServoList[0]->id = 4;

	serial_initialize(57600);
	dxl_initialize( 0, DEFAULT_BAUDNUM ); // Not using device index
	sei();	// Interrupt Enable
	
	printf( "\n\nSyncWrite example for CM-700\n\n" );
	
#ifdef MODE_SYNC
	for( i=0; i<NUM_ACTUATOR; i++ )
	{
		id[i] = i+2;
		phase[i] = 2*PI * (float)i / (float)NUM_ACTUATOR;
	}
#else
	int wPresentPos = 512;
#endif	
	
	//Set EEP Lock
	dxl_write_word( BROADCAST_ID, P_EEP_LOCK, 1 );
	// Set goal speed
	dxl_write_word( BROADCAST_ID, P_GOAL_SPEED_L, 0 );
	// Set goal position
	dxl_write_word( BROADCAST_ID, P_GOAL_POSITION_L, AmpPos );
	dxl_write_word( 4, P_TORQUE_LIMIT_L, 0);
	_delay_ms(1000);
	
	while(1)
	{
		if(~PIND & SW_START){
			isPress = 1;
		}else{
 		    if( isPress == 1 ){
				if( isOn == 0 ){
					isOn = 1;
				}else{
					isOn = 0;
				}
			}
			isPress = 0;
		}
		
//		while( ReceivedData = getchar() != NULL ){
			if(ReceivedData == 'u')
			Value++;
			else if(ReceivedData == 'd')
			Value--;
			printf("%d, %d\r\n", Value, ReceivedData);
//		}
		
		if( isOn ){
#ifdef MODE_SYNC
		// Make syncwrite packet
		dxl_set_txpacket_id(BROADCAST_ID);
		dxl_set_txpacket_instruction(INST_SYNC_WRITE);
		dxl_set_txpacket_parameter(0, P_GOAL_POSITION_L);
		dxl_set_txpacket_parameter(1, 2);
		for( i=0; i<NUM_ACTUATOR; i++ )
		{
			dxl_set_txpacket_parameter(2+3*i, id[i]);
			GoalPos = (int)((sin(theta+phase[i]) + 1.0) * (float)AmpPos);
			printf( "%d  ", GoalPos );
			dxl_set_txpacket_parameter(2+3*i+1, dxl_get_lowbyte(GoalPos));
			dxl_set_txpacket_parameter(2+3*i+2, dxl_get_highbyte(GoalPos));
		}
		dxl_set_txpacket_length((2+1)*NUM_ACTUATOR+4);
		
		printf( "\n" );
		
		dxl_txrx_packet();
		CommStatus = dxl_get_result();
		if( CommStatus == COMM_RXSUCCESS )
		PrintErrorCode();
		else
		PrintCommStatus(CommStatus);
		
		theta += STEP_THETA;

		if( theta > 2*PI )
		theta -= 2*PI;
#else
	    wPresentPos = dxl_read_word( 4, P_PRESENT_POSITION_L );
        printf( "%d\n", wPresentPos );

		dxl_write_word( 2, P_GOAL_POSITION_L, wPresentPos );
		dxl_write_word( 3, P_GOAL_POSITION_L, wPresentPos );
		PrintErrorCode();
#endif
		}
		getServoStatus();
		_delay_ms(CONTROL_PERIOD);
	}
	return 0;
#endif

#if 0
	DDRC  = 0x7F;
	PORTC = 0x7E;
	
	DDRD  = 0x70;
	PORTD = 0x11;

	while (1)
	{
		if(~PIND & SW_START)
		PORTC = ~(LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY);
		else PORTC = LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY;
	}
	return 1;
#endif


	while(isFinish == 0){
		_delay_ms(500);
		getSerialData();
//		ReceivedData = getchar();

		//if(ReceivedData == 'u'){
			//printf("%d\r\n", Value);
			//Value++;
		//}else if(ReceivedData == 'd'){
			//printf("%d\r\n", Value);
			//Value--;
		//}else if(ReceivedData == 10 || ReceivedData == 13 ){
			//printf("%s\r\n", "end");
			//break;
		//}
		printf("%s\r\n", "Loop");
	}

	printf("%s\r\n", "finish");

	return 0;
}
Esempio n. 24
0
void board_init_r(gd_t *id, ulong dest_addr)
{
	ulong malloc_start;
#if !defined(CONFIG_SYS_NO_FLASH)
	ulong flash_size;
#endif

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");

	monitor_flash_len = (ulong)&__rel_dyn_end - (ulong)_start;

	/* Enable caches */
	enable_caches();

	debug("monitor flash len: %08lX\n", monitor_flash_len);
	board_init();	/* Setup chipselects */
	/*
	 * TODO: printing of the clock inforamtion of the board is now
	 * implemented as part of bdinfo command. Currently only support for
	 * davinci SOC's is added. Remove this check once all the board
	 * implement this.
	 */
#ifdef CONFIG_CLOCKS
	set_cpu_clk_info(); /* Setup clock information */
#endif
	serial_initialize();

	debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);

#ifdef CONFIG_LOGBUFFER
	logbuff_init_ptrs();
#endif
#ifdef CONFIG_POST
	post_output_backlog();
#endif

	/* The Malloc area is immediately below the monitor copy in DRAM */
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);

#ifdef CONFIG_ARCH_EARLY_INIT_R
	arch_early_init_r();
#endif
	power_init_board();

#if !defined(CONFIG_SYS_NO_FLASH)
	puts("Flash: ");

	flash_size = flash_init();
	if (flash_size > 0) {
# ifdef CONFIG_SYS_FLASH_CHECKSUM
		print_size(flash_size, "");
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
		if (getenv_yesno("flashchecksum") == 1) {
			printf("  CRC: %08X", crc32(0,
				(const unsigned char *) CONFIG_SYS_FLASH_BASE,
				flash_size));
		}
		putc('\n');
# else	/* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size(flash_size, "\n");
# endif /* CONFIG_SYS_FLASH_CHECKSUM */
	} else {
		puts(failed);
		hang();
	}
#endif

#if defined(CONFIG_CMD_NAND)
	puts("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_GENERIC_MMC
	puts("MMC:   ");
	mmc_initialize(gd->bd);
#endif

#ifdef CONFIG_CMD_SCSI
	puts("SCSI:  ");
	scsi_init();
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	if (should_load_env())
		env_relocate();
	else
		set_default_env(NULL);

#if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
	arm_pci_init();
#endif

	stdio_init();	/* get the devices list going. */

	jumptable_init();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init();
#endif

	console_init_r();	/* fully init console as a device */

#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
# ifdef CONFIG_OF_CONTROL
	/* Put this here so it appears on the LCD, now it is ready */
	display_fdt_model(gd->fdt_blob);
# else
	checkboard();
# endif
#endif

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

	 /* set up exceptions */
	interrupt_init();
	/* enable exceptions */
	enable_interrupts();

	/* Initialize from environment */
	load_addr = getenv_ulong("loadaddr", 16, load_addr);

#ifdef CONFIG_BOARD_LATE_INIT
	board_late_init();
#endif

#ifdef CONFIG_FASTBOOT
	fastboot_setup();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
	puts("Net:   ");
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif

#ifdef CONFIG_POST
	post_run(NULL, POST_RAM | post_bootmode_get(0));
#endif

#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
		ulong pram = 0;
		uchar memsz[32];

#ifdef CONFIG_PRAM
		pram = getenv_ulong("pram", 10, CONFIG_PRAM);
#endif
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
		/* Also take the logbuffer into account (pram is in kB) */
		pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
#endif
#endif
		sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram);
		setenv("mem", (char *)memsz);
	}
#endif

#ifdef CONFIG_FASTBOOT
	check_fastboot();
#endif

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
Esempio n. 25
0
static int initr_serial(void)
{
	serial_initialize();
	return 0;
}
Esempio n. 26
0
/* Symbol for common u-boot code to call. */
int serial_init(void)
{
	serial_initialize();
	serial_setbrg();
	return 0;
}
Esempio n. 27
0
void start_armboot (void)
{
	init_fnc_t **init_fnc_ptr;
	char *s;
	int mmc_exist = 0;
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
	unsigned long addr;
#endif

	/* Pointer is writable since we allocated a register for it */
	gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("": : :"memory");

	memset ((void*)gd, 0, sizeof (gd_t));
	gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
	memset (gd->bd, 0, sizeof (bd_t));

//	gd->flags |= GD_FLG_RELOC;

	monitor_flash_len = _bss_start - _armboot_start;

	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

	/* armboot_start is defined in the board-specific linker script */
	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
			CONFIG_SYS_MALLOC_LEN);

#ifndef CONFIG_SYS_NO_FLASH
	/* configure available FLASH banks */
	display_flash_config (flash_init ());
#endif /* CONFIG_SYS_NO_FLASH */

#ifdef CONFIG_VFD
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
	/*
	 * reserve memory for VFD display (always full pages)
	 */
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
	vfd_setmem (addr);
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

#ifdef CONFIG_LCD
	/* board init may have inited fb_base */
	if (!gd->fb_base) {
#		ifndef PAGE_SIZE
#		  define PAGE_SIZE 4096
#		endif
		/*
		 * reserve memory for LCD display (always full pages)
		 */
		/* bss_end is defined in the board-specific linker script */
		addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
		lcd_setmem (addr);
		gd->fb_base = addr;
	}
#endif /* CONFIG_LCD */

#if defined(CONFIG_CMD_NAND)
	puts ("NAND:	");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_GENERIC_MMC
	puts ("MMC:   ");
	mmc_exist = mmc_initialize (gd->bd);
	if (mmc_exist != 0)
	{
		puts ("0 MB\n");
	}

#endif


#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	env_relocate ();

#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
#endif /* CONFIG_VFD */

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

	stdio_init ();	/* get the devices list going. */

	jumptable_init ();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init ();
#endif

	console_init_r ();	/* fully init console as a device */

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init ();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r ();
#endif

	/* enable exceptions */
	enable_interrupts ();

	/* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_TI_EMAC
	/* XXX: this needs to be moved to board init */
extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
	if (getenv ("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		davinci_eth_set_mac_addr(enetaddr);
	}
#endif

#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
	/* XXX: this needs to be moved to board init */
	if (getenv ("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
	}
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

	/* Initialize from environment */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
#if defined(CONFIG_CMD_NET)
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
#endif

#ifdef BOARD_LATE_INIT
	board_late_init ();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts ("Net:   ");
#endif
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif
	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop ();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
Esempio n. 28
0
int main(int argc, char **argv)
{
	int robot_state = FORWARD;
	int last_robot_state = FORWARD;
	int front_infrared_value = 0;
	int back_infrared_value = 0;
	int front_infrared_num = 0;
	int back_infrared_num = 0;
	int front_infrared_amount = 0;
	int back_infrared_amount = 0;
	int front_infrared_weight = 0;
	int back_infrared_weight = 0;
	uint32_t car_distence = 0;
	uint8_t get_char = 0;
	int change_num = 0;
	bool_t switch_state = 0;
	int detect_num = 0;
	int angle = 0;

	/* 模块初始化 */
	exc_init(); /* 中断初始化 */
	sys_timer_init(); /* 系统时钟初始化 */
	light_init(); /* 灯初始化 */
	switch_init(); /* 开关初始化 */
	serial_initialize((intptr_t) (NULL)); /* 初始化串口 */
	motor_init(); /* 电机初始化 */
	steer_init(); /* 舵机初始化 */
	decoder_init((intptr_t) (NULL)); /* 编码器初始化 */
	infrared_init(); /* 红外初始化 */

	while(1)
	{
		light_open(LIGHT2);
		light_open(LIGHT3);
	}
//    gpio_init(PORT_NO_GET(PTC0), PIN_NO_GET(PTC0), OUT_PUT, 0);
//    gpio_init(PORT_NO_GET(PTC2), PIN_NO_GET(PTC2),OUT_PUT, 1);
//    while(1)
//    {
//    	motor_output(MOTOR_LEFT, 50);
//    	motor_output(MOTOR_RIGHT, 50);
//    }

	while((get_char != 's') && (switch_state != SWITCH_ON))
	{
		 light_open_some(0x0f);
		 get_char = serial_get_char(UART_NO_GET(UART_NO));
		 switch_state = switch_read(SWITCH0);
	}

	while (1)
	{
		get_char = serial_get_char(UART_NO_GET(UART_NO));
		if(get_char == 'p')
		{
			last_robot_state = robot_state;
			robot_state = STOP;
		}

		/* 读取光电管的数据 */
		front_infrared_value = infrared_read_loc(INFRARED_FRONT);
		back_infrared_value = infrared_read_loc(INFRARED_BACK);

		/* 读取红外从右第一个亮灯的位置 */
		front_infrared_num = infrared_read_num(front_infrared_value);
		back_infrared_num = infrared_read_num(back_infrared_value);

		/* 读取传感器亮灯的总数 */
		front_infrared_amount = infrared_read_amount(front_infrared_value);
		back_infrared_amount = infrared_read_amount(back_infrared_value);

		/* 读取权值 */
		front_infrared_weight = infrared_read_weight(front_infrared_value);
		back_infrared_weight = infrared_read_weight(back_infrared_value);

		switch (robot_state)
		{
/**********************************前进*************************************/
		case FORWARD:
			light_open_some(0x01);
			light_bar_open(LIGHT_BAR0);
			light_bar_close(LIGHT_BAR1);
			if (front_infrared_amount == 1)
			{
				if (front_infrared_weight == 3)
				{
					angle = 40;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -3)
				{
					angle = -40;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 2)
				{
					angle = 20;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -2)
				{
					angle = -20;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 1)
				{
					angle = 5;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -1)
				{
					angle = -5;
					//motor_output2(13, 13);
				}
			}
			else if (front_infrared_amount == 2)
			{
				if (front_infrared_weight == 5)
				{
					angle = 30;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -5)
				{
					angle = -30;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 3)
				{
					angle = 10;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -3)
				{
					angle = -10;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 0)
				{
					angle = 0;
					//motor_output2(13, 13);
				}
			}
			steer_output_angle(STEER_DIR, angle);
			speed_control_forward(30,angle);

			if (front_infrared_amount > 4)
			{
				if(change_num == 4)
				{
					robot_state = STOP;
				}

				detect_num ++;
				if(detect_num > 2)
				{
					detect_num = 0;
					robot_state = FORWARD_CHANGE;
					car_distence = gl_distanceTotal;
				}
			}
			else
			{
				detect_num = 0;
			}
			break;

/**********************************前进转换1*************************************/
		case FORWARD_CHANGE:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x02);
			steer_output_angle(STEER_DIR, 40);
			//motor_output2(-25, -10);
			speed_control_backward(30,angle);

            if((gl_distanceTotal - car_distence)>9)
            {
            	robot_state = FORWARD_CHANGE2;
            }
		    break;

/**********************************前进转换2*************************************/
		case FORWARD_CHANGE2:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x02);
			steer_output_angle(STEER_DIR, 40);
			//motor_output2(-25, -10);
			speed_control_backward(30,angle);
			if((back_infrared_value & 0x30) && (!(back_infrared_value & 0x03)) && (front_infrared_amount < 3))
			{
				robot_state = BACKWARD;
				car_distence = gl_distanceTotal;
				change_num ++;
			}
			break;

/************************************后退****************************************/
		case BACKWARD:
			light_bar_open(LIGHT_BAR1);
			light_bar_close(LIGHT_BAR0);
			light_open_some(0x04);
			if (back_infrared_amount == 1)
			{
				if (back_infrared_weight == 3)
				{
					angle = -40;
					//motor_output2(-5, -22);
				}
				else if (back_infrared_weight == -3)
				{
					angle = 40;
					//motor_output2(-22, -5);
				}
				else if (back_infrared_weight == 2)
				{
					angle = -40;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -2)
				{
					angle = 40;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 1)
				{
					angle = -5;
					//motor_output2(-14, -14);
				}
				else if (back_infrared_weight == -1)
				{
					angle = 5;
					//motor_output2(-14, -14);
				}
			}
			else if (back_infrared_amount == 2)
			{
				if (back_infrared_weight == 5)
				{
					angle = -40;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -5)
				{
					angle = 40;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 3)
				{
					angle = -20;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -3)
				{
					angle = 20;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 0)
				{
					angle = 0;
					//motor_output2(-14, -14);
				}
			}
			steer_output_angle(STEER_DIR, angle);
			speed_control_backward(30,angle);

			if(back_infrared_amount > 4)
			{
				detect_num ++;
				if(detect_num > 2)
				{
					detect_num = 0;
					robot_state = BACKWARD_CHANGE;
					car_distence = gl_distanceTotal;
				}
			}
			else
			{
				detect_num  = 0;
			}
			break;

/************************************后退转换1****************************************/
		case BACKWARD_CHANGE:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x8);
			steer_output_angle(STEER_DIR, -35);
			speed_control_forward(30,angle);
            if((gl_distanceTotal - car_distence)>7)
            {
            	robot_state = BACKWARD_CHANGE2;
            }
		    break;

/************************************后退转换2****************************************/
		case BACKWARD_CHANGE2:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x8);
			steer_output_angle(STEER_DIR, -35);
			speed_control_forward(30,angle);
			if((front_infrared_value & 0x38) && (!(front_infrared_value & 0x03)) && (back_infrared_amount < 3))
			{
				robot_state = FORWARD;
				change_num ++;
			}
			break;

/************************************停车****************************************/
		case STOP:
			light_open_some(0x03);
			light_bar_close(LIGHT_BAR0);
			light_bar_close(LIGHT_BAR1);
			motor_output2(0, 0);
			steer_output_angle(STEER_DIR, 0);
			if(get_char == 's')
			{
				robot_state = last_robot_state;
			}
			break;
		}
	}
}
Esempio n. 29
0
void board_init_r(gd_t *id, ulong dest_addr)
{
	char *s;
	bd_t *bd;
	ulong malloc_start;
#if !defined(CONFIG_SYS_NO_FLASH)
	ulong flash_size;
#endif

	gd = id;
	bd = gd->bd;

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */

	monitor_flash_len = _end_ofs;
	/*
	 * Enable D$:
	 * I$, if needed, must be already enabled in start.S
	 */
	dcache_enable();

	debug("monitor flash len: %08lX\n", monitor_flash_len);
	board_init();	/* Setup chipselects */

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

	debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);

#ifdef CONFIG_LOGBUFFER
	logbuff_init_ptrs();
#endif
#ifdef CONFIG_POST
	post_output_backlog();
#endif

	/* The Malloc area is immediately below the monitor copy in DRAM */
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);

#if !defined(CONFIG_SYS_NO_FLASH)
	puts("Flash: ");

	flash_size = flash_init();
	if (flash_size > 0) {
# ifdef CONFIG_SYS_FLASH_CHECKSUM
		print_size(flash_size, "");
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
		s = getenv("flashchecksum");
		if (s && (*s == 'y')) {
			printf("  CRC: %08X", crc32(0,
				(const unsigned char *) CONFIG_SYS_FLASH_BASE,
				flash_size));
		}
		putc('\n');
# else	/* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size(flash_size, "\n");
# endif /* CONFIG_SYS_FLASH_CHECKSUM */
	} else {
		puts(failed);
		hang();
	}
#endif

#if defined(CONFIG_CMD_NAND)
	puts("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_GENERIC_MMC
       puts("MMC:   ");
       mmc_initialize(bd);
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	env_relocate();

#if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
	arm_pci_init();
#endif

	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");

	stdio_init();	/* get the devices list going. */

	jumptable_init();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init();
#endif

	console_init_r();	/* fully init console as a device */

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

	 /* set up exceptions */
	interrupt_init();
	/* enable exceptions */
	enable_interrupts();

	/* Perform network card initialisation if necessary */
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
	/* XXX: this needs to be moved to board init */
	if (getenv("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
	}
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

	/* Initialize from environment */
	s = getenv("loadaddr");
	if (s != NULL)
		load_addr = simple_strtoul(s, NULL, 16);
#if defined(CONFIG_CMD_NET)
	s = getenv("bootfile");
	if (s != NULL)
		copy_filename(BootFile, s, sizeof(BootFile));
#endif

#ifdef BOARD_LATE_INIT
	board_late_init();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts("Net:   ");
#endif
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif

#ifdef CONFIG_POST
	post_run(NULL, POST_RAM | post_bootmode_get(0));
#endif

#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
		ulong pram;
		uchar memsz[32];
#ifdef CONFIG_PRAM
		char *s;

		s = getenv("pram");
		if (s != NULL)
			pram = simple_strtoul(s, NULL, 10);
		else
			pram = CONFIG_PRAM;
#else
		pram = 0;
#endif
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
		/* Also take the logbuffer into account (pram is in kB) */
		pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
#endif
#endif
		sprintf((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
		setenv("mem", (char *)memsz);
	}
#endif

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
Esempio n. 30
0
/*
 * This is the next part if the initialization sequence: we are now
 * running from RAM and have a "normal" C environment, i. e. global
 * data can be written, BSS has been cleared, the stack size in not
 * that critical any more, etc.
 */
void board_init_r(gd_t *id, ulong dest_addr)
{
	bd_t *bd;
	ulong malloc_start;

#ifndef CONFIG_SYS_NO_FLASH
	ulong flash_size;
#endif

	gd = id;		/* initialize RAM version of global data */
	bd = gd->bd;

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */

	/* The Malloc area is immediately below the monitor copy in DRAM */
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;

#if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
	/*
	 * The gd->arch.cpu pointer is set to an address in flash before
	 * relocation.  We need to update it to point to the same CPU entry
	 * in RAM.
	 */
	gd->arch.cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;

	/*
	 * If we didn't know the cpu mask & # cores, we can save them of
	 * now rather than 'computing' them constantly
	 */
	fixup_cpu();
#endif

#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
	/*
	 * Some systems need to relocate the env_addr pointer early because the
	 * location it points to will get invalidated before env_relocate is
	 * called.  One example is on systems that might use a L2 or L3 cache
	 * in SRAM mode and initialize that cache from SRAM mode back to being
	 * a cache in cpu_init_r.
	 */
	gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
#endif

	serial_initialize();

	debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);

	WATCHDOG_RESET();

	/*
	 * Setup trap handlers
	 */
	trap_init(dest_addr);

#ifdef CONFIG_ADDR_MAP
	init_addr_map();
#endif

#if defined(CONFIG_BOARD_EARLY_INIT_R)
	board_early_init_r();
#endif

	monitor_flash_len = (ulong)&__init_end - dest_addr;

	WATCHDOG_RESET();

#ifdef CONFIG_LOGBUFFER
	logbuff_init_ptrs();
#endif
#ifdef CONFIG_POST
	post_output_backlog();
#endif

	WATCHDOG_RESET();

#if defined(CONFIG_SYS_DELAYED_ICACHE)
	icache_enable();	/* it's time to enable the instruction cache */
#endif

#if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
	unlock_ram_in_cache();	/* it's time to unlock D-cache in e500 */
#endif

#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
	/*
	 * Do early PCI configuration _before_ the flash gets initialised,
	 * because PCU ressources are crucial for flash access on some boards.
	 */
	pci_init();
#endif
#if defined(CONFIG_WINBOND_83C553)
	/*
	 * Initialise the ISA bridge
	 */
	initialise_w83c553f();
#endif

	asm("sync ; isync");

	mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);

#if !defined(CONFIG_SYS_NO_FLASH)
	puts("Flash: ");

	if (board_flash_wp_on()) {
		printf("Uninitialized - Write Protect On\n");
		/* Since WP is on, we can't find real size.  Set to 0 */
		flash_size = 0;
	} else if ((flash_size = flash_init()) > 0) {
#ifdef CONFIG_SYS_FLASH_CHECKSUM
		print_size(flash_size, "");
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
		if (getenv_yesno("flashchecksum") == 1) {
			printf("  CRC: %08X",
			       crc32(0,
				     (const unsigned char *)
				     CONFIG_SYS_FLASH_BASE, flash_size)
				);
		}
		putc('\n');
#else  /* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size(flash_size, "\n");
#endif /* CONFIG_SYS_FLASH_CHECKSUM */
	} else {
		puts(failed);
		hang();
	}

	/* update start of FLASH memory    */
	bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
	/* size of FLASH memory (final value) */
	bd->bi_flashsize = flash_size;

#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
	/* Make a update of the Memctrl. */
	update_flash_size(flash_size);
#endif


#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
	/* flash mapped at end of memory map */
	bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
	bd->bi_flashoffset = monitor_flash_len;	/* reserved area for monitor */
#endif
#endif /* !CONFIG_SYS_NO_FLASH */

	WATCHDOG_RESET();

	/* initialize higher level parts of CPU like time base and timers */
	cpu_init_r();

	WATCHDOG_RESET();

#ifdef CONFIG_SPI
#if !defined(CONFIG_ENV_IS_IN_EEPROM)
	spi_init_f();
#endif
	spi_init_r();
#endif

#if defined(CONFIG_CMD_NAND)
	WATCHDOG_RESET();
	puts("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#ifdef CONFIG_GENERIC_MMC
/*
 * MMC initialization is called before relocating env.
 * Thus It is required that operations like pin multiplexer
 * be put in board_init.
 */
	WATCHDOG_RESET();
	puts("MMC:  ");
	mmc_initialize(bd);
#endif

	/* relocate environment function pointers etc. */
	env_relocate();

	/*
	 * after non-volatile devices & environment is setup and cpu code have
	 * another round to deal with any initialization that might require
	 * full access to the environment or loading of some image (firmware)
	 * from a non-volatile device
	 */
	cpu_secondary_init_r();

	/*
	 * Fill in missing fields of bd_info.
	 * We do this here, where we have "normal" access to the
	 * environment; we used to do this still running from ROM,
	 * where had to use getenv_f(), which can be pretty slow when
	 * the environment is in EEPROM.
	 */

#if defined(CONFIG_SYS_EXTBDINFO)
#if defined(CONFIG_405GP) || defined(CONFIG_405EP)
#if defined(CONFIG_I2CFAST)
	/*
	 * set bi_iic_fast for linux taking environment variable
	 * "i2cfast" into account
	 */
	{
		if (getenv_yesno("i2cfast") == 1) {
			bd->bi_iic_fast[0] = 1;
			bd->bi_iic_fast[1] = 1;
		}
	}
#endif /* CONFIG_I2CFAST */
#endif /* CONFIG_405GP, CONFIG_405EP */
#endif /* CONFIG_SYS_EXTBDINFO */

#if defined(CONFIG_SC3)
	sc3_read_eeprom();
#endif

#if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
	mac_read_from_eeprom();
#endif

#ifdef CONFIG_CMD_NET
	/* kept around for legacy kernels only ... ignore the next section */
	eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr);
#ifdef CONFIG_HAS_ETH1
	eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr);
#endif
#ifdef CONFIG_HAS_ETH2
	eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr);
#endif
#ifdef CONFIG_HAS_ETH3
	eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr);
#endif
#ifdef CONFIG_HAS_ETH4
	eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr);
#endif
#ifdef CONFIG_HAS_ETH5
	eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr);
#endif
#endif /* CONFIG_CMD_NET */

	WATCHDOG_RESET();

#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
	/*
	 * Do pci configuration
	 */
	pci_init();
#endif

/** leave this here (after malloc(), environment and PCI are working) **/
	/* Initialize stdio devices */
	stdio_init();

	/* Initialize the jump table for applications */
	jumptable_init();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init();
#endif

	/* Initialize the console (after the relocation and devices init) */
	console_init_r();

#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

#if defined(CONFIG_CMD_KGDB)
	WATCHDOG_RESET();
	puts("KGDB:  ");
	kgdb_init();
#endif

	debug("U-Boot relocated to %08lx\n", dest_addr);

	/*
	 * Enable Interrupts
	 */
	interrupt_init();

#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
#endif

	udelay(20);

	/* Initialize from environment */
	load_addr = getenv_ulong("loadaddr", 16, load_addr);

	WATCHDOG_RESET();

#if defined(CONFIG_CMD_SCSI)
	WATCHDOG_RESET();
	puts("SCSI:  ");
	scsi_init();
#endif

#if defined(CONFIG_CMD_DOC)
	WATCHDOG_RESET();
	puts("DOC:   ");
	doc_init();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
	WATCHDOG_RESET();
	puts("Net:   ");
	eth_initialize(bd);
#endif

#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
	WATCHDOG_RESET();
	debug("Reset Ethernet PHY\n");
	reset_phy();
#endif

#ifdef CONFIG_POST
	post_run(NULL, POST_RAM | post_bootmode_get(0));
#endif

#if defined(CONFIG_CMD_PCMCIA) \
    && !defined(CONFIG_CMD_IDE)
	WATCHDOG_RESET();
	puts("PCMCIA:");
	pcmcia_init();
#endif

#if defined(CONFIG_CMD_IDE)
	WATCHDOG_RESET();
#ifdef	CONFIG_IDE_8xx_PCCARD
	puts("PCMCIA:");
#else
	puts("IDE:   ");
#endif
#if defined(CONFIG_START_IDE)
	if (board_start_ide())
		ide_init();
#else
	ide_init();
#endif
#endif

#ifdef CONFIG_LAST_STAGE_INIT
	WATCHDOG_RESET();
	/*
	 * Some parts can be only initialized if all others (like
	 * Interrupts) are up and running (i.e. the PC-style ISA
	 * keyboard).
	 */
	last_stage_init();
#endif

#if defined(CONFIG_CMD_BEDBUG)
	WATCHDOG_RESET();
	bedbug_init();
#endif

#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
		ulong pram = 0;
		char memsz[32];

#ifdef CONFIG_PRAM
		pram = getenv_ulong("pram", 10, CONFIG_PRAM);
#endif
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
		/* Also take the logbuffer into account (pram is in kB) */
		pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
#endif
#endif
		sprintf(memsz, "%ldk", (ulong) (bd->bi_memsize / 1024) - pram);
		setenv("mem", memsz);
	}
#endif

#ifdef CONFIG_PS2KBD
	puts("PS/2:  ");
	kbd_init();
#endif

	/* Initialization complete - start the monitor */

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		WATCHDOG_RESET();
		main_loop();
	}

	/* NOTREACHED - no way out of command loop except booting */
}