Ejemplo n.º 1
0
/*
 *  Setup ADC module to read in accelerometer and potentiometer values
 */   
void SEC_InitializeADC(void) {
    _mqx_int i;
    char dev_name[10];
    
    fd_adc = fopen(MY_ADC, (const char*)&adc_init);
    if (NULL == fd_adc) {    
        printf("ADC device open failed\n");
        _task_block();
    }
    
    for (i = 0; i < ADC_CH_COUNT; i++) {
        sprintf(dev_name, "%s%d", MY_ADC, i);
        fd_ch[i] = fopen(dev_name, (const char*)&adc_ch_param[i]);
        if (NULL == fd_ch[i]) {    
            printf("adc:%d channel open failed\n", i);
            _task_block();
        }
    }
    
    _time_delay (100);

#if ADC_CH_COUNT > 1
    for (i = 0; i < 3; i++) {
      SEC_Params.last[i] = ReadADC(ADC_ACCX + i);
    }
    
    SEC_Params.flat=SEC_Params.last[ACCY];
#endif

    _time_delay (200);
}
Ejemplo n.º 2
0
void ADC_Task(uint_32 initial_data)
{
    ADC_RESULT_STRUCT data;
    _mqx_int i;
    MQX_FILE_PTR f, f_ch1;

    printf("Opening ADC device ...");
    f = fopen("adc1:", (const char*)&adc_init);
    if(f != NULL)
    {
        printf("done\n");
    }
    else
    {
        printf("failed\n");
        _task_block();
    }

    printf("Opening channel #1 ...");
    f_ch1 = fopen("adc1:" "first", (const char*)&adc_channel_param1);
    if(f_ch1 != NULL)
    {
        printf("done, prepared to start by trigger\n");
    }
    else
    {
        printf("failed\n");
        _task_block();
    }

    _time_delay(300);

    printf("Triggering channel #1...");
    ioctl(f, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);
    printf("triggered!\n");

    for(i = 0; ; i++)
    {
        /* channel 1 sample ready? */
        if (read(f_ch1, &data, sizeof(data)))
        {
        	adc_value = data.result;
            printf("ADC ch 1: %4d \n", data.result);
        }
        else
            printf("               ");

        _time_delay(300);
    }
}
Ejemplo n.º 3
0
void test_tamper (void)
{
    RTC_TAMPER_TYPE         tamper_status;
    RTC_TIME_STRUCT         tamper_time;
    VMCF51EM_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();

    /* Test tamper event */
    puts("\nPress tamper button or remove battery\n");
    puts("or press/hold reset to repeat whole test again.\n\n");

    while (1)
    {
        /* Wait for tamper event assertion */
        while ((_rtc_get_status() & RTC_INT_TMPR_MASK) != RTC_INT_TMPR_MASK) {};

        _rtc_get_tamper_timestamp(&tamper_time);
        tamper_status = _rtc_get_tamper_status();
        print_tamper_event(tamper_status, &tamper_time);

        /* Wait until tamper event is cleared */
        while ((_rtc_get_status() & RTC_INT_TMPR_MASK) == RTC_INT_TMPR_MASK)
        {
            /* Clear tamper event */
            _rtc_clear_requests(RTC_INT_TMPR_MASK);
            /* Wait 200ms time before tamper status checking */
            _time_delay(200);
        }

        /* Print when tamper event was cleared */
        _rtc_get_tamper_timestamp(&tamper_time);
        tamper_status = _rtc_get_tamper_status();
        print_tamper_event(tamper_status, &tamper_time);
    }
}
Ejemplo n.º 4
0
void for_loop_led_task
    (
        uint32_t initial_data
    )
{
    volatile uint32_t i = 0;
    LWGPIO_STRUCT led2;

    /* Initialize LED pin for output */
    if (!lwgpio_init(&led2, BSP_LED2, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH))
    {
        printf("\nLED2 initialization failed.\n");
        _task_block();
    }
    /* Set LED pin to GPIO functionality */
    lwgpio_set_functionality(&led2, BSP_LED2_MUX_GPIO);

    while(1)
    {
        /* Duration of this loop depends on actual core clock */
        for (i = 0; i < 800000; i++) {};
        
        /* To let the idle task run too */
        _time_delay (50);
        
        /* Toggle led 2 */
        lwgpio_toggle_value(&led2);
    }
}
Ejemplo n.º 5
0
static bool phy_ksz8041_init
   (
       ENET_CONTEXT_STRUCT_PTR     enet_ptr
   )
{ 
   uint32_t              phy_status=0;

   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_PHY_LOOPBACK) {
      if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, PHY_MII_REG_CR, &phy_status, MII_TIMEOUT)) {
         phy_status |= PHY_MII_REG_CR_LOOP;
         (*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_WRITE)(enet_ptr, PHY_MII_REG_CR, phy_status, MII_TIMEOUT);
         return TRUE;
      }
   } else {
      if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, PHY_MII_REG_SR, &phy_status, MII_TIMEOUT)) {
         if (phy_status & PHY_MII_REG_SR_AN_ABLE) { 
            // Has auto-negotiate ability
            int i;
            for (i = 0; i < 3 * BSP_ALARM_FREQUENCY; i++) {
               if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, PHY_MII_REG_SR, &phy_status, MII_TIMEOUT)) 
                  if ((phy_status & PHY_MII_REG_SR_AN_COMPLETE) != 0) 
                     return TRUE;
               _time_delay(BSP_ALARM_RESOLUTION);
            }  
         }
         return TRUE;
      }  
   }  
   return FALSE;
}  
Ejemplo n.º 6
0
void runStatusUpdate(os_task_param_t task_init_data)
{
	printf("[Status Update] Task started.\n");

	uint64_t currentIdleCount;						// The current value of the idle task's counter
	uint64_t previousIdleCount = _getIdleCount();	// The value of the idle task counter at the start of the previous update
	uint32_t idleCountDuringPeriod;					// The number of times the idle task counter was incrmeneted during this period
	uint32_t inactiveMilliseconds;					// The number of milliseconds the CPU was inactive for during this period
	uint32_t activeMilliseconds;					// The number of milliseconds the CPU was active for during this period
	uint32_t cpuUtilization;						// The CPU utilization during this period

	while(1){
		_time_delay(STATUS_UPDATE_PERIOD);

		currentIdleCount = _getIdleCount();
		idleCountDuringPeriod = currentIdleCount - previousIdleCount;
		inactiveMilliseconds = _getIdleMilliseconds(idleCountDuringPeriod);

		// It may be possible that the number of elapsed milliseconds is slightly greater than the milliseconds in the status update period
		// due to randomness in the MQX scheduler. If it is greater, simply set the active milliseconds to zero to avoid an overflow.
		activeMilliseconds = (inactiveMilliseconds > STATUS_UPDATE_PERIOD) ? 0 : STATUS_UPDATE_PERIOD - inactiveMilliseconds;
		cpuUtilization = (activeMilliseconds * 100) / STATUS_UPDATE_PERIOD;

		printf("[Status Update] CPU Utilization is: %u %% \n", cpuUtilization);

		previousIdleCount = currentIdleCount;
	}
}
Ejemplo n.º 7
0
void io_task
   (
      uint_32 initial_data
   )
{
    
    puts("*****************************\n");
    puts("IO Task running\n");

    io_init();

    /* Run in 100ms loop to read buttons state  */
    while(1)
    {
    
       /* IO Task is running, wait for timeout */
        _time_delay(100);
    
        switch_poll();
        
        /* blink by LED1 to signalize io_task is running */
        if(timeout == 0) {
            timeout = 1;
            ioctl(file_leds, GPIO_IOCTL_WRITE_LOG1, NULL);
        }
        else {
            timeout = 0;
            ioctl(file_leds, GPIO_IOCTL_WRITE_LOG0, NULL);
        } 
    }
}
Ejemplo n.º 8
0
static uint16_t GPS__u16WaitChar(const char kcChar)
{
	uint16_t u16Counter;
	uint16_t u16Retries=GPS_U16_ERROR;
	char cTemp;
	uint8_t u8Temp;
	
	u16Counter = 0;
	while(  (u16Counter < GPS_MAX_LEN) && (cTemp != kcChar) && (u16Retries>0) )
	{
		u8Temp = Sci_Read((uint8_t*)&cTemp,1);
		if(0 == u8Temp )
		{
			_time_delay(1);
			u16Counter++;
		}
		else
		{
			/* do nothing */
		}
		u16Retries--;
	}
	
	if(0 == u16Retries)
	{
		u16Counter=GPS_U8_ERROR;
	}
	return u16Counter;
}
Ejemplo n.º 9
0
/*TASK*----------------------------------------------------------
*
* Task Name : blink_led_task
* Comments  :
*   Set up LED and button.
*   When user presses a button this task blinks the LED and prints
*   out the number of times the system timer interrupt occurred.
*   If the button is pressed again, the LED is turned off and
*   the number of times the system timer interrupt occurred
*   is also printed out.
*END*-----------------------------------------------------------*/
void blink_led_task
    (
        uint32_t initial_data
    )
{
    /* Initialize led */
    init_led((void *)(&led1));
    /* Initialize button 1 */
    init_interrupt_btn((void *)(&btn1));
    while(1)
    {
        if(TRUE == btn_pressed)
        {
            if (TRUE == prv_btn_pressed)
            {
                prv_btn_pressed = FALSE;
                printf("\nLed starts blinking at tick No. = %d\n", num_tick);
            }
            lwgpio_toggle_value(&led1);
            _time_delay(200);
        }
        else if (FALSE == prv_btn_pressed)
        {
            prv_btn_pressed = TRUE;
            printf("\nLed is off at tick No. = %d\n", num_tick);
            lwgpio_set_value(&led1, LWGPIO_VALUE_HIGH);
        }
    }
}
Ejemplo n.º 10
0
int32_t adc_measure_pm2p5()
{
	//
	uint16_t val = 0;
    if((ADC_SC2_REG(adc_ptr) & ADC_SC2_ADACT_MASK) == 0) {
		/* set once conversion mode */
		ADC_SC3_REG(adc_ptr) = (ADC_SC3_REG(adc_ptr) & (~ADC_SC3_ADCO_MASK) | ADCO_SINGLE);
		/* set sw triger */
		ADC_SC2_REG(adc_ptr) = (ADC_SC2_REG(adc_ptr) & (~ADC_SC2_ADTRG_MASK) | ADTRG_SW);

		ADC_SC1_REG(adc_ptr,0) = ADC_INPUT_CH;

		while(!(ADC_SC1_REG(adc_ptr,0) & ADC_SC1_COCO_MASK)){
			//printf("adc calculating...\n");
			//_time_delay(1);
		}

		val = (uint16_t) (ADC_R_REG(adc_ptr,0));
    }
    else {
      printf("Conversion in progress...\n");
      _time_delay(50);
      val = (uint16_t) (ADC_R_REG(adc_ptr,0));
    }
    return val;
}
Ejemplo n.º 11
0
static boolean phy_dp83xxx_init
   (
       ENET_CONTEXT_STRUCT_PTR     enet_ptr
   )
{ 
   uint_32              phy_status=0;

   if (enet_ptr->PARAM_PTR->OPTIONS & ENET_OPTION_PHY_LOOPBACK) {
      if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMCR, &phy_status, MII_TIMEOUT)) {
         phy_status |= DP83XXX_REG_BMCR_LOOPBACK;
         (*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_WRITE)(enet_ptr, DP83XXX_REG_BMCR, phy_status, MII_TIMEOUT);
         return TRUE;
      }
   } else {
     if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &phy_status, MII_TIMEOUT)) {
        if (phy_status & DP83XXX_REG_BMSR_AUTO_NEG_ABILITY) { 
           // Has auto-negotiate ability
           int i;
           for (i = 0; i < 3 * BSP_ALARM_FREQUENCY; i++) {
              if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &phy_status, MII_TIMEOUT)) 
                 if ((phy_status & DP83XXX_REG_BMSR_AUTO_NEG_COMPLETE) != 0) 
                    return TRUE;
              _time_delay(BSP_ALARM_RESOLUTION);
           }  
        }
        return TRUE;
      }
   }  
   return FALSE;
}  
Ejemplo n.º 12
0
/* 1: Power up mode, 0: Power down mode */
void set_wifi_power_up(uint8_t power_up)
{
  Custom_Api_PowerUpDown(power_up);
  
  if(power_up == 0){
    _time_delay(200);
    set_mcu_lpmode(0);
  }

  if(power_up == 1){
    set_mcu_lpmode(1);
    _time_delay(200);
    AJ_ResetWiFi();
    _time_delay(200);
  }
}
Ejemplo n.º 13
0
void lcd_task
(
        uint32_t initial_data
)
{
    DATE_STRUCT      time_rtc;
    uint32_t         time;
    TIME_STRUCT      ts;
    eLCD_Symbols     spec_sym;
    char             time[5];
    char             state = 0;

    puts("\n\n");
    if (_lcd_init() == IO_ERROR)
    {
        puts("_lcd_init() function returned IO_ERROR\n");
        puts("lcd_task blocked\n\n");
        _task_block();
    }

    puts("TWRPI-SLCD display is connected and lcd_task is running\n");

    _lcd_segments( FALSE );
    while(1)
    {
        _rtc_get_time(&time);
        ts.SECONDS = time;
        ts.MILLISECONDS = 0;
        _time_to_date(&ts, &time_rtc);

        /* post meridiem */
        if( time_rtc.HOUR > 12 )
        {
            time_rtc.HOUR -= 12;
            spec_sym = LCD_AM;
            _lcd_symbol( spec_sym, FALSE );
            spec_sym = LCD_PM;
            _lcd_symbol( spec_sym, TRUE);
        }
        else
        {
            spec_sym = LCD_PM;
            _lcd_symbol( spec_sym, FALSE);
            spec_sym = LCD_AM;
            _lcd_symbol( spec_sym, TRUE);
        }
        sprintf( time, "%2d%2d", time_rtc.HOUR, time_rtc.MINUTE);
        if( time_rtc.MINUTE < 10 )
        {
            time[2] = '0';
        }
        _lcd_puts( time );
        spec_sym = LCD_COL1;
        state = (state + 1) & 1;
        _lcd_symbol( spec_sym, (bool)state );
        _time_delay(1000);
    } /* Endwhile */
} /* Endbody */
Ejemplo n.º 14
0
void Switch_Task(uint_32 param)
{
 
   while (TRUE) {
      Switch_Poll();
      
      // Delay 50 ms 
      _time_delay(50);
   }
}
Ejemplo n.º 15
0
/*TASK*-----------------------------------------------------
 *
 * Task Name : led1_task
 * Comments :
 * This task toggles the LED1 every 1111 milliseconds
 *
 *END*-----------------------------------------------------*/
