2 changed files with 110 additions and 3 deletions
@ -1,6 +1,112 @@ |
|||
#include <stdio.h> |
|||
|
|||
void app_main(void) |
|||
{ |
|||
#include "freertos/FreeRTOS.h" |
|||
#include "freertos/task.h" |
|||
#include "freertos/semphr.h" |
|||
|
|||
#include "driver/gpio.h" |
|||
|
|||
#include "driver/spi_master.h" |
|||
#include <string.h> |
|||
|
|||
// definicion de pines
|
|||
// Definir los pines utilizados para MOSI, MISO, SCLK y CS
|
|||
#define PIN_NUM_MOSI 13 |
|||
#define PIN_NUM_MISO 12 |
|||
#define PIN_NUM_CLK 14 |
|||
#define PIN_NUM_CS 15 |
|||
#define IRQ_PIN 26 |
|||
|
|||
// parámetros ADC
|
|||
#define LEN_MAP_bytes 24 // cantidad de bitts en la memoria desde 0x1 a 0xD, adicionando 8 bits para el comando
|
|||
|
|||
#define FAST_COMMAND 0b00 |
|||
#define STATIC_READ 0b01 |
|||
#define INCREMENTAL_WRITE 0b10 |
|||
#define INCREMENTAL_READ 0b11 |
|||
|
|||
uint8_t register_map[LEN_MAP_bytes] = {0}; |
|||
#define ADCDATA_index 0 |
|||
#define CONFIG0_index 1 |
|||
#define CONFIG1_index 2 |
|||
#define CONFIG2_index 3 |
|||
#define CONFIG3_index 4 |
|||
#define IRQ_index 5 |
|||
#define MUX_index 6 |
|||
#define SCAN_index 7 |
|||
#define TIMER_index 10 |
|||
#define OFFSETCAL_index 13 |
|||
#define GAINCAL_index 16 |
|||
#define LOCK_index 23 |
|||
|
|||
#define ADC_CONV_START_FC 0b1010 |
|||
#define ADC_STBY_MODE_FC 0b1011 |
|||
#define ADC_SHDN_MODE_FC 0b1100 |
|||
#define FULL_SHDN_MODE_FC 0b1101 |
|||
#define FULL_RESET_FC 0b1110 |
|||
|
|||
#define COMMAND_READ_ADC 0b01000001 |
|||
|
|||
// variables SPI
|
|||
spi_device_handle_t *spi_handle; |
|||
spi_bus_config_t *bus_cfg_SPI; |
|||
spi_device_interface_config_t *mcp3561_cfg_SPI; |
|||
|
|||
// Declaración de la cola de semáforo
|
|||
SemaphoreHandle_t xSemaphore; |
|||
|
|||
void IRAM_ATTR isr_IRQ_handler(void *arg) { |
|||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; |
|||
xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken); |
|||
// if (xHigherPriorityTaskWoken == pdTRUE) {
|
|||
// portYIELD_FROM_ISR();
|
|||
// }
|
|||
} |
|||
|
|||
// Tarea de base (bare-metal)
|
|||
void base_task(void *pvParameters) { |
|||
while (1) { |
|||
// Espera al semáforo
|
|||
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) { |
|||
// La tarea responde al semáforo aquí
|
|||
// Realiza el trabajo necesario
|
|||
printf("- "); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void app_main() { |
|||
// Inicializa el semáforo
|
|||
xSemaphore = xSemaphoreCreateBinary(); |
|||
|
|||
// configuración PIN
|
|||
gpio_config_t irq_config; |
|||
irq_config.intr_type = GPIO_INTR_POSEDGE; |
|||
irq_config.mode = GPIO_MODE_INPUT; |
|||
irq_config.pin_bit_mask = (1ULL << IRQ_PIN); |
|||
irq_config.pull_down_en = GPIO_PULLDOWN_DISABLE; |
|||
irq_config.pull_up_en = GPIO_PULLDOWN_ENABLE; |
|||
gpio_config(&irq_config); |
|||
|
|||
gpio_install_isr_service(0); // Instala el servicio de interrupción en el núcleo 0
|
|||
gpio_isr_handler_add(IRQ_PIN, isr_IRQ_handler, NULL); // Asocia la función de interrupción al pin
|
|||
|
|||
// Configura la rutina de interrupción para activar el semáforo
|
|||
// ...
|
|||
|
|||
// Crea la tarea de base
|
|||
// xTaskCreate(base_task, "base_task", 2048, NULL, 15, NULL);
|
|||
// xTaskCreatePinnedToCore(base_task, "base_task", 2048, NULL, 15, NULL, 0);
|
|||
|
|||
// Inicia el sistema operativo en tiempo real
|
|||
// vTaskStartScheduler();
|
|||
|
|||
while(1){ |
|||
// Espera al semáforo
|
|||
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) { |
|||
// La tarea responde al semáforo aquí
|
|||
// Realiza el trabajo necesario
|
|||
printf("- "); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue