Skip to content

Commit df8995a

Browse files
Merge pull request #186 from JamesTimothyMeech/master
Adding more examples
2 parents fc513a0 + aad69da commit df8995a

29 files changed

+166940
-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 960000000
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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
#include <limits.h>
5+
#include <stdbool.h>
6+
#include "sf-types.h"
7+
#include "tag.h"
8+
#include "devsim7708.h"
9+
#include "sh7708.h"
10+
#include "devscc.h"
11+
#include "devrtc.h"
12+
#include "devexcp.h"
13+
#include "devlog.h"
14+
#include "devloc.h"
15+
#include "devsensor.h"
16+
#include "misc.h"
17+
#include "print.h"
18+
#include <math.h>
19+
#include <complex.h>
20+
21+
/*
22+
* Note that the number of samples must be a power of two for the FFT to work.
23+
* Currently the program will crash if numberOfSamples is not a power of 2.
24+
*/
25+
const intnumberOfSamples = 16;
26+
27+
int
28+
main(void)
29+
{
30+
floatX[numberOfSamples];
31+
/*
32+
* kK = Number of samples in output vector (number of points for Fourier transform)
33+
*/
34+
floatkK = numberOfSamples;
35+
/*
36+
* kN = Number of samples in inputs
37+
*/
38+
floatkN = numberOfSamples;
39+
floatkX[numberOfSamples];
40+
for(int j = 0; j < numberOfSamples; j++)
41+
{
42+
/*
43+
* Insert delay of 2500 uSeconds to simulate 400 Hz sample rate
44+
*/
45+
xudelay(2500);
46+
/*
47+
* Read sensor readings from sigsrc 0 which is the x-axis accelerometer readings
48+
*/
49+
kX[j] = devsignal_read(0);
50+
/*
51+
* Please note that sigsrc simulates a real signal which changes in time.
52+
* The value returned by devsignal_read() will be different at different simulation times.
53+
* Here we use delay to wait for 1/f seconds where f is the 400 Hz sample frequency specified in the run.m file.
54+
* 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.
55+
* 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
56+
* devsignal_read() at a frequency lower than 400 Hz.
57+
*/
58+
}
59+
60+
for(int k = 0; k < kK; k++)
61+
{
62+
for(int n = 0; n < kN; n++)
63+
{
64+
X[k] = kX[n]*(cos((2*M_PI/kN)*k*n)-I*sin((2*M_PI/kN)*k*n));
65+
}
66+
}
67+
68+
printf("Input: ");
69+
70+
for(int i = 0 ; i < numberOfSamples ; ++i)
71+
{
72+
printf("%f ", kX[i]);
73+
}
74+
75+
printf("\n");
76+
printf("Output: ");
77+
78+
for(int i = 0 ; i < numberOfSamples ; ++i)
79+
{
80+
printf("%f ", X[i]);
81+
}
82+
83+
printf("\n");
84+
85+
return 0;
86+
}
87+

0 commit comments

Comments
 (0)