[sky9x] Bug in SD Init fixed. Temperature alarm added.

This commit is contained in:
bsongis
2012-09-02 21:00:22 +00:00
parent 5ddc88d8a4
commit 1bd590195f
23 changed files with 289 additions and 113 deletions
+16 -4
View File
@@ -33,9 +33,12 @@
#include "../open9x.h"
#if defined(SDCARD)
const char * audioFilenames[] = {
"inactiv",
"lowbatt",
"hightemp",
"thralert",
"swalert",
"eebad",
@@ -76,9 +79,8 @@ const char * audioFilenames[] = {
#endif
};
uint32_t sdAvailableAudioFiles = (1 << AU_TADA);
uint32_t sdAvailableAudioFiles = 0;
#if defined(SDCARD)
// TODO enable the assert when it's C++
extern "C" {
void retrieveAvailableAudioFiles()
@@ -175,6 +177,7 @@ void audioTask(void* pdata)
{
#if defined(SDCARD)
sdInit();
AUDIO_TADA();
#endif
while (1) {
@@ -477,16 +480,15 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag
CoLeaveMutexSection(audioMutex);
}
#if defined(SDCARD)
void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
{
#ifdef SIMU
printf("playFile(\"%s\")\n", filename); fflush(stdout);
#endif
#if defined(SDCARD)
if (Card_initialized && !sd_card_mounted())
return;
#endif
CoEnterMutexSection(audioMutex);
@@ -508,6 +510,7 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
CoLeaveMutexSection(audioMutex);
}
#endif
void audioEvent(uint8_t e, uint8_t f)
{
@@ -545,9 +548,18 @@ void audioEvent(uint8_t e, uint8_t f)
audioQueue.play(80, 40, 6, 2, -1);
}
break;
case AU_TX_TEMP_HIGH:
if (!audioQueue.busy()) {
// TODO Rob something better here?
audioQueue.play(60, 40, 6, 2, 1);
audioQueue.play(80, 40, 6, 2, -1);
}
break;
// error
#if defined(VOICE)
case AU_THROTTLE_ALERT:
case AU_SWITCH_ALERT:
#endif
case AU_ERROR:
audioQueue.play(BEEP_DEFAULT_FREQ, 50, 2, PLAY_NOW);
break;
+5
View File
@@ -115,8 +115,13 @@ void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
#define AUDIO_WARNING1() audioEvent(AU_WARNING1)
#define AUDIO_WARNING2() audioEvent(AU_WARNING2)
#define AUDIO_TX_BATTERY_LOW() audioEvent(AU_TX_BATTERY_LOW)
#define AUDIO_TX_TEMP_HIGH() audioEvent(AU_TX_TEMP_HIGH)
#define AUDIO_ERROR() audioEvent(AU_ERROR)
#if defined(VOICE)
#define AUDIO_ERROR_MESSAGE(e) audioEvent(e)
#else
#define AUDIO_ERROR_MESSAGE(e) audioEvent(AU_ERROR)
#endif
#define AUDIO_TIMER_30() audioEvent(AU_TIMER_30)
#define AUDIO_TIMER_20() audioEvent(AU_TIMER_20)
#define AUDIO_TIMER_10() audioEvent(AU_TIMER_10)
+142 -34
View File
@@ -33,10 +33,15 @@
#include "../open9x.h"
void btSetBaudrate(uint32_t index)
{
uint32_t baudrate = (index==0 ? 115200 : (index==1 ? 9600 : 19200));
UART3_Configure(baudrate, Master_frequency);
}
void btInit()
{
uint32_t baudrate = (g_eeGeneral.btBaudrate==0 ? 115200 : (g_eeGeneral.btBaudrate==1 ? 9600 : 19200));
UART3_Configure(baudrate, Master_frequency);
btSetBaudrate(g_eeGeneral.btBaudrate);
}
class Fifo32
@@ -74,12 +79,13 @@ class Fifo32
};
OS_FlagID btFlag;
Fifo32 btFifo;
Fifo32 btTxFifo;
Fifo32 btRxFifo;
struct t_serial_tx btTx ;
uint8_t btTxBuffer[32] ;
extern struct t_serial_tx * Current_bt ;
struct t_serial_tx * Current_bt ;
uint32_t txPdcBt(struct t_serial_tx *data)
{
@@ -100,6 +106,27 @@ uint32_t txPdcBt(struct t_serial_tx *data)
return 0 ; // Busy
}
extern "C" void UART1_IRQHandler()
{
Uart *pUart = BT_USART ;
if ( pUart->UART_SR & UART_SR_TXBUFE ) {
pUart->UART_IDR = UART_IDR_TXBUFE ;
pUart->UART_PTCR = US_PTCR_TXTDIS ;
Current_bt->ready = 0 ;
}
if ( pUart->UART_SR & UART_SR_RXRDY ) {
btRxFifo.push(pUart->UART_RHR);
}
}
uint16_t rxBtuart()
{
uint8_t result;
if (!btRxFifo.pop(result))
return 0xffff;
return result;
}
void btSendBuffer()
{
@@ -111,46 +138,93 @@ void btSendBuffer()
btTx.size = 0;
}
void btPollDevice()
#define BT_POLL_TIMEOUT 500
uint32_t btChangeBaudrate( uint32_t baudIndex )
{
#if 0
uint16_t x;
uint32_t y;
uint16_t rxchar;
uint16_t x ;
uint32_t y ;
uint16_t rxchar ;
x = 'O';
#endif
btTxBuffer[0] = 'A';
btTxBuffer[1] = 'T';
btTx.size = 2;
btSendBuffer();
#if 0
for (y = 0; y < 300; y += 1) {
if ((rxchar = rxBtuart()) != 0xFFFF) {
if (rxchar == x) {
if (x == 'O') {
x = 'K';
x = 4 ; // 9600
if ( baudIndex == 0 )
{
x = 8 ; // 115200
}
else if ( baudIndex == 2 )
{
x = 5 ; // 19200
}
btTxBuffer[0] = 'A' ;
btTxBuffer[1] = 'T' ;
btTxBuffer[2] = '+' ;
btTxBuffer[3] = 'B' ;
btTxBuffer[4] = 'A' ;
btTxBuffer[5] = 'U' ;
btTxBuffer[6] = 'D' ;
btTxBuffer[7] = '0' + x ;
btTx.size = 8 ;
btSendBuffer() ;
x = 'O' ;
for( y = 0 ; y < BT_POLL_TIMEOUT ; y += 1 ) {
if ( ( rxchar = rxBtuart() ) != 0xFFFF ) {
if ( rxchar == x ) {
if ( x == 'O' ) {
x = 'K' ;
}
else {
break; // Found "OK"
break ; // Found "OK"
}
}
}
else {
CoTickDelay(1); // 2mS
CoTickDelay(1) ; // 2mS
}
}
if (y < 300) {
return 1;
if ( y < BT_POLL_TIMEOUT ) {
return 1 ;
}
else {
return 0;
return 0 ;
}
#endif
}
uint32_t btPollDevice()
{
uint16_t x ;
uint32_t y ;
uint16_t rxchar ;
x = 'O' ;
btTxBuffer[0] = 'A' ;
btTxBuffer[1] = 'T' ;
btTx.size = 2 ;
btSendBuffer() ;
for( y = 0 ; y < BT_POLL_TIMEOUT ; y++) {
if ( ( rxchar = rxBtuart() ) != 0xFFFF ) {
if ( rxchar == x ) {
if ( x == 'O' ) {
x = 'K' ;
}
else {
break ; // Found "OK"
}
}
}
else {
CoTickDelay(1) ; // 2mS
}
}
if ( y < BT_POLL_TIMEOUT ) {
return 1 ;
}
else {
return 0 ;
}
}
/*
Commands to BT module
@@ -178,6 +252,8 @@ Then we can change the baudrate to the required value.
Or maybe just AT and get OK back
*/
uint32_t btStatus;
void btTask(void* pdata)
{
uint8_t byte;
@@ -185,9 +261,41 @@ void btTask(void* pdata)
btFlag = CoCreateFlag(true, false);
btTx.size = 0;
// Look for BT module baudrate, try 115200, and 9600
// Already initialised to g_eeGeneral.bt_baudrate
// 0 : 115200, 1 : 9600, 2 : 19200
// Look for BT module baudrate, try 115200, and 9600
// Already initialised to g_eeGeneral.bt_baudrate
// 0 : 115200, 1 : 9600, 2 : 19200
uint32_t x = g_eeGeneral.btBaudrate;
btStatus = btPollDevice() ; // Do we get a response?
for (int y=0; y<2; y++) {
if (btStatus == 0) {
x += 1 ;
if (x > 2) {
x = 0 ;
}
btSetBaudrate(x) ;
CoTickDelay(1) ; // 2mS
btStatus = btPollDevice() ; // Do we get a response?
}
}
if (btStatus) {
btStatus = x + 1 ;
if ( x != g_eeGeneral.btBaudrate ) {
x = g_eeGeneral.btBaudrate ;
// Need to change Bt Baudrate
btChangeBaudrate( x ) ;
btStatus += (x+1) * 10 ;
btSetBaudrate( x ) ;
}
}
else {
btInit();
}
CoTickDelay(1) ;
btPollDevice(); // Do we get a response?
@@ -195,7 +303,7 @@ void btTask(void* pdata)
uint32_t x = CoWaitForSingleFlag(btFlag, 10); // Wait for data in Fifo
if (x == E_OK) {
// We have some data in the Fifo
while (btFifo.pop(byte)) {
while (btTxFifo.pop(byte)) {
btTxBuffer[btTx.size++] = byte;
if (btTx.size > 31) {
btSendBuffer();
@@ -210,6 +318,6 @@ void btTask(void* pdata)
void btPushByte(uint8_t data)
{
btFifo.push(data);
btTxFifo.push(data);
CoSetFlag(btFlag); // Tell the Bt task something to do
}
+1 -1
View File
@@ -512,7 +512,7 @@
#define SD_ST_MOUNTED 10
extern int32_t Card_state;
extern uint32_t Card_initialized;
extern volatile uint32_t Card_initialized;
/*
#define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \
+16 -5
View File
@@ -70,7 +70,7 @@ uint32_t Card_ID[4] ;
uint32_t Card_SCR[2] ;
uint32_t Card_CSD[4] ;
int32_t Card_state = SD_ST_STARTUP ;
uint32_t Card_initialized = 0;
volatile uint32_t Card_initialized = 0;
uint32_t Sd_128_resp[4] ;
uint32_t Sd_rca ;
uint32_t Cmd_8_resp ;
@@ -873,13 +873,21 @@ void sdInit()
if (!CardIsConnected()) {
Card_state = SD_ST_EMPTY;
Card_initialized = 1;
return;
}
sdCmd0();
CoTickDelay(5); // 10ms
sdCmd8(1);
sdMemInit(1, &Cmd_A41_resp);
#if 0
// sdAvailableAudioFiles = 0;
Card_state = SD_ST_READY;
Card_initialized = 1;
#else
uint8_t retry;
for (retry=0; retry<10; retry++) {
if (!sdCmd2()) break;
@@ -888,6 +896,7 @@ void sdInit()
if (retry == 10) {
Card_state = SD_ST_READY;
Card_initialized = 1;
return;
}
@@ -898,6 +907,7 @@ void sdInit()
if (retry == 10) {
Card_state = SD_ST_IDENT;
Card_initialized = 1;
return;
}
@@ -910,10 +920,11 @@ void sdInit()
// Should check the card can do this ****
Card_state = SD_ST_DATA;
f_mount(0, &g_FATFS_Obj);
retrieveAvailableAudioFiles();
Card_state = SD_ST_MOUNTED;
if (f_mount(0, &g_FATFS_Obj) == FR_OK) {
retrieveAvailableAudioFiles();
Card_state = SD_ST_MOUNTED;
}
#endif
Card_initialized = 1;
}