libnile
Loading...
Searching...
No Matches
eeprom.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, 2024, 2025 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
23#ifndef NILE_MCU_EEPROM_H_
24#define NILE_MCU_EEPROM_H_
25
26#include "../mcu.h"
27
37
44 int16_t result;
45 bool retval = false;
46 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x10, mode), NULL, 0)) < 0) return result;
47 if ((result = nile_mcu_native_recv_cmd(&retval, 1)) <= 0) return result;
48 return retval;
49}
50
51static inline int16_t nile_mcu_native_eeprom_erase_sync(void) {
52 int16_t result;
53 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x11, 0), NULL, 0)) < 0) return result;
54 return nile_mcu_native_recv_cmd(NULL, 0);
55}
56
57static inline int16_t nile_mcu_native_eeprom_read_sync(void __far* buffer, uint16_t offset, uint16_t buflen) {
58 int16_t result;
59 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x12, buflen >> 1), &offset, 2)) < 0) return result;
60 return nile_mcu_native_recv_cmd(buffer, buflen);
61}
62
63static inline int16_t nile_mcu_native_eeprom_write_sync(const void __wf_cram* buffer, uint16_t buflen) {
64 int16_t result;
65 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x13, buflen), buffer, buflen)) < 0) return result;
66 if ((result = nile_mcu_native_recv_cmd(NULL, 0)) < 0) return result;
67 return 0;
68}
69
70static inline int16_t nile_mcu_native_eeprom_write_async_start(const void __wf_cram* buffer, uint16_t buflen) {
71 int16_t result;
72 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x13, buflen), buffer, buflen)) < 0) return result;
74}
75#define nile_mcu_native_eeprom_write_async_finish nile_mcu_native_recv_cmd_response_none
76
82static inline int16_t nile_mcu_native_eeprom_get_mode_sync(void) {
83 int16_t result;
84 uint8_t mode;
85 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(0x15, 0), NULL, 0)) < 0) return result;
86 if ((result = nile_mcu_native_recv_cmd(&mode, 1)) <= 0) return result;
87 return mode;
88}
89
90#endif /* NILE_MCU_EEPROM_H_ */
static int16_t nile_mcu_native_eeprom_read_sync(void __far *buffer, uint16_t offset, uint16_t buflen)
Definition eeprom.h:57
nile_mcu_eeprom_mode_t
Definition eeprom.h:28
@ NILE_MCU_EEPROM_MODE_NONE
Definition eeprom.h:29
@ NILE_MCU_EEPROM_MODE_M93LC76
Definition eeprom.h:34
@ NILE_MCU_EEPROM_MODE_M93LC46
Definition eeprom.h:31
@ NILE_MCU_EEPROM_MODE_M93LC86
Definition eeprom.h:35
@ NILE_MCU_EEPROM_MODE_M93LC66
Definition eeprom.h:33
@ NILE_MCU_EEPROM_MODE_M93LC56
Definition eeprom.h:32
@ NILE_MCU_EEPROM_MODE_M93LC06
Definition eeprom.h:30
static int16_t nile_mcu_native_eeprom_write_async_start(const void __wf_cram *buffer, uint16_t buflen)
Definition eeprom.h:70
static int16_t nile_mcu_native_eeprom_set_mode_sync(nile_mcu_eeprom_mode_t mode)
Set EEPROM emulation mode.
Definition eeprom.h:43
static int16_t nile_mcu_native_eeprom_erase_sync(void)
Definition eeprom.h:51
static int16_t nile_mcu_native_eeprom_write_sync(const void __wf_cram *buffer, uint16_t buflen)
Definition eeprom.h:63
static int16_t nile_mcu_native_eeprom_get_mode_sync(void)
Get EEPROM emulation mode.
Definition eeprom.h:82
int16_t nile_mcu_native_recv_cmd(void __far *buffer, uint16_t buflen)
Receive the response of a "native protocol" MCU command synchronously.
#define NILE_MCU_NATIVE_CMD(cmd, arg)
Definition mcu.h:55
int16_t nile_mcu_native_recv_cmd_start(uint16_t resplen)
Start receiving the response of a "native protocol" MCU command asynchronously.
static int16_t nile_mcu_native_send_cmd(uint16_t cmd, const void __far *buffer, int buflen)
Send a "native protocol" MCU command asynchronously.
Definition mcu.h:163