Somo14D interrupt was blocking. pushPrompt needs a CLI to write TIMSK4
This commit is contained in:
+26
-10
@@ -59,19 +59,17 @@ volatile uint8_t somo14WIdx = 0;
|
|||||||
|
|
||||||
#ifdef SIMU
|
#ifdef SIMU
|
||||||
#define BUSY busy
|
#define BUSY busy
|
||||||
bool TIMER4_COMPA_vect()
|
|
||||||
#else
|
#else
|
||||||
#define BUSY
|
#define BUSY
|
||||||
ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
NOINLINE uint8_t SomoWakeup()
|
||||||
{
|
{
|
||||||
static uint16_t somo14_current;
|
static uint16_t somo14_current;
|
||||||
static uint8_t i = 0;
|
static uint8_t i = 0;
|
||||||
static uint8_t busy = 0; // debugging make BOOL when done
|
static uint8_t busy = 0; // debugging make BOOL when done
|
||||||
static uint8_t startstop = SOMOSSBIT; // Only the first playback can have this short delay
|
static uint8_t startstop = SOMOSSBIT; // Only the first playback can have this short delay
|
||||||
|
|
||||||
OCR4A = 0x7d; //another 0.5ms
|
|
||||||
|
|
||||||
// printf("startstop=%d i=%d\n", startstop, i); fflush(stdout);
|
// printf("startstop=%d i=%d\n", startstop, i); fflush(stdout);
|
||||||
|
|
||||||
// Send no data unless we are either not busy or it's a command
|
// Send no data unless we are either not busy or it's a command
|
||||||
@@ -86,8 +84,7 @@ ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
|||||||
}
|
}
|
||||||
else if (!SOMOBUSY) {
|
else if (!SOMOBUSY) {
|
||||||
if (somo14RIdx == somo14WIdx) {
|
if (somo14RIdx == somo14WIdx) {
|
||||||
TIMSK4 &= ~(1<<OCIE4A);
|
return 1;
|
||||||
return BUSY;
|
|
||||||
}
|
}
|
||||||
somo14_current = somo14playlist[somo14RIdx];
|
somo14_current = somo14playlist[somo14RIdx];
|
||||||
somo14RIdx = (somo14RIdx + 1) % QUEUE_LENGTH;
|
somo14RIdx = (somo14RIdx + 1) % QUEUE_LENGTH;
|
||||||
@@ -106,14 +103,14 @@ ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
|||||||
PORTH &= ~(1<<OUT_H_14DCLK); // Start Bit, CLK low for 2ms
|
PORTH &= ~(1<<OUT_H_14DCLK); // Start Bit, CLK low for 2ms
|
||||||
}
|
}
|
||||||
startstop--;
|
startstop--;
|
||||||
return BUSY;
|
return 0;
|
||||||
}
|
}
|
||||||
// Stop bit
|
// Stop bit
|
||||||
if (i==16) {
|
if (i==16) {
|
||||||
PORTH &= ~(1<<OUT_H_14DDATA); // Data low
|
PORTH &= ~(1<<OUT_H_14DDATA); // Data low
|
||||||
PORTH |= (1<<OUT_H_14DCLK); // Stop Bit, CLK high for 2ms
|
PORTH |= (1<<OUT_H_14DCLK); // Stop Bit, CLK high for 2ms
|
||||||
startstop--;
|
startstop--;
|
||||||
return BUSY;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +121,7 @@ ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
|||||||
i=0;
|
i=0;
|
||||||
busy=0;
|
busy=0;
|
||||||
startstop = SOMOSTART;
|
startstop = SOMOSTART;
|
||||||
return BUSY;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the data
|
// Send the data
|
||||||
@@ -147,14 +144,33 @@ ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BUSY;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SIMU
|
||||||
|
ISR(TIMER4_COMPA_vect) //Every 0.5ms
|
||||||
|
{
|
||||||
|
OCR4A = 0x7d; // another 0.5ms
|
||||||
|
|
||||||
|
TIMSK4 &= ~(1<<OCIE4A); // stop reentrance
|
||||||
|
|
||||||
|
sei();
|
||||||
|
|
||||||
|
uint8_t finished = SomoWakeup();
|
||||||
|
|
||||||
|
cli();
|
||||||
|
|
||||||
|
if (!finished) TIMSK4 |= (1<<OCIE4A);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void pushPrompt(uint16_t prompt)
|
void pushPrompt(uint16_t prompt)
|
||||||
{
|
{
|
||||||
somo14playlist[somo14WIdx] = prompt;
|
somo14playlist[somo14WIdx] = prompt;
|
||||||
somo14WIdx = (somo14WIdx + 1) % QUEUE_LENGTH;
|
somo14WIdx = (somo14WIdx + 1) % QUEUE_LENGTH;
|
||||||
|
cli();
|
||||||
TIMSK4 |= (1<<OCIE4A);
|
TIMSK4 |= (1<<OCIE4A);
|
||||||
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPlaying()
|
bool isPlaying()
|
||||||
|
|||||||
Reference in New Issue
Block a user