forked from betaflight/betaflight-esc
-
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.
[Drivers]Add some drivers.It need implement in the future.
- Loading branch information
1 parent
e4b169a
commit 27f5dd4
Showing
8 changed files
with
90 additions
and
82 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
126 changes: 63 additions & 63 deletions
126
src/main/drivers/multi_timer.c → src/main/drivers/drv_scheduler.c
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 |
---|---|---|
@@ -1,63 +1,63 @@ | ||
#include "include.h" | ||
|
||
static struct Timer* head_handle = NULL; | ||
|
||
static volatile uint32_t _timer_ticks = 0; | ||
|
||
void timer_init(struct Timer* handle, void(*timeout_cb)(), uint32_t timeout, uint32_t repeat) | ||
{ | ||
// memset(handle, sizeof(struct Timer), 0); | ||
handle->timeout_cb = timeout_cb; | ||
handle->timeout = _timer_ticks + timeout; | ||
handle->repeat = repeat; | ||
} | ||
|
||
int timer_start(struct Timer* handle) | ||
{ | ||
struct Timer* target = head_handle; | ||
while(target) { | ||
if(target == handle) { | ||
return -1; | ||
} | ||
target = target->next; | ||
} | ||
handle->next = head_handle; | ||
head_handle = handle; | ||
|
||
return 0; | ||
} | ||
|
||
void timer_stop(struct Timer* handle) | ||
{ | ||
struct Timer** curr; | ||
|
||
for(curr = &head_handle; *curr; ) { | ||
struct Timer* entry = *curr; | ||
if (entry == handle) { | ||
*curr = entry->next; | ||
} else { | ||
curr = &entry->next; | ||
} | ||
} | ||
} | ||
|
||
void timer_loop(void) | ||
{ | ||
struct Timer* target; | ||
|
||
for(target = head_handle; target; target = target->next) { | ||
if(_timer_ticks >= target->timeout) { | ||
if(target->repeat == 0) { | ||
timer_stop(target); | ||
} else { | ||
target->timeout = _timer_ticks + target->repeat; | ||
} | ||
target->timeout_cb(); | ||
} | ||
} | ||
} | ||
|
||
void timer_ticks(void) | ||
{ | ||
_timer_ticks++; | ||
} | ||
#include "include.h" | ||
|
||
static struct Timer* head_handle = NULL; | ||
|
||
static volatile uint32_t _timer_ticks = 0; | ||
|
||
void timer_init(struct Timer* handle, void(*timeout_cb)(), uint32_t timeout, uint32_t repeat) | ||
{ | ||
// memset(handle, sizeof(struct Timer), 0); | ||
handle->timeout_cb = timeout_cb; | ||
handle->timeout = _timer_ticks + timeout; | ||
handle->repeat = repeat; | ||
} | ||
|
||
int timer_start(struct Timer* handle) | ||
{ | ||
struct Timer* target = head_handle; | ||
while(target) { | ||
if(target == handle) { | ||
return -1; | ||
} | ||
target = target->next; | ||
} | ||
handle->next = head_handle; | ||
head_handle = handle; | ||
|
||
return 0; | ||
} | ||
|
||
void timer_stop(struct Timer* handle) | ||
{ | ||
struct Timer** curr; | ||
|
||
for(curr = &head_handle; *curr; ) { | ||
struct Timer* entry = *curr; | ||
if (entry == handle) { | ||
*curr = entry->next; | ||
} else { | ||
curr = &entry->next; | ||
} | ||
} | ||
} | ||
|
||
void timer_loop(void) | ||
{ | ||
struct Timer* target; | ||
|
||
for(target = head_handle; target; target = target->next) { | ||
if(_timer_ticks >= target->timeout) { | ||
if(target->repeat == 0) { | ||
timer_stop(target); | ||
} else { | ||
target->timeout = _timer_ticks + target->repeat; | ||
} | ||
target->timeout_cb(); | ||
} | ||
} | ||
} | ||
|
||
void timer_ticks(void) | ||
{ | ||
_timer_ticks++; | ||
} |
32 changes: 16 additions & 16 deletions
32
src/main/drivers/multi_timer.h → src/main/drivers/drv_scheduler.h
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#pragma once | ||
|
||
#include "stdint.h" | ||
|
||
typedef struct Timer { | ||
uint32_t timeout; | ||
uint32_t repeat; | ||
void (*timeout_cb)(void); | ||
struct Timer* next; | ||
} Timer; | ||
|
||
void timer_init(struct Timer* handle, void(*timeout_cb)(), uint32_t timeout, uint32_t repeat); | ||
int timer_start(struct Timer* handle); | ||
void timer_stop(struct Timer* handle); | ||
void timer_ticks(void); | ||
void timer_loop(void); | ||
#pragma once | ||
|
||
#include "stdint.h" | ||
|
||
typedef struct Timer { | ||
uint32_t timeout; | ||
uint32_t repeat; | ||
void (*timeout_cb)(void); | ||
struct Timer* next; | ||
} Timer; | ||
|
||
void timer_init(struct Timer* handle, void(*timeout_cb)(), uint32_t timeout, uint32_t repeat); | ||
int timer_start(struct Timer* handle); | ||
void timer_stop(struct Timer* handle); | ||
void timer_ticks(void); | ||
void timer_loop(void); |
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 @@ | ||
#include "include.h" |
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 @@ | ||
#pragma once |
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
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 @@ | ||
#include "include.h" |
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 @@ | ||
#pragma once |