2024-01-21 08:45:22 +08:00
|
|
|
/*
|
2024-01-03 17:48:34 +08:00
|
|
|
* This file is part of DeskHop (https://github.com/hrvach/deskhop).
|
|
|
|
* Copyright (c) 2024 Hrvoje Cavrak
|
2024-01-21 08:45:22 +08:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2024-01-03 17:48:34 +08:00
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
2024-01-21 08:45:22 +08:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2024-01-03 17:48:34 +08:00
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2024-01-21 08:45:22 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2024-01-03 17:48:34 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-12-25 06:22:05 +08:00
|
|
|
#include "main.h"
|
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
/********* Global Variables **********/
|
|
|
|
device_t global_state = {0};
|
|
|
|
device_t *device = &global_state;
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
firmware_metadata_t _firmware_metadata __attribute__((section(".section_metadata"))) = {
|
|
|
|
.version = 0x0001,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ================================================== *
|
2023-12-25 06:22:05 +08:00
|
|
|
* ============== Main Program Loops ============== *
|
|
|
|
* ================================================== */
|
|
|
|
|
2024-01-28 05:38:46 +08:00
|
|
|
int main(void) {
|
2024-07-29 04:24:28 +08:00
|
|
|
static task_t tasks_core0[] = {
|
|
|
|
[0] = {.exec = &usb_device_task, .frequency = _TOP()}, // .-> USB device task, needs to run as often as possible
|
|
|
|
[1] = {.exec = &kick_watchdog_task, .frequency = _HZ(30)}, // | Verify core1 is still running and if so, reset watchdog timer
|
|
|
|
[2] = {.exec = &process_kbd_queue_task, .frequency = _HZ(2000)}, // | Check if there were any keypresses and send them
|
|
|
|
[3] = {.exec = &process_mouse_queue_task, .frequency = _HZ(2000)}, // | Check if there were any mouse movements and send them
|
|
|
|
[4] = {.exec = &process_cfg_queue_task, .frequency = _HZ(1000)}, // | Check if there are any packets to send over vendor link
|
|
|
|
[5] = {.exec = &process_uart_tx_task, .frequency = _TOP()}, // | Check if there are any packets to send over UART
|
|
|
|
}; // `----- then go back and repeat forever
|
|
|
|
const int NUM_TASKS = ARRAY_SIZE(tasks_core0);
|
|
|
|
|
2023-12-25 06:22:05 +08:00
|
|
|
// Wait for the board to settle
|
|
|
|
sleep_ms(10);
|
|
|
|
|
2024-01-03 17:48:34 +08:00
|
|
|
// Initial board setup
|
2024-01-21 08:45:22 +08:00
|
|
|
initial_setup(device);
|
2023-12-25 06:22:05 +08:00
|
|
|
|
|
|
|
// Initial state, A is the default output
|
2024-01-21 08:45:22 +08:00
|
|
|
switch_output(device, OUTPUT_A);
|
|
|
|
|
2023-12-25 06:22:05 +08:00
|
|
|
while (true) {
|
2024-07-29 04:24:28 +08:00
|
|
|
for (int i = 0; i < NUM_TASKS; i++)
|
|
|
|
task_scheduler(device, &tasks_core0[i]);
|
2024-08-04 01:03:38 +08:00
|
|
|
}
|
2023-12-25 06:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void core1_main() {
|
2024-07-29 04:24:28 +08:00
|
|
|
static task_t tasks_core1[] = {
|
|
|
|
[0] = {.exec = &usb_host_task, .frequency = _TOP()}, // .-> USB host task, needs to run as often as possible
|
|
|
|
[1] = {.exec = &packet_receiver_task, .frequency = _TOP()}, // | Receive data over serial from the other board
|
|
|
|
[2] = {.exec = &led_blinking_task, .frequency = _HZ(30)}, // | Check if LED needs blinking
|
|
|
|
[3] = {.exec = &screensaver_task, .frequency = _HZ(120)}, // | Handle "screensaver" movements
|
|
|
|
[4] = {.exec = &firmware_upgrade_task, .frequency = _HZ(4000)}, // | Send firmware to the other board if needed
|
|
|
|
[5] = {.exec = &heartbeat_output_task, .frequency = _HZ(1)}, // | Output periodic heartbeats
|
|
|
|
}; // `----- then go back and repeat forever
|
2024-08-04 01:03:38 +08:00
|
|
|
const int NUM_TASKS = ARRAY_SIZE(tasks_core1);
|
2023-12-25 06:22:05 +08:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Update the timestamp, so core0 can figure out if we're dead
|
2024-01-21 08:45:22 +08:00
|
|
|
device->core1_last_loop_pass = time_us_64();
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-07-29 04:24:28 +08:00
|
|
|
for (int i = 0; i < NUM_TASKS; i++)
|
2024-08-04 01:03:38 +08:00
|
|
|
task_scheduler(device, &tasks_core1[i]);
|
2023-12-25 06:22:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* ======= End of Main Program Loops ======= */
|