-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39003e3
commit 81f362d
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "stdint.h" | ||
|
||
namespace edge::drivers { | ||
|
||
typedef struct node_t { | ||
|
||
uint32_t id; | ||
uint32_t freq; | ||
|
||
//callback | ||
etl::delegate<void> callback; | ||
|
||
|
||
uint32_t timer_value; | ||
struct node_t* next; | ||
|
||
|
||
} node_t; | ||
|
||
|
||
void list_insert_sorted(node_t* node); | ||
|
||
node_t* list_get_first(); | ||
|
||
node_t* list_remove_first(); | ||
|
||
void list_remove(node_t* node); | ||
|
||
} // namespace edge::drivers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "drivers/virtual_timer_linked_list.hpp" | ||
|
||
namespace edge::drivers | ||
{ | ||
static node_t* linked_list = nullptr; | ||
|
||
void list_insert_sorted(node_t *node) | ||
{ | ||
if (linked_list == nullptr) { | ||
node->next = nullptr; | ||
linked_list = node; | ||
} | ||
else | ||
{ | ||
if (node->timer_value < linked_list->timer_value) | ||
{ | ||
node->next = linked_list; | ||
linked_list = node; | ||
} | ||
else | ||
{ | ||
node_t* prev_node = linked_list; | ||
node_t* curr_node = linked_list->next; | ||
while (curr_node != nullptr && curr_node->timer_value < node->timer_value) | ||
{ | ||
|
||
prev_node = curr_node; | ||
curr_node = curr_node->next; | ||
} | ||
prev_node->next = node; | ||
node->next = curr_node; | ||
} | ||
} | ||
} | ||
|
||
node_t* list_get_first() | ||
{ | ||
return linked_list; | ||
} | ||
|
||
node_t* list_remove_first() | ||
{ | ||
node_t* head = linked_list; | ||
if (head != nullptr) | ||
{ | ||
linked_list = head->next; | ||
} | ||
return head; | ||
} | ||
|
||
void list_remove(node_t* node) | ||
{ | ||
if (linked_list != nullptr) | ||
{ | ||
if (linked_list == node) | ||
{ | ||
linked_list = linked_list->next; | ||
} | ||
else | ||
{ | ||
node_t* prev_node = linked_list; | ||
node_t* curr_node = linked_list->next; | ||
while (curr_node != nullptr && curr_node != node) | ||
{ | ||
prev_node = curr_node; | ||
curr_node = curr_node->next; | ||
} | ||
if (curr_node != nullptr) | ||
{ | ||
prev_node->next = curr_node->next; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace edge::drivers |