title: Hardware interrupt with FreeRTOS binary semaphore
body: <p>I'm basically trying to get a LED to light up after I push a button. Below is the snippet of the code that's supposed to handle this:</p>
  <pre><code>void task_player1(void *pvParameters)
  {   
      while (1)
      {
          if (xSemaphoreTake(player1_signal, portMAX_DELAY))
          {
              printf(&quot;&gt;&gt;&gt;Semaphore taken\n&lt;&lt;&lt;&quot;);
              ioport_set_pin_level(L1, HIGH);
              xSemaphoreGive(player1_signal);
          }
          else
          {
              ioport_set_pin_level(L1, LOW);
          }
      }
  }
  
  void task_ctrl(void *pvParameters)
  {
      bool button1 = 0;       
      
      while (1)
      {
          button1 = ioport_get_pin_level(B1);
          if (button1)
          {
              xSemaphoreGive(player1_signal);
              printf(&quot;Semaphore given\n&quot;);
          }
      }
  }
  </code></pre>
  <p>The way I'm envisioning this is that <code>task_ctrl</code> gives the semaphore on button press. <code>Task_player1</code> is blocked until it takes the semaphore after which it should turn on the LED.</p>
  <p>The problem is it never seems to take the semaphore. I'm running the <code>printf</code> statements to show me how far the program reaches and it never gets into the part where the LED lights up. But when I run <code>xSemaphoreGive</code> without the button press in <code>task_ctrl</code> the semaphore is taken.</p>
  <p>The weird part is that <code>&quot;Semaphore given\n&quot;</code> statement gets printed out on button click which should mean that the semaphore is given as well but never gets taken.</p>
  <p>The tasks work on their own, I've even managed to give the semaphore without the button press if-statement like I stated above.</p>
  <p>I'm guessing it's something with the button press code, which also works on it's own outside the tasks. So what am I doing wrong? Am I not using the FreeRTOS correctly?</p>
  <p>Edit: Including the task creation code</p>
  <pre><code>#define TASK_STACK_SIZE (2048/ sizeof(portSTACK_TYPE))
  
  xTaskCreate(task_ctrl, (const signed char * const) &quot;Control&quot;, TASK_STACK_SIZE, NULL, 1, NULL);
      
  xTaskCreate(task_player1, (const signed char * const) &quot;Player1&quot;, TASK_STACK_SIZE, NULL, 1, NULL);
  </code></pre>
  <p>Edit 2: Probably something I should have mentioned is that I'm using FreeRTOS 7.3 since Atmel Studio doesn't have any newer versions. So no yield functions are available, as far as I can tell.</p>