Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name:
- * Synchronizing tasks with a queue (sending a message)
- *
- * Description:
- * - a FreeRTOS example application for the Silicon Labs
- * EFM32 Giant Gecko Starter Kit (STK3700A)
- * - There are two tasks. One is sending a message via a queue and the other
- * is waiting for this message.
- * - The sender task is supposed to send a message (a value incremented by
- * one) once in every second
- *
- * Created by:
- * NASZALY Gabor <naszaly@mit.bme.hu>
- *
- * Last modified on:
- * 2016-03-23
- */
- /* --------------------------------------------------------------------------
- INCLUDES
- -------------------------------------------------------------------------- */
- // Application specific includes
- #include <stdio.h>
- #include <retargetserial.h>
- // FreeRTOS includes
- #include "FreeRTOS.h"
- #include "task.h"
- // TODO: include header for queue API
- #include "queue.h"
- /* --------------------------------------------------------------------------
- DEFINES
- -------------------------------------------------------------------------- */
- #define mainTASK_MESSAGE_SENDER_PRIORITY ( tskIDLE_PRIORITY + 2 )
- #define mainTASK_MESSAGE_SENDER_STACK_SIZE configMINIMAL_STACK_SIZE
- #define mainTASK_MESSAGE_RECEIVER_PRIORITY ( tskIDLE_PRIORITY + 1 )
- #define mainTASK_MESSAGE_RECEIVER_STACK_SIZE configMINIMAL_STACK_SIZE
- /* --------------------------------------------------------------------------
- VARIABLES
- -------------------------------------------------------------------------- */
- // A variable storing the number of button presses
- uint32_t message = 0;
- /*
- * TODO: define a variable for the queue used to convey the message
- * Use type QueueHandle_t
- */
- QueueHandle_t queue;
- /* --------------------------------------------------------------------------
- FUNCTION DECLARATIONS
- -------------------------------------------------------------------------- */
- static void prvTaskMessageSender(void *pvParam);
- static void prvTaskMessageReceiver(void *pvParam);
- /* --------------------------------------------------------------------------
- MAIN
- -------------------------------------------------------------------------- */
- int main(void) {
- // Initialize starter kit
- RETARGET_SerialInit();
- RETARGET_SerialCrLf(1);
- // Initialize FreeRTOS
- /*
- * TODO: create the queue used to convey the messages
- * Use function xQueueCreate().
- */
- queue = xQueueCreate(1, sizeof(uint32_t));
- // Create the message sender task
- xTaskCreate(
- prvTaskMessageSender,
- "Message Sender",
- mainTASK_MESSAGE_SENDER_STACK_SIZE,
- NULL,
- mainTASK_MESSAGE_SENDER_PRIORITY,
- NULL);
- // Create the message receiver task
- xTaskCreate(
- prvTaskMessageReceiver,
- "Message Receiver",
- mainTASK_MESSAGE_RECEIVER_STACK_SIZE,
- NULL,
- mainTASK_MESSAGE_RECEIVER_PRIORITY,
- NULL);
- // Start the scheduler
- vTaskStartScheduler();
- // Prevent compiler warning
- return 0;
- }
- /* --------------------------------------------------------------------------
- FUNCTION DEFINITIONS
- -------------------------------------------------------------------------- */
- /*
- * TODO: This task sends the messages (a number incremented by one each time).
- */
- static void prvTaskMessageSender(void *pvParam) {
- while (1) {
- vTaskDelay(configTICK_RATE_HZ);
- /*
- * TODO: send the message via the queue
- * Use function xQueueSend()
- */
- xQueueSend(queue, (void*) &message, (TickType_t) 100);
- message = message + 1;
- }
- }
- /*
- * This task receives the messages
- */
- static void prvTaskMessageReceiver(void *pvParam) {
- uint32_t local_copy_of_message;
- while (1) {
- /*
- * TODO: receive the message from queue
- * Use function xQueueReceive()
- */
- xQueueReceive(queue, &local_copy_of_message, (TickType_t) 1000);
- printf("kapott uzenet: %lu\n", local_copy_of_message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement