main/task_dcf.c

Fri, 20 Oct 2023 15:57:56 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 20 Oct 2023 15:57:56 +0200
changeset 1
86b275481021
child 2
053649608c09
permissions
-rw-r--r--

Added framework for the DCF77 transmitter. Added two debug LEDs.

/**
 * @file task_dcf.c
 * @brief DCF77 task.
 */


#include "dcf77tx.h"


static const char *TAG = "task_dcf";


SemaphoreHandle_t               xSemaphoreDCF = NULL;		///< Semaphore DCF task.
EventGroupHandle_t              xEventGroupDCF;			///< Events DCF task.
DCF_State			*dcf_state = NULL;		///< Public state for other tasks.

#define LED1			CONFIG_LED1_PIN
#define	LED2			CONFIG_LED2_PIN


const int TASK_DCF_REQUEST_START = BIT0;
const int TASK_DCF_REQUEST_STOP = BIT1;

const int TASK_DCF_RUN = BIT2;


bool ready_DCF(void)
{
    return dcf_state->DCF_running;
}



void request_DCF(bool run)
{
}



void task_DCF(void *pvParameters)
{
    ESP_LOGI(TAG, "Starting DCF77");

    xEventGroupDCF = xEventGroupCreate();
    xSemaphoreDCF = xSemaphoreCreateMutex();
    dcf_state = malloc(sizeof(DCF_State));
    memset(dcf_state, 0x00, sizeof(DCF_State));

    gpio_reset_pin(LED1);
    gpio_reset_pin(LED2);
    gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
    gpio_set_direction(LED2, GPIO_MODE_OUTPUT);

    xEventGroupClearBits(xEventGroupDCF, TASK_DCF_RUN);
    EventBits_t uxBits;

    for (;;) {
	uxBits = xEventGroupWaitBits(xEventGroupDCF, TASK_DCF_REQUEST_START | TASK_DCF_REQUEST_STOP, pdFALSE, pdFALSE, portMAX_DELAY );

	if (uxBits & TASK_DCF_REQUEST_START) {
	    if (dcf_state->DCF_running) {
		/* Already running */
		xEventGroupClearBits(xEventGroupDCF, TASK_DCF_REQUEST_START);
	    }

	} else if (uxBits & TASK_DCF_REQUEST_STOP) {

	}
    } /* for(;;) */
}

mercurial