GPIO polling in freeRTOS

ajinkya
2013-01-31
2013-09-16
  • ajinkya

    ajinkya - 2013-01-31

    I have very simple program written for polling a GPIO pin.

    void main( void )
    {
          #ifdef DEBUG
                  debug();
          #endif
          prvSetupHardware();
          xTaskCreate( vOnOffPoll, "AC_ON_OFF_Poll", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL);

          vTaskStartScheduler();
          for( ;; );
    }

    First I tried simple if else loop inside while(1) 

    void vOnOffPoll(void *pvParameters)
    {
      while(1)
      {
        if( GPIO_ReadBit(GPIO4,GPIO_Pin_7) == Bit_RESET)
              GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
        else
              GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);
    }

    then I tried switch case statement to do the same task in while(1)

    void vOnOffPoll(void *pvParameters)
    {
      while(1)
      {
        int state=0;
        state = GPIO_ReadBit(GPIO4,GPIO_Pin_7);
        switch(state)
        {
        case 1:
                GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
                break;
        case 0:
                GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);
                break;
        }
      }
    }

    I have no other task but still it gets executed once it dose not poll continuously.

    Initially pin (GPIO4,GPIO_Pin_7) is connected to on board GND  then (GPIO4,GPIO_Pin_0) is set
    but when I connect  (GPIO4,GPIO_Pin_7) to on board VCC it is not changing state ((GPIO4,GPIO_Pin_0) is not reset) untill I reset kit keeping  (GPIO4,GPIO_Pin_7) to on board VCC.

    What is the problem? A task cannot be more simpler than this and still it is not working.

     
  • Dave

    Dave - 2013-01-31

    There is nothing wrong with the code you have written and because there is only one task that never blocks and the task runs with a priority that is higher than the idle priority the task should just run continuously.

    If you put a break point on the first line of the task then step through the code you should see what it is doing.

    You can also replace the while loop with a simple increment variable like

    volatile int i = 0;
    while( 1 ) {
        i++;
        i++;
    }
    

    run your code and check that the value of i is counted up. If it is then the task is being executed as expected. If the task does not execute as expected with the original GPIO code then it must be something in the GPIO functions that stops it.

     
  • ajinkya

    ajinkya - 2013-01-31

    Thanks davedoors for reply,
    Actually I was doing small mistake in pin configuration.
    Whole project we divided in modules and couldn't notice hardware config than should have changed at first place.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks