Esempio n. 1
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATTC_READ_IND message.
 * Generic event received after every simple read command sent to peer server.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gattc_read_ind_handler(ke_msg_id_t const msgid,
                                    struct gattc_read_ind const *param,
                                    ke_task_id_t const dest_id,
                                    ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct anpc_env_tag *anpc_env = PRF_CLIENT_GET_ENV(dest_id, anpc);

    if (anpc_env != NULL)
    {
        ASSERT_ERR(anpc_env->operation != NULL);

        // Prepare the indication to send to the application
        struct anpc_value_ind *ind = KE_MSG_ALLOC(ANPC_VALUE_IND,
                                                  anpc_env->con_info.appid,
                                                  anpc_env->con_info.prf_id,
                                                  anpc_value_ind);

        ind->conhdl   = gapc_get_conhdl(anpc_env->con_info.conidx);

        switch (((struct anpc_cmd *)anpc_env->operation)->operation)
        {
            // Read Supported New Alert Category Characteristic value
            case (ANPC_ENABLE_RD_NEW_ALERT_OP_CODE):
            {
                ind->att_code = ANPC_RD_SUP_NEW_ALERT_CAT;
                ind->value.supp_cat.cat_id_mask_0 = param->value[0];
                // If cat_id_mask_1 not present, shall be considered as 0
                ind->value.supp_cat.cat_id_mask_1 = (param->length > 1)
                                                    ? param->value[1] : 0x00;
            } break;

            case (ANPC_ENABLE_RD_UNREAD_ALERT_OP_CODE):
            {
                ind->att_code = ANPC_RD_SUP_UNREAD_ALERT_CAT;
                ind->value.supp_cat.cat_id_mask_0 = param->value[0];
                // If cat_id_mask_1 not present, shall be considered as 0
                ind->value.supp_cat.cat_id_mask_1 = (param->length > 1)
                                                    ? param->value[1] : 0;
            } break;

            case (ANPC_READ_OP_CODE):
            {
                ind->att_code      = ((struct anpc_read_cmd *)anpc_env->operation)->read_code;
                ind->value.ntf_cfg = co_read16(&param->value[0]);
            } break;

            default:
            {
                ASSERT_ERR(0);
            } break;
        }

        // Send the indication
        ke_msg_send(ind);
    }
    // else ignore the message

    return (KE_MSG_CONSUMED);
}
Esempio n. 2
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATTC_DISC_SVC_IND message.
 * The handler stores the found service details for service discovery.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gattc_disc_svc_ind_handler(ke_msg_id_t const msgid,
                                      struct gattc_disc_svc_ind const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct anpc_env_tag *anpc_env = PRF_CLIENT_GET_ENV(dest_id, anpc);

    if (anpc_env != NULL)
    {
        ASSERT_ERR(anpc_env->operation != NULL);
        ASSERT_ERR(((struct anpc_cmd *)anpc_env->operation)->operation == ANPC_ENABLE_OP_CODE);

        // Keep only one instance of the service
        if (anpc_env->nb_svc == 0)
        {
            // Keep the start handle and the end handle of the service
            anpc_env->ans.svc.shdl = param->start_hdl;
            anpc_env->ans.svc.ehdl = param->end_hdl;
            anpc_env->nb_svc++;
        }
    }

    return (KE_MSG_CONSUMED);
}
Esempio n. 3
0
/**
 ****************************************************************************************
 * @brief Handles reception of the APP_MODULE_INIT_CMP_EVT messgage
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_module_init_cmp_evt_handler(ke_msg_id_t const msgid,
                                           const struct app_module_init_cmp_evt *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_DB_INIT)
    {
        if (param->status == CO_ERROR_NO_ERROR)
        {
            // Add next required service in the database
            if (app_db_init())
            {
                // No more service to add in the database, start application
                app_db_init_complete_func();
            }
        }
        else
        {
            // An error has occurred during database creation
            ASSERT_ERR(0);
        }
    }
    else
    {
        // APP_DB_INIT state is used to wait the APP_MODULE_INIT_CMP_EVT message
        ASSERT_ERR(0);
    }
    
    return (KE_MSG_CONSUMED);
}
void uart_write_ext_wkup_func(uint8_t *bufptr, uint32_t size, void (*callback) (uint8_t))
{
    // Sanity check
    ASSERT_ERR(bufptr != NULL);
    ASSERT_ERR(size != 0);
    ASSERT_ERR(uart_env.tx.bufptr == NULL);
	
		GPIO_SetActive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN);
			
    // Prepare TX parameters
    uart_env.tx.size = size;
    uart_env.tx.bufptr = bufptr;
		uart_env.tx.callback = callback;

    /* start data transaction
     * first isr execution is done without interrupt generation to reduce
     * interrupt load
     */
    uart_thr_empty_isr();
    if (uart_env.tx.bufptr != NULL)
    {
			uart_thr_empty_setf(1);
    }
		GPIO_SetInactive (EXT_WAKEUP_PORT, EXT_WAKEUP_PIN);
}
Esempio n. 5
0
//##ModelId=48DC5D4603A0
bool TiLib_OSD_Driver::Init()
{
// Init a big GraphicsDisplaySurface to draw.
    if (gfxMap.uwWidth != 0) {
    	return false;
    }
	//enable argb4444 surface to both Component & Composite out
	ASSERT_ERR( (GI_NO_ERROR == GraphicsSurfaceCreate( HAL_GRAPHICS_MODE_ARGB8888, SCREEN_WIDTH, SCREEN_HEIGHT, &gfxMap)));

    ASSERT_ERR( (GI_NO_ERROR == GraphicsDisplayDestRectSet( HAL_GRAPHICS_DISPLAY0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)));
    ASSERT_ERR( (GI_NO_ERROR == GraphicsDisplayDestRectSet( HAL_GRAPHICS_DISPLAY1, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)));

    ASSERT_ERR( (GI_NO_ERROR == GraphicsDisplaySurfaceSet( HAL_GRAPHICS_DISPLAY_ALL, &gfxMap, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)));

    GraphicsDisplaySurfaceEnableSet(HAL_GRAPHICS_DISPLAY0, TRUE);
    GraphicsDisplaySurfaceEnableSet(HAL_GRAPHICS_DISPLAY1, TRUE); 

    getSetOnScreenHandle(DO_SET, (PSURFACE) &gfxMap);    //set CURRENT_ONSCREEN to newSurf_FrontSurf
    //init a pattern in the buffer:
    
    ClearScreen();
	
    return true;
    
ERR_EXIT: 
    return false;
}
Esempio n. 6
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATT_DISC_SVC_BY_UUID_CMP_EVT message.
 * @param[in] msgid Id of the message received.
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance.
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gatt_disc_svc_by_uuid_evt_handler(ke_msg_id_t const msgid,
                                             struct gatt_disc_svc_by_uuid_cmp_evt const *param,
                                             ke_task_id_t const dest_id,
                                             ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    // Check if the environment exists
    if (cscpc_env != NULL)
    {
        ASSERT_ERR(cscpc_env->operation != NULL);
        ASSERT_ERR(((struct cscpc_cmd *)cscpc_env->operation)->operation == CSCPC_ENABLE_OP_CODE);

        // Keep only one instance of the service
        if (cscpc_env->nb_svc == 0)
        {
            // Keep the start handle and the end handle of the service
            cscpc_env->cscs.svc.shdl = param->list[0].start_hdl;
            cscpc_env->cscs.svc.ehdl = param->list[0].end_hdl;
            cscpc_env->nb_svc++;
        }
    }
    // else drop the message

    return (KE_MSG_CONSUMED);
}
Esempio n. 7
0
	bool LoadFile(const char * path, std::vector<byte> * pDataOut, LFK lfk /*= LFK_Binary*/)
	{
		ASSERT_ERR(path);
		ASSERT_ERR(pDataOut);

		FILE * pFile = nullptr;
		if (fopen_s(&pFile, path, (lfk == LFK_Text) ? "rt" : "rb") != 0)
		{
			WARN("Couldn't open file %s", path);
			return false;
		}
		ASSERT_ERR(pFile);

		// Determine file size
		fseek(pFile, 0, SEEK_END);
		size_t size = ftell(pFile);

		// Read the whole file into memory
		pDataOut->resize((lfk == LFK_Text) ? size+1 : size);
		rewind(pFile);
		size_t sizeRead = fread(&(*pDataOut)[0], sizeof(byte), size, pFile);

		// Size can be smaller for text files, due to newline conversion
		ASSERT_ERR(sizeRead == size || ((lfk == LFK_Text) && sizeRead <= size));
		fclose(pFile);

		// Automatically null-terminate text files so string functions can be used
		if (lfk == LFK_Text)
		{
			pDataOut->resize(sizeRead + 1);
			(*pDataOut)[sizeRead] = 0;
		}

		return true;
	}
/**
 ****************************************************************************************
 * @brief Handles GAP manager command complete events.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation) {
    // reset completed
    case GAPM_RESET:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        else {
            // set device configuration
            struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD,
                    TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd);

            app_configuration_func(dest_id, cmd);

            ke_msg_send(cmd);
        }
        break;
    // device configuration updated
    case GAPM_SET_DEV_CONFIG:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        else {
            app_set_dev_config_complete_func();
        }
        break;
    // Advertising finished
    case GAPM_ADV_UNDIRECT:
        app_adv_undirect_complete(param->status);
        break;
    // Directed advertising finished
    case GAPM_ADV_DIRECT:
        app_adv_direct_complete(param->status);  
        break;
    case GAPM_RESOLV_ADDR:
    case GAPM_ADD_DEV_IN_WLIST:
    case GAPM_RMV_DEV_FRM_WLIST:
#if (USE_CONNECTION_FSM)
        app_con_fsm_handle_cmp_evt(param);
#endif
        break;
    case GAPM_CANCEL:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    default:
        ASSERT_ERR(0); // unexpected error
        break;
    }

    return (KE_MSG_CONSUMED);
}
Esempio n. 9
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATT_WRITE_CHAR_RESP message.
 * @param[in] msgid Id of the message received.
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance.
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gatt_write_char_rsp_handler(ke_msg_id_t const msgid,
                                       struct gatt_write_char_resp const *param,
                                       ke_task_id_t const dest_id,
                                       ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    if (cscpc_env != NULL)
    {
        ASSERT_ERR(cscpc_env->operation != NULL);

        // Retrieve the operation currently performed
        uint8_t operation = ((struct cscpc_cmd *)cscpc_env->operation)->operation;

        switch (operation)
        {
            case (CSCPC_CFG_NTF_IND_OP_CODE):
            {
                // Send the complete event status
                cscpc_send_cmp_evt(cscpc_env, operation, param->status);
            } break;

            case (CSCPC_CTNL_PT_CFG_WR_OP_CODE):
            {
                if (param->status == PRF_ERR_OK)
                {
                    // Start Timeout Procedure
                    ke_timer_set(CSCPC_TIMEOUT_TIMER_IND, dest_id, CSCPC_PROC_TIMEOUT_TIMER_VAL);

                    // Wait for the response indication
                    ((struct cscpc_cmd *)cscpc_env->operation)->operation = CSCPC_CTNL_PT_CFG_IND_OP_CODE;
                }
                else
                {
                    // Send the complete event status
                    cscpc_send_cmp_evt(cscpc_env, operation, param->status);
                }

            } break;

            default:
            {
                ASSERT_ERR(0);
            } break;
        }
    }
    // else ignore the message

    return (KE_MSG_CONSUMED);
}
Esempio n. 10
0
/**
 ****************************************************************************************
 * @brief   User initialize
 ****************************************************************************************
 */
