Skip to content

Commit

Permalink
⭐ ferat(GPIO_EXTI) extract int callbacks to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
polesskiy-dev committed Oct 7, 2024
1 parent 5ed54dc commit 2795200
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 75 deletions.
1 change: 1 addition & 0 deletions firmware/iot-risk-logger-stm32l4/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
#include "actor.h"
#include "event_manager.h"
#include "power_mode_manager.h"
#include "gpio_ext_interrupts.h"
#include "nfc.h"
#include "memory.h"
#include "temperature_humidity_sensor.h"
Expand Down
33 changes: 20 additions & 13 deletions firmware/iot-risk-logger-stm32l4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ DEBUG = 1
OPT = -Og

# NOR Flash: erase & write FAT12 filesystem boot header
ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR = 0

FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR = 0
# NOR Flash: actual writing is enabled
FLASH_WRITE_ENABLED = 0


#######################################
Expand Down Expand Up @@ -114,14 +115,15 @@ libraries/SystemView/SYSVIEW/SEGGER_SYSVIEW.c \
libraries/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c \
app/core/trace/SEGGER_SYSVIEW_Config_FreeRTOS.c \
app/core/actor/actor.c \
app/core/gpio_ext_interrupts/gpio_ext_interrupts.c \
app/core/power_mode_manager/power_mode_manager.c \
app/core/cron/cron.c \
app/core/fs_static/fs_static.c \
app/core/info_led/info_led.c \
app/config/actors_list/actors_list.c \
app/config/events_list/events_list.c \
app/config/bsp_bus/bsp_bus.c \
app/core/power_mode_manager/power_mode_manager.c \
app/tasks/event_manager/event_manager.c \
app/core/cron/cron.c \
app/core/info_led/info_led.c \
app/core/fs_static/fs_static.c \
app/drivers/opt3001/opt3001.c \
app/drivers/sht3x/sht3x.c \
app/drivers/w25q/w25q.c \
Expand Down Expand Up @@ -215,19 +217,20 @@ C_INCLUDES = \
-Ilibraries/SystemView/SYSVIEW \
-Ilibraries/SystemView/Sample/FreeRTOSV10 \
-Iapp/core/actor \
-Iapp/config/actors_list/actors_list \
-Iapp/config/events_list/events_list \
-Iapp/config/bsp_bus \
-Iapp/core/trace \
-Iapp/core/power_mode_manager \
-Iapp/config/bsp_bus \
-Iapp/core/fs_static \
-Iapp/core/power_mode_manager \
-Iapp/core/cron \
-Iapp/core/info_led \
-Iapp/core/gpio_ext_interrupts \
-Iapp/config/actors_list/actors_list \
-Iapp/config/events_list/events_list \
-Iapp/tasks/event_manager \
-Iapp/drivers/opt3001 \
-Iapp/drivers/sht3x \
-Iapp/drivers/w25q \
-Iapp/middlewares/usb_msc_storage \
-Iapp/core/cron \
-Iapp/core/info_led \
-Iapp/tasks/memory \
-Iapp/tasks/temperature_humidity_sensor \
-Iapp/tasks/light_sensor \
Expand All @@ -242,10 +245,14 @@ ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 -DDEBUG
endif

ifeq ($(ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR), 1)
ifeq ($(FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR), 1)
CFLAGS += -DERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR
endif

ifeq ($(FLASH_WRITE_ENABLED), 1)
CFLAGS += -FLASH_WRITE_ENABLED
endif


# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* @file gpio_ext_interrupts.c
* @brief implementation of gpio_ext_interrupts
*
* Detailed description of the implementation file.
*
* @date 07/10/2024
* @author artempolisskyi
*/

#include "gpio_ext_interrupts.h"

extern actor_t* ACTORS_LIST_SystemRegistry[MAX_ACTORS];

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == USB_VBUS_SENSE_Pin) {
GPIO_PinState usbVBusPin = HAL_GPIO_ReadPin(USB_VBUS_SENSE_GPIO_Port, USB_VBUS_SENSE_Pin);
osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId;

if (usbVBusPin == GPIO_PIN_SET) {
osMessageQueuePut(evManagerQueue, &(message_t) {USB_CONNECTED}, 0, 0);
#if DEBUG
fprintf(stdout, "USB connected\n");
#endif
} else {
osMessageQueuePut(evManagerQueue, &(message_t) {USB_DISCONNECTED}, 0, 0);
#if DEBUG
fprintf(stdout, "USB disconnected\n");
#endif
}
}

