int main()
{
	rcc_clock_enable();
	delay_config();
	uart4_init(115200);
//	print_clock_freq();
	
	STM_EVAL_LEDInit(LED3);
	STM_EVAL_LEDInit(LED4);
	STM_EVAL_LEDInit(LED5);
	STM_EVAL_LEDInit(LED6);
//	NRF24L01_Init(NRF_TX_MODE);
//	micros_time_init();
	capture_config();
	
	while(1){
//		NRF24L01_TxPacket(nrf_tx_buffer);
//		STM_EVAL_LEDToggle(LED3);
//		delay_ms(250);
		printf("hello world");
		delay_ms(100);
		STM_EVAL_LEDOff(LED3);
		STM_EVAL_LEDOff(LED4);
		STM_EVAL_LEDOff(LED4);
		STM_EVAL_LEDOff(LED5);
		STM_EVAL_LEDOff(LED6);
	}
}
void uart_init(u32 bound)
{
	uart4_init(bound);
	uart5_init(bound);
}  
/*!
 * Board specific initialization.
 */
static void __init mx6_evk_init(void)
{
	u32 i;

	mxc_iomux_v3_setup_multiple_pads(mx6sl_brd_pads,
					ARRAY_SIZE(mx6sl_brd_pads));

	elan_ts_init();

	gp_reg_id = mx6sl_evk_dvfscore_data.reg_id;
	soc_reg_id = mx6sl_evk_dvfscore_data.soc_id;

	imx6q_add_imx_snvs_rtc();

	imx6q_add_imx_i2c(0, &mx6_evk_i2c0_data);
	imx6q_add_imx_i2c(1, &mx6_evk_i2c1_data);
	i2c_register_board_info(0, mxc_i2c0_board_info,
			ARRAY_SIZE(mxc_i2c0_board_info));

	/*  setting sii902x address when hdmi enabled */
	if (hdmi_enabled) {
		for (i = 0; i < ARRAY_SIZE(mxc_i2c1_board_info); i++) {
			if (!strcmp(mxc_i2c1_board_info[i].type, "sii902x")) {
				mxc_i2c1_board_info[i].addr = 0x39;
				break;
			}
		}
	}

	i2c_register_board_info(1, mxc_i2c1_board_info,
			ARRAY_SIZE(mxc_i2c1_board_info));
	/* only camera on I2C3, that's why we can do so */
	if (csi_enabled == 1) {
		mxc_register_device(&csi_v4l2_devices, NULL);
		imx6q_add_imx_i2c(2, &mx6_evk_i2c2_data);
		i2c_register_board_info(2, mxc_i2c2_board_info,
				ARRAY_SIZE(mxc_i2c2_board_info));
	}

	/* SPI */
	imx6q_add_ecspi(0, &mx6_evk_spi_data);
	spi_device_init();

	mx6sl_evk_init_pfuze100(0);

	imx6q_add_anatop_thermal_imx(1, &mx6sl_anatop_thermal_data);

	mx6_evk_init_uart();
	/* get enet tx reference clk from FEC_REF_CLK pad.
	 * GPR1[14] = 0, GPR1[18:17] = 00
	 */
	mxc_iomux_set_gpr_register(1, 14, 1, 0);
	mxc_iomux_set_gpr_register(1, 17, 2, 0);

	imx6_init_fec(fec_data);

	platform_device_register(&evk_vmmc_reg_devices);
	imx6q_add_sdhci_usdhc_imx(1, &mx6_evk_sd2_data);
	imx6q_add_sdhci_usdhc_imx(0, &mx6_evk_sd1_data);
	imx6q_add_sdhci_usdhc_imx(2, &mx6_evk_sd3_data);

	mx6_evk_init_usb();
	imx6q_add_otp();
	imx6q_add_mxc_pwm(0);
	imx6q_add_mxc_pwm_backlight(0, &mx6_evk_pwm_backlight_data);

	if (hdmi_enabled) {
		imx6dl_add_imx_elcdif(&hdmi_fb_data[0]);
	} else {
		imx6dl_add_imx_elcdif(&wvga_fb_data[0]);

		gpio_request(MX6_BRD_LCD_PWR_EN, "elcdif-power-on");
		gpio_direction_output(MX6_BRD_LCD_PWR_EN, 1);
		mxc_register_device(&lcd_wvga_device, NULL);
	}

	imx6dl_add_imx_pxp();
	imx6dl_add_imx_pxp_client();
	mxc_register_device(&max17135_sensor_device, NULL);
	setup_spdc();
	if (csi_enabled) {
		imx6sl_add_fsl_csi();
	} else  {
		if (!spdc_sel)
			imx6dl_add_imx_epdc(&epdc_data);
		else
			imx6sl_add_imx_spdc(&spdc_data);
	}
	imx6q_add_dvfs_core(&mx6sl_evk_dvfscore_data);

	imx6q_init_audio();

	/* uart2 for bluetooth */
#ifdef SXSDMAN_BLUETOOTH_ENABLE
	if (uart4_enabled)
		uart4_init();
#else
	if (uart2_enabled)
		uart2_init();
#endif

	mxc_register_device(&mxc_bt_rfkill, &mxc_bt_rfkill_data);

	imx6q_add_viim();
	imx6q_add_imx2_wdt(0, NULL);

	imx_add_viv_gpu(&imx6_gpu_data, &imx6q_gpu_pdata);
	imx6sl_add_imx_keypad(&mx6sl_evk_map_data);
	imx6q_add_busfreq();
	imx6sl_add_dcp();
	imx6sl_add_rngb();
	imx6sl_add_imx_pxp_v4l2();

	mxc_spdif_data.spdif_core_clk = clk_get_sys("mxc_spdif.0", NULL);
	clk_put(mxc_spdif_data.spdif_core_clk);
	imx6q_add_spdif(&mxc_spdif_data);
	imx6q_add_spdif_dai();
	imx6q_add_spdif_audio_device();

	imx6q_add_perfmon(0);
	imx6q_add_perfmon(1);
	imx6q_add_perfmon(2);
	/* Register charger chips */
	platform_device_register(&evk_max8903_charger_1);
	pm_power_off = mx6_snvs_poweroff;
	imx6q_add_pm_imx(0, &mx6sl_evk_pm_data);

	if (imx_ion_data.heaps[0].size)
		platform_device_register_resndata(NULL, "ion-mxc", 0, NULL, 0, \
		&imx_ion_data, sizeof(imx_ion_data) + sizeof(struct ion_platform_heap));

}
示例#4
0
文件: mcu.c 项目: WenFly123/openPPZ
void mcu_init(void) 
{

  mcu_arch_init();

#ifdef PERIPHERALS_AUTO_INIT
  sys_time_init();
#ifdef USE_LED
  led_init();
#endif
  /* for now this means using spektrum */
#if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC
  RADIO_CONTROL_BIND_IMPL_FUNC();
#endif
#ifdef USE_UART0
  uart0_init();
#endif
#ifdef USE_UART1
  uart1_init();
#endif
#ifdef USE_UART2
  uart2_init();
#endif
#ifdef USE_UART3
  uart3_init();
#endif
#ifdef USE_UART4
  uart4_init();
#endif
#ifdef USE_UART5
  uart5_init();
#endif
#ifdef USE_I2C0
  i2c0_init();
#endif
#ifdef USE_I2C1
  i2c1_init();
#endif
#ifdef USE_I2C2
  i2c2_init();
#endif
#ifdef USE_ADC
  adc_init();
#endif
#ifdef USE_USB_SERIAL
  VCOM_init();
#endif

#if USE_SPI
#if SPI_MASTER

#if USE_SPI0
  spi0_init();
#endif
#if USE_SPI1
  spi1_init();
#endif
#if USE_SPI2
  spi2_init();
#endif
#if USE_SPI3
  spi3_init();
#endif
  spi_init_slaves();
#endif // SPI_MASTER

#if SPI_SLAVE
#if USE_SPI0_SLAVE
  spi0_slave_init();
#endif
#if USE_SPI1_SLAVE
  spi1_slave_init();
#endif
#if USE_SPI2_SLAVE
  spi2_slave_init();
#endif
#if USE_SPI3_SLAVE
  spi3_slave_init();
#endif
#endif // SPI_SLAVE
#endif // USE_SPI

#ifdef USE_DAC
  dac_init();
#endif
#else
INFO("PERIPHERALS_AUTO_INIT not enabled! Peripherals (including sys_time) need explicit initialization.")
#endif /* PERIPHERALS_AUTO_INIT */

}
示例#5
0
int main(void)
{		

	u16 times=0,i=0; 

	NORMALTIME cur_time; //设置RTC的时间用
	
	//Flash_Write(0x08041000,(u8 *)IndCalib,sizeof(IndCalib));

	Flash_Read(0x08041000,(u8 *)IndCalib,sizeof(IndCalib));



	delay_init();	    	 //延时函数初始化	  
  	NVIC_Configuration(); 	 //设置NVIC中断分组2:2位抢占优先级,2位响应优先级

	uart1_init(115200);	 //上位机通信模块
	uart2_init(9600);	 //风速传感器模块 A2 A3 要转为232
	//uart3_init(19200);	 //SD卡模块	(兼职风向-因为3有重映射功能)
	uart4_init(9600);	 //称重模块
	uart5_init(9600);	 //AD模块

 	LED_Init();			 //LED端口初始化
	KEY_Init();          //初始化与按键连接的硬件接口
	SD_init();

	OPEN_SD_POWER;
	CLOSE_SD_POWER;
	OPEN_SD_POWER;
	CLOSE_SD_POWER;
	OPEN_SD_POWER;

	cur_time.tm_year = 2016; //2016-1900
	cur_time.tm_mon = 5;
	cur_time.tm_mday = 29;
	cur_time.tm_hour = 23;
	cur_time.tm_min = 56;
	cur_time.tm_sec = 2;

    RTC_Init(cur_time);//

	while(DS18B20_Init())//初始化DS18B20,兼检测18B20
	{
		printf("DS18B20 Check Failed!"); 
		printf("Please Check!  ");   
	}
	printf("DS18B20 Ready!     ");

 	while(1)
	{		

		if(IS_BUT_DN) 
		{
			BEEP = 0;
		}
		else
		{
			BEEP = 1;
			g_PaOffset= -g_Pa;

			g_IndValOffset[0]= -Volt2Distance(0,g_IndVal[0]);
			g_IndValOffset[1]= -Volt2Distance(1,g_IndVal[1]);
			g_IndValOffset[2]= -Volt2Distance(2,g_IndVal[2]);
			g_IndValOffset[3]= -Volt2Distance(3,g_IndVal[3]);
		}
		
		if(times%60==0) 
		{
			windSpeedDirFlag++;
			sendWindSpeedCmd(); //串口2 带232
			//printf("3\r\n");
			if(5 == windSpeedDirFlag)
			{
				windSpeedDirFlag = 0; 	
			}
			//printf("4\r\n");
			//风速的反应慢 一秒钟最多发一次指令 不然传感器要疯掉
			if(0 == windSpeedDirFlag)
			{
				uart3_init(19200);	 //SD卡模块	(兼职风向-因为3有重映射功能)
				g_uart3_used_for_SD = 1;
								//				日期			时间		  位移1, 2,   3,  4	 |拉力|                    温度 |SD|风速|风向
				sprintf(CmdStr,"#01,%02d-%02d-%02d,%02d:%02d:%02d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%1d,%04d,%04d!\r\n",
												cur_time.tm_year,cur_time.tm_mon,cur_time.tm_mday,
												cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec,
												dateSendtoPC[0],dateSendtoPC[1],dateSendtoPC[2],dateSendtoPC[3],
												dateSendtoPC[4],
												dateSendtoPC[6],dateSendtoPC[7],dateSendtoPC[8],dateSendtoPC[9],
												g_Temper,lastSDerr,g_WindSpeed,g_WindDir);
				//printf("7\r\n");
				lastSDerr = write_string_to_files(CmdStr);
			}
			else
			{
				//printf("8\r\n");
				uart3_init2(9600);
				//SD卡的usart3 重映射到 PB10 和PB11口 来读风向
				g_uart3_used_for_SD = 0;
				send_byte_to_usart3(0x02);//初始化完后第一个字节会发不成功
				sendWindDirCmd();//串口3
			}
			//printf("11\r\n");
			cur_time = Time_GetTime();
		}  

		if(times%10==0) 
		{			
			//sendWeightLoad1Cmd();
			//称重标定代码
			//printf("12\r\n");
			switch(PC_Wcmd)
			{
				case 0x30:
					//printf("13\r\n");
					BEEP = 1;
					sendWeightZeroCmd();
					BEEP = 0;
					PC_Wcmd = 0;
				break;
	
				case 0x40:
					//printf("14\r\n");
					BEEP = 1;
					sendWeightLoad1Cmd();					
					PC_Wcmd = 0;
					BEEP = 0;
				break;
				case 0x41:
					//printf("15\r\n");
					BEEP = 1;
					sendWeightLoad2Cmd(g_weightCalib[0],g_weightCalib[1]);
					PC_Wcmd = 0;
					BEEP = 0;
				break;
				default:
					//printf("16\r\n");
					//sendWeightLoad2Cmd(0x27,0x10);
					sendWeightCmd(); //串口4
				break;
			}

			BLED3=1;
			sendADCmd(); //串口5
			BLED3=0;
			dateSendtoPC[0] = g_IndVal[0];
			dateSendtoPC[1] = g_IndVal[1];
			dateSendtoPC[2] = g_IndVal[2];
			dateSendtoPC[3] = g_IndVal[3];
			dateSendtoPC[4] = g_PaOffset + g_Pa;

			dateSendtoPC[6] = g_IndValOffset[0] + Volt2Distance(0,g_IndVal[0]);
			dateSendtoPC[7] = g_IndValOffset[1] + Volt2Distance(1,g_IndVal[1]);
			dateSendtoPC[8] = g_IndValOffset[2] + Volt2Distance(2,g_IndVal[2]);
			dateSendtoPC[9] = g_IndValOffset[3] + Volt2Distance(3,g_IndVal[3]);
		}
		switch(PC_cmd)
		{
			case 1:
				BLED2 = 1;
					//				日期			时间		  位移1, 2,   3,  4	 |拉力|                    温度 |SD|风速|风向
				sprintf(CmdStr,"#01,%02d-%02d-%02d,%02d:%02d:%02d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%04d,%d,%04d,%04d!\r\n",
												cur_time.tm_year,cur_time.tm_mon,cur_time.tm_mday,
												cur_time.tm_hour,cur_time.tm_min,cur_time.tm_sec,
												dateSendtoPC[0],dateSendtoPC[1],dateSendtoPC[2],dateSendtoPC[3],
												dateSendtoPC[4],
												dateSendtoPC[6],dateSendtoPC[7],dateSendtoPC[8],dateSendtoPC[9],
												g_Temper,lastSDerr,g_WindSpeed,g_WindDir);
				send_string_to_usart1(CmdStr);
				BLED2 = 0;
				PC_cmd = 0;
			break;
			case 0x10:
			case 0x11:
			case 0x12:
			case 0x13:
			case 0x14:
				BEEP = 1;
				sprintf(CmdStr,"#%02x",PC_cmd);
				for(i=0;i<21;i++)
				{
					sprintf(CmdStr,"%s,%+05d",CmdStr,IndCalib[PC_cmd-0x10][i]);	
				}
				sprintf(CmdStr,"%s!\r\n",CmdStr);
				send_string_to_usart1(CmdStr);
				PC_cmd = 0;
				BEEP = 0;
			break;
			case 0x20:
			case 0x21:
			case 0x22:
			case 0x23:
			case 0x24:
				sprintf(CmdStr,"#%02x",PC_cmd-0x10);
				for(i=0;i<21;i++)
				{
					sprintf(CmdStr,"%s,%+05d",CmdStr,IndCalib[PC_cmd-0x20][i]);	
				}
				sprintf(CmdStr,"%s!\r\n",CmdStr);
				send_string_to_usart1(CmdStr);
				PC_cmd = 0;

			break; 		
		}
		times++;  
		delay_ms(10);  
	}	 
 }