Skip to content

Instantly share code, notes, and snippets.

@T3sT3ro
Created January 20, 2019 22:36
Show Gist options
  • Save T3sT3ro/69baf2a9771ad0f36ce5beee0f42b495 to your computer and use it in GitHub Desktop.
Save T3sT3ro/69baf2a9771ad0f36ce5beee0f42b495 to your computer and use it in GitHub Desktop.
/******************************************************************************
* Header file inclusions.
******************************************************************************/
#include "FreeRTOSConfig.h"
// #undef configUSE_TICK_HOOK
// #define configUSE_TICK_HOOK 0
// #undef configQUEUE_REGISTRY_SIZE
// #define configQUEUE_REGISTRY_SIZE 5
#include "FreeRTOS.h"
#include "task.h"
#include <avr/io.h>
#include <stdio.h>
#include "queue.h"
#include "uart.h"
/******************************************************************************
* Private macro definitions.
******************************************************************************/
#define mainLED_TASK_PRIORITY 1
#define mainSERIAL_TASK_PRIORITY 1
/******************************************************************************
* Private function prototypes.
******************************************************************************/
static void vUartReceive(void* pvParameters);
static void vLedBlink(void* pvParameters);
/******************************************************************************
* Public function definitions.
******************************************************************************/
/**************************************************************************/ /**
* \fn int main(void)
*
* \brief Main function.
*
* \return
******************************************************************************/
int main(void) {
uart_init();
stdout = stdin = &uart_file;
// Create task.
xTaskHandle blink_handle;
xTaskHandle serial_handle;
xQueueHandle Q = xQueueCreate(5, sizeof(uint16_t));
if(Q == NULL)puts("jprf");
xTaskCreate(
vUartReceive,
"blink",
configMINIMAL_STACK_SIZE,
(void *)Q,
mainLED_TASK_PRIORITY,
&blink_handle);
xTaskCreate(
vLedBlink,
"serial",
configMINIMAL_STACK_SIZE,
(void *)Q,
mainSERIAL_TASK_PRIORITY,
&serial_handle);
// Start scheduler.
vTaskStartScheduler();
return 0;
}
/**************************************************************************/
void vApplicationIdleHook(void);
void vApplicationIdleHook(void){
}
#define LED_STATE(state) PORTB = state ? PORTB | _BV(PB5) : PORTB & ~_BV(PB5);
static void vLedBlink(void* pvParameters) {
xQueueHandle Q = (xQueueHandle)pvParameters;
DDRB |= _BV(PB5); // D5 as output
uint16_t val = 0;
while (1) {
val = 0;
if (xQueueReceive(Q, &val, 0) == pdTRUE) {
printf("v: %u\r\n", val);
LED_STATE(1);
vTaskDelay(100 / portTICK_PERIOD_MS);
LED_STATE(0);
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
static void vUartReceive(void* pvParameters) {
xQueueHandle Q = (xQueueHandle)pvParameters;
uint16_t l = 0;
char c = 0;
while (1) {
l = 0;
c = getchar();
while(c>= '0' && c <= '9') {
l *= 10;l += c - '0';
c = getchar();
} //while (c >= '0' && c <= '9');
printf("%u\r\n", l);
if (xQueueSendToBack(Q, &l, 10) != pdTRUE)
puts("FAIL\r");
else puts("senf");
taskYIELD();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment