示例#1
0
//------------------------------------------------------------------------------
//! Firmware start point
void main(void)
{
    // Device initialization

    // Initialize watchdog timer
    WDT_init();

    // Initialize CLOCKs
    CLK_init();

    // Initialize device system timer (used by scheduler)
    STIMER_init();

    // Initialize task queue and schedule
    TASK_init();

    // Enable global interrupts
    MCU_enableInterrupts();
    
    // Initialize system logic
    LED_init();
    
    // Start scheduler which replaces MAIN LOOP and RTOS
    TASK_runScheduler();
    
    // As the scheduler has been started the firmware should never get here!
    while(true);
}
int	main(void) 
{
  extern uchar usbNewDeviceAddr;
  uint8_t i;
  PORTC |= (1<<PC2);

//Reconnect USB
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 0;
  while(--i)
     _delay_ms(2);
  usbDeviceConnect();
  usbInit();
  sei();
  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;
  LED_poll();
//  wdt_enable(WDTO_60MS);
  i2c_init();

  for(;;) 
    {
      if(usbNewDeviceAddr)
	    {
          leds[LED_BLUE].frequency = LED_ON;
		}
      wdt_reset();
      LED_poll();
      usbPoll();
    }
  return 0;
}
示例#3
0
void
setup( void )
{
    NVM_ResetReason_t resetReason;

    /* Assume data is invalid to begin with */
    g_sampleDataValid = false;

    WDT_init();

    LED_init();

    /* Initialize serial UART drivers */
    Serial_init();

    /* Initialize sensors */
    GPS_init();
    OBD_init();

    /* Print or initialize the reset reason */
    if ( NVM_getResetReason( &resetReason ) ) {
        /* Valid reset reason */
        if ( NVM_RESET_REASON_NORMAL != resetReason ) {
            Log_printf( "Reset Reason: 0x%02X\n", resetReason );
        }
    } else {
        /* Invalid reset reason, initialize it */
        NVM_setResetReason( NVM_RESET_REASON_NORMAL );
    }

    /* Start the watchdog timer */
    WDT_enable( WDT_TIMEOUT_MAX );
}
示例#4
0
文件: main.c 项目: gapry/ARM_Labs
int main()
{
	/*
	 * Initialize the SYSTICK timer
	 */
	systick_init();

	/*
	 * Demonstrate use of LED.h/LED.c - modifies hardware registers using C
	 */
	LED_init();
	LED_update(LED_BLUE_ON);
	LED_update(LED_BLUE_OFF);
	LED_update(LED_RED_ON | LED_BLUE_ON | LED_ORANGE_ON | LED_GREEN_ON );

	/*
	 * Demonstrate use of in-line assembly - enable interrupts
	 */
	__asm ("  cpsie i \n" );


	/* Initialize the USART for 9600, 8N1, send '!' - calls into USART2.S */
	/* NOTE: must set USART2 interrupt config register to enable TX/RX interrupts */
	USART2_init();
	USART2_send('!');

	uint32_t test_val = 785904457;
	printHex(785904457);

	/* Wait here forever */
	while(1);

	/* We'll never reach this line */
	return 0;
}
示例#5
0
int main(void)
{
    extern uchar usbNewDeviceAddr;
    uint8_t i;
//Reconnect USB
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i)
        _delay_ms(2);
    usbDeviceConnect();
    usbInit();
    sei();

    leds[LED_RED].frequency = LED_ON;
    LED_init();
    for (i=0; i<3; i++)
        TIMER_delay(250);
    leds[LED_RED].frequency = LED_OFF;
    leds[LED_GREEN].frequency = 1;


    while(1)
    {
        if (TIMER_timeout == 0)
        {
            if(usbNewDeviceAddr)
                leds[LED_BLUE].frequency = LED_ON;
            PORTD ^= (1<<PD7);
            TIMER_start(1);
            usbPoll();
            LED_poll();
        }
    }
}
示例#6
0
文件: main.c 项目: xkwy/xkwy_Lanqiao
int main(void)
{
    u32 t0;
    u32 i;
    RCC->APB2ENR = 0x3D;
    while (1 &~ GPIOA->IDR);
    
    SysTick_Config(72000);
    STM3210B_LCD_Init();
    LED_init();
    
    LCD_DrawPicture(pic);
    
    LCD_SetBackColor(White);
    LCD_SetTextColor(Red);
    
    LCD_DisplayStringLine(Line1, " Hello? ");
    
    while (1)
    {
        if (tick-t0 >= 10)
        {
            t0 = tick;
            LED_Set(~(1<<(++i/20%8)));
            
            sprintf(s, " times: %.2lf s.", t0/1000.0);
            LCD_SetTextColor(Blue);
            LCD_DisplayStringLine(Line3, (u8*)s);
            
        }
    }
}
示例#7
0
文件: main.c 项目: PlugaruT/PAIIP
int main(void)
{
	char ch;
	serial_init(51);
	LED_init();
	
	while(1)
	{
		//print messages on the screen
		printf("Press 1 to turn LED on. \r");
		printf("Press 0 to turn LED off. \r\r");
		//get the input char from keyboard
		ch = serial_getchar();
		
		switch(ch)
		{
			case '0':
				//turn off LED
				printf("LED off!\r");
				LED_off();
				break;
			case '1':
				//turn on LED
				printf("LED on!\r");
				LED_on();
				break;
			default:
				printf("Wrong key!\r");
				break;
		}
	}
}
示例#8
0
int main(void)
{
	clock_prescale_set(clock_div_1);
	SYSTEM_init();
	TIMER_init();

	USB_init();

	/* initialize with 65 keys */
	LAYOUT_init(65);
	LAYOUT_set((struct layout*)LAYOUT_BEGIN);
	LAYOUT_set_callback(&HID_set_scancode_state);

	MATRIX_init(5, rows, 14, cols, (const uint8_t*)matrix, &on_key_press);

	HID_init();
	HID_commit_state();

	LED_init();

	SYSTEM_subscribe(USB_SOF, ANY, MAIN_handle_sof);
	int sleep_tmr = TIMER_add(32, true);
	SYSTEM_subscribe(TIMER, sleep_tmr, MAIN_sleep_timer_handler);

	SYSTEM_add_task(main_task, 0);
	SYSTEM_add_task(RAWHID_PROTOCOL_task, 0);

	SYSTEM_main_loop();
}
示例#9
0
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {                               /* Main Program               */
  char state = 0;
	uint8_t buf[] = {0x5, 0xA, 0x3, 0x5A};
	
	SysTick_Config(SystemCoreClock/100);          /* Generate IRQ each ~10 ms   */
	
  LED_init();                                   /* LED Initialization         */
  SER_init();                                   /* UART#1 Initialization      */
	SPI0_init();

  while (1)
	{                                             /* Loop forever               */		
		if (clock_1s)
		{
			clock_1s = 0;
			state++;
			
			if (state & 0x01)
			{
			  LED_On();
		    sendchar('A');
		    sendchar('\n');
		    sendchar('\r');

        SPI0_send(buf, 4);
		  }
			else
				LED_Off();

		}	
  }
}
示例#10
0
void ICACHE_FLASH_ATTR user_init(void)
{
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	os_delay_us(1000000);

	INFO("System started!\n\r");

	LED_init();
	WIFI_Connect("your-wifi-ssid", "your-wifi-password", userWifiConnectCb);
}
示例#11
0
文件: Blinky.c 项目: nganthony/ECE254
/*----------------------------------------------------------------------------
 *        Main: Initialize and start RTX Kernel
 *---------------------------------------------------------------------------*/
int main (void) {

  SystemInit();                             /* Initialize the MCU clocks     */

  LED_init ();                              /* Initialize the LEDs           */
 
  GLCD_Init();                              /* Initialize the GLCD           */
  GLCD_Clear(White);                        /* Clear the GLCD                */

  os_sys_init(init);                        /* Initialize RTX and start init */
}
示例#12
0
文件: main.c 项目: henrychoi/realtime
int main(void) {
	uint16_t status;

	WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
	LED_init();
	LED_on();
    /* configure the Basic Clock Module */
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;

    BCSCTL2 = SELM_3 + DIVM_0;//MCLK = LFXTCLK/1
#ifdef NECESSARY
    do {
    	int i;
        IFG1 &= ~OFIFG;                           // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--);               // Time for flag to set
    } while ((IFG1 & OFIFG)); // OSCFault flag still set?
#endif
    TACTL = TASSEL_2 | MC_1; /* SMCLK, upmode */
    TACCR0 = TIMER_CLK_HZ/SYSTICK_HZ;
	TACCTL0 = CCIE; /*Enable timer A0 interrupt*/

	//Enable SCLK, SDI, SDO, master
	USICTL0 |= USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE;
	USICKCTL |= USIDIV_0 //this actually means divide by 1
			  | USISSEL_2//Use SMCLK to drive the SPI clk
			  //| USICKPL
			  ;
	USICTL1 |= USICKPH;//delay?
	//USICTL1 |= USIIE;//interrupt enable
	//		;
	P1OUT = BIT4;//Pull up nCS at first
	P1DIR |= BIT4;//nCS is P1.4
	//P1REN |= 0x10;?

	_enable_interrupts();//vs. _BIS_SR(LPM0_bits + GIE);
	LED_off();

	dSPIN_Soft_Stop();
	dSPIN_Reset_Device();

	status = dSPIN_Get_Status();
   	if(status & dSPIN_STATUS_SW_EVN
   		|| (status & dSPIN_STATUS_MOT_STATUS) != dSPIN_STATUS_MOT_STATUS_STOPPED
   		|| status & dSPIN_STATUS_NOTPERF_CMD
   		|| status & dSPIN_STATUS_WRONG_CMD
   		// !(status & dSPIN_STATUS_UVLO)
   		|| !(status & dSPIN_STATUS_TH_SD)
   		|| !(status & dSPIN_STATUS_OCD))
		Q_ERROR();
    if(dSPIN_Busy_HW()) Q_ERROR();
    return 0;
}
示例#13
0
/**
 * @mainpage   
 * 04_UART: implements the UART0 at 115200N8. This example writes "UART0 Initialized..." ,
 *          and the proceeds to repeat everything received. this is polling-only, no interrupt.
 **/
void _main (void)
{
   LED_init();
   
   UART_initUART(UART0,115200,STOP1,PARITY_NONE,FLOW_OFF);
   UART_putString(UART0,"UART0 Initialized...\n",21);
   while(1)
   {
      UART_putC(UART0,UART_getC(UART0));
   }
   return;
}
示例#14
0
/*!
 @brief Program entry point
 */
int main (void) {
	Mode currentMode;
	mainThread_ID = osThreadGetId();
	
	// start threads. Low priority ensures main will finish
	osThreadDef (tM_run, osPriorityBelowNormal, 1, 0);
	tempThread_ID = osThreadCreate( osThread (tM_run), NULL);
	osThreadDef (aM_run, osPriorityBelowNormal, 1, 0);
	accThread_ID = osThreadCreate( osThread (aM_run), NULL);
	
	LED_init();
	buttonInit();
	tM_init();
	aM_init();
	
	// lock both mode semaphores, they are both in "used" mode
	osSemaphoreWait( tempSema, osWaitForever);
	osSemaphoreWait( accSema, osWaitForever);
	

	
	// start in TEMP_MODE
	currentMode = TEMP_MODE;
	osSemaphoreRelease( tempSema);
	
	TIM3_Init(ACC_FREQ);
	
	while(1) {
        //will start and wait for a tap before anything happends
        //it will run the threads though
		osSignalWait(0x1, osWaitForever);
        
        // once we're past here, it means a tap has been detected!
        
		switch( currentMode) {
			case TEMP_MODE:
                // we wait until the semaphore becomes available
				osSemaphoreWait( tempSema, osWaitForever);
				osDelay	(500);
				acc_clearLatch();
				osSemaphoreRelease(accSema);
				currentMode = ACC_MODE;           
			break;
			case ACC_MODE:                
				osSemaphoreWait( accSema, osWaitForever);
				osDelay	(500);
				acc_clearLatch();
				osSemaphoreRelease(tempSema);
				currentMode = TEMP_MODE;
			break;
		}		
	}
}
示例#15
0
文件: main.c 项目: xkwy/xkwy_Lanqiao
int main(void)
{
    RCC->APB2ENR = 0x3D;
    while (1&~GPIOA->IDR);
    
    LED_init();
    
    while (1)
    {
        LED_Set(0xAA); for (u32 i = 0; i < 1000000; i++);
        LED_Set(0x55); for (u32 i = 0; i < 1000000; i++);
    }
}
示例#16
0
/**
 * @mainpage   
 * 03_LED: uses the previous GPIO functions specifically for the USER leds.
 * this should count in binary on the USER leds, from 0 to 15
 **/
void _main (void)
{
	volatile unsigned int ra;
   LED_init();

   unsigned char c = 0;
   for(;;)
	{
      LED_setValue(c++);
		for(ra = 0; ra < TIME; ra ++);
	}
   return;
}
示例#17
0
文件: HINT.c 项目: jmpeer/Audiometer
void HINT_init () {
	
	BTN_init();
	BTQ_init();
	P24_init();
	DISP_init();
	LED_init();
	TIM7_init();
	ROT_init();

	reset();

}
示例#18
0
//如果断言条件不成立,进入了错误状态,就会打印错误信息和用LED来显示状态
void assert_failed(char *file, int line)
{
    //int i;
    LED_init();
    while (1)
    {
#ifdef DEBUG_PRINT
        printf(ASSERT_FAILED_STR, file, line);  //打印错误信息
#endif
        //for (i = 0xffffff; i; i--) ;
        water_lights();                         //用流水灯来指示进入错误状态
        //for (i = 0xffffff; i; i--) ;
    }
}
示例#19
0
文件: main.c 项目: hyrant/fulcrum
int main(void)
{
    /* Set these since libopencm3 expects them and the kernel has already
     * set the clock. */
    rcc_ppre1_frequency = 24000000;
    rcc_ppre2_frequency = 24000000;
    
    LED_init();
    GPIO_init();
    Serial_init();
    HTTP_init();
    
    Serial_run();
}
示例#20
0
int main(void)
{
  extern uchar usbNewDeviceAddr;
  PORTC |= (1<<PC2);
  uint8_t i;
//Reconnect USB
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 0;
  while(--i)
     _delay_ms(2);
  usbDeviceConnect();
  usbInit();
  sei();


  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;

  CHANNELDDR1 &= ~((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELPORT1 |= ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4));
  CHANNELDDR2 &= ~((1 << CHANNEL_5) | (1 << CHANNEL_6));
  CHANNELPORT2 |= ((1 << CHANNEL_5) | (1 << CHANNEL_6));

  uint8_t tmp1,tmp1_old; 
  uint8_t tmp2,tmp2_old;
  while(1)
    {
      if (TIMER_timeout == 0)
        {
          if(usbNewDeviceAddr)
            leds[LED_BLUE].frequency = LED_ON;
          TIMER_start(49);
          usbPoll();
          LED_poll();
        }
      tmp1 = CHANNELPIN1; 
      tmp2 = CHANNELPIN2;
	  if ((tmp1 != tmp1_old) || (tmp2 != tmp2_old))
//      if (((channel1trigger & tmp1) == channel1trigger) || ((channel2trigger & tmp2) == channel2trigger))
        {
		  buffer[buffer_put++] = (tmp1 & ((1 << CHANNEL_1) | (1 << CHANNEL_2) | (1 << CHANNEL_3) | (1 << CHANNEL_4)))
		                        +(tmp2 & ((1 << CHANNEL_5) | (1 << CHANNEL_6))); 
	    }
      tmp1_old = tmp1; 
      tmp2_old = tmp2; 
	}
}
示例#21
0
文件: Exti.c 项目: nganthony/ECE254
/**
 * @brief  Main Function
 */
