Ejemplo n.º 1
0
Archivo: main.c Proyecto: liyanfeng/WSN
void rfSendData(void)
{
    uint8 pTxData[20];
    uint8 ret;
    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();
    //sprintf(pTxData,"distince:%u CM.", uWaveDistance());
    printf("goto while...\r\n");
    // Main loop
    while (TRUE) {
       printf("in while...\r\n");
       dht11_update(pTxData);
       printf("get data ok...\r\n");
       ret = basicRfSendPacket(RECV_ADDR, pTxData, sizeof pTxData);       
       if (ret == SUCCESS) {
          printf("send msg ok!!!\r\n");
          hal_led_on(1);
          halMcuWaitMs(100);
          hal_led_off(1);
          halMcuWaitMs(900); 
       } else {
          printf("send msg error!!!\r\n");
          hal_led_on(1);
          halMcuWaitMs(1000);
          hal_led_off(1);
       }
       
    }
}
Ejemplo n.º 2
0
void rfSendData(void)
{
  uint8 pTxData[20] ={'l','i','y','a','n','f','e','n','g','v','5','8','7','a','b',0};
    uint8 ret;
    uint8 recvCnt=0;
    uint8 ch=0;
    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();
    
    // Main loop
    while (TRUE) {
      recvCnt=0;
      
       ret = basicRfSendPacket(0xffff, pTxData, sizeof pTxData); //广播地址      
       if (ret == SUCCESS) {
          printf("send msg ok\r\n");
          hal_led_on(1);
          halMcuWaitMs(100);
          hal_led_off(1);
          halMcuWaitMs(900); 
       } else {
          printf("send msg error\r\n");
          hal_led_on(1);
          halMcuWaitMs(1000);
          hal_led_off(1);
       }
       
    }
}
Ejemplo n.º 3
0
 __interrupt void T1_ISR(void)            
 {       
          
         
      ++counter;
      if(counter>myrate){
          counter=0;  
          dht11_update();
          sprintf(pTsxData,"shidu:%utmp%u℃\r\n", gdat1, gdat2);
          //printf("sensor data.....");
          //printf(pTsxData);
          //printf("\r\n");
          ret = basicRfSendPacket(0xffff, pTsxData, sizeof pTsxData);       
          ledflashcounter=8;
          hal_led_on(1);
          /*if (ret == SUCCESS) {
              printf("send msg ok\r\n");
           } else {
              printf("send msg error\r\n");
           }*/ 
      }
      if(ledflashcounter>0)
      {
          --ledflashcounter;
          if(ledflashcounter==0)
          {
               hal_led_off(1);
          }
      }
      T1IF=0;       
 }
Ejemplo n.º 4
0
extern hal_result_t hal_led_init(hal_led_t id, const hal_led_cfg_t *cfg)
{
    const hal_gpio_map_t *gm = NULL;
    hal_result_t res = hal_res_NOK_generic;

    if(hal_false == s_hal_led_supported_is(id))
    {
        return(hal_res_NOK_generic);
    }
    
    if(hal_true == s_hal_led_initted_is(id))
    {
        return(hal_res_OK);
    }       
     
    gm = &hal_led__theboardconfig.gpiomap[HAL_led_id2index(id)].led;
    
    // much better to init w/ hal_gpio_init() and not with hl_gpio_init() so that we fill the data structure of the gpio in hal.  
    res = hal_gpio_init(gm->gpio, &s_hal_led_gpio_config);
    
    if(hal_res_OK != res)
    {
        return(res);
    }
    
    s_hal_led_initted_set(id);    
    
    // hal_led_off() must be after s_hal_led_initted_set();
    hal_led_off(id);

    return(hal_res_OK);
}
Ejemplo n.º 5
0
void hal_cpu_enable_irqs_and_sleep(void){
	hal_led_off();
	__enable_irq();
	__asm__("wfe");	// go to sleep if event flag isn't set. if set, just clear it. IRQs set event flag

	// note: hal_uart_needed_during_sleep can be used to disable peripheral clock if it's not needed for a timer
	hal_led_on();
}
Ejemplo n.º 6
0
static void s_osal_cfg_on_fatal_error(void* task, osal_fatalerror_t errorcode, const char * errormsg)
{
    uint8_t tskid = 0;
    char str[128];
    
    osal_task_id_get(task, &tskid);
    snprintf(str, sizeof(str), "error %d from taskid %d: %s\n\r", errorcode, tskid, errormsg);
    hal_trace_puts(str);
    
    hal_sys_irq_disable();

    //hal_led_off(hal_led0);
    hal_led_off(hal_led1);
    hal_led_off(hal_led2);
    hal_led_off(hal_led3);
    hal_led_off(hal_led4);
    hal_led_off(hal_led5);     
    for(;;)
    {
        hal_led_toggle(hal_led5);
        hal_sys_delay(250*1000);        
    }
}
Ejemplo n.º 7
0
static void s_osal_cfg_on_fatal_error(void* task, osal_fatalerror_t errorcode, const char * errormsg)
{
    uint8_t tskid = 0;
    char str[64];    
    osal_task_id_get((osal_task_t*)task, &tskid);
    snprintf(str, sizeof(str), "osalerror %d taskid %d: %s", errorcode, tskid, errormsg);
    
    if(eobool_true == eo_errman_IsErrorHandlerConfigured(eo_errman_GetHandle()))
    {
        // ok ... use the error manager, either in its simple form or in its networked form
        eOerrmanDescriptor_t errdes = {0};
        errdes.code             = eoerror_code_get(eoerror_category_System, eoerror_value_SYS_osalerror);
        errdes.par16            = errorcode;
        errdes.par64            = 0;
        errdes.sourcedevice     = eo_errman_sourcedevice_localboard;
        errdes.sourceaddress    = 0;    
        eo_errman_Error(eo_errman_GetHandle(), eo_errortype_fatal, str, "OSAL", &errdes);                
    }
    else
    {
        if(NULL != errormsg)
        {
            hal_trace_puts(errormsg);
        }
        

        // in case of fatal error we blink all leds but led1
        hal_led_init(hal_led0, NULL);
        hal_led_init(hal_led1, NULL);
        hal_led_init(hal_led2, NULL);
        hal_led_init(hal_led3, NULL);
        hal_led_init(hal_led4, NULL);
        hal_led_init(hal_led5, NULL);
    
        hal_led_off(hal_led0);
        hal_led_off(hal_led1);
        hal_led_off(hal_led2);
        hal_led_off(hal_led3);
        hal_led_off(hal_led4);
        hal_led_off(hal_led5);   

        for(;;)
        {
            hal_sys_delay(100);
            
            hal_led_toggle(hal_led0);
            //hal_led_toggle(hal_led1);
            hal_led_toggle(hal_led2);
            hal_led_toggle(hal_led3);
            hal_led_toggle(hal_led4);
            hal_led_toggle(hal_led5);  
        }
    }    
   
}
Ejemplo n.º 8
0
static void s_hal_core_cfg_on_fatalerror(hal_fatalerror_t errorcode, const char * errormsg)
{
    if(eobool_true == eo_errman_IsErrorHandlerConfigured(eo_errman_GetHandle()))
    {
        // ok ... use the error manager, either in its simple form or in its networked form
        eOerrmanDescriptor_t errdes = {0};
        errdes.code             = eoerror_code_get(eoerror_category_System, eoerror_value_SYS_halerror);
        errdes.par16            = errorcode;
        errdes.par64            = 0;
        errdes.sourcedevice     = eo_errman_sourcedevice_localboard;
        errdes.sourceaddress    = 0;    
        eo_errman_Error(eo_errman_GetHandle(), (hal_fatalerror_warning == errorcode) ? eo_errortype_warning : eo_errortype_fatal, errormsg, "HAL", &errdes);                
    }
    else
    {
        if(NULL != errormsg)
        {
            hal_trace_puts(errormsg);
        }
        
        if(hal_fatalerror_warning == errorcode)
        {
            return;
        }

        // in case of fatal error we blink all leds but led0
        hal_led_init(hal_led0, NULL);
        hal_led_init(hal_led1, NULL);
        hal_led_init(hal_led2, NULL);
        hal_led_init(hal_led3, NULL);
        hal_led_init(hal_led4, NULL);
        hal_led_init(hal_led5, NULL);
    
        hal_led_off(hal_led0);
        hal_led_off(hal_led1);
        hal_led_off(hal_led2);
        hal_led_off(hal_led3);
        hal_led_off(hal_led4);
        hal_led_off(hal_led5);   

        for(;;)
        {
            hal_sys_delay(100);
            
            //hal_led_toggle(hal_led0);
            hal_led_toggle(hal_led1);
            hal_led_toggle(hal_led2);
            hal_led_toggle(hal_led3);
            hal_led_toggle(hal_led4);
            hal_led_toggle(hal_led5);  
        }
    }
}
Ejemplo n.º 9
0
static void overridden_appl_led_error_init(void)
{
    // marco.accame: we init all the leds and we switch them off
    hal_led_init(hal_led0, NULL);
    hal_led_init(hal_led1, NULL);
    hal_led_init(hal_led2, NULL);
    hal_led_init(hal_led3, NULL);
    hal_led_init(hal_led4, NULL);
    hal_led_init(hal_led5, NULL);
    
    hal_led_off(hal_led0);
    hal_led_off(hal_led1);
    hal_led_off(hal_led2);
    hal_led_off(hal_led3);
    hal_led_off(hal_led4);
    hal_led_off(hal_led5);   
}