The command queue is a ring buffer and will try to schedule.
}
void i_input_poll(void) {
+ u32 i;
+ struct i_input_map_ent *e;
p_poll_events();
i_input_update();
+
+ /* translate inputs
+ * to command queue
+ */
+ for (i = 0; i < I_INPUT_ACTION_LEN; i++) {
+ e = &i_input_map.inputs[i];
+ LRTS_UNUSED(e);
+ switch (i) {
+ case I_INPUT_ACTION_CAMERA_UP:
+ case I_INPUT_ACTION_CAMERA_DOWN:
+ case I_INPUT_ACTION_CAMERA_LEFT:
+ case I_INPUT_ACTION_CAMERA_RIGHT:
+ case I_INPUT_ACTION_CURSOR_CLICK:
+ case I_INPUT_ACTION_CURSOR_ACTION:
+ case I_INPUT_ACTION_CURSOR_DRAG:
+ break;
+ default:
+ u_log(U_LOG_CRIT, "Critical: unhandeled input action %d\n", i);
+ p_exit(P_EXIT_FAIL);
+ break;
+ }
+ }
}
#include <assert.h>
+
+
+void p_exit(i8 exit_code) {
+ exit(exit_code);
+}
* This module contains init code for platforms
*/
+#define P_EXIT_OK 0
+#define P_EXIT_FAIL -1
+
/*
* Init call for IO routines.
* This should set up stdin, stdout and stderr
*/
void p_delay(u64 time);
+void p_exit(i8 exit_code);
/**
#include "t_command.h"
+struct t_command_queue t_command_queue;
+
+void t_command_queue_process(void) {
+}
lrts_bool t_command_exec(struct t_command *c) {
LRTS_UNUSED(c);
return LRTS_TRUE;
}
+
+void t_command_push(struct t_command c) {
+ if (t_command_queue.write_idx >= T_COMMANDS_MAX) {
+ t_command_queue.write_idx = 0;
+ }
+
+ if (t_command_queue.buffer[t_command_queue.write_idx].type != T_COMMAND_NONE) {
+ u_log(U_LOG_CRIT, "Command queue overflow!\n");
+ p_exit(P_EXIT_FAIL);
+ }
+
+ t_command_queue.buffer[t_command_queue.write_idx++] = c;
+}
* each unit has a command queue.
*/
-#define T_COMMANDS_MAX 8
+#define T_COMMANDS_MAX 0x4FF
enum t_command_type {
T_COMMAND_NONE = 0,
/**
* This is a comamnd buffer
* It wraps around and keeps track of the current command
+ * This is a ring buffer. If the current write is already allocated (not type NONE
+ * the program will exit!)
*/
struct t_command_queue {
- u8 current;
+ u16 write_idx;
+ u16 read_idx;
struct t_command buffer[T_COMMANDS_MAX];
};
+extern struct t_command_queue t_command_queue;
+
+/* runs the command queue */
+void t_command_queue_process(void);
+
/* executes a command. Returns true if command was executed. */
lrts_bool t_command_exec(struct t_command *c);
+/* pushes a new command to the command queue */
+void t_command_push(struct t_command c);
+
#endif