Skip to content

Commit b4d266e

Browse files
Low pass filter working
1 parent 0211286 commit b4d266e

File tree

7 files changed

+4228
-0
lines changed

7 files changed

+4228
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
TREEROOT= ../../../..
2+
include $(TREEROOT)/conf/setup.conf
3+
4+
TARGET= superH
5+
TARGET-ARCH= sh-elf
6+
7+
PROGRAM= virtualSensorExample
8+
9+
PORT= ../port
10+
LIBOS= mOS
11+
TOOLSLIB= $(TREEROOT)/tools/tools-lib
12+
INCLUDES= -I../port/ -I$(TREEROOT)/sys/include -I$(TREEROOT)/sys/kern/superH -I$(TREEROOT)/benchmarks/include -I$(TREEROOT)/sys/libOS/port
13+
OPTFLAGS= -gstabs3 -O0
14+
CFLAGS= $(TARGET-ARCH-FLAGS) -nostdlib -fno-builtin -Wall # Do not do since we are linking mOS for libc implementation: -nostdlib -fno-builtin
15+
LDFLAGS = -Ttext $(LOADADDR) -TsuperH.ld -L$(TOOLSLIB)/$(TARGET) -L$(TREEROOT)/sys/libOS/$(LIBOS) -Map $(PROGRAM).map
16+
LOADADDR= 0x08004000
17+
18+
19+
OBJS=\
20+
init-$(TARGET).o\
21+
devrtc.o\
22+
misc.o\
23+
devsensor.o\
24+
$(PROGRAM).o\
25+
26+
27+
all:$(PROGRAM) $(PROGRAM).sr
28+
29+
$(PROGRAM): $(OBJS)
30+
$(LD) $(LDFLAGS) $(OBJS) -o $@ -lc -lgcc -lm -l$(LIBOS)-$(TARGET)
31+
32+
$(PROGRAM).sr:$(PROGRAM)
33+
$(OBJCOPY) -O srec $(PROGRAM) $@
34+
35+
$(PROGRAM).o: $(PROGRAM).c Makefile
36+
$(CC) $(CFLAGS) $(OPTFLAGS) $(INCLUDES) -c $(PROGRAM).c
37+
38+
devsensor.o: $(PORT)/devsensor.c Makefile
39+
$(CC) $(CFLAGS) $(OPTFLAGS) $(INCLUDES) -c $(PORT)/devsensor.c
40+
41+
devrtc.o: $(PORT)/devrtc.c Makefile
42+
$(CC) $(CFLAGS) $(OPTFLAGS) $(INCLUDES) -c $(PORT)/devrtc.c
43+
44+
misc.o: $(PORT)/misc.c Makefile
45+
$(CC) $(CFLAGS) $(OPTFLAGS) $(INCLUDES) -c $(PORT)/misc.c
46+
47+
init-$(TARGET).o: init-$(TARGET).S
48+
$(CPP) init-$(TARGET).S > init-$(TARGET).i; $(AS) init-$(TARGET).i -o $@
49+
50+
clean:
51+
$(RM) init-$(TARGET).i *.o $(PROGRAM) $(PROGRAM).sr $(PROGRAM).map
52+
53+
install: all
54+
cp $(PROGRAM).sr ../../../
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#defineMOVLMOV.L
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "asm.h"
2+
3+
/*fake errno*/
4+
.global___errno
5+
.global _sleep
6+
7+
.align2
8+
start:
9+
/*Clear Status Reg*/
10+
AND#0, r0
11+
LDC r0, sr
12+
13+
/*Go !*/
14+
15+
MOVL stack_addr, r15
16+
MOVL start_addr, r0
17+
JSR @r0
18+
NOP
19+
20+
/*SYSCALL SYS_exit*/
21+
mov#1, r4
22+
trapa #34
23+
24+
25+
.align2
26+
/*Stack is 64M above us*/
27+
stack_addr:
28+
.long (0x8001000 + 1<<26)
29+
start_addr:
30+
.long _main
31+
32+
___errno:
33+
.long0
34+
35+
_sleep:
36+
SLEEP
37+
RTS
38+
NOP
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
v
2+
3+
--
4+
--
5+
--
6+
setquantum 1
7+
setfreq 40
8+
-- All signals have sample rate 400 to simulate the 400 Hz acceleromter used to collect them, interpolation is off and we aren't using location data
9+
-- Tell sunflower where to find x-axis acceleration readings
10+
sigsrc 0 "X-Axis Acceleration" 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 " " 0 0.0 0.0 0.0 0 "xAcceleration.txt" 400 1 0 0
11+
--
12+
-- Node 0
13+
--
14+
cacheoff
15+
-- subscribe to all three signals with a seperate virtual sensor for each
16+
sigsubscribe 0 0
17+
sizemem 96000000
18+
srecl virtualSensorExample.sr
19+
run
20+
setrandomseed 936977
21+
setnode 0
22+
v
23+
on
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
OUTPUT_FORMAT("coff-sh")
2+
OUTPUT_ARCH(sh)
3+
SECTIONS
4+
{
5+
.text . :
6+
{
7+
_text = . ;
8+
*(.text)
9+
*(.strings)
10+
_etext = . ;
11+
}
12+
.tors :
13+
{
14+
___ctors = . ;
15+
*(.ctors)
16+
___ctors_end = . ;
17+
___dtors = . ;
18+
*(.dtors)
19+
___dtors_end = . ;
20+
}
21+
.data . :
22+
{
23+
_data = . ;
24+
*(.data)
25+
*(.gcc_exc*)
26+
___EH_FRAME_BEGIN__ = . ;
27+
*(.eh_fram*)
28+
___EH_FRAME_END__ = . ;
29+
LONG(0);
30+
_edata = . ;
31+
}
32+
.bss . :
33+
{
34+
_bss = . ;
35+
*(.bss)
36+
*(COMMON)
37+
_ebss = . ;
38+
_end = . ;
39+
}
40+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Aya Helmy wrote this example for her 4B25 coursework.
3+
* James Meech adapted it to run over sunflower and take input from the sigsrc command.
4+
*/
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <stdlib.h>
8+
#include <limits.h>
9+
#include <stdbool.h>
10+
#include "sf-types.h"
11+
#include "tag.h"
12+
#include "devsim7708.h"
13+
#include "sh7708.h"
14+
#include "devscc.h"
15+
#include "devrtc.h"
16+
#include "devexcp.h"
17+
#include "devlog.h"
18+
#include "devloc.h"
19+
#include "devsensor.h"
20+
#include "misc.h"
21+
#include "print.h"
22+
23+
float LowPassFilter(float *in, float *out, int N, double in0)
24+
{
25+
out[0] = in[0] + in0;
26+
for (int n=1; n < N ; n++)
27+
{
28+
out[n] = in[n] + in[n-1];
29+
}
30+
return in[N-1];
31+
}
32+
33+
int
34+
main(void)
35+
{
36+
const int numberOfSamples = 30;
37+
int halfNumberOfSamples = numberOfSamples/2;
38+
float xBuffer[numberOfSamples];
39+
float xBufferOut[numberOfSamples];
40+
float in0 = 0;
41+
for(int j = 0; j < numberOfSamples; j++)
42+
{
43+
/*
44+
* Insert delay of 2500 uSeconds to simulate 400 Hz sample rate
45+
*/
46+
xudelay(2500);
47+
/*
48+
* Read sensor readings from sigsrc 0 which is the x-axis accelerometer readings
49+
*/
50+
xBuffer[j] = devsignal_read(0);
51+
/*
52+
* Please note that sigsrc simulates a real signal which changes in time.
53+
* The value returned by devsignal_read() will be different at different simulation times.
54+
* Here we use delay to wait for 1/f seconds where f is the 400 Hz sample frequency specified in the run.m file.
55+
* If we don't wait for this amount of time and instead sample as quickly as we can we will see the same sensor value many times.
56+
* If we set xudelay to a higher value we will start to miss some samples in the file as we are looking at the return value of i
57+
* devsignal_read() at a frequency lower than 400 Hz.
58+
*/
59+
}
60+
61+
in0 = LowPassFilter(xBuffer, xBufferOut, halfNumberOfSamples, in0);
62+
in0 = LowPassFilter(&xBuffer[halfNumberOfSamples], &xBufferOut[halfNumberOfSamples], halfNumberOfSamples, in0);
63+
64+
for(int i = 0; i < numberOfSamples; i++)
65+
{
66+
printf("x[%d]=%f\ty[%d]=%f\n",i,xBuffer[i], i, xBufferOut[i]);
67+
}
68+
69+
return 0;
70+
}
71+

0 commit comments

Comments
 (0)