-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
8e8b7e2
commit 80b9b51
Showing
3 changed files
with
267 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,188 @@ | ||
#include <Sts1CobcSw/Periphery/FlashMock.hpp> | ||
|
||
#include <strong_type/type.hpp> | ||
|
||
#include <cstring> | ||
|
||
|
||
namespace sts1cobcsw::flash | ||
{ | ||
std::int64_t initializeDelay = 0; | ||
|
||
|
||
auto doInitialize = empty::DoInitialize; | ||
auto doReadJedecId = empty::DoReadJedecId; | ||
auto doReadStatusRegister = empty::DoReadStatusRegister; | ||
|
||
auto doReadPage = empty::DoReadPage; | ||
auto doProgramPage = empty::DoProgramPage; | ||
auto doEraseSector = empty::DoEraseSector; | ||
auto doWaitWhileBusy = empty::DoWaitWhileBusy; | ||
auto doActualBaudRate = empty::DoActualBaudRate; | ||
|
||
|
||
// --- Mocked functions --- | ||
|
||
auto Initialize() -> void | ||
{ | ||
return doInitialize(); | ||
} | ||
|
||
|
||
auto ReadJedecId() -> JedecId | ||
{ | ||
return doReadJedecId(); | ||
} | ||
|
||
|
||
auto ReadStatusRegister(std::int8_t registerNo) -> Byte | ||
{ | ||
return doReadStatusRegister(registerNo); | ||
} | ||
|
||
|
||
auto ReadPage(std::uint32_t address) -> Page | ||
{ | ||
return doReadPage(address); | ||
} | ||
|
||
|
||
auto ProgramPage(std::uint32_t address, PageSpan data) -> void | ||
{ | ||
return doProgramPage(address, data); | ||
} | ||
|
||
|
||
auto EraseSector(std::uint32_t address) -> void | ||
{ | ||
return doEraseSector(address); | ||
} | ||
|
||
|
||
auto WaitWhileBusy(std::int64_t timeout) -> Result<void> | ||
{ | ||
return doWaitWhileBusy(timeout); | ||
} | ||
|
||
|
||
auto ActualBaudRate() -> std::int32_t | ||
{ | ||
return doActualBaudRate(); | ||
} | ||
|
||
|
||
// --- Set functions --- | ||
|
||
auto SetDoInitialize(void (*doInitializeFunction)()) -> void | ||
{ | ||
doInitialize = doInitializeFunction; | ||
} | ||
|
||
|
||
auto SetDoReadJedecId(JedecId (*doReadJedecIdFunction)()) -> void | ||
{ | ||
doReadJedecId = doReadJedecIdFunction; | ||
} | ||
|
||
|
||
auto SetDoReadStatusRegister(Byte (*doReadStatusRegisterFunction)(std::int8_t registerNo)) -> void | ||
{ | ||
doReadStatusRegister = doReadStatusRegisterFunction; | ||
} | ||
|
||
|
||
auto SetDoReadPage(Page (*doReadPageFunction)(std::uint32_t address)) -> void | ||
{ | ||
doReadPage = doReadPageFunction; | ||
} | ||
|
||
|
||
auto SetDoProgramPage(void (*doProgramPageFunction)(std::uint32_t address, PageSpan data)) -> void | ||
{ | ||
doProgramPage = doProgramPageFunction; | ||
} | ||
|
||
|
||
auto SetDoEraseSector(void (*doEraseSectorFunction)(std::uint32_t address)) -> void | ||
{ | ||
doEraseSector = doEraseSectorFunction; | ||
} | ||
|
||
|
||
auto SetDoWaitWhileBusyFunction(Result<void> (*doWaitWhileBusy)(std::int64_t timeout)) -> void | ||
{ | ||
doWaitWhileBusy = doWaitWhileBusyFunction; | ||
} | ||
|
||
|
||
auto SetDoActualBaudRate(std::int32_t (*doActualBaudRateFunction)()) -> void | ||
{ | ||
doActualBaudRate = doActualBaudRateFunction; | ||
} | ||
|
||
|
||
// --- Predefined do functions --- | ||
|
||
namespace empty | ||
{ | ||
auto SetAllDoFunctions() -> void | ||
{ | ||
SetDoInitialize(DoInitialize); | ||
SetDoReadJedecId(DoReadJedecId); | ||
SetDoReadStatusRegister(DoReadStatusRegister); | ||
|
||
SetDoReadPage(DoReadPage); | ||
SetDoProgramPage(DoProgramPage); | ||
SetDoEraseSector(DoEraseSector); | ||
SetDoWaitWhileBusy(DoWaitWhileBusy); | ||
SetDoActualBaudRate(DoActualBaudRate); | ||
} | ||
|
||
|
||
auto DoInitialize() -> void | ||
{ | ||
RODOS::AT(initializeDelay); | ||
} | ||
|
||
|
||
auto DoReadJedecId() -> JedecId | ||
{ | ||
return JedecId; | ||
} | ||
|
||
|
||
auto DoReadStatusRegister(std::int8_t registerNo) -> Byte | ||
{ | ||
return 0x0000; | ||
} | ||
|
||
|
||
auto DoReadPage(std::uint32_t address) -> Page | ||
{ | ||
return 0; | ||
} | ||
|
||
|
||
auto DoProgramPage(std::uint32_t address, PageSpan data) -> void | ||
{ | ||
} | ||
|
||
|
||
auto DoEraseSector(std::uint32_t address) -> void | ||
{ | ||
} | ||
|
||
|
||
auto DoWaitWhileBusy(std::int64_t timeout) -> Result<void> | ||
{ | ||
return outcome_v2::success(); | ||
} | ||
|
||
|
||
auto DoActualBaudRate() -> std::int32_t | ||
{ | ||
return 0; | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! @file | ||
//! @brief Driver for the flash memory W25Q01JV. | ||
|
||
#pragma once | ||
|
||
|
||
#include <Sts1CobcSw/Hal/Spi.hpp> | ||
#include <Sts1CobcSw/Outcome/Outcome.hpp> | ||
#include <Sts1CobcSw/Serial/Byte.hpp> | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <span> | ||
|
||
|
||
namespace sts1cobcsw::flash | ||
{ | ||
/*struct JedecId | ||
{ | ||
std::uint8_t manufacturerId = 0; | ||
std::uint16_t deviceId = 0; | ||
}; | ||
enum class ErrorCode | ||
{ | ||
timeout = 1 | ||
}; | ||
template<typename T> | ||
using Result = outcome_v2::experimental::status_result<T, ErrorCode, RebootPolicy>; | ||
[[maybe_unused]] constexpr std::size_t pageSize = 256; // bytes | ||
[[maybe_unused]] constexpr std::size_t sectorSize = 4 * 1024; // bytes | ||
[[maybe_unused]] constexpr std::size_t smallBlockSize = 32 * 1024; // bytes | ||
[[maybe_unused]] constexpr std::size_t largeBlockSize = 64 * 1024; // bytes | ||
[[maybe_unused]] constexpr std::size_t flashSize = 128 * 1024 * 1024; // bytes | ||
[[maybe_unused]] constexpr std::size_t nSectors = flashSize / sectorSize; | ||
[[maybe_unused]] constexpr std::size_t nSmallBlocks = flashSize / smallBlockSize; | ||
[[maybe_unused]] constexpr std::size_t nLargeBlocks = flashSize / largeBlockSize; | ||
using Page = std::array<Byte, pageSize>; | ||
using PageSpan = std::span<Byte const, pageSize>; | ||
inline constexpr auto correctJedecId = JedecId{.manufacturerId = 0xEF, .deviceId = 0x4021}; | ||
extern hal::Spi spi;*/ | ||
|
||
auto SetDoInitialize(void (*doInitializeFunction)()) -> void; | ||
auto SetDoReadJedecId(JedecId (*doReadJedecIdFunction)()) -> void; | ||
auto SetDoReadStatusRegister(Byte (*doReadStatusRegisterFunction)(std::int8_t registerNo)) -> void; | ||
|
||
auto SetDoReadPage(Page (*doReadPageFunction)(std::uint32_t address)) -> void; | ||
auto SetDoProgramPage(void (*doProgramPageFunction)(std::uint32_t address, PageSpan data)) -> void; | ||
auto SetDoEraseSector(void (*doEraseSectorFunction)(std::uint32_t address)) -> void; | ||
auto SetDoWaitWhileBusyFunction(Result<void> (*doWaitWhileBusy)(std::int64_t timeout)) -> void; | ||
auto SetDoActualBaudRate(std::int32_t (*doActualBaudRateFunction)()) -> void; | ||
} | ||
|
||
namespace empty | ||
{ | ||
auto SetAllDoFunctions() -> void; | ||
|
||
auto DoInitialize() -> void; | ||
auto DoReadJedecId() -> JedecId; | ||
auto DoReadStatusRegister(std::int8_t registerNo) -> Byte; | ||
|
||
auto DoReadPage(std::uint32_t address) -> Page; | ||
auto DoProgramPage(std::uint32_t address, PageSpan data) -> void; | ||
auto DoEraseSector(std::uint32_t address) -> void; | ||
auto DoWaitWhileBusy(std::int64_t timeout) -> Result<void>; | ||
auto DoActualBaudRate() -> std::int32_t; | ||
} |