void usr_init(void)
{
    if(KE_EVENT_OK != ke_evt_callback_set(EVENT_BUTTON1_PRESS_ID, 
                                            app_event_button1_press_handler))
    {
        ASSERT_ERR(0);
    }
		
		//register event callback for accelerometer interrupt
		if(KE_EVENT_OK != ke_evt_callback_set(EVENT_ACCEL_INT_ID, 
                                            app_event_accel_handler))
    {
        ASSERT_ERR(0);
    }
		
		//PROTOCOL
		//testing protocol
		char *data; 
		data = malloc(sizeof(char)*14);
		data[0] = 0x00;//PROTOCOL_COMMAND_ENABLE;
		data[1] = 0x00;//PROTOCOL_BATT;
		
		data[2] = 0x00;//PROTOCOL_COMMAND_ENABLE;
		data[3] = 0x00;//PROTOCOL_TEMP;
		
		data[4] = 0x00;//PROTOCOL_COMMAND_ENABLE;
		data[5] = 0x00;//PROTOCOL_PED;
		
		//data[4] = PROTOCOL_COMMAND_ENABLE;
		//data[5] = PROTOCOL_PED;
		
		//data[6] = 0x00;//PROTOCOL_COMMAND_ENABLE;
		//data[7] = 0x00;//PROTOCOL_DISTANCE;
		
		//for testing streaming ADC output set:
		data[6] = PROTOCOL_COMMAND_ENABLE;
		data[7] = PROTOCOL_ADC_SAMPLE;
		//data[6] = 0x00;//PROTOCOL_COMMAND_ENABLE;
		//data[7] = 0x00;//PROTOCOL_ADC_SAMPLE;
		
		data[8] = PROTOCOL_COMMAND_RATE;
		data[9] = 100;
		data[10] = 0x00;   //4 int
		data[11] = 0x00;
		data[12] = 0x04;
		
		data[13] = '\0';
		receive_packet(13, data);
		//print_list();
}
Esempio n. 11
0
/**
 ****************************************************************************************
 * @brief   User initialize
 ****************************************************************************************
 */
void usr_init(void)
{
    if(KE_EVENT_OK != ke_evt_callback_set(EVENT_BUTTON1_PRESS_ID, 
                                            app_event_button1_press_handler))
    {
        ASSERT_ERR(0);
    }
#if		(FB_JOYSTICKS)
		 if(KE_EVENT_OK != ke_evt_callback_set(EVENT_ADC_KEY_SAMPLE_CMP_ID,
                                           app_event_adc_key_sample_cmp_handler))
		{
				ASSERT_ERR(0);
		}
#endif
}
/**
 ****************************************************************************************
 * @brief Initialise the database.
 *
 * @return If database initialization completed.
 ****************************************************************************************
 */
bool app_db_init_func(void)
{  
    // Indicate if more services need to be added in the database
    bool end_db_create = false;

    // Check if another should be added in the database
    if (app_env.next_prf_init < APP_PRF_LIST_STOP)
    {
        switch (app_env.next_prf_init)
        {
            default:
            {
                ASSERT_ERR(0);
            } break;
        }

        // Select following service to add
        app_env.next_prf_init++;
    }
    else
    {
        end_db_create = true;
    }

    return end_db_create;
}
Esempio n. 13
0
static void uart_rec_error_isr(void)
{
    void (*callback) (uint8_t) = NULL;
    // Reset RX parameters
    uart_env.rx.size = 0;
    uart_env.rx.bufptr = NULL;

    // Disable RX interrupt
    SetBits16(UART_IER_DLH_REG, ERBFI_dlh0, 0); // uart_rec_data_avail_setf(0);

    // Reset RX FIFO
    // uart_rxfifo_res_setf(1); @WIK commented

    // Retrieve callback pointer
    callback = uart_env.rx.callback;

    if(callback != NULL)
    {
        // Clear callback pointer
        uart_env.rx.callback = NULL;

        // Call handler
        callback(UART_STATUS_ERROR);
    }
    else
    {
        ASSERT_ERR(0);
    }
}
Esempio n. 14
0
/**
 ****************************************************************************************
 * @brief Handles GAP controller command complete events.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gapc_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapc_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation) {
    // reset completed
    case GAPC_UPDATE_PARAMS:
        if (ke_state_get(dest_id) == APP_PARAM_UPD) {
            if ((param->status != CO_ERROR_NO_ERROR)) {
                // it's application specific what to do when the Param Upd request is rejected
                app_update_params_rejected_func(param->status);
            }
            else {
                // Go to Connected State
                ke_state_set(dest_id, APP_CONNECTED);

                // if state is APP_CONNECTED then the request was accepted
                app_update_params_complete_func();
            }
        }
        break;
    default:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    }

    return (KE_MSG_CONSUMED);
}
Esempio n. 15
0
int app_entry_point_handler (ke_msg_id_t const msgid,
                                         void const *param,
                                         ke_task_id_t const dest_id,
                                         ke_task_id_t const src_id)
{
    int i=0;
    enum ke_msg_status_tag process_msg_handling_result;
    
    while (i<sizeof(app_process_handlers)/sizeof(process_event_func_t))
    {
        ASSERT_ERR(app_process_handlers[i]);
         if (app_process_handlers[i](msgid,param,dest_id,src_id, &process_msg_handling_result)==PR_EVENT_HANDLED)
               return (process_msg_handling_result);
         i++;
    }

    //user cannot do anything else than consume the message
    if (app_process_catch_rest_cb!=NULL)
    {
        app_process_catch_rest_cb(msgid,param,dest_id,src_id);
    }
    
    return (KE_MSG_CONSUMED);
    
};
Esempio n. 16
0
void uart_sps_read(uint8_t *bufptr, uint32_t size, uint8_t *state, void (*callback) (uint8_t, uint32_t))
{
    // Sanity check
    ASSERT_ERR(bufptr != NULL);
    ASSERT_ERR(size != 0);
    ASSERT_ERR(uart_sps_env.rx.bufptr == NULL);

    // Prepare RX parameters
    uart_sps_env.rx.size 		= size;
    uart_sps_env.rx.bufptr 		= bufptr;
	  uart_sps_env.rx.state 		= state;
	  uart_sps_env.rx.callback 	= callback; 
	
    // Start data transaction
    uart_rec_data_avail_setf(1); //=SetBits16(UART_IER_DLH_REG, ETBEI_dlh0, 1); 
}
Esempio n. 17
0
const struct rwip_eif_api* rwip_eif_get_func(uint8_t type)
{
    const struct rwip_eif_api* ret = NULL;
    switch(type)
    {
        case RWIP_EIF_AHI:
        case RWIP_EIF_HCIC:
        {
#ifdef CFG_HCI_BOTH_EIF
            if (GPIO_GetPinStatus(HCI_EIF_SELECT_PORT,HCI_EIF_SELECT_PIN))
                ret = &uart_api;
            else
                ret = &spi_api;
#else
  #ifdef CFG_HCI_SPI
            ret = &spi_api;     // select spi api
  #else
            ret = &uart_api;    // select uart api
  #endif
#endif
        }
        break;
        default:
        {
            ASSERT_ERR(0);
        }
        break;
    }
    return ret;
}
void app_disconnect_func(ke_task_id_t task_id, struct gapc_disconnect_ind const *param)
{
    
    uint8_t state = ke_state_get(task_id);
    
#if BLE_BATT_SERVER
 app_batt_poll_stop();
#endif // BLE_BATT_SERVER
    
    if ((state == APP_SECURITY) || (state == APP_CONNECTED)  || (state == APP_PARAM_UPD))
    {
        
/**************************************************
            Handle disconnection event
***************************************************/    

        // Restart Advertising
			 //app_adv_start();	


    }
    else
    {
        // We are not in a Connected State
        ASSERT_ERR(0);
    }
      
}    
Esempio n. 19
0
static void uart_sps_rec_error_isr(void)
{
    void (*callback) (uint8_t, uint32_t) = NULL;
    // Reset RX parameters
    uart_sps_env.rx.size = 0;
    uart_sps_env.rx.bufptr = NULL;
    
    // Disable RX interrupt
    SetBits16(UART_IER_DLH_REG, ERBFI_dlh0, 0);
    
    // Retrieve callback pointer
    callback = uart_sps_env.rx.callback;

    if(callback != NULL)
    {
        // Clear callback pointer
        uart_sps_env.rx.callback = NULL;

        // Call handler
        callback(UART_STATUS_ERROR, NULL);
    }
    else
    {
        ASSERT_ERR(0);
    }
}
Esempio n. 20
0
/**
 ****************************************************************************************
 * @brief Disconnection indication to ANPC.
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance
 * @param[in] src_id    ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gap_discon_cmp_evt_handler(ke_msg_id_t const msgid,
                                      struct gap_discon_cmp_evt const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    ASSERT_ERR(cscpc_env != NULL);

    // Free the stored operation if needed
    if (cscpc_env->operation != NULL)
    {
        // Check if we were waiting for a SC Control Point indication
        if (((struct cscpc_cmd *)cscpc_env->operation)->operation == CSCPC_CTNL_PT_CFG_IND_OP_CODE)
        {
            // Stop the procedure timeout timer
            ke_timer_clear(CSCPC_TIMEOUT_TIMER_IND, dest_id);
        }

        ke_msg_free(ke_param2msg(cscpc_env->operation));
        cscpc_env->operation = NULL;
    }

    PRF_CLIENT_DISABLE_IND_SEND(cscpc_envs, dest_id, CSCPC);

    return (KE_MSG_CONSUMED);
}
Esempio n. 21
0
/**
 ****************************************************************************************
 * @brief Handles the temperature timer.
 *
 * @param[in] msgid     APP_HTPT_PERIOD_MEAS_TIMER
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description
 *  Handles the temperature timer.
 ****************************************************************************************
 */
