Memory Management in ZigBee (a murder caused by a memory space)

Source: Internet
Author: User

This ZigBee project for a long time did not write, and now a little strange to this project, a lot of things do not understand. Today write a simple wireless send applet, has been a problem, the program calls Zstack in the Af_datarequest function, as follows

Af_datarequest ( &Coor_Addr, &App_epDesc,                        APP_CLUSTERID_ADC,                         sizeof (Adc_value),                         (uint8 *) adc_value,                         &AppTransID,                        AF_DISCV_ROUTE,                         AF_DEFAULT_RADIUS ); 

(Uint8 *) Adc_value for the address to send the data, must be a 8-bit unsigned pointer. Then I was very sad to write a structure adc_value, all the code is as follows.

VOID ADC (void)   {  adc_value *adc_value;  adc_value->x=haladcread ( Hal_adc_channel_0,hal_adc_resolution_12);  //calculates the value   adc_value->y=haladcread (HAL_ADC_CHANNEL_1, Hal_adc_resolution_12);//Calculate numerical   adc_value->z=haladcread (Hal_adc_channel_4,hal_adc_resolution_12); /Calculate numerical   af_datarequest ( &Coor_Addr, &App_epDesc,                //Sending Data                         app_clusterid_ adc,                        sizeof (Adc_value),                         (uint8 *) Adc_value,                         &AppTransID,                        AF_DISCV_ROUTE,                        af_ default_radius );  osal_start_timerex (apptaskid,app_adc_evt,5000);    //set timer, loop send   }

after compiling a warning, "the adc_value is used before it value is set", also did not care, download the program to the board, the data sent the first normal, the rest is all the wrong data, and the data values are all the same, Or the program went straight to the fly.

I was baffled, very depressed, but did not know where the problem. Then I found out where the problem was. I wonder if you crossing see what the problem is?

The first line of code Adc_value *adc_value; Only one pointer was declared, but no memory space was allocated, causing the problem. With the Java with the basic problem is ignored! This shows that I am not enough to study hard enough depth. The correct code is:

VOID ADC (void)   {  adc_value *adc_value;  adc_value= (ADC_Value *) Osal_msg_allocate (sizeof (Adc_value));   adc_value->x=haladcread (hal_adc_channel_0,hal_adc_ Resolution_12);   adc_value->y=haladcread (Hal_adc_channel_1,hal_adc_resolution_12);   ADC _value->z=haladcread (Hal_adc_channel_4,hal_adc_resolution_12);   af_datarequest ( &Coor_ addr, &app_epdesc,                        APP_CLUSTERID_ADC,                         sizeof (Adc_value),                         (uint8 *) adc_value,                        &apptransid,                         AF_DISCV_ROUTE,                        AF_DEFAULT_RADIUS );  osal_msg_deallocate (( uint8 *) adc_value);  osal_start_timerex (apptaskid,app_adc_evt,5000);   }


This article is from the "Flying Fish Technology" blog, please be sure to keep this source http://flyingfish.blog.51cto.com/9580339/1586077

Memory Management in ZigBee (a murder caused by a memory space)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.