文档详情

CC2530简介课件.ppt

发布:2017-05-22约2.84万字共80页下载文档
文本预览下载声明
* 应用程序任务 Z-stack的任何一个子系统都作为OSAL的一个任务,因此在开发应用层的时候,必须通过创建OSAL任务来运行应用程序。通过osalInitTasks( )函数创建OSAL任务 任何OSAL任务必须分为两步:一是进行任务初始化;二是处理任务事件。 * OSAL的任务处理 主循环中的两个关键数组*tasksEvents与*tasksArr。 tasksEvents存放从序号为0到tasksCnt每个任务在本次循环中是否要被运行, 需要运行的任务其值非0,否则为0。 tasksArr数组则存放了对应每个任务的入口地址,只有在tasksEvents中记录的需要运行的任务,在本次循环中才会被调用到。 * Sensor发送数据的函数 static void sendReport(void) { uint8 pData[SENSOR_REPORT_LENGTH]; // 存放数据的数组 static uint8 reportNr = 0; uint8 txOptions; pData[SENSOR_TEMP_OFFSET] = readTemp(); // Read and report temperature value pData[SENSOR_VOLTAGE_OFFSET] = readVoltage(); // Read and report voltage value pData[SENSOR_PARENT_OFFSET] = HI_UINT16(parentShortAddr); pData[SENSOR_PARENT_OFFSET + 1] = LO_UINT16(parentShortAddr); // Set ACK request on each ACK_INTERVAL report // If a report failed, set ACK request on next report if ( ++reportNrACK_REQ_INTERVAL reportFailureNr == 0 ) { txOptions = AF_TX_OPTIONS_NONE; } else { txOptions = AF_MSG_ACK_REQUEST; reportNr = 0; } // Destination address 0xFFFE: Destination address is sent to previously // established binding for the commandId. zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 ); } * Sensor读温度的函数 static int8 readTemp(void) { static uint16 voltageAtTemp22; static uint8 bCalibrate=TRUE; // Calibrate the first time the temp sensor is read uint16 value; int8 temp; ATEST = 0x01; TR0 |= 0x01; ADCIF = 0; /* Clear ADC interrupt flag */ ADCCON3 = (HAL_ADC_REF_125V | HAL_ADC_DEC_512 | HAL_ADC_CHN_TEMP); while ( !ADCIF ); /* Wait for the conversion to finish */ value = ADCL; /* Get the result */ value |= ((uint16) ADCH) 8; value = 4; // Use the 12 MSB of adcValue/* /* Assume ADC = 1480 at 25C and ADC = 4/C */ #define VOLTAGE_AT_TEMP_25 1480 #define TEMP_COEFFICIENT 4 temp = 22 + ( (value - voltageAtTemp22) / TEMP_COEFFICIENT ); if( temp = 100) { // Set 0C
显示全部
相似文档