int app_htpt_period_meas_timer_handler(ke_msg_id_t const msgid,
                                       void const *param,
                                       ke_task_id_t const dest_id,
                                       ke_task_id_t const src_id)
{
    bool start_meas = false;

    // Measurement Ready - send if Client Configuration is Configured,
    // and regardless of connected
    if(usr_env.is_temp_meas_config)
    {
        ++usr_env.meas_counter;

        ASSERT_ERR(app_htpt_env->meas_intv != 0);
        //if interval is zero, don't send indication
        if( usr_env.meas_counter % app_htpt_env->meas_intv == 0 )
        {
            start_meas = true;
            usr_env.is_should_indicate = true;
        }
    }

    if (usr_env.is_temp_imeas_config)
        start_meas = true;

    if(start_meas)
        start_measure_temperature();

    ke_timer_set(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP, HTPT_PERIOD_MEAS_TIME);

    return (KE_MSG_CONSUMED);
}
Esempio n. 22
0
	/*
 	 *	Init TX and RX buffers, they are in EM but not in the retainable part
 	 *  so the pointers have to be programmed again	*
 	 */
	if(func_check_mem_flag)
	{
		if (func_check_mem_flag==2)
		{
	  //init TX/RX buffers after DEEPSLEEP	
		co_buf_init_deep_sleep();
		// Set the first RX descriptor pointer into the HW
        ble_currentrxdescptr_set(REG_BLE_EM_RX_ADDR_GET(co_buf_rx_current_get()));
		}   	
       //INIT NONE RET. HEAP after DEEPSLEEP	
       	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]);

		func_check_mem_flag = 0;//false;
		
	}
    
 #endif //RW_BLE_SUPPORT
#endif //DEEP_SLEEP
}

#endif //0

// /*********************************************************************************
//  *** SLP_INT ISR
//  ***/
void lld_sleep_compensate_func_patched(void)
{
    uint32_t dur_us;
    uint32_t slot_corr;
    uint32_t fine_corr;
    
    // Get the number of low power sleep period
    uint32_t slp_period = ble_deepslstat_get();

    // Sanity check: The duration of a sleep is limited
    ASSERT_ERR(slp_period < LLD_EVT_MAX_SLEEP_DURATION);

    // Convert sleep duration into us
    dur_us = lld_sleep_lpcycles_2_us_sel_func(slp_period);
    slot_corr = dur_us / 625;
    fine_corr = 624 - (dur_us % 625);
    if (fine_corr == 0)
        fine_corr = 1;

    // The correction values are then deduced from the sleep duration in us
    ble_basetimecntcorr_set(slot_corr);
    ble_finecntcorr_set(fine_corr);

    // Start the correction
    ble_deep_sleep_corr_en_setf(1);
}
Esempio n. 23
0
/**
 ****************************************************************************************
 * @brief Handles button press after cancel the jitter.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_button_timer_handler(ke_msg_id_t const msgid, void const *param,
                               ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
    switch(msgid)
    {
        case APP_SYS_BUTTON_1_TIMER:
            // make sure the button is pressed
            if(gpio_read_pin(BUTTON1_PIN) == GPIO_LOW)
            {
                if(APP_IDLE == ke_state_get(TASK_APP))
                {
                    struct app_proxr_env_tag *app_proxr_env = &app_env.proxr_ev;
                    if(!app_proxr_env->enabled)
                    {
                        // start adv
                        app_gap_adv_start_req(GAP_GEN_DISCOVERABLE|GAP_UND_CONNECTABLE,
                                app_env.adv_data, app_set_adv_data(GAP_GEN_DISCOVERABLE),
                                app_env.scanrsp_data, app_set_scan_rsp_data(app_get_local_service_flag()),
                                GAP_ADV_FAST_INTV1, GAP_ADV_FAST_INTV2);

#if (QN_DEEP_SLEEP_EN)
                        // prevent entering into deep sleep mode
                        sleep_set_pm(PM_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                    }
                }
                else if(APP_ADV == ke_state_get(TASK_APP))
                {
                    // stop adv
                    app_gap_adv_stop_req();

#if (QN_DEEP_SLEEP_EN)
                    // allow entering into deep sleep mode
                    sleep_set_pm(PM_DEEP_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                }
            }
            break;

        case APP_SYS_BUTTON_2_TIMER:
            if(gpio_read_pin(BUTTON2_PIN) == GPIO_LOW)
            {
                buzzer_off();
            }
            break;

        default:
            ASSERT_ERR(0);
            break;
    }

    return (KE_MSG_CONSUMED);
}
Esempio n. 24
0
/**
 ****************************************************************************************
 * @brief Serves the receive data available interrupt requests. It clears the requests and
 *        executes the callback function.
 *
 * @return void
 ****************************************************************************************
 */