// TODO maybe check only falling edge (configure in CubeMX)
if (GPIO_Pin == _NFC_INT_Pin) {
#ifdef DEBUG
fprintf(stdout, "NFC GPO Interrupt\n");
#endif
osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* @file gpio_ext_interrupts.h
* @brief Brief description of the file.
*
* Detailed description of the file.
*
* @date 07/10/2024
* @author artempolisskyi
*/

#ifndef GPIO_EXT_INTERRUPTS_H
#define GPIO_EXT_INTERRUPTS_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>

#include "main.h"


#ifdef __cplusplus
}
#endif

#endif //GPIO_EXT_INTERRUPTS_H
34 changes: 6 additions & 28 deletions firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,6 @@ uint32_t MEMORY_SeekFreeSpaceAddress(void) {
return addr;
}

// TODO move to more suitable place
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == USB_VBUS_SENSE_Pin) {
GPIO_PinState usbVBusPin = HAL_GPIO_ReadPin(USB_VBUS_SENSE_GPIO_Port, USB_VBUS_SENSE_Pin);
osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId;

if (usbVBusPin == GPIO_PIN_SET) {
osMessageQueuePut(evManagerQueue, &(message_t) {USB_CONNECTED}, 0, 0);
#if DEBUG
fprintf(stdout, "USB connected\n");
#endif
} else {
osMessageQueuePut(evManagerQueue, &(message_t) {USB_DISCONNECTED}, 0, 0);
#if DEBUG
fprintf(stdout, "USB disconnected\n");
#endif
}
}

if (GPIO_Pin == _NFC_INT_Pin) {
#ifdef DEBUG
fprintf(stdout, "NFC GPO Interrupt\n");
#endif
osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0);
}
}

/**
* @brief Writes FAT12 boot sector to the NOR Flash
Expand Down Expand Up @@ -229,7 +203,7 @@ static osStatus_t handleInit(MEMORY_Actor_t *this, message_t *message) {
fprintf(stdout, "W25Q NOR MF ID: 0x%x, Device ID: 0x%x\n", norFlashID[0], norFlashID[1]);
#endif

#ifdef ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR
#ifdef FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR
writeFAT12BootSector(&MEMORY_Actor);
#endif

Expand Down Expand Up @@ -324,6 +298,8 @@ static void publishMemoryWriteOnMeasurementsReady(MEMORY_Actor_t *this) {
}

static osStatus_t appendMeasurementsToNORFlashLogTail(MEMORY_Actor_t *this) {
osStatus_t ioStatus = osOK;

// sensors actors pointers from the system registry
TH_SENS_Actor_t *thSensActor = (TH_SENS_Actor_t *)ACTORS_LIST_SystemRegistry[TEMPERATURE_HUMIDITY_SENSOR_ACTOR_ID];
LIGHT_SENS_Actor_t *lightSensorActor = (LIGHT_SENS_Actor_t *)ACTORS_LIST_SystemRegistry[LIGHT_SENSOR_ACTOR_ID];
Expand All @@ -350,7 +326,9 @@ static osStatus_t appendMeasurementsToNORFlashLogTail(MEMORY_Actor_t *this) {
#endif

// write measurements to the memory
osStatus_t ioStatus = osOK; //W25Q_WriteData(&MEMORY_W25QHandle, (uint8_t *) &sensorsMeasurementEntry, this->logFileTailAddress, MEMORY_LOG_ENTRY_SIZE);
#ifdef FLASH_WRITE_ENABLED
ioStatus = W25Q_WriteData(&MEMORY_W25QHandle, (uint8_t *) &sensorsMeasurementEntry, this->logFileTailAddress, MEMORY_LOG_ENTRY_SIZE);
#endif

// increment tail free space address for the next entry
this->logFileTailAddress += MEMORY_LOG_ENTRY_SIZE;
Expand Down
7 changes: 6 additions & 1 deletion firmware/iot-risk-logger-stm32l4/app/tasks/nfc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
@startuml
title NFC FSM
hide empty description
STANDBY: RF free\nI2C free
[*] --> STANDBY : INITIALIZE
MAILBOX_TRANSMISSION: Mailbox data exchange
ERROR: Error state\n\nGLOBAL_ERROR: Error message
[*] --> STANDBY : GLOBAL_CMD_INITIALIZE
STANDBY --> MAILBOX_TRANSMISSION : NFC_GPO_INTERRUPT
STANDBY --> ERROR : ERROR
@enduml
```
Expand Down
18 changes: 6 additions & 12 deletions firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
static osStatus_t handleNFCFSM(NFC_Actor_t *this, message_t *message);
static osStatus_t handleInit(NFC_Actor_t *this, message_t *message);

extern actor_t* ACTORS_LIST_SystemRegistry[MAX_ACTORS];

NFC_Actor_t NFC_Actor = {
.super = {
.actorId = NFC_ACTOR_ID,
Expand Down Expand Up @@ -53,24 +55,16 @@ void NFC_Task(void *argument) {
// Wait for messages from the queue
if (osMessageQueueGet(NFC_Actor.super.osMessageQueueId, &msg, NULL, osWaitForever) == osOK) {
osStatus_t status = NFC_Actor.super.messageHandler((actor_t *) &NFC_Actor, &msg);

if (status != osOK) {
// TODO Handle error, emit common error event and reinitialize module
NFC_Actor.state = NFC_STATE_ERROR;
osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId;
osMessageQueuePut(evManagerQueue, &(message_t){GLOBAL_ERROR, .payload.value = NFC_ACTOR_ID}, 0, 0);
TO_STATE(&NFC_Actor, NFC_STATE_ERROR);
}
}
}
}

/** Handle GPO interrupt */
//void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
// if (GPIO_Pin == _NFC_INT_Pin) {
// #ifdef DEBUG
// fprintf(stdout, "NFC GPO Interrupt\n");
// #endif
// osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0);
// }
//}

