This commit is contained in:
2022-11-04 16:42:46 +01:00
parent 0c0741aef3
commit 3a9ccfd28d
11 changed files with 3023 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
idf_component_register(
SRC_DIRS "."
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,2 @@
COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := .

View File

@@ -0,0 +1,133 @@
/****************************************************************************
* Copyright (C) 2020 by Fabrice Muller *
* *
* This file is useful for ESP32 Design course. *
* *
****************************************************************************/
/**
* @file lab3-1_main.c
* @author Fabrice Muller
* @date 20 Oct. 2020
* @brief File containing the lab3-1 of Part 3.
*
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include "esp_log.h"
/* FreeRTOS.org includes. */
#include "freertos/FreeRTOSConfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "my_helper_fct.h"
static const char* TAG = "SEM";
/* Application constants */
#define STACK_SIZE 4096
#define TABLE_SIZE 400
/* Task Priority */
const uint32_t TIMER_TASK_PRIORITY = 5;
const uint32_t INC_TABLE_TASK_PRIORITY = 4;
const uint32_t DEC_TABLE_TASK_PRIORITY = 4;
/* Communications */
SemaphoreHandle_t xSemClk;
/* Tasks */
void vTaskTimer(void *pvParameters);
void vTaskIncTable(void *pvParameters);
void vTaskDecTable(void *pvParameters);
/* Datas */
int Table[TABLE_SIZE];
/* Main function */
void app_main(void) {
/* Init Table */
memset(Table, 0, TABLE_SIZE*sizeof(int));
/* Create semaphore */
xSemClk = xSemaphoreCreateBinary();
if (xSemClk == NULL) {
ESP_LOGE(TAG, "Error xSemClk cannot be created");
vTaskDelete(NULL);
}
/* Stop scheduler */
vTaskSuspendAll();
/* Create Tasks */
xTaskCreatePinnedToCore(vTaskTimer,"Timer", STACK_SIZE, NULL, TIMER_TASK_PRIORITY, NULL,CORE_0) ;
/* Continue scheduler */
xTaskResumeAll();
/* to ensure its exit is clean */
vTaskDelete(NULL);
}
/*-----------------------------------------------------------*/
void vTaskTimer(void *pvParameters) {
TickType_t xLastWakeTime =xTaskGetTickCount();
for(;;){
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(250UL));
COMPUTE_IN_TIME_MS(20);
DISPLAY("Task Timer : give sem Clk");
xSemaphoreGive(xSemClk);
}
}
void vTaskIncTable(void *pvParameters) {
int index;
int NbActivations = 0;
uint32_t constNumber = ((uint32_t *)pvParameters);
for(;;){
//Wait on clk
xSemaphoreTake(xSemClk, portMAX_DELAY);
DISPLAY ("TASK IncTable is running");
if (NbActivations ==0) {
DISPLAY ("TASK IncTable is starting computation");
for (index = 0 ; index < TABLE_SIZE; index++)
Table[index] = Table[index] + constNumber;
COMPUTE_IN_TIME_MS(50);
NbActivations = 4;
}
else {
NbActivations = NbActivations - 1;
}
}
}
void vTaskDecTable(void *pvParameters) {
int index;
for(;;){
for (index = 0 ; index < TABLE_SIZE; index++)
Table[index] = Table[index] + 1;
COMPUTE_IN_TIME_MS(50);
}
}

View File

@@ -0,0 +1,47 @@
#ifndef _MY_HELPER_FCT_
#define _MY_HELPER_FCT_
#include <unistd.h>
#include "esp_log.h"
/* Core constants fot xTaskCreatePinnedToCore() function */
const uint32_t CORE_0 = 0;
const uint32_t CORE_1 = 1;
const uint32_t PRO_CPU = 0;
const uint32_t APP_CPU = 1;
/**
* @brief Macro to display the buffer with arguments. msg is a formatted string as printf() function.
*
*/
#define DISPLAY(msg, ...) printf("%d:%d>\t"msg"\r\n", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
/**
* @brief Macro to display error/warning/info for the buffer with arguments. msg is a formatted string as printf() function.
*
*/
#define DISPLAYE(tag, msg, ...) ESP_LOGE(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
#define DISPLAYW(tag, msg, ...) ESP_LOGW(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
#define DISPLAYI(tag, msg, ...) ESP_LOGI(tag, "%d:%d>\t"msg"", xTaskGetTickCount(), xPortGetCoreID(), ##__VA_ARGS__);
/**
* @brief Macro to display the buffer without argument
*
*/
#define DISPLAYB(msg) printf("%d:%d>\t", xTaskGetTickCount(), xPortGetCoreID());\
printf(msg);\
printf("\r\n");
/* Consume CPU cycles. Time parameter is for the default frequency: 160MHz (ESP32_DEFAULT_CPU_FREQ_MHZ=160) */
#define COMPUTE_IN_TIME_US(time_us) {register uint32_t i=(uint32_t)time_us*5.02*100/22; while (i-- > 0) {asm(" nop");}}
#define COMPUTE_IN_TIME_MS(time_ms) {register uint32_t i=(uint32_t)time_ms*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
#define COMPUTE_IN_TICK(tick) {register uint32_t i=(uint32_t)(tick*1000/configTICK_RATE_HZ)*1000*5.02*100/22; while (i-- > 0) {asm(" nop");}}
#endif