|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** @file pcd_common.h |
| 8 | + * |
| 9 | + * @ingroup pcd |
| 10 | + * @{ |
| 11 | + * @brief Common definitions for the PCD API. |
| 12 | + * |
| 13 | + * Common definitions are split out from the main PCD API to allow usage |
| 14 | + * from non-Zephyr code. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef PCD_COMMON_H__ |
| 18 | +#define PCD_COMMON_H__ |
| 19 | + |
| 20 | +#ifndef CONFIG_SOC_SERIES_NRF53X |
| 21 | +#error "PCD is only supported on nRF53 series" |
| 22 | +#endif |
| 23 | + |
| 24 | +#ifdef CONFIG_PCD_CMD_ADDRESS |
| 25 | +/* PCD command block location is static. */ |
| 26 | +#define PCD_CMD_ADDRESS CONFIG_PCD_CMD_ADDRESS |
| 27 | + |
| 28 | +#else |
| 29 | +/* PCD command block location is configured with Partition Manager. */ |
| 30 | +#include <pm_config.h> |
| 31 | + |
| 32 | +#ifdef PM_PCD_SRAM_ADDRESS |
| 33 | +/* PCD command block is in this domain, we are compiling for application core. */ |
| 34 | +#define PCD_CMD_ADDRESS PM_PCD_SRAM_ADDRESS |
| 35 | +#else |
| 36 | +/* PCD command block is in a different domain, we are compiling for network core. |
| 37 | + * Extra '_' since its in a different domain. |
| 38 | + */ |
| 39 | +#define PCD_CMD_ADDRESS PM__PCD_SRAM_ADDRESS |
| 40 | +#endif /* PM_PCD_SRAM_ADDRESS */ |
| 41 | + |
| 42 | +#endif /* CONFIG_PCD_CMD_ADDRESS */ |
| 43 | + |
| 44 | +/** Magic value written to indicate that a copy should take place. */ |
| 45 | +#define PCD_CMD_MAGIC_COPY 0xb5b4b3b6 |
| 46 | +/** Magic value written to indicate that debug should be locked. */ |
| 47 | +#define PCD_CMD_MAGIC_LOCK_DEBUG 0xb6f249ec |
| 48 | +/** Magic value written to indicate that a something failed. */ |
| 49 | +#define PCD_CMD_MAGIC_FAIL 0x25bafc15 |
| 50 | +/** Magic value written to indicate that a copy is done. */ |
| 51 | +#define PCD_CMD_MAGIC_DONE 0xf103ce5d |
| 52 | +/** Magic value written to indicate that a version number read should take place. */ |
| 53 | +#define PCD_CMD_MAGIC_READ_VERSION 0xdca345ea |
| 54 | + |
| 55 | +struct pcd_cmd { |
| 56 | + uint32_t magic; /* Magic value to identify this structure in memory */ |
| 57 | + const void *data; /* Data to copy*/ |
| 58 | + size_t len; /* Number of bytes to copy */ |
| 59 | + __INTPTR_TYPE__ offset; /* Offset to store the flash image in */ |
| 60 | +} __aligned(4); |
| 61 | + |
| 62 | +#define PCD_CMD ((volatile struct pcd_cmd * const)(PCD_CMD_ADDRESS)) |
| 63 | + |
| 64 | +static inline void pcd_write_cmd_lock_debug(void) |
| 65 | +{ |
| 66 | + *PCD_CMD = (struct pcd_cmd){ |
| 67 | + .magic = PCD_CMD_MAGIC_LOCK_DEBUG, |
| 68 | + }; |
| 69 | +} |
| 70 | + |
| 71 | +static inline bool pcd_read_cmd_done(void) |
| 72 | +{ |
| 73 | + return PCD_CMD->magic == PCD_CMD_MAGIC_DONE; |
| 74 | +} |
| 75 | + |
| 76 | +static inline bool pcd_read_cmd_lock_debug(void) |
| 77 | +{ |
| 78 | + return PCD_CMD->magic == PCD_CMD_MAGIC_LOCK_DEBUG; |
| 79 | +} |
| 80 | + |
| 81 | +#endif /* PCD_COMMON_H__ */ |
| 82 | + |
| 83 | +/**@} */ |
0 commit comments