cleanup
This commit is contained in:
5
1 software design/components/drivers/nvm/CMakeLists.txt
Normal file
5
1 software design/components/drivers/nvm/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
idf_component_register(
|
||||
SRCS "com/nvm.cpp"
|
||||
INCLUDE_DIRS "com"
|
||||
REQUIRES nvs_flash logger
|
||||
)
|
||||
87
1 software design/components/drivers/nvm/com/nvm.cpp
Normal file
87
1 software design/components/drivers/nvm/com/nvm.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* @file nvm.cpp
|
||||
* @brief NVM driver component implementation
|
||||
* @author Mahmoud Elmohtady
|
||||
* @company Nabd solutions - ASF
|
||||
* @copyright Copyright (c) 2025
|
||||
*/
|
||||
|
||||
#include "nvm.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
static const char* TAG = "NvmDriver";
|
||||
|
||||
NvmDriver::NvmDriver()
|
||||
: m_isInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
NvmDriver::~NvmDriver()
|
||||
{
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool NvmDriver::initialize()
|
||||
{
|
||||
// TODO: Implement NVM initialization
|
||||
m_isInitialized = true;
|
||||
ASF_LOGI(TAG, 3200, asf::logger::Criticality::LOW, "NVM driver initialized successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NvmDriver::deinitialize()
|
||||
{
|
||||
if (!m_isInitialized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Implement NVM deinitialization
|
||||
m_isInitialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
NvmResult NvmDriver::read(const char* key, void* value, size_t* length)
|
||||
{
|
||||
if (!m_isInitialized || key == nullptr || value == nullptr || length == nullptr)
|
||||
{
|
||||
return NvmResult::ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// TODO: Implement NVM read
|
||||
(void)key;
|
||||
(void)value;
|
||||
(void)length;
|
||||
return NvmResult::OK;
|
||||
}
|
||||
|
||||
NvmResult NvmDriver::write(const char* key, const void* value, size_t length)
|
||||
{
|
||||
if (!m_isInitialized || key == nullptr || value == nullptr)
|
||||
{
|
||||
return NvmResult::ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// TODO: Implement NVM write
|
||||
(void)key;
|
||||
(void)value;
|
||||
(void)length;
|
||||
return NvmResult::OK;
|
||||
}
|
||||
|
||||
NvmResult NvmDriver::erase(const char* key)
|
||||
{
|
||||
if (!m_isInitialized || key == nullptr)
|
||||
{
|
||||
return NvmResult::ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// TODO: Implement NVM erase
|
||||
(void)key;
|
||||
return NvmResult::OK;
|
||||
}
|
||||
|
||||
bool NvmDriver::isInitialized() const
|
||||
{
|
||||
return m_isInitialized;
|
||||
}
|
||||
49
1 software design/components/drivers/nvm/com/nvm.hpp
Normal file
49
1 software design/components/drivers/nvm/com/nvm.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file nvm.hpp
|
||||
* @brief NVM driver component header - Non-volatile memory management
|
||||
* @author Mahmoud Elmohtady
|
||||
* @company Nabd solutions - ASF
|
||||
* @copyright Copyright (c) 2025
|
||||
*/
|
||||
|
||||
#ifndef NVM_HPP
|
||||
#define NVM_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief NVM result enumeration
|
||||
*/
|
||||
enum class NvmResult
|
||||
{
|
||||
OK,
|
||||
ERROR_INVALID_PARAM,
|
||||
ERROR_NOT_FOUND,
|
||||
ERROR_FAIL
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief NVM driver class
|
||||
*
|
||||
* Provides non-volatile memory management functionality.
|
||||
*/
|
||||
class NvmDriver
|
||||
{
|
||||
public:
|
||||
NvmDriver();
|
||||
~NvmDriver();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
NvmResult read(const char* key, void* value, size_t* length);
|
||||
NvmResult write(const char* key, const void* value, size_t length);
|
||||
NvmResult erase(const char* key);
|
||||
bool isInitialized() const;
|
||||
|
||||
private:
|
||||
bool m_isInitialized;
|
||||
};
|
||||
|
||||
#endif // NVM_HPP
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ID,Component,Level,Criticality,Message
|
||||
3200,NVM,INFO,Low,NVM driver initialized successfully
|
||||
|
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
folder_path = os.path.abspath(os.path.join("components", "system_tests"))
|
||||
if folder_path not in sys.path:
|
||||
sys.path.append(folder_path)
|
||||
|
||||
from scan_serial import ESP32Runner
|
||||
|
||||
def test_nvm_initialize():
|
||||
runner = ESP32Runner(mode="SIM", port="COM9")
|
||||
runner.start()
|
||||
print("--- QEMU Runner Started ---", flush=True)
|
||||
try:
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < 30:
|
||||
line = runner.get_line(timeout=1.0)
|
||||
if line:
|
||||
print(line, flush=True)
|
||||
if "NVM driver initialized successfully" in line:
|
||||
print("SUCCESS CRITERIA MET!", flush=True)
|
||||
return 0
|
||||
if runner.process.poll() is not None:
|
||||
print(f"Process exited with code: {runner.process.returncode}", flush=True)
|
||||
return 1
|
||||
finally:
|
||||
runner.stop()
|
||||
print("Done.", flush=True)
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = test_nvm_initialize()
|
||||
sys.exit(exit_code)
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test_scenario>
|
||||
<!-- The configuration for the test environment. -->
|
||||
<!-- Available configurations: SIMULATE, HIL -->
|
||||
<config>SIMULATE</config>
|
||||
|
||||
<test_case>
|
||||
<test_case_id>NVM_INIT_TEST</test_case_id>
|
||||
<!-- The main command that executes the test itself. -->
|
||||
<test_exec>python components/drivers/nvm/test/nvm_init_test.py</test_exec>
|
||||
</test_case>
|
||||
|
||||
|
||||
</test_scenario>
|
||||
47
1 software design/components/drivers/nvm/test/test_nvm.cpp
Normal file
47
1 software design/components/drivers/nvm/test/test_nvm.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file test_nvm.cpp
|
||||
* @brief Unit tests for NVM driver component
|
||||
* @author Mahmoud Elmohtady
|
||||
* @company Nabd solutions - ASF
|
||||
* @copyright Copyright (c) 2025
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "nvm.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_nvm_initialize(void)
|
||||
{
|
||||
NvmDriver nvm;
|
||||
bool result = nvm.initialize();
|
||||
TEST_ASSERT_TRUE(result);
|
||||
TEST_ASSERT_TRUE(nvm.isInitialized());
|
||||
}
|
||||
|
||||
void test_nvm_read_write(void)
|
||||
{
|
||||
NvmDriver nvm;
|
||||
nvm.initialize();
|
||||
|
||||
uint32_t writeValue = 12345;
|
||||
size_t length = sizeof(writeValue);
|
||||
|
||||
NvmResult result = nvm.write("test_key", &writeValue, length);
|
||||
TEST_ASSERT_EQUAL(NvmResult::OK, result);
|
||||
|
||||
uint32_t readValue = 0;
|
||||
result = nvm.read("test_key", &readValue, &length);
|
||||
TEST_ASSERT_EQUAL(NvmResult::OK, result);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user