-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
614 additions
and
635 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,83 @@ | ||
// core_boot.cpp | ||
|
||
#ifdef NSPANEL_HA_BLUEPRINT_CORE_BOOT | ||
|
||
#include "core_boot.h" // Include the header file for function and variable declarations. | ||
|
||
namespace nspanel_ha_blueprint { | ||
|
||
// Definition of the global variable to track completed boot steps. | ||
// Each bit in this variable represents whether a boot step has been completed. | ||
DRAM_ATTR uint32_t completed_boot_steps = 0; | ||
// Total number of defined boot steps. | ||
uint8_t total_boot_steps = 0; | ||
uint32_t completed_boot_steps = 0; | ||
uint32_t registered_applications = 0; | ||
|
||
// Function to mark a boot step as completed. | ||
// Parameters: | ||
// step - The boot step constant representing the step to be marked as completed. | ||
bool complete_boot_step(const uint32_t step) { | ||
// Validate that the step is a power of two (i.e., only one bit is set). | ||
// This ensures that only valid boot step constants are accepted. | ||
if (step == 0 || (step & (step - 1)) != 0) { | ||
// If the step is zero or not a power of two, it's invalid. | ||
return false; | ||
} | ||
// Use bitwise OR to set the corresponding bit in completed_boot_steps. | ||
// This marks the boot step as completed. | ||
completed_boot_steps |= step; | ||
return true; | ||
} | ||
|
||
// Function to register an application for boot. | ||
bool register_application(const uint32_t app_bit) { | ||
// Validate that the app_bit is a power of two (i.e., only one bit is set). | ||
if (app_bit == 0 || (app_bit & (app_bit - 1)) != 0) { | ||
return false; | ||
} | ||
// Check if the application is already registered, if not, increment total_boot_steps. | ||
if ((registered_applications & app_bit) == 0) { | ||
total_boot_steps++; | ||
} | ||
// Use bitwise OR to set the corresponding bit in registered_applications. | ||
registered_applications |= app_bit; | ||
return true; | ||
} | ||
|
||
// Helper function to count the number of bits set to '1' in a uint32_t value. | ||
// Parameters: | ||
// value - The uint32_t value whose bits are to be counted. | ||
// Returns: | ||
// The number of bits set to '1' as an integer. | ||
uint8_t count_bits_set(uint32_t value) { | ||
uint8_t count = 0; | ||
while (value) { | ||
// Increment count if the least significant bit is '1'. | ||
count += value & 1; | ||
// Right-shift the value to check the next bit. | ||
value >>= 1; | ||
} | ||
return count; | ||
} | ||
|
||
// Function to get the number of unique boot steps that have been completed. | ||
// Returns: | ||
// The count of completed boot steps as an integer. | ||
uint8_t get_boot_steps_completed() { | ||
return count_bits_set(completed_boot_steps); | ||
} | ||
|
||
// Function to calculate the boot progress percentage with rounding. | ||
// Returns: | ||
// The boot progress percentage as a uint8_t between 0 and 100. | ||
uint8_t get_boot_progress_percentage() { | ||
// Calculate the percentage with rounding | ||
return static_cast<uint8_t>((get_boot_steps_completed() * 100 + TOTAL_BOOT_STEPS / 2) / TOTAL_BOOT_STEPS); | ||
if (total_boot_steps == 0) { | ||
return 0; | ||
} | ||
return static_cast<uint8_t>((get_boot_steps_completed() * 100 + total_boot_steps / 2) / total_boot_steps); | ||
} | ||
|
||
// Function to check if all boot steps have been completed. | ||
// Returns: | ||
// true if all boot steps are completed, false otherwise. | ||
// Function to check if all registered applications have completed boot. | ||
bool is_boot_complete() { | ||
return get_boot_steps_completed() == TOTAL_BOOT_STEPS; | ||
// Boot is complete if all bits set in registered_applications are also set in completed_boot_steps. | ||
return (registered_applications & completed_boot_steps) == registered_applications; | ||
} | ||
|
||
// Function to reset the completed boot steps to zero. | ||
// This clears all tracked boot steps. | ||
// Function to reset the completed boot steps and registered applications to zero. | ||
void reset_boot_steps() { | ||
total_boot_steps = 0; | ||
completed_boot_steps = 0; | ||
registered_applications = 0; | ||
} | ||
|
||
// Function to check if a specific boot step has been completed. | ||
// Parameters: | ||
// step - The boot step constant representing the step to check. | ||
// Returns: | ||
// true if the boot step has been completed; false otherwise. | ||
bool is_boot_step_completed(uint32_t step) { | ||
return (completed_boot_steps & step) != 0; | ||
} | ||
|
||
} // namespace nspanel_ha_blueprint | ||
|
||
#endif // NSPANEL_HA_BLUEPRINT_CORE_BOOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.