kestrel.h 1.94 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(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
12 13
#endif

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

36 37 38 39
struct firmware_buffer_region {
	uint8_t *buffer_address;
	unsigned long long buffer_length;
	uintptr_t current_write_offset;
40
	unsigned long long valid_bytes;
41 42 43 44 45 46
	uint8_t locked;
	uint8_t overflow;
};

extern struct firmware_buffer_region main_firmware_buffer;

47 48 49
extern uint8_t kestrel_basic_init_complete;
extern uint8_t host_background_service_task_active;
extern uint8_t host_console_service_task_requested;
50
extern uint8_t host_power_status;
51 52 53 54 55 56 57 58 59 60 61

#if (WITH_ZEPHYR)
extern k_tid_t kestrel_service_thread_id;
extern k_tid_t kestrel_console_thread_id;
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);
62
int write_flash_buffer_to_flash(void);
63 64 65 66 67 68 69 70

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