Esempio n. 1
0
/*******************************************************************************
 * Code
 ******************************************************************************/
status_t LOG_Init(uint32_t baseAddr, uint8_t device, uint32_t baudRate, uint32_t clkSrcFreq)
{
    io_state_t io;
    /* init io */
    io.ioBase = (void *)baseAddr;
    io.ioType = device;

#ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
    /* memset the global queue */
    memset(&s_log_buffer, 0U, sizeof(s_log_buffer));
    /* init callback for NON-BLOCKING */
    io.callBack = LOG_Transferred;
    /* io init function */
    IO_Init(&io, baudRate, clkSrcFreq, s_log_buffer.rxBuf);
    /* Debug console buffer push lock create */
    LOG_CREATE_MUTEX_SEMAPHORE(s_logPushSemaphore);
#else
    IO_Init(&io, baudRate, clkSrcFreq, NULL);
#endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */

    /* Debug console lock create */
    LOG_CREATE_MUTEX_SEMAPHORE(s_logPopSemaphore);
    LOG_CREATE_BINARY_SEMAPHORE(s_logReadSemaphore);

    return kStatus_Success;
}
Esempio n. 2
0
int main(void)
{		
 	Stm32_Clock_Init(9); //system clock init   always init first
	IO_Init();
	delay_init(72);	     //delay init
	uart_init(72,115200);  //uart init
	PWM4_Init(150,18000);				 // ultra ping sig

//	PWM2_2Init(100,1800);	 //count to 100, freq/1800	 //IR aqusition pulse
	Timer3_Init(65535,256);	  //time refrence for echo/ultrasonic

//	setup 5 for motors?
	Timer2_Init(65535,10);	// motor try1
	motor_Init();

	EXTIX_Init();
//	Adc_Init();
//	LED0_PWM_VAL2_2=0x44;
//	LED0_PWM_VAL2_1=0x34;
	LED0_PWM_VAL4=0x34;
	IRO=0;//turn on IR LEDs

   	while(1)
	{	
		printf("adcx1\tadcx2\tadcx3\tadcx4\tGyro\tBatt\techo\n");
		printf("%u\t%u\t%u\t%u\t%u\t%u\t%u",adcx1,adcx2,adcx3,adcx4,Gyro_raw,Batt,echo);
		printf("\n");
	//	USART1->DR=echo/0xff;
	//	while((USART1->SR&0X40)==0);//wait for transfer to compleate
		LED0=!LED0; 
		delay_us(100000);//wait for the end of transmission	   
	}	 
} 																						 
Esempio n. 3
0
int main(){

    int Fig_In[R*C/4];
    int Fig_Out[R*C/4];

    int Gx[3][3]={
        { -1, 0, 1 },
        { -2, 0, 2 },
        { -1, 0, 1 }
    };

    int Gy[3][3]={
        {  1,  2,  1 },
        {  0,  0,  0 },
        { -1, -2, -1 }
    };

    std::vector<Operand*> OP_Array;
    std::vector<Instruction*> Inst_Array;
    std::string DFG_Name="sobel";

    IO_Init(Fig_In, Gx, Gy, Fig_Out);
    OP_Array_Init(OP_Array, Fig_In, Gx, Gy, Fig_Out);
    Kernel_To_DFG(OP_Array, Inst_Array);
    DFG_Compute(OP_Array, Inst_Array);
    //Verify(OP_Array, Fig_Out);
    DFG_Dump(DFG_Name, OP_Array, Inst_Array);
    Initial_IO_Placement(DFG_Name);
    Head_File_Dump(Fig_In, Gx, Gy, Fig_Out);
}
Esempio n. 4
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{


  #ifdef DEBUG
    debug();
  #endif
  
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);         /*Use OSC as the default clock source*/
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1);      /* ARM Peripheral bus clokdivisor = 1*/
    
    
  System_Setup();/*PCLK=8MHz*/

  IO_Init();

  LED_OFF(LD1);
  LED_OFF(LD2);
  LED_OFF(LD3);
  LED_OFF(LD4);

  /* CAN tests */
  CAN_Com_LoopBack();/* send and receive some frame */
  CAN_Com_LoopBack_IRQ();/* send and receive some frame, received in 91x_it.c */

  /* LD2, LD3 should be lit */
  /* If LD4 lit so something's wrong */

	return 0;
}
Esempio n. 5
0
File: main.c Progetto: rmr1012/SEDS
int main(void)
{	
//	u8 i;		   	
 	Stm32_Clock_Init(9); //system clock init   always init first
	IO_Init();
	delay_init(72);	     //delay init
<<<<<<< HEAD
Esempio n. 6
0
int main(){

    int Sig_In[N+L];
    int Coeff[N];
    int Sig_Out[L];

    std::vector<Operand*> OP_Array;
    std::vector<Instruction*> Inst_Array;
    std::string DFG_Name="fir";

    IO_Init(Sig_In, Coeff, Sig_Out);

    OP_Array_Init(OP_Array, Sig_In, Coeff, Sig_Out);

    Kernel_To_DFG(OP_Array, Inst_Array);

    DFG_Compute(OP_Array, Inst_Array);

    Verify(OP_Array, Sig_Out);

    DFG_Dump(DFG_Name, OP_Array, Inst_Array);

    Initial_IO_Placement(DFG_Name);

    Head_File_Dump();

}
Esempio n. 7
0
void main(void){
//	UCHAR Test[3]={0x88,0x01,0x02};
	
IO_Init();
init_Uart();
Timer0Init();
INT_Init();
System_SetParaInit();
EA=1;
//		USART_Send(Test,sizeof(Test),1);
		Delay_ms(100);
		BuzzerTriggrt = 1;


while(1){
//		Delay_ms(1000);
//		SBUF = 0xaf;while(!(SCON&0x02));SCON &= ~0x02;
//if(Com1DataCounter != 0){
//	Muti_Send_Byte(Com1DataBuffer,Com1DataCounter);		//将上位机的数据直接下发到下面的单片机
//	Com1DataCounter=0;
//	memset(Com1DataBuffer,0x00,600);
//}
	
	P34 = 1;
	ENTM = 1;
if(HeartbeatTrigger == 1)
{
	UART_Fe_Seq++;
	USART1_Send(CommonDataBuffer,Fe_data_Organize(CMD_Heartbeat,&ReplySucc,1,0));
	HeartbeatTrigger = 0;
}

if(ResetWifiTrigger == 1)
{	/*由徐志坚禁止了没有收到服务器的命令而重启WiFi的功能*/
	//nResetWifi = 0;   
	//Delay_ms(500);
	//nResetWifi = 1;
	//ResetWifiOnOff  = 0;//关闭WIFI重置开关,WIFI重启以后,必须关闭重置开关防止WIFI模块连接服务器过程中再次重启。
	ResetWifiTrigger = 0;
}

if(Com1HaveDate)
{
	USART4_Send(Com1DataBuffer,Com1DataCounter);
	Com1DataCounter=0;
	memset(Com1DataBuffer,0x00,600);
	Com1HaveDate = 0;
}


if(Exint0Counter != 0)
{
	Exint0_DATA_deal();
}

	}

}
Esempio n. 8
0
void SRC_OnResizeScreen(int width, int height){
    
    renderer.glBuffersDimensions[HEIGHT] = height;
    renderer.glBuffersDimensions[WIDTH]  = width;
    
    SRC_CalcViewPortDimensions();
    IO_Init();
    
    //Also need to reset the viewPort in the renderer.
    renderer.RefreshViewPort();
}
Esempio n. 9
0
/*总初始化*/
void Init()																			
{
	CLI(); 
	IO_Init();
	ADC_Init();
	Usart_init(); 
	LCD_Init();
	Driver_595_Init();
	SPI_Init ();
	T2_Init();
 	SEI();  
}
Esempio n. 10
0
void System_Init ( void )
{
    __set_PRIMASK ( 1 );	//¹Ø±Õ×ÜÖжÏ
    SYS_Init();
    IO_Init();
    I2C_Init();
    // WDT_Init();
    UART1_Init();
    ADC_Init();
    TMR0_Init();
    __set_PRIMASK ( 0 );
}
Esempio n. 11
0
int main()
{
	MCU_Init();
	Timer1_Init();
	Timer2_Init();
	IO_Init();
	ADC_Init();
	Timer1_ON;		//start 16 bit timer1
	Timer2_ON;		//start 16 bit timer2
	ADC_ON;			//turns on ADC module

	while(1)
	{
		ADC_Convert();
	}
}
Esempio n. 12
0
void main(void)
{	

	TimerInit();		

	//mSYNC_SetCOBID(0x1000);		

	mCO_SetNodeID(0x03);	

        // 0x05 => 125kbps
        // 0x00 => 1Mbps
	mCO_SetBaud(0x05);		

	mNMTE_SetHeartBeat(0x0004);
	mNMTE_SetGuardTime(0000);	
	mNMTE_SetLifeFactor(0x00);	

        IO_Init();
        InitializeGPS();
        Slave_Init();
        
	mCO_InitAll();
        CO_NMTStateChangeEvent();

        if( !COMM_STATE_PREOP )
            while( 1 );             //Wrong mode

        // Enable TPDO:s and RPDO:s
        mTPDOOpen(1);
        mTPDOOpen(2);
        
     
	while(1)
	{
		mCO_ProcessAllEvents();

                Slave_ProcessEvents();
		
		// 1ms timer events
		if (TimerIsOverflowEvent())
		{
			mCO_ProcessAllTimeEvents();	
		}

	}
}
Esempio n. 13
0
int main(void)
{
	// Init all needed hardware
	IO_Init();
	VPRG_Off();
	DCPRG_Off();
	Layer_On(-1);
	TIM1_Config();
	TIM8_Config();
	HardwareSPI_init();
	Interrupts_Init();
	SysTick_Init();

	while (1)
	{
		;
	}
}
Esempio n. 14
0
//------------------------------------------------------------------------------
void PIN_Setup()
{
 outb(GIMSK, 0);			// disable external interupts
 outb(MCUCR, 0);
 sbi(TIMSK, TOIE1); // Enable timer1 interrupt

  // Timer 1
 outb(TCCR1A, 0);
 outb(TCCR1B, (_BV(CS12)) | (_BV(CS10)));	// Prescaler /1024
 outb(TCNT1H, TI1_H);						// Load counter value hi
 outb(TCNT1L, TI1_L);						// Load counter value lo

 IO_Init();
 RS232_Init();
 Event = EV_NOTHING;
 sei();

 //MCUCR     = (0<<ISC11)|(1<<ISC10)|(0<<ISC01)|(1<<ISC00);
}
Esempio n. 15
0
int main (void){
	
	/* Local Variables */
	char Data[256];
//	float GPS_Altitude = 0;
	
	/* Initialize I2C,XBEE,ADC,USART1,USART2,LPUART1,CLOCK,ISK01A1,GPIO */
	IO_Init();
	
	/* Wait for Button press */
	while(Button_Get_State() == 0){
		//Nop
	}
	
	/* Turn on Green LED */
	GPIO_On(GPIOA,Green_LED);
	
	/* Enable Timer */
	Start_15s_Timer();
	
	/* Grab data from sensors and send */
  while (1) {	

//		GPS_Altitude = atof(FGPMMOPA6H_Get_GGA_Altitude());
//		
//		if((FGPMMOPA6H_Get_RMC_Status() == 1) && (GPS_Altitude <= CHUTE_DEPLOY_ALT)){
//			Servo_Position(180);
//		}
		
		while(GPS_Ready.Status == 0){
			//Nop
		}
		
		/* Congregate Data */
		sprintf(Data,"%s%s",FGPMMOPA6H_Package_Data(),ISK01A1_Package_Data());
		
		/* Send data over the XBEE */
		LPUART1_Send(Data);
  }
	
}
Esempio n. 16
0
int main(){

    int A_In[M][N];
    int B_In[N];
    int C_Out[M];

    std::vector<Operand*> OP_Array;
    std::vector<Instruction*> Inst_Array;
    std::string DFG_Name="mm";

    IO_Init(A_In, B_In, C_Out);
    OP_Array_Init(OP_Array, A_In, B_In, C_Out);
    Kernel_To_DFG(OP_Array, Inst_Array);
    DFG_Compute(OP_Array, Inst_Array);
    Verify(OP_Array, C_Out);
    DFG_Dump(DFG_Name, OP_Array, Inst_Array);
    Initial_IO_Placement(DFG_Name);
    Head_File_Dump();
    Loop_Stat(OP_Array, Inst_Array);

}
Esempio n. 17
0
int main(void)
{
    //uint16_t kezdet, vege;
    vSemaphoreCreateBinary(xADCSemaphore);
    RCC_Config();

    IO_Init();
    UART_Config();
    PWM_Config();
    DMA_Config();
    I2C_Config();
    NVIC_Config();
    DebugTimerInit();

    xTaskCreate(prvInitTask,(signed char*)"INIT", configMINIMAL_STACK_SIZE,NULL,TASK_INIT_PRIORITY,NULL);

    vTaskStartScheduler();
    while (1)
    {



    }
}
Esempio n. 18
0
void vDos_Init(void)
	{
	hideWinTill = GetTickCount()+2500;												// Auto hidden till first keyboard check, parachute at 2.5 secs

	LOG_MSG("vDos version: %s", vDosVersion);

#ifndef WITHIRQ1
	// Wil have been called earlier in starup if WITHIRQ1 is defined
	vDos_LoadConfig();
#endif

	GUI_StartUp();
	IO_Init();
	PAGING_Init();
	MEM_Init();
	CALLBACK_Init();
	PIC_Init();
	PROGRAMS_Init();
	TIMER_Init();
//	CMOS_Init();
	VGA_Init();
	CPU_Init();
	KEYBOARD_Init();
	BIOS_Init();
	INT10_Init();
	MOUSE_Init();
	SERIAL_Init();
	PARALLEL_Init();
	printTimeout = ConfGetBool("timeout");
	DOS_Init();
	XMS_Init();
	EMS_Init();
	if (errorMess[0])
		MessageBox(NULL, errorMess+1, "vDos: CONFIG.TXT has unresolved items", MB_OK|MB_ICONWARNING);
	SHELL_Init();																	// Start up main machine
	}
Esempio n. 19
0
int main( void )
{
	unsigned long * ptr;
	unsigned char aux;
	unsigned int tempo = 500;

	IO_Init();
	SysTick_Init_ms( tempo );
	UART_Init_16MHz();
	Nokia5110_Init();
	Bluetooth_Init();
	
  Nokia5110_OutString("SENAI");	

	for(;;)
	{
		if( UART_InCharAvailable() )
			Bluetooth_OutChar( UART_InChar() );
		
		if( Bluetooth_InCharAvailable() )
		  UART_OutChar ( aux = Bluetooth_InChar() );


		if( SysTickRun() )
		{
			if( *ptr )
		    *ptr = 0x00; 
			else
			  *ptr = 0xFF; 
		}

			switch( aux )
			{
				case 0:
				case 'R': 	*ptr = 0x00; ptr = (unsigned long *)&LED_RED;				break;
				case 'B': 	*ptr = 0x00; ptr = (unsigned long *)&LED_BLUE;			break;
				case 'G': 	*ptr = 0x00; ptr = (unsigned long *)&LED_GREEN;			break;
				case 'Y': 	*ptr = 0x00; ptr = (unsigned long *)&LED_YELLOW;		break;
				case 'P': 	*ptr = 0x00; ptr = (unsigned long *)&LED_PINK;			break;
				case 'S': 	*ptr = 0x00; ptr = (unsigned long *)&LED_SKYBLUE;		break;
				case 'W':   *ptr = 0x00; ptr = (unsigned long *)&LED_WHITE;			break;
				case 'D':   *ptr = 0x00; ptr = (unsigned long *)&LED_DARK;			break;
				case 'T': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Temp: " );
										UART_OutUDec( (unsigned long)sensor.temperatura );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Temp: " );
										Bluetooth_OutUDec( (unsigned long)sensor.temperatura ); 		
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
				case 'U': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Umidade: " );
										UART_OutUDec( (unsigned long)sensor.umidade );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Umidade: " );
										Bluetooth_OutUDec( (unsigned long)sensor.umidade ); 
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
			}


	} //for(;;)	
} //int main( void )
Esempio n. 20
0
void IO_Shutdown()
{
    IO_Close();
	IO_Init();
}
Esempio n. 21
0
/**
 * @brief This function used to read the saved IO status or register default IO settings
 * @param None
 * @return None
 */
void IO_status_init(void)
{
	uint8_t i;
	read_IOstorage(&IOdata, sizeof(IOdata));

	// IO Status & Alias Initialization
	// Initialize for WIZ550web Baseboard Configuration
	if(!((IOdata.io_statuscode[0] == 0xAA) && (IOdata.io_statuscode[1] == 0x01)))
	{
#ifdef _WEB_DEBUG_
		printf("\r\nIO Status Detection code: [%.02x][%.02x]\r\n", IOdata.io_statuscode[0], IOdata.io_statuscode[1]);
#endif
		// IO Status Detection code Initialize
		IOdata.io_statuscode[0] = 0xAA;
		IOdata.io_statuscode[1] = 0x01;

		// IO Direction Initialize
		IOdata.io[D0] = Output;
		IOdata.io[D1] = Output;
		IOdata.io[D2] = Output;
		IOdata.io[D3] = Output;
		IOdata.io[D4] = Output;
		IOdata.io[D5] = Output;
		IOdata.io[D6] = Output;
		IOdata.io[D7] = Output;
		IOdata.io[D8] = Input;
		IOdata.io[D9] = Input;
		IOdata.io[D10] = Input;
		IOdata.io[D11] = Input;
		IOdata.io[D12] = Input;
		IOdata.io[D13] = Input;
		IOdata.io[D14] = Input;
		IOdata.io[D15] = Input;

		// Each IO Status Initialize
		for(i = 0; i < IOn; i++)
		{
			IOdata.ios[i] = Off;
		}

		// IO Alias fields Initialize
		for(i = 0; i < IOn; i++)
		{
			memset(IOdata.io_alias[i], 0x00, 25);
			sprintf((char *)IOdata.io_alias[i], "Digital IO #%d", i);
		}

		write_IOstorage(&IOdata, sizeof(IOdata));

#ifdef _WEB_DEBUG_
		printf(">> Default IO Status / Alias Initialize Success\r\n\r\n");
#endif
	}
#ifdef _WEB_DEBUG_
	else
	{
		printf(">> IO Status / Alias Load Success\r\n\r\n");
	}
#endif

	GPIO_PinRemapConfig (GPIO_Remap_SWJ_Disable, ENABLE);

	// IO Direction setting after load or set default
	for(i = 0; i < IOn; i++)
	{
		if((IOdata.io[i] != NotUsed) && (IOdata.io[i] != 0xFF))
		{
			IO_Init(i);
		}
	}

	// Each IO Status Initialize
	for(i = 0; i < IOn; i++)
	{
		if(IOdata.io[i] == Output)
		{
			if(IOdata.ios[i] == Off)	IO_Off(i);
			else						IO_On(i);
		}
	}
}
Esempio n. 22
0
int main()
{

    initialize_stk();
    
    /* Chip errata */
    CHIP_Init();
    /* Ensure core frequency has been updated */
    SystemCoreClockUpdate();
    
    IO_Init();
    
    UART1->ROUTE = UART_ROUTE_LOCATION_LOC3
    | UART_ROUTE_TXPEN | UART_ROUTE_RXPEN;
    
    static const uint32_t baud = 9600;
    static const uint32_t ovs = 16;
    static const uint32_t refclk = 14060000;
    
    UART1->CLKDIV = (256 * refclk) / ((ovs * baud) - 1);
    UART1->CMD = UART_CMD_TXEN | UART_CMD_RXEN;
    UART1->IEN = UART_IEN_RXDATAV;

    
    //TIMER_IntClear(TIMER0, TIMER_IF_OF);
    //InitRGBLEDPWM();
    //TIMER_IntClear(TIMER0, TIMER_IF_OF);
  
    clockAppDisplay();
    float time0 = atoi(&displayStringBuf);
    for (;;){
        
        
        clockAppDisplay();
        float time1 = atoi(&displayStringBuf);

        if(time1-time0>=1){
             printf("%.3f",time1);
             printf(" ");
             printf("%.4f",5556.5404+(distance*SPEEDLAT));
             printf(" ");
             printf("%0010.4f",311.4366+(distance*SPEEDLONG));
             printf("\n");
            if((distancef < DIS1 && fw) || STRAIGHT){
                distanceb=0;
                distance+=FINC;
                distancef+=FINC;
            }
            else{
                fw =0;
                distancef=0;
                distance-=BINC;
                distanceb+=BINC;
                if (distanceb >= DIS2){
                    fw = 1;
                }
            }
             time0 = time1;
        }
        
          
    }
    
}
Esempio n. 23
0
// ---------------------------------------------------------------------------
int main(int argc, char* argv[]) {
 signal(SIGINT, (sig_t)cleanup);

 // load settings file
 char* settings_file = NULL;
 int settings = 0;
 if(argc == 2) {
   settings_file = argv[1];
   settings = Settings_Load(argv[1]);
 } 
 if(!settings) {
   settings_file = "default.conf";
   if(!Settings_Load("default.conf")) {
      printf("%s\r\n", _lng(ERROR_LOADING_SETTINGS));
      return 0;
   }
 }

 // load settings
 FW_VERSION = Settings_Get("gui", "version");
 SONG_FILE = Settings_Get("files", "song");
 CURRENT_STATION_FILE = Settings_Get("files", "current_station");
 STATIONS_FILE = Settings_Get("files", "stations");
 USB_PATH = Settings_Get("files", "usb");
 
 // check for running instance
 char* single_instance_cmd = Settings_Get("programs", "check_running");
 ignore_result(system(single_instance_cmd));
 FILE *running = fopen("fw.running", "r");
 if(running == NULL) {
   printf("Cannot check if firmware is running, aborting.\r\n");
   exit(0);
 }
 if(fgetc(running) >= '2') {
   fclose(running);
   printf("Firmware is already running!\r\nExiting...\r\n");
   exit(0);
 } else {
   fclose(running);
 }
 

 if(strcmp(Settings_Get("hardware", "io"), "sim") == 0) IO_SetSimulate(1);
 if(strcmp(Settings_Get("hardware", "lcd"), "sim") == 0) GLCDD_SetSimulate(1);
 else if(strcmp(Settings_Get("hardware", "lcd"), "bmp") == 0) GLCDD_SetSimulate(2);
  
 GLCDD_Init();
 IO_Init();

 Language_Init(Settings_Get("gui", "language"));
 Screen_Init(silkscreen_8);
 
 Screen screen = SCREEN_MAIN;
 
 // create fonts
 fnt_dejavu_9 = createFont(dejavu_9);
 fnt_dejavu_9b = createFont(dejavu_9_b);
 fnt_silkscreen_8 = createFont(silkscreen_8);
 
 // register screens
 Screen_Add(SCREEN_MAIN, init_Main, draw_Main, exit_Main);
 Screen_Add(SCREEN_NOW_PLAYING, init_NowPlaying, draw_NowPlaying, exit_NowPlaying);
 Screen_Add(SCREEN_STATIONS, init_Stations, draw_Stations, exit_Stations);
 Screen_Add(SCREEN_INFO, NULL, draw_Info, NULL);
 Screen_Add(SCREEN_USB, init_USB, draw_USB, NULL);
 Screen_Add(SCREEN_SHUTDOWN, init_Shutdown, draw_Shutdown, NULL);
 Screen_Add(SCREEN_SETTINGS, init_Settings, draw_Settings, exit_Settings);
 Screen_Add(SCREEN_WIFI_SCAN, init_WifiScan, draw_WifiScan, exit_WifiScan);
 Screen_Add(SCREEN_WIFI_AUTH, init_WifiAuth, draw_WifiAuth, NULL);
 Screen_Add(SCREEN_WIFI_CONNECT, init_WifiConnect, draw_WifiConnect, NULL);
 Screen_Add(SCREEN_LANGUAGE, init_Language, draw_Language, exit_Language);
 Screen_Add(SCREEN_VOLUME, init_Volume, draw_Volume, NULL);
 Screen_Add(SCREEN_SHOUTCAST, init_Shoutcast, draw_Shoutcast, exit_Shoutcast);
 Screen_Add(SCREEN_SHOUTCAST_LIST, init_ShoutcastList, draw_ShoutcastList, exit_ShoutcastList);
 Screen_Add(SCREEN_SHOUTCAST_GENRE, init_ShoutcastGenre, draw_ShoutcastGenre, exit_ShoutcastGenre);
 Screen_Add(SCREEN_SHOUTCAST_SEARCH, init_ShoutcastSearch, draw_ShoutcastSearch, NULL);
 Screen_Add(SCREEN_MANAGE_STATION, init_ManageStation, draw_ManageStation, exit_ManageStation);
 Screen_Add(SCREEN_SNOOZE, init_Snooze, draw_Snooze, exit_Snooze);
 Screen_Add(SCREEN_TIMEOUT, init_Timeout, draw_Timeout, NULL);
 Screen_SetRefreshTimeout(SCREEN_INFO, 2);
 Screen_SetRefreshTimeout(SCREEN_MAIN, 10);
 Screen_SetRefreshTimeout(SCREEN_NOW_PLAYING, 1);
 Screen_SetRefreshTimeout(SCREEN_STATIONS, 10);
 Screen_SetRefreshTimeout(SCREEN_USB, 1);
 Screen_SetRefreshTimeout(SCREEN_SHUTDOWN, 10);
 Screen_SetRefreshTimeout(SCREEN_WIFI_SCAN, 1); 
 Screen_SetRefreshTimeout(SCREEN_WIFI_AUTH, 10);
 Screen_SetRefreshTimeout(SCREEN_WIFI_CONNECT, 1);
 Screen_SetRefreshTimeout(SCREEN_LANGUAGE, 10);
 Screen_SetRefreshTimeout(SCREEN_VOLUME, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_LIST, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_GENRE, 10);
 Screen_SetRefreshTimeout(SCREEN_SHOUTCAST_SEARCH, 10);
 Screen_SetRefreshTimeout(SCREEN_MANAGE_STATION, 10);
 Screen_SetRefreshTimeout(SCREEN_SNOOZE, 10);
 Screen_SetRefreshTimeout(SCREEN_TIMEOUT, 10);
 Screen_ShowLoadingScreen(SCREEN_USB, 1);
 Screen_ShowLoadingScreen(SCREEN_VOLUME, 1);
 Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_LIST, 1);
 Screen_ShowLoadingScreen(SCREEN_SHOUTCAST_GENRE, 1);
 
  
 // reset song info
 resetMetaInfo();
 
 // start ui
 Screen_Goto(SCREEN_MAIN);
 
 // background light
 GLCDD_BacklightTimeout(atoi(Settings_Get("hardware", "timeout")));
 int keep_light_when_playing = 0;
 if(strcmp(Settings_Get("gui", "keep_light_when_playing"), "true") == 0) keep_light_when_playing = 1;
 GLCDD_BacklightReset();
 
 uint64_t last_io = 0;
 
 while(1) {

#ifndef SIMULATE
  if(getTimeMillisecond() - last_io >= 25) {
    IO_Get();
    last_io = getTimeMillisecond();
  }
#else
  IO_Get();
#endif
  if(IO_HasChanged()) {
    Screen_ForceRedraw();
    GLCDD_BacklightReset();
  }
  
  screen = Screen_GetActive();
  
  // ---------------------------------------------------------------------------
  if(screen == SCREEN_MAIN) {
    int selection = Menu_IsChosen(menu_main);
    if(selection == 0) {
      // goto now playing screen
      Screen_Goto(SCREEN_NOW_PLAYING);
    } else if(selection == 1) {
      // goto stations screen
      Screen_Goto(SCREEN_STATIONS);	
    } else if(selection == 2) {
      // goto shoutcast browser
      Screen_Goto(SCREEN_SHOUTCAST);
    } else if(selection == 3) {
      // goto usb screen
      Screen_Goto(SCREEN_USB);
    } else if(selection == 4) {
      // goto info screen
      Screen_Goto(SCREEN_SETTINGS);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_INFO) {
    if(IO_GetButton(0)) {
      Screen_Goto(SCREEN_SETTINGS);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_STATIONS) {
    int selection = Menu_IsChosen(menu_stations);
    if(selection != -1) {
      // start station
      playStation(Menu_GetItemTag(menu_stations, selection));
    }
    
    // add station as favorite
    if(IO_GetButtonLong(3)) asFavorite(1);
    if(IO_GetButtonLong(4)) asFavorite(2);
    if(IO_GetButtonLong(5)) asFavorite(3);
    if(IO_GetButtonLong(6)) asFavorite(4);
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_NOW_PLAYING) {
    // if at now playing screen, backlight is always on
    if(keep_light_when_playing) GLCDD_BacklightReset(); 
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SETTINGS) {
      int selection = Menu_IsChosen(menu_settings);
      if(selection == 0) {
	// goto info screen
	Screen_Goto(SCREEN_INFO);
      } else if(selection == 1) {
	// goto wifi scanning screen
	Screen_Goto(SCREEN_WIFI_SCAN);
      } else if(selection == 2) {
	// goto language selection
	Screen_Goto(SCREEN_LANGUAGE);
      } else if(selection == 3) {
	// goto volume adjustment
	Screen_Goto(SCREEN_VOLUME);
      } else if(selection == 4) {
	// goto backlight timeout
	Screen_Goto(SCREEN_TIMEOUT);
      } else if(selection == 5) {
	// goto station manager
	Screen_Goto(SCREEN_MANAGE_STATION);
      } else if(selection == 6) {
	// restart firmware
	// stop all music
	stopMusic();
	// kill all streams
	ignore_result(system(Settings_Get("programs", "killall")));
	// restart self
	execv(argv[0], argv);
      } else if(selection == 7) {
	// shutdown
	Screen_Goto(SCREEN_SHUTDOWN); 
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_WIFI_SCAN) {
      int selection = Menu_IsChosen(menu_wifi_scan);
      if(selection != -1) {
	// save ssid
	Settings_Add("wifi", "ssid", Menu_GetItemText(menu_wifi_scan, selection));
	// go to authentification
	Screen_Goto(SCREEN_WIFI_AUTH);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_WIFI_AUTH) {
      if(Keyboard_IsConfirmed()) {
	// connect to wifi network
	Settings_Add("wifi", "pwd", Keyboard_GetText());
	printf("Connecting to '%s' with key '%s'\r\n", Settings_Get("wifi", "ssid"), Settings_Get("wifi", "pwd"));
	Screen_Goto(SCREEN_WIFI_CONNECT);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_LANGUAGE) {
      // change language
      int selection = Menu_IsChosen(menu_language);
      if(selection != -1) {
	char disp[64];
	int i;
	strcpy(disp, Menu_GetItemText(menu_language, selection));
	for(i = strlen(disp) - 1; i >= 0; i--) {
	  if(disp[i] == ')') disp[i] = 0;
	  if(disp[i] == '(') {
	   i++;
	   break;
	  }
	}
	Settings_Add("gui", "language", &disp[i]);
	Language_Cleanup();
	Language_Init(&disp[i]);
	Settings_Save(settings_file);
	Screen_Goto(SCREEN_SETTINGS);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_VOLUME) {
      if(IO_GetButton(0)) {
	// go back to settings
	Screen_Goto(SCREEN_SETTINGS);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST) {
      int selection = Menu_IsChosen(menu_shoutcast);
      if(selection == 0) {
	// go to shoutcast top stations
	setShoutcastListUrl(Settings_Get("shoutcast", "list_url"));
	printf("'%s'\r\n", Settings_Get("shoutcast", "list_url"));
	setStationsParentGenre("X");
	setCurrentGenre(" ");
	Screen_Goto(SCREEN_SHOUTCAST_LIST);
      } 
      else if(selection == 1) { 
	// random station
	setShoutcastListUrl(Settings_Get("shoutcast", "random_url"));
	setStationsParentGenre("X");
	setCurrentGenre(" ");
	Screen_Goto(SCREEN_SHOUTCAST_LIST);
      }
      else if(selection == 2) {
	// go to genre list
	setShoutcastGenreParent("0");
	Screen_Goto(SCREEN_SHOUTCAST_GENRE);
      }
      else if(selection == 3) {
	// go to station search
	Screen_Goto(SCREEN_SHOUTCAST_SEARCH);
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_GENRE) {
      int selection = Menu_IsChosen(menu_genres);
      if(selection != -1) {
	if(selection == 0) { // back
	  if(strcmp(getShoutcastGenreParent(), "0") == 0) { // main genres
	    Screen_Goto(SCREEN_SHOUTCAST);
	  } else { // sub genre -> go back to main genres
	    setShoutcastGenreParent("0");
	    Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	  }
	} else { // list stations or sub genre
	  ShoutcastGenre* info = getChosenGenre((int)Menu_GetItemTag(menu_genres, selection));
	  // show sub genres
	  if(info->has_children) {
	    setStationsParentGenre(info->id);
	    setShoutcastGenreParent(info->id);
	    Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	  } else { // show stations
	    char buffer[128];
	    sprintf(buffer, Settings_Get("shoutcast", "stations_by_genre_url"), info->name);
	    setShoutcastListUrl(buffer);
	    setCurrentGenre(info->name);
	    Screen_Goto(SCREEN_SHOUTCAST_LIST);
	  }
	}
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_LIST) {
      if(Menu_GetAutoIO(menu_station_list)) {
	int selection = Menu_IsChosen(menu_station_list);
	if(selection != -1) {
	  if(selection == 0) { // back
	      if(strcmp(getStationsParentGenre(), "X") == 0) { // go to shoutcast menu
		Screen_Goto(SCREEN_SHOUTCAST); 
	      } else { // go to genre list
		setShoutcastGenreParent(getStationsParentGenre());
		Screen_Goto(SCREEN_SHOUTCAST_GENRE);
	      }
	  } else { // show play/as_favorite/cancel menu
	      Menu_SetAutoIO(menu_station_list, 0);
	      Screen_ForceRedraw();
	  }
	}
      } else {
	int selection = Menu_IsChosen(menu_play_fav);
	if(selection != -1) {
	  Menu_SetAutoIO(menu_station_list, 1);
	  Screen_ForceRedraw();
	  
	  if(selection == 0) { // play
	      ShoutcastStation* info = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list)));
	      StationInfo* station = parseShoutcastList(info);
	      station->genre = getCurrentGenre();
	      playStation(station);
	      free(station->url);
	      free(station);
	  }
	  else if(selection == 1) { // add to station list
	      ShoutcastStation* sc_stat = getChosenStation((int)Menu_GetItemTag(menu_station_list, Menu_GetSelectedItem(menu_station_list)));
	      StationInfo* stat = parseShoutcastList(sc_stat);
	      
	      StationInfo* info = (StationInfo*)malloc(sizeof(StationInfo));
	      info->tag = '\0';
	      info->name = stat->name;
	      info->url = stat->url;
	      info->genre = getCurrentGenre();
	      
	      ArrayList* stations = readStations();
	      AList_Add(stations, info);
	      writeStations(stations);
	      AList_Delete(stations, AList_Length(stations) - 1);
	      freeStations(stations);
	      AList_Destroy(stations);
	      free(stat->url);
	      free(stat);
	      free(info);
	  }
	  else if(selection == 2) { // cancel
	    // do nothing
	  } 
	}
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_SHOUTCAST_SEARCH) {
    if(Keyboard_IsConfirmed()) {
      char buffer[256];
      sprintf(buffer, Settings_Get("shoutcast", "search_url"), Keyboard_GetText());
      setShoutcastListUrl(buffer);
      setStationsParentGenre("X");
      setCurrentGenre(" ");
      Screen_Goto(SCREEN_SHOUTCAST_LIST);
    }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_MANAGE_STATION) {
      if(Menu_GetAutoIO(menu_m_station)) { // handle station list menu
	int selection = Menu_IsChosen(menu_m_station);
	if(selection != -1) { // show menu
	  Menu_SetAutoIO(menu_m_station, 0);
	  Menu_ScrollTo(menu_m_menu, 0);
	  Screen_ForceRedraw();
	}
      } else {
	if(Menu_GetAutoIO(menu_m_menu)) { // handle station menu
	    int selection = Menu_IsChosen(menu_m_menu);
	    
	    if(selection == 0) {
	      // do nothing (cancel)
	    }
	    else if(selection == 1) {
	      // move -> handled below
	    }
	    else if(selection == 2) {
	      deleteStation(Menu_GetSelectedItem(menu_m_station));
	      Screen_Goto(SCREEN_MANAGE_STATION);
	    }
	    
	    // close menu
	    if(selection != -1) {
	      if(selection == 1) { // move -> disable all menus
		Menu_SetAutoIO(menu_m_menu, 0);
		Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), '*');
		Screen_ForceRedraw();
	      } else {
		Menu_SetAutoIO(menu_m_station, 1);
		Screen_ForceRedraw();
	      }
	    }
	}
	
	else { // moving stations
	  if(IO_GetButton(0)) { // we are done
	    Menu_SetTitleTag(menu_m_station, Menu_GetSelectedItem(menu_m_station), 0);
	    ArrayList* new_stations = AList_Create();
	    int i;
	    for(i = 0; i < Menu_GetItems(menu_m_station); i++) {
	      StationInfo* info = Menu_GetItemTag(menu_m_station, i);
	      AList_Add(new_stations, info);
	    }
	    writeStations(new_stations);
	    AList_Destroy(new_stations);
	    
	    Menu_SetAutoIO(menu_m_menu, 1);
	    Menu_SetAutoIO(menu_m_station, 1);
	    Screen_ForceRedraw();
	  }
	  else {
	   int8_t rotary = IO_GetRotaryValue();
	   if(rotary != 0) {
	      int index = Menu_GetSelectedItem(menu_m_station);
	      int new_index = index + ((rotary > 0) ? 1 : -1);
	      Menu_SwapItems(menu_m_station, index, new_index); 
	      Menu_Scroll(menu_m_station, (rotary > 0) ? 1 : -1);
	   }
	  }
	  
	}
	
      }
  }
  // ---------------------------------------------------------------------------
  else if(screen == SCREEN_TIMEOUT) {
     if(IO_GetButton(0)) {
      // go back to settings
      char buffer[8];
      sprintf(buffer, "%d", Timeout_Get());
      Settings_Add("hardware", "timeout", buffer);
      Settings_Save(settings_file);
      GLCDD_BacklightTimeout(Timeout_Get());      
      Screen_Goto(SCREEN_SETTINGS); 
    }     
  }
  // ---------------------------------------------------------------------------

  // home button
  if(IO_GetButton(1)) Screen_Goto(SCREEN_MAIN);
  
  // play/stop button
  if(IO_GetButton(2)) {
    if(screen != SCREEN_USB) {
      // stop music
      stopMusic();
    } else {
      // play folder
      int i;
      FILE* f = fopen("/tmp/playlist1.m3u", "w");
      for(i = 0; i < Menu_GetItems(menu_usb); i++) {
	// a file, add it to the list
	if((int)Menu_GetItemTag(menu_usb, i) == 0) {
	  fprintf(f, "%s/%s\r\n", usb_root, Menu_GetItemText(menu_usb, i));
	}
      }
      fclose(f);
      char cmd[128];
      sprintf(cmd, "%s /tmp/playlist1.m3u > /tmp/playlist.m3u", Settings_Get("programs", "shuffle"));
      ignore_result(system(cmd));
      
      playUSB("/tmp/playlist.m3u");
    }
  }
  
  // end of snooze time
  if(checkSnoozeStop()) {
   // stop the music
   stopMusic();
   // go to main screen
   Screen_Goto(SCREEN_MAIN);
  }
  
  // (1) button
  if(IO_GetButton(3)) playFavorite(1);
  // (2) button
  if(IO_GetButton(4)) playFavorite(2);
  // (3) button
  if(IO_GetButton(5)) playFavorite(3);
  // (4) button
  if(IO_GetButton(6)) playFavorite(4);
  
  Screen_Draw();

  GLCDD_BacklightUpdate();
  
  usleep(100);
//sleep(1);
 
 }
 
 // really no need to cleanup, as firmware runs as long as device is powered
 // plus, the operating system frees all resources anyway
 
}
Esempio n. 24
0
void CurrentDetectionT1_Init(uint8 task_id)
{
   IO_Init();

   CurrentDetectionT1_TaskID = task_id;
   CurrentDetectionT1_NwkState = DEV_INIT;
   CurrentDetectionT1_TransID = 0;

   MT_UartInit();
   MT_UartRegisterTaskID(task_id);

   // Device hardware initialization can be added here or in main() (Zmain.c).
   // If the hardware is application specific - add it here.
   // If the hardware is other parts of the device add it in main().

#if defined ( BUILD_ALL_DEVICES )
   // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
   // We are looking at a jumper (defined in CurrentDetectionT1Hw.c) to be jumpered
   // together - if they are - we will start up a coordinator. Otherwise,
   // the device will start as a router.
   if (readCoordinatorJumper())
      zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
   else
      zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

   // Setup for the periodic message's destination address
   // Broadcast to everyone
   CurrentDetectionT1_Periodic_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
   CurrentDetectionT1_Periodic_DstAddr.endPoint = HEARTBEAT_ENDPOINT;
   CurrentDetectionT1_Periodic_DstAddr.addr.shortAddr = 0;

   // Fill out the endpoint description.
   CurrentDetectionT1_epDesc.endPoint = HEARTBEAT_ENDPOINT;
   CurrentDetectionT1_epDesc.task_id = &CurrentDetectionT1_TaskID;
   CurrentDetectionT1_epDesc.simpleDesc
      = (SimpleDescriptionFormat_t *)&CurrentDetectionT1_SimpleDesc;
   CurrentDetectionT1_epDesc.latencyReq = noLatencyReqs;

   // Register the endpoint description with the AF
   afRegister(&CurrentDetectionT1_epDesc);

   // Register for all key events - This app will handle all key events
   RegisterForKeys(CurrentDetectionT1_TaskID);

   nv_read_config();

   HalAdcInit();
   HalAdcSetReference(HAL_ADC_REF_AVDD);
#ifdef DEBUG_TRACE
   //memset(serialNumber, 0, SN_LEN);
   //serialNumber[SN_LEN - 1] = 20;
#endif

   memcpy(serialNumber, aExtendedAddress, SN_LEN);
   //Feed WatchDog
   WDCTL = 0xa0;
   WDCTL = 0x50;

   osal_start_timerEx(CurrentDetectionT1_TaskID, DTCT_HEARTBEAT_MSG_EVT, 10);
   osal_start_timerEx(CurrentDetectionT1_TaskID, DTCT_LED_WTD_EVT, 10);
}
Esempio n. 25
0
int main(void) {
	char buf[22];
	int len;

	PLLCFG = (1<<5) | (4<<0); //PLL MSEL=0x4 (+1), PSEL=0x1 (/2) so 11.0592*5 = 55.296MHz, Fcco = (2x55.296)*2 = 221MHz which is within 156 to 320MHz
	PLLCON = 0x01;
	PLLFEED = 0xaa;
	PLLFEED = 0x55; // Feed complete
	while(!(PLLSTAT & (1<<10))); // Wait for PLL to lock
	PLLCON = 0x03;
	PLLFEED = 0xaa;
	PLLFEED = 0x55; // Feed complete
	VPBDIV = 0x01; // APB runs at the same frequency as the CPU (55.296MHz)
	MAMTIM = 0x03; // 3 cycles flash access recommended >40MHz
	MAMCR = 0x02; // Fully enable memory accelerator
	
	Sched_Init();
	IO_Init();
	Set_Heater(0);
	Set_Fan(0);
	Serial_Init();
	I2C_Init();
	EEPROM_Init();
	NV_Init();

	if( NV_GetConfig(REFLOW_BEEP_DONE_LEN) == 255 ) {
		NV_SetConfig(REFLOW_BEEP_DONE_LEN, 10); // Default 1 second beep length
	}

	printf("\nInitializing improved reflow oven...");
	LCD_Init();
	LCD_BMPDisplay(logobmp,0,0);

	// Setup watchdog
	WDTC = PCLKFREQ / 3; // Some margin (PCLKFREQ/4 would be exactly the period the WD is fed by sleep_work)
	WDMOD = 0x03; // Enable
	WDFEED = 0xaa;
	WDFEED = 0x55;

	uint8_t resetreason = RSIR;
	RSIR = 0x0f; // Clear it out
	printf("\nReset reason(s): %s%s%s%s", (resetreason&(1<<0))?"[POR]":"", (resetreason&(1<<1))?"[EXTR]":"",
			(resetreason&(1<<2))?"[WDTR]":"", (resetreason&(1<<3))?"[BODR]":"");

	// Request part number
	command[0] = IAP_READ_PART;
	iap_entry(command, result);
	const char* partstrptr = NULL;
	for(int i=0; i<NUM_PARTS; i++) {
		if(result[1] == partmap[i].id) {
			partstrptr = partmap[i].name;
			break;
		}
	}
	// Read part revision
	partrev=*(uint8_t*)PART_REV_ADDR;
	if(partrev==0 || partrev > 0x1a) {
		partrev = '-';
	} else {
		partrev += 'A' - 1;
	}
	len = snprintf(buf,sizeof(buf),"%s rev %c",partstrptr,partrev);
	LCD_disp_str((uint8_t*)buf, len, 0, 64-6, FONT6X6);
	printf("\nRunning on an %s", buf);

	LCD_FB_Update();
	Keypad_Init();
	Buzzer_Init();
	ADC_Init();
	RTC_Init();
	OneWire_Init();
	Reflow_Init();

	Sched_SetWorkfunc( MAIN_WORK, Main_Work );
	Sched_SetState( MAIN_WORK, 1, TICKS_SECS( 2 ) ); // Enable in 2 seconds

	Buzzer_Beep( BUZZ_1KHZ, 255, TICKS_MS(100) );

	while(1) {
		int32_t sleeptime;
		sleeptime=Sched_Do( 0 ); // No fast-forward support
		//printf("\n%d ticks 'til next activity"),sleeptime);
	}
	return 0;
}
Esempio n. 26
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  
  /*Initialize IO*/
  IO_Init();
  
  /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); 
  
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);
  
  /* SysTick end of count event each 2.5ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / TimeDev);
  
  if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
  {
    /* Turn on LEDs available on STM32F4-Discovery ---------------------------*/
    STM_EVAL_LEDOn(LED4);
    STM_EVAL_LEDOn(LED3);
    STM_EVAL_LEDOn(LED5);
    STM_EVAL_LEDOn(LED6); 

    if ((*(__IO uint32_t*) TESTRESULT_ADDRESS) == ALLTEST_PASS)
    {
      TimingDelay = 300;
      /* Waiting User Button is pressed or Test Program condition verified */
      while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00))
      {}
    }
    else
    {
      /* Waiting User Button is Released  or TimeOut*/
      TimingDelay = 300;
      while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00))
      {}
      if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
      {
        TimingDelay = 0x00;
      }
    }
    if (TimingDelay == 0x00)
    {
      /* Turn off LEDs available on STM32F4-Discovery ------------------------*/
      STM_EVAL_LEDOff(LED4);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED5);
      STM_EVAL_LEDOff(LED6); 
      
      /* Waiting User Button is released */
      while (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)
      {}
      
      /* Unlocks the FLASH control register access */
      FLASH_Unlock();
      
      /* Move discovery kit to detect negative and positive acceleration values 
      on X, Y and Z axis */
      Accelerometer_MEMS_Test();
      
      /* Write PASS code at last word in the flash memory */
      FLASH_ProgramWord(TESTRESULT_ADDRESS, ALLTEST_PASS);
      
      while(1)
      {
        /* Toggle Green LED: signaling the End of the Test program */
        STM_EVAL_LEDToggle(LED4);
        Delay(10);
      }
    }
    else
    {
      Demo_Exec();
    }
  }
  else
  {    
    Demo_Exec();
  }
}
Esempio n. 27
0
void MAIN_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  //// -----------------------------------------------------------------------
  //// Begin of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------
  ///  All following settings must be set in the start-up file. You can use 
  ///  DAvE's project file (*.dpt) to include this register values into your 
  ///  compiler EDE.

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON Register:
    ///  ---------------------------------------------------------------------
    ///  - 256 words system stack
    ///  - Internal ROM area mapped to segment 1
    ///  - the segmentation is enabled (CSP is saved/restored during 
    ///  interrupt entry/exit)
    ///  - Internal ROM disabled
    ///  - the pin #BHE is enabled
    ///  - the pins #WR and #BHE retain their normal functions
    ///  - system clock output CLKOUT is disabled
    ///  - latched #CS mode
    ///  - pin #RSTIN is pulled low during the internal reset sequence
    ///  - the on-chip X-Peripherals are enabled and can be accessed
    ///  - accesses to the XBUS peripherals are done internally

    //// this register must be set in the start-up file
    //// SYSCON  =  0x101C

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON1 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON1  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON2 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON2  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON3 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON3  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  --- initialization of the BUSCON 0-4 and ADRRSEL Registers 1-4 ---
    ///  ---------------------------------------------------------------------


    ///  ---------------------------------------------------------------------
    ///  ---------- external bus 0 is enabled ----------
    ///  ---------------------------------------------------------------------
    ///  - 16-bit Multiplexed Bus
    ///  - memory cycle time control: 15 waitstates
    ///  - With read/write delay: activate command 1 TCL after falling edge 
    ///  of ALE
    ///  - chip select mode: address chip select
    ///  - memory tristate control: 1 waitstate
    ///  - ALE lengthening control: lengthened ALE signal
    ///  - Address windows are switched immediately
    ///  - Normal #WR signal

    //// this register must be set in the start-up file
    //// BUSCON0  =  0x06C0




  //// -----------------------------------------------------------------------
  //// End of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------




  //   -----------------------------------------------------------------------
  //   Initialization of the Peripherals:
  //   -----------------------------------------------------------------------

  //   initializes the Parallel Ports
  IO_Init();

  //   initializes the Asynchronous/Synchronous Serial Interface (ASC0)
  ASC0_Init();

  //   initializes the General Purpose Timer Unit (GPT1)
  GPT1_vInit();

  //   initializes the Watchdog Timer (WDT)
  WDT_Init();

  //   initializes the Real Timer Clock (RTC)
  RTC_Init();

  //   initializes the Analog / Digital Converter (ADC)
  ADC_vInit();

  //   initializes the Capture / Compare Unit 2 (CAPCOM2)
  CC2_Init();

  //   initializes the Capture / Compare Unit 6 (CAPCOM6)
  CC6_Init();

  //   initializes the On-Chip CAN Interface 1 (CAN1)
  CAN1_Init();

  // USER CODE BEGIN (Init,3)

  // USER CODE END

  //   globally enable interrupts
  PSW_IEN        =  1;          

} //  End of function MAIN_vInit
Esempio n. 28
0
/*
 *  ======== WCD_Init ========
 *  Purpose:
 *      Module initialization is done by SERVICES Init.
 */
