コード例 #1
0
ファイル: app_neb.c プロジェクト: GumpYangchh/wuzhuangbo
void app_neb_init(void)
{
    #if (NVDS_SUPPORT)
    uint8_t length = NVDS_LEN_NEB_ID;
    #endif // NVDS_SUPPORT

    // Reset the environment
    memset(&app_neb_env, 0, sizeof(app_neb_env));


    #if (NVDS_SUPPORT)
    // Get the current nebulizer ID from the storage
    if (nvds_get(NVDS_TAG_NEB_ID, &length, (uint8_t *)&app_neb_env.curr_neb_id) != NVDS_OK)
    #endif // NVDS_SUPPORT
    {
        // Initialize Nebulizer ID to 0
        app_neb_env.curr_neb_id = 0;
    }

    // Create APP task
    ke_task_create(TASK_APP_NEB, &TASK_DESC_APP_NEB);

    // Go to Disabled state
    ke_state_set(TASK_APP_NEB, APP_NEB_DISABLED);
}
コード例 #2
0
ファイル: app_diss_task.c プロジェクト: nephen/BluetoothLamp
/*
 ****************************************************************************************
 * @brief Handles create database message.      *//**
 *
 * @param[in] msgid     DISS_CREATE_DB_CFM
 * @param[in] param     Pointer to the struct diss_create_db_cfm
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_DISS
 *
 * @return If the message was consumed or not.
 * @description
 * This handler will be called after a database creation. 
 * The status parameter indicates if the DIS has been successfully added or not.
 * Possible values for the status are: ATT_ERR_NO_ERROR and ATT_INSUFF_RESOURCE.
 ****************************************************************************************
 */
int app_diss_create_db_cfm_handler(ke_msg_id_t const msgid,
                                   struct diss_create_db_cfm *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    if (param->status == ATT_ERR_NO_ERROR) 
    {
        app_clear_local_service_flag(BLE_DIS_SERVER_BIT);

#if (QN_WORK_MODE == WORK_MODE_SOC)
        if (app_diss_env->features & DIS_MANUFACTURER_NAME_CHAR_SUP)
            app_set_char_val_req(DIS_MANUFACTURER_NAME_CHAR, sizeof(DIS_MANU_NAME_VAL) - 1, DIS_MANU_NAME_VAL);
        if (app_diss_env->features & DIS_MODEL_NB_STR_CHAR_SUP)
            app_set_char_val_req(DIS_MODEL_NB_STR_CHAR, sizeof(DIS_MODEL_NB_VAL) - 1, DIS_MODEL_NB_VAL);
        if (app_diss_env->features & DIS_SERIAL_NB_STR_CHAR_SUP)
            app_set_char_val_req(DIS_SERIAL_NB_STR_CHAR, sizeof(DIS_SERIAL_NB_VAL) - 1, DIS_SERIAL_NB_VAL);
        if (app_diss_env->features & DIS_HARD_REV_STR_CHAR_SUP)
            app_set_char_val_req(DIS_HARD_REV_STR_CHAR, sizeof(DIS_HW_REV_VAL) - 1, DIS_HW_REV_VAL);
        if (app_diss_env->features & DIS_FIRM_REV_STR_CHAR_SUP)
            app_set_char_val_req(DIS_FIRM_REV_STR_CHAR, sizeof(DIS_FW_REV_VAL) - 1, DIS_FW_REV_VAL);
        if (app_diss_env->features & DIS_SW_REV_STR_CHAR_SUP)
            app_set_char_val_req(DIS_SW_REV_STR_CHAR, sizeof(DIS_SW_REV_VAL) - 1, DIS_SW_REV_VAL);
        if (app_diss_env->features & DIS_SYSTEM_ID_CHAR_SUP)
						app_set_char_val_req(DIS_SYSTEM_ID_CHAR,sizeof(DIS_SYS_ID_VAL) - 1, DIS_SYS_ID_VAL);
        if (app_diss_env->features & DIS_IEEE_CHAR_SUP)
				{
						uint8_t bd_addr[BD_ADDR_LEN];
						nvds_tag_len_t addr_len =  BD_ADDR_LEN;
						if (NVDS_OK != nvds_get(NVDS_TAG_BD_ADDRESS,&addr_len, &bd_addr[0]))
						{
								// NVDS is empty, use default name
								app_set_char_val_req(DIS_IEEE_CHAR, sizeof("NVDS ERR") - 1, (uint8_t *)"NVDS ERR");
						}
            else
						{
//								QPRINTF("\r\nfunc : %s,BD_ADDR : ",__func__);
//								for (uint8_t i = 0;i < BD_ADDR_LEN;i++)
//									QPRINTF("%02X",bd_addr[i]);
//								QPRINTF("\r\n\r\n");
								
								uint8_t dis_bd_addr[sizeof("\x00\x00\x00\xBE\x7C\x08")] = "\x00\x00\x00\xBE\x7C\x08";
								dis_bd_addr[0] = bd_addr[0];
								dis_bd_addr[1] = bd_addr[1];
								dis_bd_addr[2] = bd_addr[2];
								app_set_char_val_req(DIS_IEEE_CHAR,sizeof(dis_bd_addr) - 1, dis_bd_addr);
						}
				}
//            app_set_char_val_req(DIS_IEEE_CHAR, sizeof(DIS_IEEE_CERTIF_VAL) - 1, DIS_IEEE_CERTIF_VAL);
        if (app_diss_env->features & DIS_PNP_ID_CHAR_SUP)
            app_set_char_val_req(DIS_PNP_ID_CHAR, sizeof(DIS_PNP_ID_VAL) - 1, DIS_PNP_ID_VAL);
#endif
    }

    return (KE_MSG_CONSUMED);
}
コード例 #3
0
ファイル: adc.c プロジェクト: NguyenTrongThinh/NTAG_I2C
/**
 ****************************************************************************************
 * @brief   ADC calibration
 * @param[in]    S  ADC initial configuration, contains work clock, reference voltage selection, resolution and input buffer setting
 * @description
 *  This function is used to get the ADC calibration result
 *
 *****************************************************************************************
 */
