config.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #ifndef CONFIG_H_
  4. #define CONFIG_H_
  5. #define I2C_TX_MAX_PACKET_SIZE (8)
  6. #define I2C_RX_MAX_PACKET_SIZE (12)
  7. #define BATTERY_THRESHOLD (20)
  8. #define TEMPERATURE_MAX_C (60)
  9. #define MAX_CYCLES (2)
  10. #define TARGET_BASE_ADDRESS (0x48)
  11. #define MEASUREMENT_CHECK_INTERVAL 160000 //Do not know yet the exact timing
  12. #define HEALTHY_BATTERY_VALUE (3800)
  13. /*
  14. * https://www.embedded.com/introduction-to-the-volatile-keyword/
  15. * https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/393364/avoid-race-condition-between-isr-and-main
  16. * https://www.omi.me/blogs/firmware-guides/how-to-handle-race-conditions-in-embedded-c-without-using-an-rtos
  17. * A variable should be declared as volatile if the value could change unexpectedly.
  18. * In practice, only three types of variable could change:
  19. * Memory-mapped peripheral registers
  20. * Global variables modified by an ISR
  21. * Global variables within a multi-threaded application
  22. * The volatile keyword in C is used to inform the compiler not to optimize access to a variable that might change unexpectedly.
  23. * This is particularly useful for variables shared between an interrupt service routine (ISR) and the main program.
  24. Observation Noted are:
  25. - Race condition while reading and storing the buffers, leading to lag the Rx Buffer during the execution at times or completely lagging by 1 for each slots; incorrect Read
  26. */
  27. typedef struct{
  28. volatile uint8_t txBuffer[I2C_TX_MAX_PACKET_SIZE];
  29. volatile uint8_t txLen;
  30. volatile uint8_t txCount;
  31. volatile bool txComplete;
  32. }tx_Packet;
  33. typedef struct{
  34. volatile uint8_t rxBuffer[I2C_RX_MAX_PACKET_SIZE];
  35. volatile uint8_t rxLen;
  36. volatile uint8_t rxCount;
  37. volatile bool rxComplete;
  38. }rx_Packet;
  39. // Global variables declared in i2c_hal.c
  40. extern tx_Packet txPacket;
  41. extern rx_Packet rxPacket;
  42. #endif