static void uart_sps_rec_data_avail_isr(void)
{
    void (*callback) (uint8_t, uint32_t) = NULL;
    uint32_t sent_bytes = 0;
    
    while (uart_data_rdy_getf())
    {
        // Read the received in the FIFO
        readData = uart_rxdata_getf();
#if (UART_SW_FLOW_ENABLED)
        if(readData == UART_XON_BYTE)
        {
            //callback function will tell application that XOFF is received
            *uart_sps_env.rx.state = UART_XON;
        }
        else if(readData == UART_XOFF_BYTE)
        {
            //callback function will tell application that XON is received
            *uart_sps_env.rx.state = UART_XOFF;
            app_override_ble_xoff();
        }
        else
#endif /*UART_SW_FLOW_ENABLED*/
        {
            //put data in buffer
            *uart_sps_env.rx.bufptr = readData;
            
            //update RX parameters
            uart_sps_env.rx.size--;
            sent_bytes++;
            uart_sps_env.rx.bufptr++;
        }
        // Check if all expected data have been received
        if (uart_sps_env.rx.size == 0)
        {
            // Reset RX parameters
            uart_sps_env.rx.bufptr = NULL;
            
            // Retrieve callback pointer
            callback = uart_sps_env.rx.callback;
            
            if(callback != NULL)
            {
                // Clear callback pointer
                uart_sps_env.rx.callback = NULL;
                
                // Call handler
                callback(UART_STATUS_OK, sent_bytes);
            }
            else
            {
                ASSERT_ERR(0);
            }
            
            // Exit loop
            break;
        }
    }
}
Esempio n. 25
0
/**
 ****************************************************************************************
 * @brief   User initialize
 ****************************************************************************************
 */
