the value of the key_flag doesn't change

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Here is my code for the application I am running. The value of key_flag doesn't change when the program flow comes back to create function. Also the what is program control flow for this?

#include "bleprofile.h"

#include "bleapp.h"

#include "gpiodriver.h"

#include "string.h"

#include "stdio.h"

#include "platform.h"

#include "bleappconfig.h"

#include "cfa.h"

#include <stdio.h>

#include <stdlib.h>

#include "adc.h"

#define GPIO_PORT(x) (x/16)

#define GPIO_PIN(x)  (x%16)

#define APPLICATION_ADC_INPUT_CHANNEL ADC_INPUT_P32

volatile unsigned char Key_flag;

static void  ble_tx_create(void);

static void  interrupt_handler (void* parameter, UINT8 arg);

static void  generic_timeout( UINT32 count );

const BLE_PROFILE_GPIO_CFG ble_tx_gpio_cfg = {

         { GPIO_PIN_WP,GPIO_PIN_BUTTON, 14, GPIO_PIN_BATTERY, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},

         {GPIO_SETTINGS_WP, GPIO_SETTINGS_BUTTON, GPIO_SETTINGS_LED, GPIO_SETTINGS_BATTERY, GPIO_SETTINGS_BUZZER, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

};

APPLICATION_INIT(){

    //ble_trace0("init_entry");

    /*Initialization*/

    bleapp_set_cfg(NULL, 0, NULL, NULL, (void*)&ble_tx_gpio_cfg, ble_tx_create);

    //ble_trace0("init_exit");

}

void ble_tx_create(void){

    ble_trace0("ble_tx_entry");

    bleprofile_GPIOInit(bleprofile_gpio_p_cfg);

    bleprofile_Init(bleprofile_p_cfg);

    //bleprofile_regTimerCb(generic_fine_timeout, generic_timeout);

    bleprofile_StartTimer();

    /* initialization of adc, mandatory call on startup */

    adc_config();

    adc_adcCalibrate(2200, ADC_INPUT_VDD_CORE);

    //register for interrupts on pin 0 (push button)

    {

        UINT16 masks[3] = {(1 << 1), 0 , 0};

        //gpio_registerForInterrupt(masks, interrupt_handler, 0);

        gpio_registerForInterrupt(masks, interrupt_handler, NULL); //gopi

    }

    gpio_configurePin(0,1, GPIO_EN_INT_BOTH_EDGE | GPIO_PULL_UP, GPIO_PIN_OUTPUT_LOW);

    //GPIO_POLL;

    ble_trace1("Key_flag =%d", Key_flag);

    if(Key_flag==1)    {

        ble_trace0("if entry");

        ble_trace1("Key_flag =%d", Key_flag);

        bleprofile_LEDBlink(250, 500, 5);

        bleprofile_BUZBeep(100);

        Key_flag = 0;

        ble_trace0("if exit");

    }

    else{

        ble_trace0("else entry");

        ble_trace1("Key_flag =%d", Key_flag);

        bleprofile_LEDBlink(100, 300, 2);

        bleprofile_BUZBeep(500);

        //Key_flag = 0;

        ble_trace0("else exit");

    }

    ble_trace0("ble_tx_exit");

}

void interrupt_handler(void* parameter, UINT8 arg) {

        ble_trace0("In isr");

        Key_flag = 1;

        ble_trace1("Key_flag =%d", Key_flag);

        ble_trace0("ISR exit");

}

/*

void interrupt_handler(void* parameter, UINT8 arg) {

    bleprofile_LEDBlink(500, 500, 3);

    bleprofile_BUZBeep(25);

    ble_trace0("!!!!!!!!!!!");

    generic_timeout(1);

    ble_trace0("@@@@@@@@@@@");

}

*/

UINT32 application_read_adc_voltage_from_gpio(UINT8 gpio_number){

    return adc_readVoltage(adc_convertGPIOtoADCInput(gpio_number));

}

/* printing adc voltage on every loop */

void generic_timeout(UINT32 arg){

    ble_trace1("ADC READOUT = %6d",application_read_adc_voltage_from_gpio(32));

}

0 Likes
1 Solution

Your program entry is APLLICATION_INIT.

After that it goes to the create function you passed within APPLICATION_INIT.

The create function is where the flow stops. From there, you can either call other application specific init functions, register for interrupts, timers, or callbacks from BLE events (connection_up, connection_down, etc).

There could be many reasons for your code freezing up. It looks like many things were stripped from the code that should remain. The most prevalent thing I see is that you should likely register timers. You call startTimers without ever registering them. Without timers or BLE callbacks, the kernel will likely not wait for your interrupt and decide to reboot.

Jacob

View solution in original post

4 Replies
Anonymous
Not applicable

the value of key_flag always remains zero. Even after it is set as 1 in Interrupt handler when it comes back to interrupt_handler it is reset to zero.

0 Likes

The program should not be returning to the create function. If your create function is being called again this is likely because you have triggered the watchdog meaning that you are stuck in an infinite loop somewhere for more than 2 seconds.

This is consistent with the variable being 0--your board has rebooted itself--resetting all variables and going back to the create function.

Jacob

0 Likes
Anonymous
Not applicable

then how to remove this condition? and also what part of the code acts as main() function?

0 Likes

Your program entry is APLLICATION_INIT.

After that it goes to the create function you passed within APPLICATION_INIT.

The create function is where the flow stops. From there, you can either call other application specific init functions, register for interrupts, timers, or callbacks from BLE events (connection_up, connection_down, etc).

There could be many reasons for your code freezing up. It looks like many things were stripped from the code that should remain. The most prevalent thing I see is that you should likely register timers. You call startTimers without ever registering them. Without timers or BLE callbacks, the kernel will likely not wait for your interrupt and decide to reboot.

Jacob