Skip to content

Commit

Permalink
update: 8 bit error status indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed Jul 28, 2024
1 parent 9a29be1 commit 3f59d1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
25 changes: 17 additions & 8 deletions device/firmware/Core/Inc/energymeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

#include "usbd_cdc_if.h"

#define TRUE 1
#define FALSE 0
/******************************************************************************
* basic definitions
*****************************************************************************/
#define TRUE (1)
#define FALSE (0)

#define BIT_SET(target, pos) ((target) |= (1 << (pos)))
#define BIT_CLEAR(target, pos) ((target) &= ~(1 << (pos)))
Expand All @@ -24,20 +27,22 @@
/******************************************************************************
* module error configuration
*****************************************************************************/
extern uint32_t error_status;
extern uint8_t error_status;

// max 8 entries
typedef enum {
EEM_NO_ERROR,
EEM_ERR_INVALID_ID,
EEM_ERR_SD_CARD,
EEM_ERR_HARDFAULT,
} error_type_t;

/******************************************************************************
* logger configuration
*****************************************************************************/
extern uint32_t boot_time;

// flash page 63, PM0075 Table 3. Flash module organization
// flash page 63, PM0075 Table 3. Flash module organization (medium density)
#define FLASH_TARGET_PAGE 0x0800FC00
#define FLASH_CANARY_DEVICE_ID 0xBADACAFE

Expand All @@ -50,6 +55,8 @@ typedef struct {
#define DEVICE_ID_INVALID 0xFFFF;
#define DEVICE_ID_BROADCAST 0xFFFE;

/* log format definitions */
// max 8 entries
typedef enum {
LOG_TYPE_REPORT, // 10Hz HV / LV report
LOG_TYPE_EVENT, // instant event record
Expand All @@ -73,8 +80,9 @@ typedef struct {
} log_item_command_t;

typedef struct {
uint32_t error_time; // error event time
uint16_t _reserved; // reserved for future use
uint32_t time; // latest error event time
uint8_t status; // all present error status
uint8_t _reserved; // reserved for future use
} log_item_error_t;

typedef struct {
Expand All @@ -87,10 +95,11 @@ typedef struct {
} payload; // 6 byte log payload
uint8_t type; // log type
uint8_t _reserved; // reserved for future use
uint16_t id; // my device id
uint16_t id; // device id
uint16_t checksum; // CRC-16 checksum
} log_item_t;

/* remote command definitions */
typedef struct {
uint16_t target; // target device id
union {
Expand Down Expand Up @@ -133,7 +142,7 @@ static inline void debug_print(const char *fmt, ...) {
vsprintf(debug_buffer, fmt, args);

CDC_Transmit_FS((uint8_t *)debug_buffer, strlen(debug_buffer));
HAL_Delay(10); // TODO: implement buffer instead of busy waiting
HAL_Delay(10); // just busy wait a bit
}

#define DEBUG_MSG(fmt, ...) debug_print(fmt, ##__VA_ARGS__)
Expand Down
6 changes: 1 addition & 5 deletions device/firmware/Core/Src/energymeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ uint8_t rf_buffer_arr[1 << 10]; // 1KB
uint32_t device_id = DEVICE_ID_INVALID;

/* ERROR STATUS */
uint32_t error_status = EEM_NO_ERROR;
uint8_t error_status = EEM_NO_ERROR;

/* USB CDC debug print buffer */
char debug_buffer[MAX_LEN_DEBUG_STR];
Expand Down Expand Up @@ -76,10 +76,6 @@ void mode_energymeter(void) {
BIT_SET(error_status, EEM_ERR_SD_CARD);
};

UINT a;
f_write(&fp, "devid", 5, &a);
f_close(&fp);

/* start 100ms timer */
HAL_TIM_Base_Start_IT(&TIMER_100ms);

Expand Down

0 comments on commit 3f59d1c

Please sign in to comment.