void led1_task(uint_32 initial_data)
{
  int value = 0;
  printf("\n led1 task \n");
  while (TRUE)
    {
      _time_delay(1111);
      SetOutput(1,value);
      value = value^1;
    }
}
Ejemplo n.º 16
0
void led2_task(uint_32 initial_data)
{
  int value = 0;
  printf("\n led2 task \n");
  while (TRUE)
    {
      _time_delay(2222);
      SetOutput(2,value);
      value = value^1;
    }
}
Ejemplo n.º 17
0
void led3_task(uint_32 initial_data)
{
  int value = 0;
  printf("\n led3 task \n");
  while (TRUE)
    {
      _time_delay(3333);
      SetOutput(3,value);
      value = value^1;
    }
}
Ejemplo n.º 18
0
void led4_task(uint_32 initial_data)
{
  int value = 0;
  printf("\n led4 task \n");
  while (TRUE)
    {
      _time_delay(4444);
      SetOutput(4,value);
      value = value^1;
    }
}
Ejemplo n.º 19
0
void button_task
(
    uint32_t initial_data
)
{

    LWGPIO_STRUCT   button;
    LWGPIO_VALUE    button_state      = LWGPIO_VALUE_HIGH;
    uint32_t        button_integrator = BUTTON_INTEGRATOR_MAXIMUM;

    /* set the pin to input */
    if (!lwgpio_init(&button, BSP_BUTTON2, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))    {
        /* Button initialization failed. */
        _task_block();
    }

    /* Set multiplexer to GPIO functionality */
    lwgpio_set_functionality(&button, BSP_SW2_MUX_GPIO);
    /* Enable pull up */
    lwgpio_set_attribute(&button, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    while(1)
    {

        /* Update the integrator based on the input signal. */
        if (LWGPIO_VALUE_LOW == lwgpio_get_value(&button))        {
            if (button_integrator > 0)  {
                button_integrator--;
            }
        }
        else if (button_integrator < BUTTON_INTEGRATOR_MAXIMUM)    {
            button_integrator++;
        }

        /* Defensive code if integrator got corrupted */
        if (button_integrator > BUTTON_INTEGRATOR_MAXIMUM)
            button_integrator = BUTTON_INTEGRATOR_MAXIMUM;


        /* Post event if integrator reaches limit */
        if ((button_integrator == 0) )   {
            if (button_state == LWGPIO_VALUE_LOW) {
                button_state = LWGPIO_VALUE_HIGH;
                _lwevent_set(&app_event, SW_EVENT_MASK);
            }
        }
        else {
            button_state = LWGPIO_VALUE_LOW;
        }

        _time_delay(BUTTON_SAMPLE_PERIOD_MS);
    }
}
Ejemplo n.º 20
0
void _bsp_aud_temp_codec_hw_init(void)
{
    MQX_FILE_PTR file;
    uint32_t k = 1;

    file = fopen("ioexp0:", NULL);
    if (file != NULL) {
        ioctl(file, IO_IOCTL_IOEXP_SET_PIN_NO,
             (void *)k);
        ioctl(file, IO_IOCTL_IOEXP_SET_PIN_DIR_OUT, NULL);
        ioctl(file, IO_IOCTL_IOEXP_SET_PIN_VAL_LOW, NULL);

        _time_delay(50);
        ioctl(file, IO_IOCTL_IOEXP_SET_PIN_VAL_HIGH, NULL);
        _time_delay(50);

        fclose(file);

        _time_delay(1000);
        _bsp_dspi_io_init(0);
    }

}
Ejemplo n.º 21
0
void Dio_Init(void)
{
	printf("Init LEDs...\n");
    if(FALSE == boLedPortsInit)
    {
    	boLedPortsInit = TRUE;
		if (!lwgpio_init(&stLedRed, BSP_RGBRED, LWGPIO_DIR_OUTPUT, PORT_OFF))
		{
			printf("...RED LED failed!!\n");
		}else
		{
			boRedInit= TRUE;
			printf("R");
			lwgpio_set_functionality(&stLedRed, BSP_RGBRED_MUX_GPIO);
		}
		/*********************************************************************************/
		if (!lwgpio_init(&stLedGreen, BSP_RGBGREEN, LWGPIO_DIR_OUTPUT, PORT_OFF))
		{
			printf("...GREEN LED failed!!\n");
		}else
		{
			boGreenInit = TRUE;
			printf("G");
			lwgpio_set_functionality(&stLedGreen, BSP_RGBGREEN_MUX_GPIO);
		}
		/*********************************************************************************/
		if (!lwgpio_init(&stLedBlue, BSP_RGBBLUE, LWGPIO_DIR_OUTPUT, PORT_OFF))
		{
			printf("...BLUE LED failed!!\n");
		}else
		{
			boBlueInit = TRUE;
			printf("B");
			lwgpio_set_functionality(&stLedBlue, BSP_RGBBLUE_MUX_GPIO);
		}
		if( (TRUE == boRedInit) && (TRUE == boGreenInit) && (TRUE == boBlueInit) )
		{
			printf("...READY!!\n");
		}
		else
		{
			printf("...ERROR on RGB!!\n");
			_time_delay(200);
		}
    }
    else
    {
    	/* do nothing */
    }
}
Ejemplo n.º 22
0
uint_32 PPP_shutdown
   (
      _ppp_handle  handle
       /* [IN] - the PPP state structure */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 
   
   PPP_CFG_PTR    ppp_ptr = handle;
   _rtcs_sem      sem;
   uint_32         error = RTCS_OK;
   /* wait time  in 0.1 Sec */
   uint_32        wait_time  = 50; 
   /* delay time in mS */ 
   uint_32        delay_time = 100; 

   PPP_lowerdown(ppp_ptr);
   ppp_ptr->STOP_RX = TRUE;    
   while(ppp_ptr->STOP_RX)  
   {  
      /* Waiting before Rx task  will be closed or kill it. */
      _time_delay(delay_time);
       wait_time--;
       if(!wait_time)
       {
          error = RTCSERR_TIMEOUT;
          RTCS_task_destroy(ppp_ptr->RX_TASKID);
          break;
       }
   }
   /* Kill Tx task */
   RTCS_sem_init(&sem);
   PPP_send_shutdown(ppp_ptr, &sem);
   RTCS_sem_wait(&sem);
   RTCS_sem_destroy(&sem);
   RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
   CCP_destroy(ppp_ptr);
   LCP_destroy(ppp_ptr);
   PPP_mutex_destroy(&ppp_ptr->MUTEX);
   PPP_memfree(handle);
   return(error);
#else

    return RTCSERR_IP_IS_DISABLED;    

#endif /* RTCSCFG_ENABLE_IP4 */   

} /* Endbody */
Ejemplo n.º 23
0
  void D4DLCD_Delay_ms_Common(unsigned short period)   //delay routine (milliseconds)
  {

    #ifdef MQX_CPU
    	_time_delay(period);
    #else

	    while (period != 0)
	    {
	        	Cpu_Delay100US (10);
	        period--;
	    }
    #endif

  }
Ejemplo n.º 24
0
static boolean MACNET_read_write_mii
   (
      ENET_MemMapPtr             macnet_ptr,
      uchar                      phy_addr,
      uint_32                    reg_index,
      uint_32                    op,
      uint_32                    write_data,
      uint_32_ptr                read_data_ptr,
      uint_32                    timeout
   )
{
   uint_32                    tm;
    
   if (macnet_ptr == NULL) 
      return FALSE;
   
   if (!MACNET_mii_enabled(macnet_ptr))
        return FALSE;
    
   // Clear the MII interrupt bit 
   macnet_ptr->EIR = ENET_EIR_MII_MASK;

   // Kick-off the MII read or write operation 
   macnet_ptr->MMFR = (vuint_32)(0 
      | (ENET_MMFR_ST_MASK & (0x01 << ENET_MMFR_ST_SHIFT))
      | op
      | (ENET_MMFR_PA_MASK & (phy_addr << ENET_MMFR_PA_SHIFT))
      | (ENET_MMFR_RA_MASK & (reg_index << ENET_MMFR_RA_SHIFT))
      | (ENET_MMFR_TA_MASK & (0x02 << ENET_MMFR_TA_SHIFT))
      | (write_data & 0xffff));

    // Poll for MII complete
   for (tm = 0; tm < timeout; tm++)
   {
      if(macnet_ptr->EIR & ENET_EIR_MII_MASK)
         break;
      _time_delay(0);
   }

   if (tm != timeout) 
      if (read_data_ptr) 
         *read_data_ptr = (ENET_MMFR_DATA_MASK & (macnet_ptr->MMFR));

   // Clear the MII interrupt bit 
   macnet_ptr->EIR = ENET_EIR_MII_MASK;

   return (tm != timeout);
}
Ejemplo n.º 25
0
void main_task(uint_32 dest_core)
{
    _pool_id        msgpool;
    THE_MESSAGE_PTR msg_ptr;
    _queue_id       my_qid,temp_qid;
    uint_32         expected;

    printf("\n\n\nMain task started\n");

    /* start aux core (M4) */
    _bsp_aux_core_start((void*)0x3f000000);

    /* wait for P1 to boot */
    _time_delay(1000);

    my_qid   = _msgq_open(MAIN_QUEUE,0);
    msgpool = _msgpool_create(sizeof(THE_MESSAGE), 8, 8, 0);
    msg_ptr = (THE_MESSAGE_PTR)_msg_alloc(msgpool);

    if (msg_ptr != NULL) {
        msg_ptr->HEADER.TARGET_QID = _msgq_get_id((_processor_number) dest_core,RESPONDER_QUEUE);
        msg_ptr->HEADER.SOURCE_QID = my_qid;
        msg_ptr->DATA = 0;
    }

    while (msg_ptr != NULL) {
        expected = msg_ptr->DATA+1;
        printf("Main task sending\n");
        _msgq_send(msg_ptr);
        printf("Main task receiving...");
        msg_ptr = _msgq_receive(MSGQ_ANY_QUEUE, 0);
        printf("done\n");
        if (msg_ptr != NULL) {
           printf("Message: Size=%x, SQID= %x, TQID=%x, DATA = %x\n", msg_ptr->HEADER.SIZE, msg_ptr->HEADER.SOURCE_QID,
               msg_ptr->HEADER.TARGET_QID, msg_ptr->DATA );
           if (msg_ptr->HEADER.SIZE != sizeof(THE_MESSAGE)) {
                log_error("Message wrong size\n");
           } else if (msg_ptr->DATA != expected) {
                log_error("Message data incorrect\n");
           }
           temp_qid                   = msg_ptr->HEADER.SOURCE_QID;
           msg_ptr->HEADER.SOURCE_QID = msg_ptr->HEADER.TARGET_QID;
           msg_ptr->HEADER.TARGET_QID = temp_qid;
           msg_ptr->DATA++;
        }
    }
    log_error("Message alloc/receive failed\n");
}
void watering_system_delay(uint64_t delay){
	uint64_t refresh_time = 60*SECOND;
	
	if (delay == 0)
		return;
	else if (delay < refresh_time)
		refresh_time = delay;
	
	ws_params.progress.total_time = delay;
	ws_params.progress.passed_time = 0;
	
	for (ws_params.progress.passed_time = 0; ws_params.progress.passed_time <= ws_params.progress.total_time; ws_params.progress.passed_time += refresh_time)
		_time_delay(refresh_time);
	
	ws_params.progress.passed_time = delay;
}
Ejemplo n.º 27
0
boolean SEC_GetTime()
{
    boolean res = FALSE;
    
#if DEMOCFG_ENABLE_SNTP
   _ip_address  ipaddr;
   TIME_STRUCT time;
   DATE_STRUCT date;
   char tries = 0;

   /* Try three times to get time */
   while(tries<3)
   {
     _time_delay(1000);
      printf("\nGetting time from time server ... ");

      if (RTCS_resolve_ip_address(SNTP_SERVER,&ipaddr,NULL,0)) {
         /* Contact SNTP server and update time */
         if(SNTP_oneshot(ipaddr,1000)==RTCS_OK)
         {
            printf("Succeeded\n");
            res = TRUE;
            break;
         }
         else
         {
            printf("Failed\n");
         }

      }
      else
      {
         printf("Failed - address not resolved\n");
         break;
      }
    tries++;
   }
   /* Get current time */
   _time_get(&time);
   _time_to_date(&time,&date);
   printf("\nCurrent Time: %02d/%02d/%02d %02d:%02d:%02d\n",
      date.YEAR,date.MONTH,date.DAY,date.HOUR,date.MINUTE,date.SECOND);
#endif

   return res;
}
Ejemplo n.º 28
0
static inline void init_set_vbus_low(LWGPIO_STRUCT * vbus){

    //LWGPIO_STRUCT vbus;
    _time_delay(50);

    /* initialize lwgpio handle vbus for PORTB 8 pin */
    if (!lwgpio_init(vbus, VBUSPIN, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE))
    {
        printf("Initializing VBUS PORTB 8 as GPIO output failed.\n");
        _task_block();
    }
    /* swich pin functionality (MUX) to GPIO mode */
    lwgpio_set_functionality(vbus, VBUS_MUX_GPIO);

    /* write logical 0 to the pin */
    lwgpio_set_value(vbus, LWGPIO_VALUE_LOW); /* set pin to 0 */
}
Ejemplo n.º 29
0
/*FUNCTION*------------------------------------------------
* 
* Function Name: Auto_boot_startup
* Comments     :
*    
*
*END*-----------------------------------------------------*/
void Auto_boot_startup(MQX_FILE_PTR flash_hdl) 
{
   uint_32  timeout;
   boolean autoboot;
   uint_32 image_index = 0;
   
   if (BOOTLOADER_OK != _bootloader_get_autoboot(flash_hdl,&timeout,&image_index)){
      printf("\nError can't get kernel image!");
      printf("\nPlease setup your network to take image from TFTP server");
      printf("\n");
      return;
   }
   if (image_index) {
      printf("\nBooting from image %d...",image_index);
      printf("\nHit any key to stop autoboot:");
      
      while(1) {
         printf("%2d",timeout);
         if(status()) {
            autoboot = FALSE;
            fflush(stdin);
            break;
         }
         _time_delay(1000);
         
         autoboot = TRUE;
         timeout--;
         if(0 == timeout)
            break;
      }
      
      if(autoboot) {
        if(MQX_OK == _bootloader_load(flash_hdl, image_index)){
            printf("\n");
            /* Exit bootloader app and execute the new image */
            _mqx_exit(0);
        }
        else {
           printf("\nError");
        }      
      }
   }
   return;
}
Ejemplo n.º 30
0
void setup_clock(void)
{
    uint32_t ret = 0, i = 0;
    uint32_t sntp_connected = 0;
    uint32_t sntp_max_tries = 3;
    TIME_STRUCT time_s;
    DATE_STRUCT date_s;

    /* NTP server: nist1-lnk.binary.net */
    _ip_address ipaddr = IPADDR(216,229,0,179);

    for (i = 0; i < sntp_max_tries; i++) {

        printf("Getting time from NTP server [ attempt %d of %d ]...\n",
                i+1, sntp_max_tries);

        /* update time from NTP server */
        ret = SNTP_oneshot(ipaddr, 5000);

        if (ret == RTCS_OK) {
            sntp_connected = 1;
            printf("SNTP successfully updated device time\n");
            break;
        } else if (ret == RTCSERR_TIMEOUT) {
            printf("SNTP attempt timed out.\n");
        }

        _time_delay(1000);
    }

    if (sntp_connected == 0) {
        err_sys("SNTP failed to update device time");
    }

    /* print device time, for debug purposes */
    _time_get(&time_s);
    _time_to_date(&time_s, &date_s);
    printf("Current time: %02d/%02d/%02d %02d:%02d:%02d\n",
            date_s.YEAR, date_s.MONTH, date_s.DAY, date_s.HOUR, date_s.MINUTE,
            date_s.SECOND);

    return;
}