int main (void) {

  SystemInit();                            /* initialize system               */

  LED_init();

  idxCur = 0;                              /* current led position from 0..7  */
  idxOld = 0;                              /* old     led position from 0..7  */
  dir    = 1;                              /* direction for switching the LED */
  LED_On (idxCur);                         /* switch on  first LED            */

  BUTTON_init();

  while (1);
}
示例#22
0
int main(void)
{
  extern uchar usbNewDeviceAddr;
  uint8_t i,j;
  PORTC |= (1<<PC2);
  /* activate pull-ups except on USB lines */
  USB_CFG_IOPORT   = (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));
  /* all pins input except USB (-> USB reset) */
#ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
  USBDDR    = 0;    /* we do RESET by deactivating pullup */
  usbDeviceDisconnect();
#else
  USBDDR    = (1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT);
#endif
  j = 0;
  while(--j){          /* USB Reset by device only required on Watchdog Reset */
      i = 0;
      while(--i);      /* delay >10ms for USB reset */
  }
#ifdef USB_CFG_PULLUP_IOPORT
  usbDeviceConnect();
#else
  USBDDR    = 0;      /*  remove USB reset condition */
#endif
  usbInit();
  sei();

  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;

  while(1)
    {
      if (TIMER_timeout == 0)
        {
          if(usbNewDeviceAddr)
            leds[LED_BLUE].frequency = LED_ON;
          TIMER_start(10);
          usbPoll();
          LED_poll();
		  KEY_pol();
        }
	}
}
示例#23
0
void ccd_all_pin_init(){
  
 /****************** 2nd Gen Main Board ******************/
   gpio_init(PORTB, 8, GPO, 1);    //PTB8 , SI
   gpio_init(PORTB, 9, GPO, 1);    //PTB9 , Clock / CLK
   gpio_init(PORTB, 10, GPI, 1);   //PTB10, AO(D1)
   
   //gpio_init(PORTE,6,GPI,0); // SW2
   gpio_init(PORTE,8,GPI,0); // SW4
   gpio_init(PORTE,9,GPI,0); // SW5
   
   LED_init(); // To test ccd sampling function is operating
   
   light_sensor_init();
   
   gpio_set(PORTE,26,0); // defatul speed mode = 0
} 
示例#24
0
文件: fsm.c 项目: gapry/ARM_Labs
void fsm_set_state(state_t new_state)
{
	/* only do this if the FSM has been locked! */
	if( fsm_mutex == MUTEX_LOCKED )
	{
		state = new_state;

		switch( state )
		{
		case STATE_RESET:
		case STATE_1:
		default:
			/* Initialize the LEDs */
			LED_init();

			/* Initialize the USART2 for x-over internet communication */
			USART2_init(state1_USART2_callback_fn);

			/* Initialize the USART3 for x-over internet communication */
			USART3_init(state1_USART3_callback_fn);

			/* Turn on just the blue LED */
			LED_update( LED_ORANGE_OFF | LED_RED_OFF | LED_BLUE_ON | LED_GREEN_OFF );
			break;

		case STATE_2:
			/* Turn on the orange LED only */
			LED_update( LED_ORANGE_ON | LED_RED_OFF | LED_BLUE_OFF | LED_GREEN_OFF );

			//Set up the USART interrupts to buffer the received data from the PING
			USART3_init(state2_USART3_callback_fn);
			USART2_init(state2_USART2_callback_fn);

			//Send a ping message to the server
			Wifly_Send_Ping();

			//Start up a 1 second timer - wait 1 second then print
			message_reported = 0;
			systick_init(receive_message_systick_callback);
			set_systick_time(1);
			break;
		}
	}
}
示例#25
0
//=============================================================================
int main(void)
{
  I2C_init();
  LED_init();
  KBD_init();
  RTC_init();
  RTOS_init();
  RTOS_setTaskFunc(set_blink, 0, 500);       // моргание
  RTOS_setTaskFunc(KBD_scan, 10, 0);         // запускаем опрос кнопок
  sei(); 				        			 // Разрешили прерывания
#if (DEBUG == 1)
  RTC_set_time(23, 58, 50); // Test time
  LED_clear();
#endif
  while (1)
  {
    RTOS_dispatchTask();    			     // Вызываем диспетчер в цикле.    
  }
}
示例#26
0
文件: main.c 项目: gapry/ARM_Labs
void main(void)
{
	/* Set up the USART2 9600-8N1 and to call USART2_callback_fn when new data arrives */
	USART2_init(USART2_callback_fn);

	/* Set up the USART3 9600-8N1 and to call USART2_callback_fn when new data arrives */
	USART3_init(USART3_callback_fn);

	/* Set up and initialize the LEDs. */
	LED_init();

	/* Configure user pushbutton and call pushbutton_callback_fn when button press-released */
 	userbutton_init(userbutton_callback_fn);

 	/* Initialize the systick timer with its callback function */
 	systick_init(systick_callback_fn);
 	set_systick_disabled();

	/* initialize the finite state machine */
	fsm_init();

	//Test ping the server
	Wifly_Send_Ping();

	/* Enable interrupts - do this after initializing the system */
	__asm ("  cpsie i \n" );

	//Put the wifi module into command mode
//	USART3_putchar('$');
//	USART3_putchar('$');
//	USART3_putchar('$');
//	USART2_putchar('$');
//	USART2_putchar('$');
//	USART2_putchar('$');//	USART2_putstr("$$$\n\r\0");

	/* Wait here forever - everything is now interrupt driven */
	while(1)
	{
		;;;
	}
}
示例#27
0
文件: main.c 项目: troshing/Eth_SNMP
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  UART_STRUCT US;

  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
  initialize the PLL and update the SystemFrequency variable. */
  SystemInit();
   
  // ------------------------------------------------------------------------
  /* GPIO clock enable */
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);

  /* CAN1 Periph clock enable */
 // RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 | RCC_APB1Periph_USB, ENABLE);
  
  // ------------------------------------------------------------------------
  

  /* Setup SysTick Timer for 10 msec interrupts  */
  RCC_GetClocksFreq(&RCC_Clocks);
  if (SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100))
  {
    /* Capture error */
    while (1);
  }


  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
  
  LED_init();
    
  W5100_Delay_ms(1000);
  
  /* ------- ѕј–јћ≈“–џ ------------------------------ */
  
  // IP
  ip_addr[0] = *((__IO uint8_t*)IP1Address);
  ip_addr[1] = *((__IO uint8_t*)IP2Address);
  ip_addr[2] = *((__IO uint8_t*)IP3Address);
  ip_addr[3] = *((__IO uint8_t*)IP4Address);
    
  // IP адрес не определен
  if ( (ip_addr[0] == 0xFF &&
        ip_addr[1] == 0xFF &&
        ip_addr[2] == 0xFF &&
        ip_addr[3] == 0xFF) ||
        (ip_addr[0] == 0x00 &&
        ip_addr[1] == 0x00 &&
        ip_addr[2] == 0x00 &&
        ip_addr[3] == 0x00)
      )
  {
    ip_addr[0] = 192;
    ip_addr[1] = 168;
    ip_addr[2] = 1;
    ip_addr[3] = 10;
    
    ip_addr32 = ip_addr[0] + (ip_addr[1]<<8) + (ip_addr[2]<<16) + (ip_addr[3]<<24);
    
    
    ui8ParSave = 1;
  }
  
  // ѕќ–“
  port = *((__IO uint16_t*)PortAddress);
  
  // порт не определен
  if (port == 0xFFFF)
  {
    port = 30001;
    ui8ParSave = 1;
  }
  
  // — ќ–ќ—“№
  rate = *((__IO uint32_t*)RateAddress);
  
  // скорость не определена
  if (rate != 9600  &&
      rate != 14400 &&
      rate != 19200 &&
      rate != 38400 &&
      rate != 57600 &&
      rate != 115200)
  {
    rate = 38400;
    ui8ParSave = 1;
  }
  
  // —“ќѕ Ѕ»“џ
  stop_bits = *((__IO uint16_t*)SBAddress);
  
  // стоп биты не определены
  if (stop_bits != USART_StopBits_1 &&
      stop_bits != USART_StopBits_2)
  {
    stop_bits = USART_StopBits_2;
    ui8ParSave = 1;
  }
  
  // „≈“Ќќ—“№
  parity = *((__IO uint16_t*)ParityAddress);
  
  // четность не определена
  if (parity != USART_Parity_No &&
      parity != USART_Parity_Even &&
      parity != USART_Parity_Odd)
  {
    parity = USART_Parity_No;
    ui8ParSave = 1;
  }
  
  // таймаут
  timeout = *((__IO uint16_t*)TimeoutAddress);
  
  // таймаут не определен
  if (timeout > 1000)
  {
    timeout = 50;
    ui8ParSave = 1;
  }
  
  if (ui8ParSave)
  {
    ui8ParSave = 0;
    
    // Unlock the internal flash
    FLASH_Unlock();
      
    __disable_interrupt();
      
    // стираем страницу
    FLASH_ErasePage(IP1Address);
        
    FLASH_ProgramWord(IP1Address, ip_addr32);   
    FLASH_ProgramHalfWord(PortAddress, port);
    FLASH_ProgramWord(RateAddress, rate);
    FLASH_ProgramHalfWord(SBAddress, stop_bits);
    FLASH_ProgramHalfWord(ParityAddress, parity);
    FLASH_ProgramHalfWord(TimeoutAddress, timeout);
      
    __enable_interrupt();
  }
  
  // TIMERS
  Timer_100us_Init();
  Timer_100ms_Init();
  
  // ETHERNET
  W5100_InitLines();
  
  PARAM_STRUCT par;
  par.ui8Mode[0] = MR_TCP;
  par.ui8Mode[1] = MR_TCP;
  par.ui8Mode[2] = MR_UDP;
  
  
  par.ip_addr[0] = ip_addr[0];
  par.ip_addr[1] = ip_addr[1];
  par.ip_addr[2] = ip_addr[2];
  par.ip_addr[3] = ip_addr[3];
  
  par.sub_mask[0] = 255;
  par.sub_mask[1] = 255;
  par.sub_mask[2] = 255;
  par.sub_mask[3] = 0;
  
  par.gtw_addr[0] = 192;
  par.gtw_addr[1] = 168;
  par.gtw_addr[2] = 10;
  par.gtw_addr[3] = 1;
  
  W5100_Init(&par);
  
  
  // RS-485 MODBUS
  US.ui32Rate = rate;
  US.ui16StopBits = stop_bits;
  US.ui16Parity = parity;
  US.ui16Timeout = timeout;
  RS485_InitLines(&US);
  
  // param reset pin init
  Param_Reset_init();
    
  GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_SET);

  while (1)
  {
    if (ui8ResetFlag == 0)
    {
      if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7) == Bit_SET)
      {
        ui8ResetFlag = 1;
        uiResetTimer = 10;
        
        GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_RESET);
      }
    }
    else
    {
      if (uiResetTimer == 0 && GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7) == Bit_RESET)
      {
        ui8ParSave = 1;
        
        GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_SET);
        
        W5100_Delay_ms(1000);
        
        ip_addr[0] = 192;
        ip_addr[1] = 168;
        ip_addr[2] = 1;
        ip_addr[3] = 10;
      }
    }
    
    
    if (ui8ParSave)
    {
      ui8ParSave = 0;
      ui8ResetFlag = 0;
      
       
      // Unlock the internal flash
      FLASH_Unlock();
      
      __disable_interrupt();
      
      // стираем страницу
      FLASH_ErasePage(IP1Address);
        
      ip_addr32 = ip_addr[0] + (ip_addr[1]<<8) + (ip_addr[2]<<16) + (ip_addr[3]<<24);
      FLASH_ProgramWord(IP1Address, ip_addr32);   
      FLASH_ProgramHalfWord(PortAddress, port);
      FLASH_ProgramWord(RateAddress, rate);
      FLASH_ProgramHalfWord(SBAddress, stop_bits);
      FLASH_ProgramHalfWord(ParityAddress, parity);
      FLASH_ProgramHalfWord(TimeoutAddress, timeout);

      __enable_interrupt();
      
      
      ip_addr[0] = *((__IO uint8_t*)IP1Address);
      ip_addr[1] = *((__IO uint8_t*)IP2Address);
      ip_addr[2] = *((__IO uint8_t*)IP3Address);
      ip_addr[3] = *((__IO uint8_t*)IP4Address);
      
      port = *((__IO uint16_t*)PortAddress);
      rate = *((__IO uint32_t*)RateAddress);
      stop_bits = *((__IO uint16_t*)SBAddress);
      parity = *((__IO uint16_t*)ParityAddress);
      timeout = *((__IO uint16_t*)TimeoutAddress);
      
      // запуск watch dog
      IWDG_Enable();
      
      // вываливаемс¤ из приложени¤
      while (1);
    }
  
    UDP_Process_handler();
    TCP_Process_handler1();
  };
  
}
示例#28
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  char is_joint = 1;

  if(is_joint)
  {
	  // init multiplexer pins
	  MX_SPI1_Init();
  }
  else
  {
	  MPX_UART_Init();
  }

  MX_USART1_UART_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
  LED_init();

  if(is_joint)
  {
	  // set spi chip select high
	  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);

	  //init_2D(hspi1, GPIOB, GPIO_PIN_1);
	  init_1D();
  }
  else
  {
	  // set spi chip select high
	  MPX_UART_ONOFF(1);
  }

  huart_T = &huart2;
  huart_U = &huart1;

  float alpha, beta, delta;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  USART_RX_FINISHED=0;
  USART_TX_FINISHED=1;

