libnile
Loading...
Searching...
No Matches
system.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_SYSTEM_H_
24#define NILE_MCU_SYSTEM_H_
25
26#include "../mcu.h"
27
31static inline int16_t nile_mcu_native_mcu_switch_mode(uint8_t mode) {
33}
34
40static inline int16_t nile_mcu_native_mcu_spi_set_speed_sync(uint8_t speed) {
41 int16_t result;
42 uint8_t op_result;
43 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_FREQ, speed), NULL, 0)) < 0) return result;
44 if ((result = nile_mcu_native_recv_cmd(&op_result, 1)) < 1) return result;
45 return op_result;
46}
47
48static inline int16_t nile_mcu_native_mcu_get_uuid_sync(void __far* buffer, uint16_t buflen) {
49 int16_t result;
50 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_ID, 0), NULL, 0)) < 0) return result;
51 return nile_mcu_native_recv_cmd(buffer, buflen);
52}
53
54static inline int16_t nile_mcu_native_mcu_get_info_sync(void __far* buffer, uint16_t buflen) {
55 int16_t result;
56 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_INFO, 0), NULL, 0)) < 0) return result;
57 return nile_mcu_native_recv_cmd(buffer, buflen);
58}
59
60static inline int16_t nile_mcu_native_mcu_reg_read_sync(uint16_t addr) {
61 int16_t result;
62 uint16_t value;
63 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_REG_READ, addr), NULL, 0)) < 0) return result;
64 if ((result = nile_mcu_native_recv_cmd(&value, 2)) < 0) return result;
65 return value;
66}
67
68static inline int16_t nile_mcu_native_mcu_reg_write_sync(uint16_t addr, uint16_t value) {
69 int16_t result;
70 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_REG_WRITE, addr), &value, 2)) < 0) return result;
71 if ((result = nile_mcu_native_recv_cmd(NULL, 0)) < 0) return result;
72 return 0;
73}
74
75static inline int16_t nile_mcu_native_mcu_get_version_sync(void __far* buffer, uint16_t buflen) {
76 int16_t result;
77 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_VERSION, 0), NULL, 0)) < 0) return result;
78 return nile_mcu_native_recv_cmd(buffer, buflen);
79}
80
81static inline int16_t nile_mcu_native_mcu_set_save_id_sync(uint16_t domain, uint32_t value) {
82 int16_t result;
83 bool retval = false;
84 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_SET_SAVE_ID, domain), &value, 4)) < 0) return result;
85 if ((result = nile_mcu_native_recv_cmd(&retval, 1)) <= 0) return result;
86 return retval;
87}
88
89static inline int16_t nile_mcu_native_mcu_get_save_id_sync(uint16_t domain, uint32_t __wf_cram* value) {
90 int16_t result;
91 if ((result = nile_mcu_native_send_cmd(NILE_MCU_NATIVE_CMD(NILE_MCU_NATIVE_CMD_GET_SAVE_ID, domain), NULL, 0)) < 0) return result;
92 if ((result = nile_mcu_native_recv_cmd(value, 4)) < 0) return result;
93 return 0;
94}
95
96#endif /* NILE_MCU_CDC_H_ */
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:56
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:164
@ NILE_MCU_NATIVE_CMD_REG_WRITE
Definition protocol.h:37
@ NILE_MCU_NATIVE_CMD_FREQ
Definition protocol.h:33
@ NILE_MCU_NATIVE_CMD_VERSION
Definition protocol.h:38
@ NILE_MCU_NATIVE_CMD_SET_SAVE_ID
Definition protocol.h:45
@ NILE_MCU_NATIVE_CMD_MODE
Definition protocol.h:32
@ NILE_MCU_NATIVE_CMD_ID
Definition protocol.h:34
@ NILE_MCU_NATIVE_CMD_INFO
Definition protocol.h:35
@ NILE_MCU_NATIVE_CMD_GET_SAVE_ID
Definition protocol.h:46
@ NILE_MCU_NATIVE_CMD_REG_READ
Definition protocol.h:36
static int16_t nile_mcu_native_mcu_get_version_sync(void __far *buffer, uint16_t buflen)
Definition system.h:75
static int16_t nile_mcu_native_mcu_spi_set_speed_sync(uint8_t speed)
Tell the MCU to operate at a specific SPI speed.
Definition system.h:40
static int16_t nile_mcu_native_mcu_reg_read_sync(uint16_t addr)
Definition system.h:60
static int16_t nile_mcu_native_mcu_get_uuid_sync(void __far *buffer, uint16_t buflen)
Definition system.h:48
static int16_t nile_mcu_native_mcu_get_save_id_sync(uint16_t domain, uint32_t __wf_cram *value)
Definition system.h:89
static int16_t nile_mcu_native_mcu_get_info_sync(void __far *buffer, uint16_t buflen)
Definition system.h:54
static int16_t nile_mcu_native_mcu_reg_write_sync(uint16_t addr, uint16_t value)
Definition system.h:68
static int16_t nile_mcu_native_mcu_switch_mode(uint8_t mode)
Switch the mode in which the MCU is operating.
Definition system.h:31
static int16_t nile_mcu_native_mcu_set_save_id_sync(uint16_t domain, uint32_t value)
Definition system.h:81