Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HardwareProfile.h"
- #include "FreeRTOS.h"
- #include "task.h"
- #include "croutine.h"
- #include "list.h"
- #include "semphr.h"
- #include "queue.h"
- #include "timers.h"
- #include <stdio.h>
- void vInitApp(void);
- void vTask1( void *pvParameters );
- void vTask2( void *pvParameters );
- void vTask3( void *pvParameters );
- void vTask4( void *pvParameters );
- xSemaphoreHandle LED1_binSemaphore=NULL;
- xSemaphoreHandle LED2_binSemaphore=NULL;
- xSemaphoreHandle LED3_binSemaphore=NULL;
- xSemaphoreHandle LED4_binSemaphore=NULL;
- int main(void)
- {
- vInitApp();
- vSemaphoreCreateBinary( LED1_binSemaphore );
- vSemaphoreCreateBinary( LED2_binSemaphore );
- vSemaphoreCreateBinary( LED3_binSemaphore );
- vSemaphoreCreateBinary( LED4_binSemaphore );
- if(LED1_binSemaphore == NULL || LED2_binSemaphore == NULL ||
- LED3_binSemaphore == NULL || LED4_binSemaphore == NULL )
- {
- while(1); //in case of semaphore creation error
- }
- xSemaphoreGive(LED1_binSemaphore);
- xSemaphoreTake(LED2_binSemaphore,portMAX_DELAY);
- xSemaphoreTake(LED3_binSemaphore,portMAX_DELAY);
- xSemaphoreTake(LED4_binSemaphore,portMAX_DELAY);
- xTaskCreate( vTask1, "Task LED1", 256, NULL, 1, NULL );
- xTaskCreate( vTask2, "Task LED2", 256, NULL, 1, NULL );
- xTaskCreate( vTask3, "Task LED3", 256, NULL, 1, NULL );
- xTaskCreate( vTask4, "Task LED4", 256, NULL, 1, NULL );
- vTaskStartScheduler();
- for( ;; );
- return 0;
- }
- void vTask1(void *pvParameters)
- {
- while(1)
- if(xSemaphoreTake(LED1_binSemaphore,portMAX_DELAY))
- {
- mTurnOnLED(0);
- vTaskDelay(250/portTICK_RATE_MS);
- mTurnOffLED(0);
- xSemaphoreGive(LED2_binSemaphore);
- }
- }
- void vTask2( void *pvParameters )
- {
- while(1)
- if(xSemaphoreTake(LED2_binSemaphore,portMAX_DELAY))
- {
- mTurnOnLED(1);
- vTaskDelay(250/portTICK_RATE_MS);
- mTurnOffLED(1);
- xSemaphoreGive(LED3_binSemaphore);
- }
- }
- void vTask3( void *pvParameters )
- {
- while(1)
- if(xSemaphoreTake(LED3_binSemaphore,portMAX_DELAY))
- {
- mTurnOnLED(2);
- vTaskDelay(250/portTICK_RATE_MS);
- mTurnOffLED(2);
- xSemaphoreGive(LED4_binSemaphore);
- }
- }
- void vTask4( void *pvParameters )
- {
- while(1)
- if(xSemaphoreTake(LED4_binSemaphore,portMAX_DELAY))
- {
- mTurnOnLED(3);
- vTaskDelay(250/portTICK_RATE_MS);
- mTurnOffLED(3);
- xSemaphoreGive(LED1_binSemaphore);
- }
- }
- void vInitApp(void) {
- mInitLEDs(); /* Initialisation of LEDs */
- mInitButtons(); /* Initialisation of Button */
- }
- void __attribute__ ((__interrupt__, __auto_psv__)) _StackError(void)
- {
- while(1){
- Nop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement