synchronize scheduler, now it works
This commit is contained in:
parent
8da88e96c2
commit
a4adf6ac27
@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <msp430g2553.h>
|
||||
|
||||
|
||||
#include "PontCoopScheduler.h"
|
||||
@ -15,7 +16,7 @@ tTask tasks[MAX_NUM_OF_TASKS];
|
||||
|
||||
|
||||
void schInit() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
tasks[i].delay = 0;
|
||||
tasks[i].period = 0;
|
||||
tasks[i].run = 0;
|
||||
@ -25,7 +26,7 @@ void schInit() {
|
||||
}
|
||||
|
||||
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec == NULL) {
|
||||
tasks[i].delay = delay;
|
||||
tasks[i].period = period;
|
||||
@ -41,23 +42,34 @@ void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void schDel(void (*exec)(void *), void *handle) {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) {
|
||||
tasks[i].exec = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void schExec() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
// synchronize access to tasks[].run
|
||||
__disable_interrupt();
|
||||
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
||||
tasks[i].run--;
|
||||
// synchronize access to tasks[].run
|
||||
// reenable interrupts before actually executing task
|
||||
__enable_interrupt();
|
||||
tasks[i].exec(tasks[i].handle);
|
||||
if (tasks[i].period == 0) {
|
||||
tasks[i].exec = NULL;
|
||||
}
|
||||
} else {
|
||||
// synchronize access to tasks[].run
|
||||
// reenable interrupts in case task is not yet executable
|
||||
__enable_interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +77,7 @@ void schExec() {
|
||||
|
||||
|
||||
void schUpdate() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec != NULL) {
|
||||
if (tasks[i].delay == 0) {
|
||||
tasks[i].delay = tasks[i].period;
|
||||
@ -76,13 +88,3 @@ void schUpdate() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t schTaskCnt() {
|
||||
uint8_t cnt = 0;
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec != NULL){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
4
led.c
4
led.c
@ -21,7 +21,7 @@ void ledBlueOff() {
|
||||
}
|
||||
|
||||
void ledExec(void *args) {
|
||||
static int i = 0;
|
||||
static uint16_t i = 0;
|
||||
|
||||
if (i == 0) {
|
||||
ledGreenOff();
|
||||
@ -41,7 +41,7 @@ void ledInit() {
|
||||
ledBlueOff();
|
||||
|
||||
|
||||
// schAdd(ledExec, NULL, 0, 50);
|
||||
schAdd(ledExec, NULL, 0, 500);
|
||||
}
|
||||
|
||||
|
||||
|
2
main.c
2
main.c
@ -29,7 +29,7 @@ int main() {
|
||||
ledInit();
|
||||
displayDriverInit();
|
||||
canvasInit();
|
||||
displayTestInit();
|
||||
displayTestInit();
|
||||
|
||||
|
||||
__enable_interrupt();
|
||||
|
14
time.c
14
time.c
@ -1,30 +1,16 @@
|
||||
#include <msp430g2553.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "time.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
|
||||
|
||||
volatile uint32_t timestamp;
|
||||
|
||||
void __attribute__ ((interrupt (TIMER0_A0_VECTOR))) ta0_isr() {
|
||||
timestamp++;
|
||||
schUpdate();
|
||||
}
|
||||
|
||||
void timeInit() {
|
||||
timestamp = 0;
|
||||
|
||||
TACCR0 = 32;
|
||||
TACCTL0 = CCIE;
|
||||
TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
|
||||
}
|
||||
|
||||
uint32_t getMillis() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
void ms_active_delay(uint16_t delay) {
|
||||
uint32_t start = timestamp;
|
||||
while (start + delay > timestamp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user