static void __adc_calibrate(const adc_init_configuration *S)
{
    // read calibration result from NVDS
    uint16_t len = 4;
    uint32_t data = 0;

    if (ADC_INT_REF == S->ref_vol) {
        
        if (NVDS_OK == nvds_get(NVDS_TAG_ADC_INT_REF_SCALE, &len, (uint8_t *)&data)) {
            if ((data>900) && (data<1100)) {
                ADC_SCALE = data;
            }
        }
        
        ADC_VREF = ADC_SCALE;
        ADC_VCM = ADC_SCALE>>1;
        if (NVDS_OK == nvds_get(NVDS_TAG_ADC_INT_REF_VCM, &len, (uint8_t *)&data)) {
            if ((data>450) && (data<550)) {
                ADC_VCM = data;
            }
        }
    }
    else {
コード例 #4
0
/*
****************************************************************************************
* @brief             get_name
* @param[in]         pcCommandString            ÃüÁîºÍ²ÎÊý´æ·ÅµØÖ·
* @param[in]         pcWriteBuffer              дÈë´ËÊý×éµÄÃüÁ±»·¢Ë͵½´®¿Ú
* @param[in]         commpare_length            ÃüÁîËùÕ¼³¤¶È
* @return            None
* @description       »ñÈ¡É豸Ãû£¬ÃüÁî¸ñʽ£ºAT+NAME OR AT+NAME?
*****************************************************************************************/
int get_name( const uint8_t * const pcCommandString,uint8_t* pcWriteBuffer,uint32_t commpare_length)
{
		nvds_tag_len_t name_length = 31 - 5; 
		int len;
		len = commpare_length+1;
		memcpy(pcWriteBuffer, pcCommandString, len);
		pcWriteBuffer[len++] = ':';

    if (NVDS_OK != nvds_get(NVDS_TAG_DEVICE_NAME, &name_length, pcWriteBuffer+len))
    {
        // NVDS is empty, use default name
        name_length = strlen(QN_LOCAL_NAME);
        strcpy((char *)pcWriteBuffer+len, QN_LOCAL_NAME);			
    }
    else
    {
        name_length--; // Discard '\0'
    }
		len+=name_length;
		len+=sprintf((char *)pcWriteBuffer+len,"\r\nOK\r\n");
	return len;
}
コード例 #5
0
/**
 ****************************************************************************************
 * @brief app_api function. Project advertising function. Setup advertise string.
 *
 *
 *
 * @return void.
 ****************************************************************************************
*/
void app_adv_func(struct gapm_start_advertise_cmd *cmd)
{

//  Start advertising. Fill GAPM_START_ADVERTISE_CMD message

     //  Device Name Length
    uint8_t device_name_length;
    int8_t device_name_avail_space;
    uint8_t device_name_temp_buf[64];
    
    cmd->op.code     = GAPM_ADV_UNDIRECT;//GAPM_ADV_UNDIRECT;//GAPM_ADV_NON_CONN;
    cmd->op.addr_src = GAPM_PUBLIC_ADDR;
    cmd->intv_min    = APP_ADV_INT_MIN;
    cmd->intv_max    = APP_ADV_INT_MAX;
    cmd->channel_map = APP_ADV_CHMAP;

    cmd->info.host.mode = GAP_GEN_DISCOVERABLE;

    /*-----------------------------------------------------------------------------------
     * Set the Advertising Data and the Scan Response Data
     *---------------------------------------------------------------------------------*/
    cmd->info.host.adv_data_len       = APP_ADV_DATA_MAX_SIZE;
    cmd->info.host.scan_rsp_data_len  = APP_SCAN_RESP_DATA_MAX_SIZE;
    
    // Advertising Data
    #if (NVDS_SUPPORT)
    if(nvds_get(NVDS_TAG_APP_BLE_ADV_DATA, &cmd->info.host.adv_data_len,
                &cmd->info.host.adv_data[0]) != NVDS_OK)
    #endif //(NVDS_SUPPORT)
    {
        cmd->info.host.adv_data_len = APP_ADV_DATA_LEN;
        memcpy(&cmd->info.host.adv_data[0], APP_ADV_DATA, cmd->info.host.adv_data_len);
    }

    // Scan Response Data
    #if (NVDS_SUPPORT)
    if(nvds_get(NVDS_TAG_APP_BLE_SCAN_RESP_DATA, &cmd->info.host.scan_rsp_data_len,
                &cmd->info.host.scan_rsp_data[0]) != NVDS_OK)
    #endif //(NVDS_SUPPORT)
    {
        cmd->info.host.scan_rsp_data_len = APP_SCNRSP_DATA_LENGTH;
        memcpy(&cmd->info.host.scan_rsp_data[0], APP_SCNRSP_DATA, cmd->info.host.scan_rsp_data_len);
    }

    // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag
    device_name_avail_space = APP_ADV_DATA_MAX_SIZE - cmd->info.host.adv_data_len - 2;

    // Check if data can be added to the Advertising data
    if (device_name_avail_space > 0)
    {
        // Get the Device Name to add in the Advertising Data (Default one or NVDS one)
        #if (NVDS_SUPPORT)
        device_name_length = NVDS_LEN_DEVICE_NAME;
        if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK)
        #endif //(NVDS_SUPPORT)
        {
            // Get default Device Name (No name if not enough space)
            device_name_length = strlen(APP_DEVICE_NAME);
            memcpy(&device_name_temp_buf[0], APP_DEVICE_NAME, device_name_length);
        }

        if(device_name_length > 0)
        {
            // Check available space
            device_name_length = co_min(device_name_length, device_name_avail_space);

            // Fill Length
            cmd->info.host.adv_data[cmd->info.host.adv_data_len]     = device_name_length + 1;
            // Fill Device Name Flag
            cmd->info.host.adv_data[cmd->info.host.adv_data_len + 1] = '\x09';
            // Copy device name
            memcpy(&cmd->info.host.adv_data[cmd->info.host.adv_data_len + 2], device_name_temp_buf, device_name_length);

            // Update Advertising Data Length
            cmd->info.host.adv_data_len += (device_name_length + 2);
        }
    }


#ifdef __DA14581__    
    if (cmd->op.code  == GAPM_ADV_UNDIRECT)
        arch_adv_int = calculate_arch_adv_time(cmd->info.host.adv_data_len,cmd->info.host.scan_rsp_data_len);
    else if (cmd->op.code  == GAPM_ADV_NON_CONN)
        arch_adv_int = 500;
#endif

    return;
}
コード例 #6
0
ファイル: app.c プロジェクト: BillyZhangZ/DA14580_SDK_3_0_4
void app_adv_start(void)
{

    uint8_t device_name_length;
    uint8_t device_name_avail_space;
    uint8_t device_name_temp_buf[64];

    // Allocate a message for GAP
    struct gapm_start_advertise_cmd *cmd = BleMsgAlloc(GAPM_START_ADVERTISE_CMD,
                                           TASK_GAPM, TASK_APP,
                                           sizeof (struct gapm_start_advertise_cmd));

    cmd->op.code     = GAPM_ADV_UNDIRECT;
    cmd->op.addr_src = GAPM_PUBLIC_ADDR;
    cmd->intv_min    = APP_ADV_INT_MIN;
    cmd->intv_max    = APP_ADV_INT_MAX;
    cmd->channel_map = APP_ADV_CHMAP;

    cmd->info.host.mode = GAP_GEN_DISCOVERABLE;

    /*-----------------------------------------------------------------------------------
     * Set the Advertising Data and the Scan Response Data
     *---------------------------------------------------------------------------------*/
    cmd->info.host.adv_data_len       = APP_ADV_DATA_MAX_SIZE;
    cmd->info.host.scan_rsp_data_len  = APP_SCAN_RESP_DATA_MAX_SIZE;

    // Advertising Data
#if (NVDS_SUPPORT)
    if(nvds_get(NVDS_TAG_APP_BLE_ADV_DATA, &cmd->info.host.adv_data_len,
                &cmd->info.host.adv_data[0]) != NVDS_OK)
#endif //(NVDS_SUPPORT)
    {
        cmd->info.host.adv_data_len = APP_DFLT_ADV_DATA_LEN;
        memcpy(&cmd->info.host.adv_data[0], APP_DFLT_ADV_DATA, cmd->info.host.adv_data_len);

        //Add list of UUID
#if (BLE_APP_HT)
        cmd->info.host.adv_data_len += APP_HT_ADV_DATA_UUID_LEN;
        memcpy(&cmd->info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_HT_ADV_DATA_UUID, APP_HT_ADV_DATA_UUID_LEN);
#else
#if (BLE_APP_NEB)
        cmd->info.host.adv_data_len += APP_NEB_ADV_DATA_UUID_LEN;
        memcpy(&cmd->info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_NEB_ADV_DATA_UUID, APP_NEB_ADV_DATA_UUID_LEN);
#endif //(BLE_APP_NEB)
#endif //(BLE_APP_HT)
    }

    // Scan Response Data
#if (NVDS_SUPPORT)
    if(nvds_get(NVDS_TAG_APP_BLE_SCAN_RESP_DATA, &cmd->info.host.scan_rsp_data_len,
                &cmd->info.host.scan_rsp_data[0]) != NVDS_OK)
#endif //(NVDS_SUPPORT)
    {
        cmd->info.host.scan_rsp_data_len = APP_SCNRSP_DATA_LENGTH;
        memcpy(&cmd->info.host.scan_rsp_data[0], APP_SCNRSP_DATA, cmd->info.host.scan_rsp_data_len);
    }

    // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag
    device_name_avail_space = APP_ADV_DATA_MAX_SIZE - cmd->info.host.adv_data_len - 2;

    // Check if data can be added to the Advertising data
    if (device_name_avail_space > 0)
    {
        // Get the Device Name to add in the Advertising Data (Default one or NVDS one)
#if (NVDS_SUPPORT)
        device_name_length = NVDS_LEN_DEVICE_NAME;
        if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK)
#endif //(NVDS_SUPPORT)
        {
            // Get default Device Name (No name if not enough space)
            device_name_length = strlen(APP_DFLT_DEVICE_NAME);
            memcpy(&device_name_temp_buf[0], APP_DFLT_DEVICE_NAME, device_name_length);
        }

        if(device_name_length > 0)
        {
            // Check available space
            device_name_length = device_name_length < device_name_avail_space ? device_name_length : device_name_avail_space;


            // Fill Length
            cmd->info.host.adv_data[cmd->info.host.adv_data_len]     = device_name_length + 1;
            // Fill Device Name Flag
            cmd->info.host.adv_data[cmd->info.host.adv_data_len + 1] = '\x09';
            // Copy device name
            memcpy(&cmd->info.host.adv_data[cmd->info.host.adv_data_len + 2], device_name_temp_buf, device_name_length);

            // Update Advertising Data Length
            cmd->info.host.adv_data_len += (device_name_length + 2);
        }
    }

    //KD app_adv_func(cmd);

    // Send the message
    BleSendMsg(cmd);

#if 0 //(DISPLAY_SUPPORT)
    // Update advertising state screen
    app_display_set_adv(true);
#endif //DISPLAY_SUPPORT

    // We are now connectable
    //ke_state_set(TASK_APP, APP_CONNECTABLE);

    return;
}
コード例 #7
0
ファイル: rwip.c プロジェクト: Samwuzhitao/My_DA14580_SPS
void rwip_init(uint32_t error)
{
    #if (NVDS_SUPPORT && DEEP_SLEEP)
    uint8_t length = 1;
    uint8_t sleep_enable;
    uint8_t ext_wakeup_enable;
    #endif //NVDS_SUPPORT && DEEP_SLEEP

    // Reset RW environment
    memset(&rwip_env, 0, sizeof(rwip_env));
	
	ke_mem_heaps_used = KE_MEM_BLOCK_MAX;

    #if (KE_SUPPORT)
    // Initialize kernel
    ke_init();
    // Initialize memory heap used by kernel.
    #if (KE_MEM_RW)
    // Memory allocated for environment variables

    //ke_mem_init(KE_MEM_ENV,           (uint8_t*)rwip_heap_env,     RWIP_HEAP_ENV_SIZE);
    ke_mem_init(KE_MEM_ENV,(uint8_t*)(jump_table_struct[rwip_heap_env_pos]),     jump_table_struct[rwip_heap_env_size]);	
    #if 1//(BLE_HOST_PRESENT)
    // Memory allocated for Attribute database
    //ke_mem_init(KE_MEM_ATT_DB,        (uint8_t*)rwip_heap_db,      RWIP_HEAP_DB_SIZE);
    ke_mem_init(KE_MEM_ATT_DB,(uint8_t*)(jump_table_struct[rwip_heap_db_pos]),      jump_table_struct[rwip_heap_db_size]);	
    #endif // (BLE_HOST_PRESENT)
    // Memory allocated for kernel messages
    //ke_mem_init(KE_MEM_KE_MSG,        (uint8_t*)rwip_heap_msg,     RWIP_HEAP_MSG_SIZE);
    ke_mem_init(KE_MEM_KE_MSG,(uint8_t*)(jump_table_struct[rwip_heap_msg_pos]),     jump_table_struct[rwip_heap_msg_size]);
    // Non Retention memory block
    //ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)rwip_heap_non_ret, RWIP_HEAP_NON_RET_SIZE);
    ke_mem_init(KE_MEM_NON_RETENTION, (uint8_t*)(jump_table_struct[rwip_heap_non_ret_pos]), jump_table_struct[rwip_heap_non_ret_size]);


    #endif // (KE_MEM_RW)
    #endif //KE_SUPPORT

    #if (GTL_ITF)
    // Initialize the Generic Transport Layer
    gtl_init(rwip_eif_get(RWIP_EIF_AHI));
    #endif //GTL_ITF

    // Initialize RF
    #if (BT_EMB_PRESENT || BLE_EMB_PRESENT)
    rf_init(&rwip_rf);
    SetBits32(BLE_RADIOCNTL1_REG, XRFSEL, 3);

    #endif //BT_EMB_PRESENT || BLE_EMB_PRESENT

    #if (BT_EMB_PRESENT)
    // Initialize BT
    rwbt_init();
    #endif //BT_EMB_PRESENT

    #if (BLE_EMB_PRESENT)
    // Initialize BLE
    rwble_init();
    #endif //BLE_EMB_PRESENT

    #if (BLE_HOST_PRESENT)
    // Initialize BLE Host stack
    rwble_hl_init();
    #endif //BLE_HOST_PRESENT

    #if (DISPLAY_SUPPORT)
    // Initialize display module
    display_init();

    // Add some configuration information to display
    display_add_config();
    #endif //DISPLAY_SUPPORT

    #if (NVDS_SUPPORT && DEEP_SLEEP)
    // Activate deep sleep feature if enabled in NVDS
    if(nvds_get(NVDS_TAG_SLEEP_ENABLE, &length, &sleep_enable) == NVDS_OK)
    {
        if(sleep_enable != 0)
        {
            rwip_env.sleep_enable = true;

            // Set max sleep duration depending on wake-up mode
            if(nvds_get(NVDS_TAG_EXT_WAKEUP_ENABLE, &length, &ext_wakeup_enable) == NVDS_OK)
            {
                if(ext_wakeup_enable != 0)
                {
                    //vm  rwip_env.ext_wakeup_enable = true;
                    rwip_env.ext_wakeup_enable = ext_wakeup_enable;
                }
            }
        }
    }
    #endif //NVDS_SUPPORT && DEEP_SLEEP

    // If FW initializes due to FW reset, send the message to Host
    if(error != RESET_NO_ERROR)
    {
        #if (BT_EMB_PRESENT && HCIC_ITF)
        rwbt_send_message(error);
        #elif (BLE_EMB_PRESENT && HCIC_ITF)
        rwble_send_message(error);
        #elif (BLE_HOST_PRESENT && GTL_ITF)
        rwble_hl_send_message(error);
        #endif //BT_EMB_PRESENT / BLE_EMB_PRESENT
    }

    /*
     ************************************************************************************
     * Application initialization
     ************************************************************************************
     */
    // vm moved to main
    //    if(jump_table_struct[0]==TASK_APP)
    // Initialize APP
    //    app_init();

    func_check_mem_flag = 0;//false;
}