|
3#
楼主 |
发表于 2015-8-6 09:30:12
|
只看该作者
2.2 Main.c
#include "my_includes.h"
#include "LED.h"
#include "SEG7.h"
#include <math.h>
#ifdef DEBUG_APP
#define APP_DEBUG(x) DEBUG(x)
#else
#define APP_DEBUG(x)
#endif
///////////////////////////////////////////////////////////////////////////////
//////////// Internal function prototype & data structure /////////////////////
///////////////////////////////////////////////////////////////////////////////
//================= internal function prototype & data structure definit =====
#define MAX_TRY_CNT 1024
#define USE_SDRAM_FOR_DATA
#ifndef USE_SDRAM_FOR_DATA
#define BUF_SAMPLE_NUM (96000*5) // 5 second @ 96K
#endif
void button_monitor_isr(void* context, alt_u32 id);
bool button_monitor_start(volatile alt_u32 *pPressedMask);
void TDC_monitor_isr(void* context, alt_u32 id);
bool TDC_monitor_start(volatile alt_u32 *pPressedMask);
void TEST_monitor_isr(void* context, alt_u32 id);
bool TEST_monitor_start(volatile alt_u32 *pPressedMask);
void display_time_elapsed(alt_u32 sample_num);
void button_monitor_isr(void* context, alt_u32 id) {
volatile alt_u32* pPressedMask = (volatile alt_u32*) context;
*pPressedMask |= IORD_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE) & 0x0F; // 4-button
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0);
printf("in ISR\r\n");
printf("wr = %d rd = %d \r\n", IORD_ALTERA_AVALON_PIO_DATA(WR_FULL_BASE) & 0x01,
IORD_ALTERA_AVALON_PIO_DATA(RD_EMPT_BASE) & 0x01);
}
bool button_monitor_start(volatile alt_u32 *pPressedMask) {
bool bSuccess = TRUE;
// enable interrupt
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE, 0x0F); // 4-button
// Reset the edge catpure register
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0);
printf("in start\r\n");
// register IRQ
if (bSuccess
&& (alt_irq_register(KEY_IRQ, (void *) pPressedMask,
button_monitor_isr) != 0)) {
printf("[SW-MONITOR]register button IRQ fail\r\n");
bSuccess = FALSE;
}
return bSuccess;
}
void TDC_monitor_isr(void* context, alt_u32 id) {
volatile alt_u32* pPressedMask = (volatile alt_u32*) context;
*pPressedMask |= IORD_ALTERA_AVALON_PIO_EDGE_CAP(WR_FULL_BASE) & 0x01; // 1-line in
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(WR_FULL_BASE, 0);
printf("in fifo-ISR\r\n");
}
bool TDC_monitor_start(volatile alt_u32 *pPressedMask) {
bool bSuccess = TRUE;
// enable interrupt
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(WR_FULL_BASE, 0x01); // 4-button
// Reset the edge catpure register
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(WR_FULL_BASE, 0);
printf("in fifo-start\r\n");
// register IRQ
if (bSuccess
&& (alt_irq_register(WR_FULL_IRQ, (void *) pPressedMask,
TDC_monitor_isr) != 0)) {
printf("Fifo IRQ fail\r\n");
bSuccess = FALSE;
}
return bSuccess;
}
void TEST_monitor_isr(void* context, alt_u32 id) {
volatile alt_u32* pPressedMask = (volatile alt_u32*) context;
*pPressedMask |= IORD_ALTERA_AVALON_PIO_EDGE_CAP(TEST_SIG_BASE) & 0x01; // 1-line in
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(TEST_SIG_BASE, 0);
printf("in test-ISR\r\n");
}
bool TEST_monitor_start(volatile alt_u32 *pPressedMask) {
bool bSuccess = TRUE;
// enable interrupt
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(TEST_SIG_BASE, 0x01); // 4-button
// Reset the edge catpure register
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(TEST_SIG_BASE, 0);
printf("in test-start\r\n");
// register IRQ
if (bSuccess
&& (alt_irq_register(TEST_SIG_IRQ, (void *) pPressedMask,
TEST_monitor_isr) != 0)) {
printf("TEST IRQ fail\r\n");
bSuccess = FALSE;
}
return bSuccess;
}
void display_time_elapsed(alt_u32 sample_num) {
// assume sample rate is 48K
alt_u32 time;
SEG7_Decimal(123456, 0x04);
}
bool init(void) {
bool bSuccess = TRUE;
SEG7_Clear();
SEG7_Decimal(0x00000000, 0x00);
return bSuccess;
}
int main() {
volatile alt_u32 button_mask = 0;
volatile alt_u32 tdc_mask = 0;
volatile alt_u32 test_mask = 0;
alt_u32 *pBuf, *pPlaying, *pRecording, RecordLen, PlayLen, data, try_cnt,
buf_sample_size;
printf("\nHello World\n");
if (!init())
return 0;
#ifdef USE_SDRAM_FOR_DATA
pBuf = (alt_u32 *) SDRAM_BASE;
buf_sample_size = SDRAM_SPAN / sizeof(alt_u32);
#else
// alloc memory to stroe PCM data
buf_sample_size = BUF_SAMPLE_NUM;
pBuf = malloc(buf_sample_size * sizeof(alt_u32));
if (!pBuf) {
LCD_TextOut("malloc fail\n\n");
printf("malloc fail\r\n");
return 0;
}
#endif
button_monitor_start(&button_mask); // button IRQ
TDC_monitor_start(&tdc_mask); // TDC IRQ
TEST_monitor_start(&test_mask); // TDC IRQ
printf("ready\n");
// infinite loop
while (1) {
//
}
}
(完)
|
|