kestrel.h 2.28 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
#define THERMAL_SERVICE_THREAD_PRIORITY		K_PRIO_PREEMPT(0)
13 14
#endif

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#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
34 35 36
#define HOST_POWER_STATUS_IPLING	2
#define HOST_POWER_STATUS_RUNNING	3
#define HOST_POWER_STATUS_POWERING_OFF	4
37

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

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

extern struct firmware_buffer_region main_firmware_buffer;

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

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

int kestrel_init(void);
int power_on_host(void);
69 70
int power_on_chassis(int has_lock);
void power_off_chassis(int has_lock);
71
void print_chassis_status(void);
72
int write_flash_buffer_to_flash(void);
73 74 75 76 77 78 79 80

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();
81
#endif