kestrel.h 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// © 2021 Raptor Engineering, LLC
//
// Released under the terms of the GPL v3
// See the LICENSE file for full details

#if (WITH_ZEPHYR)
#include <shell/shell.h>
#endif

#if (WITH_ZEPHYR)
11
#define KESTREL_SERVICE_THREAD_PRIORITY		K_PRIO_PREEMPT(0)
12 13
#endif

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#if (WITH_ZEPHYR)
#define SW0_NODE				DT_ALIAS(sw0)
#if DT_NODE_HAS_STATUS(SW0_NODE, okay)
#define KESTREL_HOST_POWER_BUTTON_GPIO		DT_GPIO_LABEL(SW0_NODE, gpios)
#define KESTREL_HOST_POWER_BUTTON_PIN		DT_GPIO_PIN(SW0_NODE, gpios)
#else
#error "No power button defined in device tree"
#endif
#define SW1_NODE				DT_ALIAS(sw1)
#if DT_NODE_HAS_STATUS(SW1_NODE, okay)
#define KESTREL_HOST_RESET_BUTTON_GPIO		DT_GPIO_LABEL(SW1_NODE, gpios)
#define KESTREL_HOST_RESET_BUTTON_PIN		DT_GPIO_PIN(SW1_NODE, gpios)
#else
#error "No reset button defined in device tree"
#endif
#endif

#define HOST_POWER_STATUS_OFFLINE	0
#define HOST_POWER_STATUS_POWERING_ON	1
33 34 35
#define HOST_POWER_STATUS_IPLING	2
#define HOST_POWER_STATUS_RUNNING	3
#define HOST_POWER_STATUS_POWERING_OFF	4
36

37 38 39 40
#define KESTREL_VERSION_MAJOR		0
#define KESTREL_VERSION_MINOR		1
#define KESTREL_VERSION_PATCHLEVEL	0

41 42 43 44
struct firmware_buffer_region {
	uint8_t *buffer_address;
	unsigned long long buffer_length;
	uintptr_t current_write_offset;
45
	unsigned long long valid_bytes;
46 47 48 49 50 51
	uint8_t locked;
	uint8_t overflow;
};

extern struct firmware_buffer_region main_firmware_buffer;

52 53 54
extern uint8_t kestrel_basic_init_complete;
extern uint8_t host_background_service_task_active;
extern uint8_t host_console_service_task_requested;
55
extern uint8_t host_power_status;
56 57 58 59

#if (WITH_ZEPHYR)
extern k_tid_t kestrel_service_thread_id;
extern k_tid_t kestrel_console_thread_id;
60 61
extern k_tid_t thermal_service_thread_id;
extern struct k_mutex occ_access_mutex;
62 63 64 65 66 67 68
extern const struct shell *host_console_service_task_shell;
#endif

int kestrel_init(void);
int power_on_host(void);
void power_off_chassis(void);
void print_chassis_status(void);
69
int write_flash_buffer_to_flash(void);
70 71 72 73 74 75 76 77

int primary_service_event_loop(void);

#if (WITH_ZEPHYR)
int attach_to_host_console(const struct shell *shell);
int host_console_event_loop(const struct shell *shell);
#else
int attach_to_host_console();
78
#endif