bool WCD_Init(void)
{
	bool fInit = true;
	bool fDRV, fDEV, fCOD, fSERVICES, fCHNL, fMSG, fIO;
	bool fMGR, fPROC, fNODE, fDISP, fNTFY, fSTRM, fRMM;
#ifdef DEBUG
	/* runtime check of Device IOCtl array. */
	u32 i;
	int cmdtable = ARRAY_SIZE(WCD_cmdTable);

	for (i = 1; i < cmdtable; i++)
		DBC_Assert(WCD_cmdTable[i - 1].dwIndex == i);

#endif
	if (WCD_cRefs == 0) {
		/* initialize all SERVICES modules */
		fSERVICES = SERVICES_Init();
		/* initialize debugging module */
		DBC_Assert(!WCD_debugMask.flags);
		GT_create(&WCD_debugMask, "CD");    /* CD for class driver */
		/* initialize class driver and other modules */
		fDRV = DRV_Init();
		fMGR = MGR_Init();
		fPROC = PROC_Init();
		fNODE = NODE_Init();
		fDISP = DISP_Init();
		fNTFY = NTFY_Init();
		fSTRM = STRM_Init();
		fRMM = RMM_init();
		fCHNL = CHNL_Init();
		fMSG = MSG_Init();
		fIO = IO_Init();
		fDEV = DEV_Init();
		fCOD = COD_Init();
		fInit = fSERVICES && fDRV && fDEV && fCHNL && fCOD &&
			fMSG && fIO;
		fInit = fInit && fMGR && fPROC && fRMM;
		if (!fInit) {
			if (fSERVICES)
				SERVICES_Exit();

			if (fDRV)
				DRV_Exit();

			if (fMGR)
				MGR_Exit();

			if (fSTRM)
				STRM_Exit();

			if (fPROC)
				PROC_Exit();

			if (fNODE)
				NODE_Exit();

			if (fDISP)
				DISP_Exit();

			if (fNTFY)
				NTFY_Exit();

			if (fCHNL)
				CHNL_Exit();

			if (fMSG)
				MSG_Exit();

			if (fIO)
				IO_Exit();

			if (fDEV)
				DEV_Exit();

			if (fCOD)
				COD_Exit();

			if (fRMM)
				RMM_exit();

		}
	}
	if (fInit)
		WCD_cRefs++;

	GT_1trace(WCD_debugMask, GT_5CLASS,
		 "Entered WCD_Init, ref count: 0x%x\n",	WCD_cRefs);
	return fInit;
}