|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/init.h> |
| 8 | +#include <zephyr/kernel.h> |
| 9 | +#include <zephyr/logging/log.h> |
| 10 | +#include <zephyr/toolchain.h> |
| 11 | + |
| 12 | +#include <services/nrfs_mram.h> |
| 13 | +#include <nrfs_backend_ipc_service.h> |
| 14 | + |
| 15 | +LOG_MODULE_REGISTER(mram, CONFIG_SOC_LOG_LEVEL); |
| 16 | + |
| 17 | +static void mram_latency_handler(nrfs_mram_latency_evt_t const *p_evt, void *context) |
| 18 | +{ |
| 19 | + ARG_UNUSED(context); |
| 20 | + |
| 21 | + switch (p_evt->type) { |
| 22 | + case NRFS_MRAM_LATENCY_REQ_APPLIED: |
| 23 | + LOG_DBG("MRAM latency not allowed setting applied"); |
| 24 | + break; |
| 25 | + case NRFS_MRAM_LATENCY_REQ_REJECTED: |
| 26 | + LOG_ERR("MRAM latency not allowed setting rejected"); |
| 27 | + k_panic(); |
| 28 | + break; |
| 29 | + default: |
| 30 | + LOG_WRN("Unexpected event: %d", p_evt->type); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +/* Turn off mram automatic suspend as it causes delays in time depended code sections. */ |
| 35 | +static int turn_off_suspend_mram(void) |
| 36 | +{ |
| 37 | + nrfs_err_t err; |
| 38 | + |
| 39 | + /* Wait for ipc initialization */ |
| 40 | + nrfs_backend_wait_for_connection(K_FOREVER); |
| 41 | + |
| 42 | + err = nrfs_mram_init(mram_latency_handler); |
| 43 | + if (err != NRFS_SUCCESS) { |
| 44 | + LOG_ERR("MRAM service init failed: %d", err); |
| 45 | + return -EIO; |
| 46 | + } |
| 47 | + |
| 48 | + LOG_DBG("MRAM service initialized, disallow latency"); |
| 49 | + |
| 50 | + err = nrfs_mram_set_latency(MRAM_LATENCY_NOT_ALLOWED, NULL); |
| 51 | + if (err != NRFS_SUCCESS) { |
| 52 | + LOG_ERR("MRAM: set latency failed (%d)", err); |
| 53 | + return -EIO; |
| 54 | + } |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +SYS_INIT(turn_off_suspend_mram, APPLICATION, 90); |
0 commit comments