Пример #1
0
void exec3(void)
{
	//RGBInit(TRUE);
    // Enable the GPIO Port and Timer for each LED
    SysCtlPeripheralEnable(RED_GPIO_PERIPH);
    SysCtlPeripheralEnable(GREEN_GPIO_PERIPH);
    SysCtlPeripheralEnable(BLUE_GPIO_PERIPH);

    // Reconfigure each LED's GPIO pad for timer control
    GPIOPadConfigSet(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
    GPIOPinTypeGPIOOutput(GREEN_GPIO_BASE, GREEN_GPIO_PIN);

    GPIOPadConfigSet(BLUE_GPIO_BASE, BLUE_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
    GPIOPinTypeGPIOOutput(BLUE_GPIO_BASE, BLUE_GPIO_PIN);

    GPIOPadConfigSet(RED_GPIO_BASE, RED_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD);
    GPIOPinTypeGPIOOutput(RED_GPIO_BASE, RED_GPIO_PIN);

	while(1)
	{
		GPIOPinWrite(BLUE_GPIO_BASE, BLUE_GPIO_PIN, BLUE_GPIO_PIN);
		DelayTask(100);
		GPIOPinWrite(BLUE_GPIO_BASE, BLUE_GPIO_PIN, 0);
		DelayTask(100);
	}
}
Пример #2
0
void exec(void)
{
  while(1)
  {
	  GPIOPinWrite(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GREEN_GPIO_PIN);
	  DelayTask(200);
	  GPIOPinWrite(GREEN_GPIO_BASE, GREEN_GPIO_PIN, 0);
	  DelayTask(200);
  }
}
Пример #3
0
void exec2(void)
{
  while(1)
  {
	  GPIOPinWrite(RED_GPIO_BASE, RED_GPIO_PIN, RED_GPIO_PIN);
	  DelayTask(150);
	  GPIOPinWrite(RED_GPIO_BASE, RED_GPIO_PIN, 0);
	  DelayTask(150);
  }
}
Пример #4
0
void Keyboard_Handler(void)
{
	// task setup
	INT16U ADSample = 0;
	INT8U Key = NO_KEY;

	// Initialize ACM keyboard for channel 1  
	ACM_Keyb_Setup(Enable, Enable, Rising, ACM_CHANNEL1);

	if (OSSemCreate(0, &sKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	if (OSQueueCreate(&KeyboardBuffer, 64, &qKeyboard) != ALLOC_EVENT_OK)
	{
		while (1){};
	};

	// task main loop
	for (;;)
	{
		// Wait for a keyboard interrupt
		OSSemPend(sKeyboard, 0);
		DelayTask(50);

		// Converts the value of AD to discover the pressed key
		UserEnterCritical();
		ADSample = ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		UserEnterCritical();
		ADSample += ADConvert(KEYB_CHANNEL);
		UserExitCritical();

		ADSample = ADSample >> 1;

		// Find out which key was pressed
		Key = FindKey(ADSample);

		// Copy the key to the keyboard buffer
		if (Key != NO_KEY)
		{
			if (OSQueuePost(qKeyboard, Key) == BUFFER_UNDERRUN)
			{
				// Buffer overflow
				OSCleanQueue(qKeyboard);
			}
		}

		// Enable interrupt to the next key detection
		DelayTask(200);
		ACMEnable();
	}
}
Пример #5
0
void Keyboard_Handler(void)
{
   // task setup
   INT8U  key      = NO_KEY;
   INT32U read = 0;

   ButtonsInit();

   if (OSSemCreate(0,&sKeyboard) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     while(1){};
   };

   if (OSQueueCreate(64, &qKeyboard) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     while(1){};
   };

   // task main loop
   for (;;)
   {
      // Wait for a keyboard interrupt
      OSSemPend (sKeyboard,0);
      DelayTask(50);

      read = GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS);

      // Find out which key was pressed
      key = (INT8U)read;

      // Copy the key to the keyboard buffer
      if(key != NO_KEY)
      {
    	if (OSQueuePost(qKeyboard, key) == BUFFER_UNDERRUN)
        {
          // Buffer overflow
          OSQueueClean(qKeyboard);
        }
      }

      key = NO_KEY;
      DelayTask(200);
      // Enable interrupt to the next key detection
      GPIOIntEnable(BUTTONS_GPIO_BASE, ALL_BUTTONS);
   }
}
Пример #6
0
void EEPROM_ByteWrite(u16 Address, u08 Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

	/* i2c por SW */
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal
	sw_i2c_write(EEPROMAddress & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char)(high_byte(Address)));// Send address to EEPROM (high byte address)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM  (low byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);// Send low byte to EEPROM  (data to write)
	delay_time(I2C_DELAY);// Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	DelayTask(WRITE_CYCLE_TIME);
#else
	/* i2c por HW */

	IIC_transmite(EEPROMAddress, Address, &Data);

#endif
}
Пример #7
0
void System_Time(void)
{
   // task setup
   INT8U i = 0;
   INT8U cnt = 0;
   
   OSResetTime();
  
   // task main loop
   for (;;)
   {
      #if (WATCHDOG == 1)
        __RESET_WATCHDOG();
      #endif
      
      DelayTask(10);
      i++;
      
      VerifyNeighbourhoodLastIDTimeout();
      
      if (i >= 100)
      {
        OSUpdateUptime();
        i = 0;
      }
   }
}
Пример #8
0
void System_Time(void)
{
   // task setup
   INT16U i = 0;

   OSResetTime();
   Init_Calendar();

   // task main loop
   for (;;)
   {
      #if (WATCHDOG == 1)
        __RESET_WATCHDOG();
      #endif

      DelayTask(10);
      i++;

      if (i >= 100)
      {
        i = 0;
        OSUpdateUptime();
        OSUpdateCalendar();
      }
   }
}
Пример #9
0
/*****************************************************************************
* Name:
*    putchar_usb
* In:
*    c: character to be sent
* Out:
*
* Description:
*    Put one character into tx_buffer.
*
* Assumptions:
*    --
*****************************************************************************/
void putchar_usb(char c)
{    
    if(GetStart_transactions() == FALSE) return;
	while(c != (char)cdc_putch(c))
	{
		DelayTask(5);
	}
}
Пример #10
0
void contiki_main(void) {

	another_net();
	//main_minimal_net();

	for (;;) {
		DelayTask(1000);
	} /* loop forever */

}
Пример #11
0
void HeartBeat_LED_Task(void)
{
   /* task setup */
  LED_HEARTBEAT_INIT();
   
   for (;;) 
   {
      LED_HEARTBEAT_TOGGLE();
      DelayTask(200);
   }
}
Пример #12
0
/*****************************************************************************
 * Name:
 *    print
 * In:
 *    s: string
 * Out:
 *    n/a
 *
 * Description:
 *    Print the specified string.
 * Assumptions:
 *
 *****************************************************************************/
void print_usb(char *s)
{
    while(*s)
    {
        while(*s != (char)putch(*s))
        {
            DelayTask(1);
        };
        s++;
    }
}
Пример #13
0
void GPSNET_TxApp(void)
{
   // task setup        
   //UINT_DWORD   latitude;
   //UINT_DWORD   longitude;
   LATITUDE     lat;
   LONGITUDE    lon;
   INT16U       node_id = 0;   
   INT8U        i = 0;     
   
   while(NeighborTable == 0)
   {
      DelayTask(1000);
   }      
          
   // task main loop       
   for (;;)
   {
      
      /* Get node to snif */
      node_id = RequestNodeID();

      if (node_id != 0xFFFE) 
      {        
        for (i=0;i<NEIGHBOURHOOD_SIZE;i++)
        {
          if (node_id == gpsnet_neighbourhood[i].Addr_16b) 
          {
            lat.x = gpsnet_neighbourhood[i].NeighborGPS_Latitude.x;            
            lon.y = gpsnet_neighbourhood[i].NeighborGPS_Longitude.y;
            break;
          }
        }          
        /* Request data */
        // SniferReq(UP_ROUTE, &lat, &lon);      
      }
      
      DelayTask(3000);
   }

}
Пример #14
0
void Tarefa_RS485(void)
{

	CHAR8 c;
	
	rs485_init(9600,UART1_PTD6_PTD7,FALSE,0);
	for(;;)
	{
		rx_rs485(&c);
		putchar_rs485(c);
		DelayTask(10); /* 10 ms */
	}
}
Пример #15
0
/* ATUALIZAR AQUI*/
static __inline void lld_lcdDelay(uint16_t us)
{
  INT16U time;
  if (us<1000)
  {
	  time = 1;
  }
  else
  {
	  time = us/1000;
  }
  DelayTask(time);
}
Пример #16
0
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////   Task Delay Function in miliseconds, seconds,   /////
/////   minutes and hours                              /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Miliseconds, seconds, minutes and hours delay
INT8U DelayTaskHMSM(INT8U hours, INT8U minutes, INT8U seconds, INT16U miliseconds)
{
  INT32U ticks=0;
  INT32U loops=0;
  
  if (minutes > 59)
    return INVALID_TIME;
  
  if (seconds > 59)
    return INVALID_TIME;
  
  if (miliseconds > 999)
    return INVALID_TIME;  
  
  ticks = (INT32U)hours   * 3600L * configTICK_RATE_HZ
        + (INT32U)minutes * 60L   * configTICK_RATE_HZ
        + (INT32U)seconds *         configTICK_RATE_HZ
        + ((INT32U)miliseconds    * configTICK_RATE_HZ)/1000L;
  
  // Task Delay limit = TickCounterOverflow
  if (ticks > 0)
  {
      loops = ticks / 60000L;
      ticks = ticks % 60000L;
      
      (void)DelayTask(ticks);
      
      while(loops > 0)
      {
        (void)DelayTask(60000);
        loops--;
      }
      return OK;
  }
  else
  {
      return NO_TASK_DELAY;
  }
}
Пример #17
0
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/////   Task Delay Function in miliseconds, seconds,   /////
/////   minutes and hours                              /////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Miliseconds, seconds, minutes and hours delay
uint8_t OSDelayTaskHMSM(uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t miliseconds)
{
  uint32_t ticks=0;
  uint32_t loops=0;
  
  if (minutes > 59)
    return INVALID_TIME;
  
  if (seconds > 59)
    return INVALID_TIME;
  
  if (miliseconds > 999)
    return INVALID_TIME;  
  
  ticks = (uint32_t)hours   * 3600L * configTICK_RATE_HZ
        + (uint32_t)minutes * 60L   * configTICK_RATE_HZ
        + (uint32_t)seconds *         configTICK_RATE_HZ
        + ((uint32_t)miliseconds    * configTICK_RATE_HZ)/1000L;
  
  // Task Delay limit = TickCounterOverflow
  if (ticks > 0)
  {
      loops = ticks / 60000L;
      ticks = ticks % 60000L;
      
      (void)DelayTask((uint16_t)ticks);
      
      while(loops > 0)
      {
        (void)DelayTask(60000);
        loops--;
      }
      return OK;
  }
  else
  {
      return NO_TASK_DELAY;
  }
}
Пример #18
0
void Task_2(void)
{
   /* task setup */
   INT8U cont = 0;   
  
   /* task main loop */
   for (;;)
   {
      cont++;
      (void)DelayTask(35);
      
      //Acorda a tarefa 3
      (void)OSSemPost(SemTeste);
   }
}
Пример #19
0
void rs485_tx(const INT8U *data, const INT16U _len)
{
	RS485_TX();
	RS485_RX_DISABLE();
	INT16U len = _len;
	while(len > 0)
	{
		RS485_PUTCHAR((*data));
		data++;		
		len--;
	}		
	RS485_RX_ENABLE();
	DelayTask(2);
	RS485_RX();
	
}
Пример #20
0
void _SoundRecorder_Start_Recording(void)
{
	INT32U RecordingSampleCount = 0;
	
    //_FlexTimer_Enable(FTM0);
  
    do
    {
		OSSemPend(Audio,0);
    	//ADCMicrophoneValues[RecordingSampleCount++] = _ADC0_Read(10,CHANNEL_A);
    
    }while (RecordingSampleCount < (sizeof(ADCMicrophoneValues)/2));
		
    //_FlexTimer_Disable(FTM0);
    //_ADC0_OFF();
    DelayTask(200);    
}
Пример #21
0
/******************************************************************************
 *
 *    @name       Virtual_Com_App
 *
 *    @brief      Implements Loopback COM Port
 *
 *    @param      None
 *
 *    @return     None
 *
 *****************************************************************************
 * Receives data from USB Host and transmits back to the Host
 *****************************************************************************/
void cdc_process(void)
{
    static uint_8 status 	 = 0;
    uint_8 		  sem_status = 0;
	uint_8 size;
	OS_SR_SAVE_VAR;

	size = g_send_size;
	g_send_size = 0;

    /*check whether enumeration is complete or not */
     if((start_app==TRUE) && (start_transactions==TRUE))
     {	
		
		OSEnterCritical();
			is_message_sent = 1;
		OSExitCritical();
		
		status = USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, g_curr_send_buf,size);
		sem_status = OSSemPend(USB_Sem,500);	   
		
		if (sem_status != OK)
		{
			OSEnterCritical();
				is_message_sent = 0;
			OSExitCritical();
		}
		
        if(status != USB_OK)
        {
            /* Send Data Error Handling Code goes here */
        	status = 0;
        }		
     }
#if 0     
     else
     {
    	  while(GetStart_transactions() == FALSE)
    	  {
    		  DelayTask(100);
    	  }
     }
#endif     


}
Пример #22
0
void Tarefa_termometro(void)
{
	/* task setup */
	INT16U digital_temp = 0;
	INT16U bandgap = 0;
	INT16S temperature = 0;

	ADSetup(NormalPower, HighSpeed, ShortSampleTime, 20, 12);

	/* task main loop */
	for (;;)
	{
		(void) DelayTask(30000); /* 30s */

		//////////////////////////////////////////////////////////////
		// Adquire temperatura do core
		//////////////////////////////////////////////////////////////
		UserEnterCritical();
		digital_temp = ADConvert(TEMP_SENSOR_CH);
		UserExitCritical();

		UserEnterCritical();
		bandgap = ADConvert(BANDGAP_CH);
		UserExitCritical();

		digital_temp = (1170 * digital_temp) / bandgap;

		if (digital_temp > 701)
		{
			temperature = 25 - (((digital_temp - 701) * 1000) / 1646);
		}
		else
		{
			temperature = 25 - (((digital_temp - 701) * 1000) / 1769);
		}

		UserEnterCritical();
		CoreTemp = temperature;
		UserExitCritical();
		//////////////////////////////////////////////////////////////         
	}
}
Пример #23
0
void System_Time(void)
{
   // task setup
   INT8U i = 0;
   OSResetTime();   
  
   /* task main loop */
   for (;;)
   {
      #if (WATCHDOG == 1)
        wdt_reset();
      #endif
      (void)DelayTask(10);
      i++;
      if (i >= 100)
      {
        OSUpdateUptime();
        i = 0;
      }
   }
}
Пример #24
0
/*-----------------------------------------------------------------------------------*/
void
slip_arch_writeb(unsigned char c)
{
#if (SLIP_COMM == SLIP_USB)
	while(GetStart_transactions() == FALSE)
	{
		DelayTask(10);
	}
	while(cdc_putch(c) != c)
	{
		//DelayTask(1);
	}
	if (c==SLIP_END)
	{
		cdc_process();
	}
#elif (SLIP_COMM == SLIP_UART)
	uart_putchar(UART_NUMBER, (char)c);
#endif

	buffer_send[buffer_send_i++]=c;
	
}
Пример #25
0
void System_Time(void)
{
   // task setup
   INT8U i = 0;
   OSResetTime(&Hora); 
   OSResetDate(&Data);  
  
   /* task main loop */
   for (;;)
   {
      #if (WATCHDOG == 1)
        __asm
        CLRWDT
        __endasm;
      #endif
      (void)DelayTask(10);
      i++;
      if (i >= 100)
      {
        OSUpdateUptime(&Hora,&Data);
        i = 0;
      }
   }
}
Пример #26
0
void _SoundRecorder_Start_Playing(void)
{
	INT16U PlayingSampleCount = 0;

	//_DAC1_Enable();
	//Sound_AudioAmplifierTurnOn();		//Turn On the Audio Amplifier
	//_FlexTimer_Enable(FTM0);
	
	#if (_VOLUME_CONTROL == 1)
		//Sound_VolumeControl(SetVolumeLevel);
	#endif
	
    do
    {
    	OSSemPend(Audio,0);
    	//_DAC1_Write(ADCMicrophoneValues[PlayingSampleCount++]);
	  
    }while (PlayingSampleCount < (sizeof(ADCMicrophoneValues)/2));

	//_FlexTimer_Disable(FTM0);   
	//_DAC1_Disable();
	Sound_AudioAmplifierStandby();		//Standby the Audio Amplifier
	DelayTask(200);
}
Пример #27
0
unsigned char SetSemaphore(SEM_ID semaphore, unsigned long int clocks_timeout)
{
    unsigned char sem_set ;
    unsigned char abort ;
    clock_t started_at ;
    FILE *file ;
    
    /* attempt to create semaphore as file in required timeout period */
    
    sem_set = FALSE ;
    abort = FALSE ;
    
    started_at = clock() ;
    
    do
    {
        if (IsSemaphoreSet(semaphore))
        {
            if (started_at != (clock_t)-1)
            {
                /* wait for semaphore to clear */

                if (clocks_timeout != 0)
                {
                    DelayTask(1 /* clocks */) ;
                    
                    /* determine if timeout exceeded */
                    
                    if ((unsigned long int)(clock() - started_at) >=
                        clocks_timeout)
                    {
                        /* timeout exceeded */
                        
                        abort = TRUE ;
                    }
                }
                else
                {
                    /* no delay */
                    
                    abort = TRUE ;
                }
            }
            else
            {
                /* failed to obtain system time */
                
                abort = TRUE ;
            }
        }
        else
        {
            /* create semaphore file */

            if ((file = fopen(semaphore, "wb")) != NULL)
            {
                /* success */
                
                sem_set = TRUE ;
                
                /* clean up */
                
                fclose(file) ;
            }
            else
            {
                /* failed to create semaphore file */
                
                abort = TRUE ;
            }
        }
        
    } while (!abort && !sem_set) ;
    
    return sem_set ;
}
Пример #28
0
void GPSNET_FOTA_Task(void)
{
   // task setup
   LATITUDE     latitude;
   LONGITUDE    longitude;   
   INT32U       i = 0;
   INT32U       j = 0;      
   INT32U       endereco_bw;
   INT8U        type = 0;
   INT8U        confirma=0;  
   INT8U        error=0;
   INT8U        nerror=0;   
   INT8U        confirma_rede_error = 0;
   INT8U        *boot_end_status;
   static       INT16U linhas; 
   static       INT16U linhas2;

   
   if (OSSemCreate(0,&Confirma) != ALLOC_EVENT_OK)
   {
     while(1){};
   }; 

   if (OSSemCreate(0,&Bootloader_Event) != ALLOC_EVENT_OK)
   {
     while(1){};
   };      
   
   if (OSMboxCreate(&Bootloader_end,NULL) != ALLOC_EVENT_OK)
   {
      while(1){};      
   }   
   
   
   // task main loop
   for (;;)
   {
      // Wait event from APP layer, no timeout
      OSSemPend(Bootloader_Event,0);
      
      // Set target node address

      UserEnterCritical();
        latitude.x  = GPS_X_tmp.int32u;
        longitude.y = GPS_Y_tmp.int32u;
      UserExitCritical(); 
      
      
      linhas = 0;
      linhas2 = 0;
      endereco_bw = CODE_START;
    
      for(;;) 
      {
           /* loop to read a line of code  */
           for(i=0;i<VECTOR32_SIZE;i++)  
           {
              // return 32-bit words
              data_checksum[i]=Flash_Read(endereco_bw); 
              bootloader_datal[i] = data_checksum[i]; 
              endereco_bw+=4;
           }
            
           linhas++;          
           j=0;                   
          
           type = (INT8U)(bootloader_data[2]);  // get line type
           
           if(type==7) 
           {
              bootloader_data[15] = (INT8U)((CRC_CODIGO_16>>8) & 0xFF);
              bootloader_data[16] = (INT8U)((CRC_CODIGO_16) & 0xFF);
              bootloader_data[17] = (INT8U)((CRC_CODIGO_162>>8) & 0xFF);
              bootloader_data[18] = (INT8U)((CRC_CODIGO_162) & 0xFF);                
              endereco_bw = CODE_START;
           }
           
           error = 0;
           nerror = 0;
           confirma_rede_error = 0;
                    
       envia_de_novo:      
           UserEnterCritical();
             confirma_rede = 0;
             //mensagem = 0;
           UserExitCritical();
             
           // send a line of code         
           i = NetSimpledataXY(UP_ROUTE, &latitude, &longitude, &bootloader_data[0]); 
             
           if(i==OK) 
           {
                 error = 0;
                 // wait for send to complete - SIGNAL_TIMEOUT ms                
                 i = OSSemPend (Confirma, SIGNAL_TIMEOUT); 
                                    
                 if(confirma_rede == DATA_OK) 
                 {
                     confirma_rede_error = 0;
                     linhas2++;
                     if(type==7) 
                       {
                         type=0;                       
                         endereco_bw = CODE_START;
                         //UserEnterCritical();
                          //mensagem = confirma_rede;
                         //UserExitCritical();
                         boot_end_status = (INT8U*)'o';
                         (void)OSMboxPost(Bootloader_end,(void *)boot_end_status);
                         break;
                       }
                 }
                 else
                 {
                     if (confirma_rede == 0)
                     {
                        /* timeout of semaphore pend */
                        confirma_rede_error++;                        
                        // DelayTask(100);
                          
                        if(confirma_rede_error>6) 
                        {
                            confirma_rede_error = 0;
                            
                            //UserEnterCritical();
                            //  mensagem = confirma_rede;
                            //UserExitCritical();                            
                            
                            if(Bootloader_ForceStop == 1){ // desiste 
                              Bootloader_ForceStop = 0;
                              endereco_bw = CODE_START; 
                              boot_end_status = (INT8U*)'f';
                              (void)OSMboxPost(Bootloader_end,(void *)boot_end_status);
                              break;
                            }
                        } 
                        
                        goto envia_de_novo;
                     }
                     endereco_bw = CODE_START;                      
                     //UserEnterCritical();
                     // mensagem = confirma_rede;
                     //UserExitCritical();
                     boot_end_status = (INT8U*)'g';
                     (void)OSMboxPost(Bootloader_end,(void *)boot_end_status);                     
                     break; 
                 } 
           }
           else 
           {
              error++;
              DelayTask(SIGNAL_TIMEOUT);  
              if(error==3) 
              {
                  DelayTask(RadioWatchdogTimeout + SIGNAL_TIMEOUT);   /* wait for a radio reset */
              }
              if(error>6) 
              {
                  error = 0;
                  //UserEnterCritical();
                  //  mensagem = confirma_rede;
                  //UserExitCritical();
                  endereco_bw = CODE_START;
                  boot_end_status = (INT8U*)'f';
                  (void)OSMboxPost(Bootloader_end,(void *)boot_end_status);                  
                  break; 
              } 
              else
              {
                   goto envia_de_novo;  
              }
           }
      }
   }
Пример #29
0
void Tarefa_GPRS(void)
{
	/* task setup */	
	/* Tarefa do Logger para comunicacao com modem na UART2 a 9600 bps */
	#define SEND_STRING0 "AT+CIPSENDI=0,\"GET node/set.json?nodeid=10&data="
	#define SEND_STRING1 "}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1\\r\\nHost: emon-gpsnetcms.rhcloud.com\\r\\n\\r\\n\\r\\n\""
	
	#define SEND_STRING2 "AT+CIPSENDI=0,\"GET /input/post.json?json={pow:"	
	//#define SEND_STRING3 ("}&" API_KEY " HTTP/1.1\r\nHost: " ESP_TCP_SERVER_NAME "\r\n\r\n\r\n")
	#define SEND_STRING3 "}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1\\r\\nHost: emon-gpsnetcms.rhcloud.com\\r\\n\\r\\n\\r\\n\""

	
	const char resp_200_OK[] = "HTTP/1.1 200 OK";
	#define REPLY_LENGTH  (sizeof(resp_200_OK) + 2)

   char valor[] = "01";
   INT8U cnt = 1;
   volatile char c;
   static char resp_serv[REPLY_LENGTH];
   static INT8U resp_cnt = 0;  
   INT16U tentativas = 0;	
	
    /* init ESP_UART */
   	uart_init(ESP_UART,ESP_BAUD,ESP_UART_BUFSIZE,ESP_UART_PINS,ESP_MUTEX,ESP_MUTEX_PRIO);
   	
   	/* init modem */
	modem_send("AT\r\n");
	modem_wait_reply();
	
	modem_send("AT+CWMODE=3\r\n");
	modem_wait_reply();
	
	modem_send(("AT+CWJAP=\"" ESP_AP "\",\"" ESP_PWD "\"\r\n"));
	modem_wait_reply();
	
	modem_send("AT+CIPCREATE=\"TCP\",10201,2048\r\n");	
	modem_wait_reply();
	
	modem_send("AT+CIPCONNECT=0,\"54.160.189.224\",80\r\n");	
	modem_wait_reply();
   	
	/* task main loop */
	for (;;)
	{
		 
		 DelayTask(5000); /* delay de 5s */
		/*   
		  Comando de envio 
		  GET /input/post.json?json={campo:valor}&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1
		  Host:emon-gpsnetcms.rhcloud.com
		  
		  GET /node/set.json?nodeid=10&data=20,20,20,20&apikey=90a004390f3530d0ba10199ac2b1ac3d HTTP/1.1
		  Host:emon-gpsnetcms.rhcloud.com
		  */
		  tentativas++; 
		  modem_send(SEND_STRING2);
		  sprintf(valor,"%d", cnt);
		  modem_send(valor);
		  modem_send(SEND_STRING3);
		  NEWLINE();
		
		  //modem_wait_reply();
		  INT8U keep_data = 0;
		  
		  DelayTask(1000); /* delay de 1s */
		  
			resp_cnt = 0; 
			
			while((c=modem_receive()) != (CHAR8)-1)
			{
				putchar_usb(c);
				
				if (keep_data < 2){
					if (c=='+') 
					{
						keep_data++;
					}
				}else{
					resp_server_ok[resp_cnt++]=c;
					if(resp_cnt == 9) 
					{
						if(c=='1'){
							resp_cnt = 0;
							break;
						}
					}
				}
			}
			
			while((c=modem_receive()) != (CHAR8)-1)
			{
				putchar_usb(c);
			}
		
		  
		  modem_send("AT+CIPRD=0\r\n");
		  
		  DelayTask(10); /* delay de 10ms */
		  
		  /* resposta:
			 HTTP/1.1 200 OK
			.Date: Wed, 03 Dec 2014 18:43:17 GMT
			.Server: Apache/2.2.15 (Red Hat)
			.Content-Length: 2
			.Content-Type: application/json
			.Vary: Accept-Encoding
			.Accept-Ranges: none
			.
			.ok
		  */
			
			while((c=modem_receive()) != (CHAR8)-1)
			{
				putchar_usb(c);
			}
			
			cnt++;
		
		   /* TODO: timeout */
#if 0			
			while(1){
			  		  
			  c=modem_receive();
			  
			  if ((c != '\r') && (c != '\n') && ((resp_cnt < sizeof(resp_serv)-2))){
				 resp_serv[resp_cnt++]=c;      			
			  }else{
				resp_serv[resp_cnt++]='\0';
				if(strcmp (resp_serv,resp_200_OK) == 0){
					cnt = (++cnt)%100;	
				}
				resp_cnt = 0;
				break;
			  }
			}
#endif			
			


	}
}
Пример #30
0
void System_Time(void)
{
	// task setup
	INT16U milis = 0;
	INT16U segundos = 0;

	OSResetTime();

	led_onboard_init();
	
	led_onboard_on();
	
	#if RTC_PRESENTE
		while(Init_Calendar() == FALSE)
		{
			DelayTask(10);
			#if (WATCHDOG == 1)
				__RESET_WATCHDOG();
			#endif			
		}
	#endif	
	
	led_onboard_off();

	// task main loop
	for (;;)
	{
		#if (WATCHDOG == 1)
			__RESET_WATCHDOG();
		#endif     

		DelayTask(10);
		milis += 10;
		
		if (milis >= 1000)
		{
			milis = 0;
			
			OSUpdateUptime();
			OSUpdateCalendar();
			
			segundos++;
			if (segundos == 3600)
			{
				segundos = 0;
				
				#if RTC_PRESENTE				
					Resync_calendar();  // resync with RTC every 3600s = 60min = 1h
				#endif				
				
			}
		}

		///////////////////////////////////////////////////
		///   FatFS Timer Handler                       ///
		///////////////////////////////////////////////////
		disk_timerproc();
		///////////////////////////////////////////////////        
	}

}