static osStatus_t handleNFCFSM(NFC_Actor_t *this, message_t *message) {
switch (this->state) {
case NFC_NO_STATE:
Expand Down
5 changes: 0 additions & 5 deletions firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ int32_t NFC_ST25DVInit(ST25DV_Object_t *pObj) {
return NFCTAG_OK;
}

int32_t NFC_LowPowerMode(ST25DV_Object_t *pObj) {

return NFCTAG_OK;
}

void NFC_HandleGPOInterrupt(ST25DV_Object_t *pObj) {
uint8_t ITStatus;
ST25DV_ReadITSTStatus_Dyn(pObj, &ITStatus);
Expand Down
34 changes: 18 additions & 16 deletions hardware-debug/iot-risk-logger-stm32l4.ozone.jdebug.user
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@


Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:132:5, State=BP_STATE_DISABLED
Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:251:9, State=BP_STATE_DISABLED
OpenDocument="memory.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c", Line=286
OpenDocument="tasks.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=3402
OpenDocument="main.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/main.c", Line=55
Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:111:5, State=BP_STATE_DISABLED
Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:140:5, State=BP_STATE_DISABLED
Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:253:5, State=BP_STATE_DISABLED
OpenDocument="stm32l4xx_it.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/stm32l4xx_it.c", Line=79
OpenDocument="memory.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c", Line=88
OpenDocument="tasks.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=3652
OpenDocument="main.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/main.c", Line=64
OpenToolbar="Debug", Floating=0, x=0, y=0
OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Registers 1", DockArea=RIGHT, x=0, y=4, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, FilteredItems=[], RefreshRate=1
OpenWindow="Source Files", DockArea=LEFT, x=0, y=2, w=323, h=187, TabPos=1, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=3, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=323, h=172, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=255
OpenWindow="Global Data", DockArea=RIGHT, x=0, y=0, w=361, h=100, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Local Data", DockArea=RIGHT, x=0, y=1, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=323, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Functions", DockArea=LEFT, x=0, y=2, w=323, h=187, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Terminal", DockArea=BOTTOM, x=0, y=0, w=544, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Console", DockArea=BOTTOM, x=1, y=0, w=735, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Source Files", DockArea=LEFT, x=0, y=2, w=323, h=175, TabPos=1, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=3, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=323, h=168, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=255
OpenWindow="Global Data", DockArea=RIGHT, x=0, y=0, w=361, h=97, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Local Data", DockArea=RIGHT, x=0, y=1, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=323, h=107, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Functions", DockArea=LEFT, x=0, y=2, w=323, h=175, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Terminal", DockArea=BOTTOM, x=0, y=0, w=302, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
OpenWindow="Console", DockArea=BOTTOM, x=1, y=0, w=959, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
SmartViewPlugin="", Page="", Toolbar="Hidden", Window="SmartView 1"
TableHeader="Source Files", SortCol="File", SortOrder="ASCENDING", VisibleCols=["File";"Status";"Size";"#Insts";"Path"], ColWidths=[197;100;100;100;980]
TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[1236;100;100;100;100]
TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[183;269;100;100;100;100]
TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[183;269;100;100;100;272]
TableHeader="Vector Catches", SortCol="", SortOrder="ASCENDING", VisibleCols=["";"Vector Catch";"Description"], ColWidths=[50;300;500]
TableHeader="Break & Tracepoints", SortCol="", SortOrder="ASCENDING", VisibleCols=["";"Type";"Location";"Extras"], ColWidths=[100;100;350;224]
TableHeader="Local Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[152;206;100;100;100;100]
Expand Down

0 comments on commit 2795200

Please sign in to comment.