//  if(HAL_UART_Receive_IT(huart_U, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
//  {
//	  char error = 1;
//  }

  int i = 0;

  //MPX_UART_Open(3);

  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

	if(is_joint & USART_TX_FINISHED)
	{
		get_2D(hspi1, GPIOB, GPIO_PIN_1, &alpha, &beta);
		get_1D(hspi1, GPIOA, GPIO_PIN_4, &delta);

		length = snprintf(usart_buffer, 128, "%f : %f : %f\r\n", alpha, beta, delta);

		USART_TX_FINISHED = 0;
		HAL_UART_Transmit(huart_T, usart_buffer, length, 20);
	}
	else
	{
		//length = snprintf(usart_buffer, 128, "hello");
		//MPX_UART_Transmit(huart_T, i%5, usart_buffer, length, 20);

		//HAL_Delay(200);

		//length = snprintf(usart_buffer, 128, "hello\r\n", alpha, beta, delta);
		//HAL_UART_Transmit(huart_U, usart_buffer, length, 20);
	}

//
//	if(USART_RX_FINISHED==1)
//	{
//		if(aRxBuffer[0]=='r')
//		{
//			HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
//		}
//		else if(aRxBuffer[0]=='b')
//		{
//			HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
//		}
//		/*else if(aRxBuffer[0]=='g')
//		{
//			HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1);
//		}*/
//		else
//		{
//			//HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1);
//			HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
//			HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
//		}
//
//		HAL_UART_Transmit(huart_T, aRxBuffer, RXBUFFERSIZE, 20);
//
//		USART_RX_FINISHED=0;
//
//		if(HAL_UART_Receive_IT(huart_U, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
//		{
//		  char error = 1;
//		}
//	}


	//HAL_UART_Transmit(&huart2, "ABC", 3, 20);

	i++;
  }
  /* USER CODE END 3 */

}
示例#29
0
/** The main function will start toogling between two images on corresponding EPD
 *  depends on specified EPD size or working with EPD Kit Tool */
int main(void) {
	/* Initialize system clock and TI LaunchPad board */
	system_init();

	/*flip image bytes*/
	flip_image_bytes((uint8_t *)&image_array_270_1,(uint8_t *)&image_array_270_1);
//	flip_image_bytes((uint8_t *)&image_array_270_2,(uint8_t *)&image_array_270_2);


	/* Initialize EPD hardware */
	EPD_display_init();
	__enable_interrupt();//enable interrupts
	//__bis_SR_register(GIE);

#if (defined EPD_KIT_TOOL_FUNCTIONS) /** if working with EPD Kit Tool ***************/
	LED_init();
	EPD_Kit_Tool_process_init();
	for(;;) {
		EPD_Kit_tool_process_task();
	}

#else /* if showing two images alternatively ***************************************/
	for(;;) {
		//puts("he");//TODO : remove debug

		/* User selects which EPD size to run demonstration by changing the
		 * USE_EPD_Type in conf_EPD.h
		 * The Image data arrays for each EPD size are predefined at image_data.c */
#if(USE_EPD_Type==EPD_144)
		EPD_display_from_pointer(EPD_144,(uint8_t *)&image_array_144_2,(uint8_t *)&image_array_144_1);
#elif(USE_EPD_Type==EPD_200)
		EPD_display_from_pointer(EPD_200,(uint8_t *)&image_array_200_2,(uint8_t *)&image_array_200_1);
#elif(USE_EPD_Type==EPD_270)
		/* Due to if loading two image arrays for 2.7", the code size will exceed the MSP430G2553 flash.
		 * So the demo will load 1st image continuously.*/
#ifdef G2_Aurora_Ma
		EPD_display_from_pointer(EPD_270,(uint8_t *)&image_array_270_1,(uint8_t *)&image_array_270_1);
#else
		EPD_display_from_pointer(EPD_270,image_array_270_1,image_array_270_1);
#endif
#elif(USE_EPD_Type==EPD_190)
        EPD_display_from_pointer(EPD_190,(uint8_t *)&image_array_190_2,(uint8_t *)&image_array_190_1);
#elif(USE_EPD_Type==EPD_260)
        EPD_display_from_pointer(EPD_260,(uint8_t *)&image_array_260_2,(uint8_t *)&image_array_260_1);
#endif

		/* The interval of two images alternatively change is 5 seconds */
		delay_ms(5000);

		P2OUT |= BIT0;

#if(USE_EPD_Type==EPD_144)
		EPD_display_from_pointer(EPD_144,(uint8_t *)&image_array_144_1,(uint8_t *)&image_array_144_2);
#elif(USE_EPD_Type==EPD_200)
		EPD_display_from_pointer(EPD_200,(uint8_t *)&image_array_200_1,(uint8_t *)&image_array_200_2);
#elif(USE_EPD_Type==EPD_270)
		/* Due to if loading two image arrays for 2.7", the code size will exceed the MSP430G2553 flash.
		 * So the demo will load 1st image continuously.*/
#ifdef G2_Aurora_Ma
		EPD_display_from_pointer(EPD_270,(uint8_t *)&image_array_270_1,(uint8_t *)&image_array_270_1);
#else
	//	EPD_display_from_pointer(EPD_270,flipped_image_array_270_2,flipped_image_array_270_1);
#endif
#elif(USE_EPD_Type==EPD_190)
        EPD_display_from_pointer(EPD_190,(uint8_t *)&image_array_190_1,(uint8_t *)&image_array_190_2);
#elif(USE_EPD_Type==EPD_260)
        EPD_display_from_pointer(EPD_260,(uint8_t *)&image_array_260_1,(uint8_t *)&image_array_260_2);
#endif

		/* The interval of two images alternatively change is 5 seconds */
		delay_ms(5000);

		P2OUT &= ~BIT0;
	}
#endif
}
示例#30
0
int main() {
	U32 T_LED = 0L;  // time of last digit update
	U32 Tow = 0L;    // 1-wire time
	U32 T_btns = 0L; // buttons timer
	U8 old_btns_state = 0;
	U8 show_temp = 0; // =0 to show number; = 1 to show temp

	// Configure clocking
	CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
	// Configure pins
	CFG_GCR |= 1; // disable SWIM
	LED_init();
	CCR |= 0x28; // make shure that we are on level 3 - disabled SW priority
	// Configure Timer1
	// prescaler = f_{in}/f_{tim1} - 1
	// set Timer1 to 1MHz: 16/1 - 1 = 15
	TIM1_PSCRH = 0;
	TIM1_PSCRL = 15; // LSB should be written last as it updates prescaler
	// auto-reload each 1ms: TIM_ARR = 1000 = 0x03E8
	TIM1_ARRH = 0x03;
	TIM1_ARRL = 0xE8;
	// interrupts: update
	TIM1_IER = TIM_IER_UIE;
	// auto-reload + interrupt on overflow + enable
	TIM1_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;

	onewire_setup();
	eeprom_default_setup();

	// enable all interrupts
	enableInterrupts();
	set_display_buf("---");
	if(get_starting_val()){
		matchROM = 1; // if ROMs not empty, start scanning
		starting_val = 0; // reset starting value
	}
	start_temp_reading();
	// Loop
	do {
		if(((U16)(Global_time - T_time) > temper_delay) || (T_time > Global_time)){
			T_time = Global_time;
			if(show_temp){ // show temperature
				temper_delay = TEMPER_delay;
				show_temp = 0;
				if(!temp_ready || temp_readed == ERR_TEMP_VAL){
					set_display_buf("eab");
				}else{
					temp_ready = 0;
					if(temp_readed > -100 && temp_readed < 1000){
						display_int((int)temp_readed, 0);
						display_DP_at_pos(1);
					}else{ // display only integer part
						display_int((int)temp_readed/10, 0);
					}
				}
				if(matchROM) ++starting_val;
			}else{ // show number
				show_temp = 1;
				temper_delay = NUMBER_delay;
				if(matchROM){
					if(get_starting_val()){
						display_int(starting_val+1,0);
						read_next_sensor();
					}else{
						starting_val = 0;
						if(start_temp_reading()){
							if(!get_starting_val()){
								matchROM = 0;
								set_display_buf("eee");
							}else{
								display_int(starting_val+1,0);
								read_next_sensor();
							}
						}
					}
				}else{
					start_temp_reading();
				}
			}
		}
		if((U8)(Global_time - T_LED) > LED_delay){
			T_LED = Global_time;
			show_next_digit();
		}
		if((U8)(Global_time - T_btns) > BTNS_delay){
			T_btns = Global_time;
			if(!block_keys && old_btns_state != buttons_state){
				U8 pressed = old_btns_state & ~buttons_state; // pressed buttons are ones
				if(pressed){ // some buttons were pressed
					if(pressed & STORE_BTN){
						if(onewire_reset()){
							delete_notexistant = 0;
							block_keys = 1;
							onewire_send_byte(OW_READ_ROM);
							while(OW_BUSY);
							ow_process_resdata = store_last_ROM;
							onewire_receive_bytes(8);
						}
					}else if(pressed & DELETE_BTN){
						delete_notexistant = 1;
					}else if(pressed & DELALL_BTN){
						U8 i;
						for(i = 0; i < MAX_SENSORS; i++){
							erase_saved_ROM(i);
							set_display_buf("---");
							matchROM = 0;
						}
					}
					//display_int(pressed, 0);
				}else{ // some buttons released
					//display_int(~old_btns_state & buttons_state, 0); // released are ones
				}
			}
			old_btns_state = buttons_state;
		}
		if(Global_time != Tow){ // process every byte not frequently than once per 1ms
			Tow = Global_time;
			process_onewire();
		}
		if(waitforread){
			if(onewire_reset()){
				ow_process_resdata = send_read_seq;
				waitforread = 0;
				if(!matchROM){
					ow_data_array[0] = OW_READ_SCRATCHPAD;
					ow_data_array[1] = OW_SKIP_ROM;
					onewire_send_bytes(2);
				}else{
					read_next_sensor();
				}
			}
		}
	} while(1);
}