You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.0 KiB
94 lines
2.0 KiB
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
#include "ringbuf_small.h"
|
|
#include "ringbuf_small.c"
|
|
#include "mmc.h"
|
|
|
|
#include "gg.h"
|
|
|
|
void timer_init_tiny26(void)
|
|
{
|
|
PLLCSR = 1 << PLLE;/* pll enable */
|
|
_delay_us(100);
|
|
while(!(PLLCSR & (1 << PLOCK))) {;}/* wait for lock */
|
|
PLLCSR |= 1 << PCKE;/* use pll */
|
|
|
|
OCR1C = 0xff;/* unused */
|
|
|
|
/* output pin: OC1A = PB1 = 1 or OC1B = PB3 = 2 */
|
|
OCR1B = 0;
|
|
cnt_to_next = 1;/* overflows to next sample */
|
|
|
|
TCCR1A = (1 << COM1B1) | (1 << PWM1B);/* pwm enable, not inverted */
|
|
TCCR1B = (1 << CS11) | (1 << CS10);/* fast pwm, prescaler / 2 */
|
|
DDRB |= (1 << PB3);
|
|
|
|
TIMSK = 1 << TOIE1;/* interrupt on overflow */
|
|
}
|
|
|
|
#define BUFFER_SIZE 32
|
|
uint16_t buffer[BUFFER_SIZE];/* buffer for mmc data */
|
|
ringbuf_t rb;
|
|
uint32_t length;/* remaining samples */
|
|
|
|
/*ISR(TIMER1_OVF1_vect, ISR_NAKED)
|
|
{
|
|
__asm__("in r2, 0x3f"); // save sreg
|
|
if(--cnt_to_ocr_incr){
|
|
OCR1A = cur_ocr + 1;
|
|
}
|
|
if(--cnt_to_next){
|
|
cur_ocr = next_ocr;
|
|
OCR1A = cur_ocr;
|
|
cnt_to_ocr_incr = next_cnt_to_incr;
|
|
cnt_to_next = 8;
|
|
needs_new_data_flag = 1;
|
|
}
|
|
__asm__("out 0x3f,r2"); // restore sreg
|
|
reti();
|
|
}// */
|
|
|
|
ISR(TIMER1_OVF1_vect){
|
|
// next try: simplistic, not too much looking at speed
|
|
uint16_t next = 0;
|
|
|
|
if(!--cnt_to_next){
|
|
ringbuf_get(&rb, &next);
|
|
OCR1B = next>>8;
|
|
cnt_to_ocr_incr = 8 - (next & 0x7);
|
|
cnt_to_next = 8;
|
|
if(!--length)
|
|
{
|
|
/* shut down */
|
|
PORTA &= ~(1 << PA7);
|
|
}
|
|
} else {
|
|
if(!--cnt_to_ocr_incr){
|
|
OCR1B += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int main(void) __attribute__((noreturn));
|
|
int main(void)
|
|
{
|
|
DDRA |= (1 << PA7);
|
|
PORTA |= (1 << PA7);
|
|
ringbuf_init(&rb, buffer, BUFFER_SIZE);
|
|
if(mmc_init() != 0) {/* mmc fail */;}
|
|
|
|
mmc_read_part(0, (unsigned char *) &length, 4);
|
|
|
|
timer_init_tiny26();
|
|
sei();
|
|
|
|
unsigned long block = 0;
|
|
for(;; block++)
|
|
{
|
|
mmc_read_to_ringbuffer(block, &rb);
|
|
}
|
|
}
|