diff --git a/Makefile.config b/Makefile.config index 7675330..74b0ef7 100755 --- a/Makefile.config +++ b/Makefile.config @@ -20,7 +20,7 @@ RM = rm -f -r AS = sh3eb-elf-as ## C compiler CC = sh3eb-elf-gcc -CFLAGS = -m3 -mb -Os -nostdlib -Wall -Wextra -Wno-main -pedantic -std=c11 -I $(INCDIR) `fxsdk --cflags` +CFLAGS = -m3 -mb -ffreestanding -O2 -nostdlib -Wall -Wextra -Wno-main -pedantic -std=c11 -I $(INCDIR) `fxsdk --cflags` ## Linker LD = sh3eb-elf-gcc LFLAGS = `fxsdk --cflags` `fxsdk --libs` diff --git a/include/sound4calc.h b/include/sound4calc.h index e977f3a..b3c28f2 100644 --- a/include/sound4calc.h +++ b/include/sound4calc.h @@ -18,9 +18,11 @@ extern struct Note unsigned int freq; } note; +extern int frequency; + void CallSequence(timer_t **timer); void Sequence(); -void CallNote(timer_t **timer); +//void CallNote(timer_t **timer); void Note(); void PutPinState(char level); void PlayNote(); diff --git a/src/main.c b/src/main.c index c6bac1b..d634139 100644 --- a/src/main.c +++ b/src/main.c @@ -41,6 +41,7 @@ int main(void) dprint(1, 20, "%d", note.wave.signal); dprint(1, 30, "%d", place); dprint(1, 40, "length %d", note.wave.length); + // dprint(50, 50, "clk : %d", clock_setting(note.freq * note.wave.length, clock_Hz)); DrawKeyF("not", 1); DrawKeyF("seq", 2); @@ -51,29 +52,13 @@ int main(void) switch(key) { - case KEY_RIGHT : note.freq+=1; break; - case KEY_LEFT : note.freq-=1; break; - case KEY_UP : note.freq+=10; break; - case KEY_DOWN : note.freq-=10; break; + case KEY_RIGHT : note.freq += 1; break; + case KEY_LEFT : note.freq -= 1; break; + case KEY_UP : note.freq += 10; break; + case KEY_DOWN : note.freq -= 10; break; - //case KEY_F5 : note.wave.signal = note.wave.signal | (0x01<0 ? place - 1 : 0); *(note.wave.signal+place) = 0; break; - case KEY_F1 : Note(); break; + case KEY_F1 : frequency = 0; Note(); break; case KEY_F2 : Sequence(); break; case KEY_EXIT : StopTimer(); return 1; diff --git a/src/sound4calc.c b/src/sound4calc.c index 5baf9be..7573e30 100644 --- a/src/sound4calc.c +++ b/src/sound4calc.c @@ -15,12 +15,15 @@ static struct { struct Note note; +int frequency; + +timer_t *timer = NULL; /* CallSequence() make a little sound sequence */ -void CallSequence(timer_t **timer) +/*void CallSequence(timer_t **timer) { static int seq_length = 0; static int seq_note = -1; @@ -40,41 +43,78 @@ void CallSequence(timer_t **timer) uint32_t constant = clock_setting(note.wave.length * seq[seq_note].freq, clock_Hz); *timer = htimer_setup(timer_user, constant, timer_Po_4, 0); - timer_attach(*timer, CallSequence, NULL); + timer_attach(*timer, CallSequence, timer); timer_start(*timer); // update of the number of turn seq_length = note.wave.length * seq[seq_note].freq * seq[seq_note].length_ms / 1000; } + PlayNote(); + seq_length--; +}*/ + +void Sequence() +{ + static int seq_length = 0; + static int seq_note = -1; + + if(seq_length<=0) + { + seq_note++; + + //Stop the timer + if(seq[seq_note].freq < 0) + { + seq_length = 0; + seq_note = -1; + timer_stop(timer); + return; + } + + uint32_t constant = clock_setting(note.wave.length * seq[seq_note].freq, clock_Hz); + + timer = htimer_setup(timer_user, constant, timer_Po_4, 0); + timer_attach(timer, Sequence, NULL); + timer_start(timer); + + // update of the number of turn + seq_length = note.wave.length * seq[seq_note].freq * seq[seq_note].length_ms / 1000; + } + PlayNote(); seq_length--; } -void Sequence() -{ - timer_t *timer = NULL; - CallSequence(&timer); -} - /* CallNote(); Create a single sound */ -void CallNote(timer_t **timer) +/*void CallNote() { - ///timer_t *timer = NULL; + //timer_t *timer = NULL; + uint32_t duration = note.freq * note.wave.length; + uint32_t constante = clock_setting(duration, clock_Hz); - *timer = htimer_setup(timer_user, clock_setting(note.freq * note.wave.length, clock_Hz), timer_Po_4, 2*note.freq * note.wave.length); - timer_attach(*timer, PlayNote, timer); - timer_start(*timer); -// timer_start(TIMER_USER, note.freq * note.wave.length, Clock_Hz, PlayNote, note.wave.length * note.freq * note.duration / 1000); -} + timer = htimer_setup(timer_user, constante, timer_Po_4, 2 * duration); + + timer_attach(timer, PlayNote, NULL); + + + +}*/ void Note() { - timer_t *timer = NULL; - CallNote(&timer); + + uint32_t duration = note.freq * note.wave.length; + uint32_t constante = clock_setting(duration, clock_Hz); + + timer = htimer_setup(timer_user, constante, timer_Po_4, 2 * duration); + + timer_attach(timer, PlayNote, NULL); + + timer_start(timer); } /* @@ -83,7 +123,7 @@ void Note() */ void StopTimer() { - //timer_stop(timer); + timer_stop(timer); } /* @@ -100,6 +140,7 @@ void PlayNote() { x = 0; } + } /* @@ -110,8 +151,8 @@ void PlayNote() state 0 : xxxx.x0xx state 1 : xxxx.x1xx - We can put 2 other state but the sound volume is too high - We could reduce the sound volumle but we have to send + We can put 2 other state (on bit 3) but the sound volume is too high + We could reduce the sound volume but we have to send a lot of bits to the port in order to reduce the volume. (Poupe solution) SH3 : @@ -168,10 +209,10 @@ void InitPorts() // set bit 4 and 5 of port U *(volatile unsigned char*)SH7305_PUDR |= 0x0C; // set port J bit 2 to output - *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x0030 ) | 0x0010; + *(unsigned short*)SH7305_PJCR = ( *(unsigned short*)SH7305_PJCR & ~0x0030 ) | 0x0010; // set port J bit 3 to input - *(unsigned short*)0xA4050110 = ( *(unsigned short*)0xA4050110 & ~0x00C0 ) | 0x0080; + *(unsigned short*)SH7305_PJCR= ( *(unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0080; // set port J bit 3 to output mode //*(volatile unsigned short*)SH7305_PJCR = ( *(volatile unsigned short*)SH7305_PJCR & ~0x00C0 ) | 0x0040;