void usr_init(void)
{
    if(KE_EVENT_OK != ke_evt_callback_set(EVENT_BUTTON1_PRESS_ID, 
                                            app_event_button1_press_handler))
    {
        ASSERT_ERR(0);
    }
}
Esempio n. 26
0
void app_gap_bond_cfm(struct gapc_bond_req_ind *param)
{
    struct gapc_bond_cfm * cfm = BleMsgAlloc(GAPC_BOND_CFM, KE_BUILD_ID(TASK_GAPC, app_env.proxr_device.device.conhdl), TASK_APP,
                                 sizeof(struct gapc_bond_cfm));
    switch(param->request)
    {
    // Bond Pairing request
    case GAPC_PAIRING_REQ:
    {


        cfm->request = GAPC_PAIRING_RSP;
        cfm->accept = true;

        // OOB information
        cfm->data.pairing_feat.oob            = GAP_OOB_AUTH_DATA_NOT_PRESENT;
        // Encryption key size
        cfm->data.pairing_feat.key_size       = KEY_LEN;
        // IO capabilities
        cfm->data.pairing_feat.iocap          = GAP_IO_CAP_NO_INPUT_NO_OUTPUT;
        // Authentication requirements
        cfm->data.pairing_feat.auth           = GAP_AUTH_REQ_NO_MITM_BOND;
        //cfm->data.pairing_feat.auth           = GAP_AUTH_REQ_MITM_NO_BOND;
        //Initiator key distribution
        //GZ cfm->data.pairing_feat.ikey_dist      = GAP_KDIST_NONE;
        cfm->data.pairing_feat.ikey_dist      = GAP_KDIST_SIGNKEY;
        //Responder key distribution
        cfm->data.pairing_feat.rkey_dist      = GAP_KDIST_ENCKEY;
        //Security requirements
        cfm->data.pairing_feat.sec_req        = GAP_NO_SEC;


    }
    break;

    // Used to retrieve pairing Temporary Key
    case GAPC_TK_EXCH:
    {
        if(param->data.tk_type == GAP_TK_DISPLAY)
        {
            uint32_t pin_code = app_gen_tk();
            cfm->request = GAPC_TK_EXCH;
            cfm->accept = true;

            memset(cfm->data.tk.key, 0, KEY_LEN);

            cfm->data.tk.key[12] = (uint8_t)((pin_code & 0xFF000000) >> 24);
            cfm->data.tk.key[13] = (uint8_t)((pin_code & 0x00FF0000) >> 16);
            cfm->data.tk.key[14] = (uint8_t)((pin_code & 0x0000FF00) >>  8);
            cfm->data.tk.key[15] = (uint8_t)((pin_code & 0x000000FF) >>  0);

        }
        else
        {
            ASSERT_ERR(0);
        }
    }
Esempio n. 27
0
void uart_sps_write(uint8_t *bufptr, uint32_t size, uint8_t *state, void (*callback) (uint8_t))
{
   // Sanity check
    ASSERT_ERR(bufptr != NULL);
		if(*state == UART_NONE && !UART_SW_FLOW_ENABLED) //size could be 0 if only flow control must be send
		{
			ASSERT_ERR(size != 0);
		}
    ASSERT_ERR(uart_sps_env.tx.bufptr == NULL);

    // Prepare TX parameters
    uart_sps_env.tx.size 		= size;
    uart_sps_env.tx.bufptr 		= bufptr;
    uart_sps_env.tx.state 		= state;
	uart_sps_env.tx.callback 	= callback; 
			
    uart_thr_empty_setf(1);
}
Esempio n. 28
0
static uint32_t rwip_slot_2_lpcycles_rcx(uint32_t slot_cnt)
{
    volatile uint32_t lpcycles;

    // Sanity check: The number of slots should not be too high to avoid overflow
    ASSERT_ERR(slot_cnt < 1000000);

    lpcycles = (uint32_t)(slot_cnt * rcx_slot_duration);
    
    return(lpcycles);
}
Esempio n. 29
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATTC_DISC_CHAR_DESC_IND message.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gattc_disc_char_desc_ind_handler(ke_msg_id_t const msgid,
                                           struct gattc_disc_char_desc_ind const *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct anpc_env_tag *anpc_env = PRF_CLIENT_GET_ENV(dest_id, anpc);

    if (anpc_env != NULL)
    {
        ASSERT_ERR(anpc_env->operation != NULL);
        ASSERT_ERR(((struct anpc_cmd *)anpc_env->operation)->operation == ANPC_ENABLE_OP_CODE);

        // Retrieve ANPS descriptors
        prf_search_descs(ANPC_DESC_MAX, &anpc_env->ans.descs[0], &anpc_ans_char_desc[0],
                         param, anpc_env->last_req);
    }

    return (KE_MSG_CONSUMED);
}
Esempio n. 30
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref CSCPC_TIMEOUT_TIMER_IND message. This message is
 * received when the peer device doesn't send a SC Control Point indication within 30s
 * after reception of the write response.
 * @param[in] msgid Id of the message received.
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance.
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int cscpc_timeout_timer_ind_handler(ke_msg_id_t const msgid,
                                           void const *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    if (cscpc_env != NULL)
    {
        ASSERT_ERR(cscpc_env->operation != NULL);
        ASSERT_ERR(((struct cscpc_cmd *)cscpc_env->operation)->operation == CSCPC_CTNL_PT_CFG_IND_OP_CODE);

        // Send the complete event message
        cscpc_send_cmp_evt(cscpc_env, CSCPC_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_PROC_TIMEOUT);
    }
    // else drop the message

    return (KE_MSG_CONSUMED);
}