Add simple queue to move jobs from systick to main/idle.

This commit is contained in:
Stefan `Sec` Zehl 2011-07-24 15:44:35 +02:00
parent 235cadaa89
commit 7a019d06e7
7 changed files with 149 additions and 0 deletions

View File

@ -115,6 +115,7 @@ void main_default(void) {
void tick_default(void) {
static int ctr;
ctr++;
incTimer();
if(ctr>100){
VoltageCheck();
LightCheck();
@ -144,3 +145,4 @@ void tick_default(void) {
return;
};

View File

@ -0,0 +1,53 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "lcd/allfonts.h"
#include "filesystem/ff.h"
#include "filesystem/select.h"
#include "funk/nrf24l01p.h"
#include "usb/usbmsc.h"
#include <string.h>
/**************************************************************************/
void s_ticks(void) {
int dx=0;
int dy=8;
lcdClear();
dx=DoString(0,dy,"Ticks:");
dx=DoString(0,dy+16,"Qdepth:");
while ((getInputRaw())==BTN_NONE){
DoInt(0,dy+8,_timectr);
DoInt(dx,dy+16,(the_queue.qend-the_queue.qstart+MAXQENTRIES)%MAXQENTRIES);
lcdDisplay();
__asm volatile ("WFI");
};
dy+=16;
dx=DoString(0,dy,"Done.");
};
void b_one(void){
gpioSetValue (RB_LED2, 0);
delayms(100);
gpioSetValue (RB_LED2, 1);
delayms(100);
gpioSetValue (RB_LED2, 0);
};
void do_qone(void) {
work_queue();
};
void do_q(void) {
idle_queue(500);
};
void push_qone(void) {
push_queue(&b_one);
};

View File

@ -15,6 +15,20 @@
/**************************************************************************/
void show_ticks(void) {
int dx=0;
int dy=8;
lcdClear();
dx=DoString(0,dy,"Ticks:");
while ((getInputRaw())==BTN_NONE){
DoInt(0,dy+8,_timectr);
lcdDisplay();
};
dy+=16;
dx=DoString(0,dy,"Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;

View File

@ -17,6 +17,7 @@ OBJS += xxtea.o
OBJS += ecc.o
OBJS += byteorder.o
OBJS += random.o
OBJS += idle.o
LIBNAME=basic

View File

@ -176,4 +176,9 @@ struct MENU {
void handleMenu(const struct MENU *the_menu);
// idle.c
#include "basic/idle.h"
#endif

52
firmware/basic/idle.c Normal file
View File

@ -0,0 +1,52 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
QUEUE the_queue;
volatile uint32_t _timectr=0;
/**************************************************************************/
void work_queue(void){
void (*elem)(void);
int start;
if (the_queue.qstart == the_queue.qend){
__asm volatile ("WFI");
return;
};
start=the_queue.qstart;
start=(start+1)%MAXQENTRIES;
elem=the_queue.queue[start].callback;
the_queue.qstart=start;
elem();
};
void idle_queue(uint32_t ms){
int end=_timectr+ms/10;
do {
if (the_queue.qstart == the_queue.qend){
__asm volatile ("WFI");
}else{
work_queue();
};
} while (end >_timectr);
};
int push_queue(void (*new)(void)){
int end;
end=the_queue.qend;
end=(end+1)%MAXQENTRIES;
if(end == the_queue.qstart) // Queue full
return -1;
the_queue.queue[end].callback=new;
the_queue.qend=end;
return 0;
};

22
firmware/basic/idle.h Normal file
View File

@ -0,0 +1,22 @@
#define MAXQENTRIES 8
typedef struct {
void (*callback)(void);
} QENTRY;
typedef struct {
int qstart;
int qend;
QENTRY queue[MAXQENTRIES];
} QUEUE;
extern QUEUE the_queue;
extern volatile uint32_t _timectr;
void work_queue(void);
void idle_queue(uint32_t delayms);
int push_queue(void (*new)(void));
int magic(void *new);
#define incTimer(void) do{_timectr++;}while(0);