// main update, gather input, propagate update ( refresh etc ) ////////////////////////////////////////////////////////////////////////// void CInterfaceManager::Update() { if( DBGU_IsRxReady() != 0 ) { char cKey = DBGU_GetChar(); bool bSystemKey = false; switch( cKey ) { // [ tab ] case 9: if( m_vRegisteredWindows.Size() > 1) { m_vRegisteredWindows[ m_iActiveWindowIdx ]->pWindow->SetActive( false ); m_iActiveWindowIdx = ( m_iActiveWindowIdx+1 ) % m_vRegisteredWindows.Size(); m_vRegisteredWindows[ m_iActiveWindowIdx ]->pWindow->SetActive( true ); bSystemKey = true; } break; default: break; } // send key event if( bSystemKey == false ) { m_vRegisteredWindows[ m_iActiveWindowIdx ]->pWindow->OnKeyEvent( cKey, EKE_PRESSED ); } } // propagate update for( int k=0; k<m_vRegisteredWindows.Size(); k++ ) { m_vRegisteredWindows[ k ]->pWindow->Update(); } }
//------------------------------------------------------------------------------ /// Main function //------------------------------------------------------------------------------ int main(void) { unsigned char key; unsigned char isValid; // Configure all pins PIO_Configure(pins, PIO_LISTSIZE(pins)); LED_Configure(0); LED_Set(0); LED_Configure(1); LED_Set(1); // Initialize the DBGU TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); // Switch to Main clock AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); // Configure PLL to 98.285MHz *AT91C_CKGR_PLLR = ((1 << 29) | (171 << AT91C_CKGR_MUL_SHIFT) \ | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \ | (21 << AT91C_CKGR_DIV_SHIFT)); while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0); // Configure master clock in two operations AT91C_BASE_PMC->PMC_MCKR = (( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK; while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); AT91C_BASE_PMC->PMC_MCKR = ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK); while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0); // DBGU reconfiguration DBGU_Configure(DBGU_STANDARD, 115200, SSC_MCK); // Configure and enable the TWI (required for accessing the DAC) *AT91C_PMC_PCER = (1<< AT91C_ID_TWI0); TWI_ConfigureMaster(AT91C_BASE_TWI0, TWI_CLOCK, SSC_MCK); TWID_Initialize(&twid, AT91C_BASE_TWI0); printf("-- OsmoSDR firmware (" BOARD_NAME ") " GIT_REVISION " --\n\r"); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); req_ctx_init(); PIO_InitializeInterrupts(0); cmd_state.out = vprintf; uart_cmd_reset(&cmd_state); uart_cmds_register(cmds, sizeof(cmds)/sizeof(cmds[0])); fastsource_init(); VBus_Configure(); power_peripherals(1); si570_init(&si570, &twid, SI570_I2C_ADDR); set_si570_freq(30000000); sam3u_e4k_init(&e4k, &twid, E4K_I2C_ADDR); e4k.vco.fosc = 30000000; osdr_fpga_init(SSC_MCK); //osdr_fpga_reg_write(OSDR_FPGA_REG_ADC_TIMING, (1 << 8) | 255); //osdr_fpga_reg_write(OSDR_FPGA_REG_PWM1, (1 << 400) | 800); osdr_fpga_set_iq_swap(0); ssc_init(); e4k_init(&e4k); e4k_init(&e4k); // Enter menu loop while (1) { if (DBGU_IsRxReady()) { key = DBGU_GetChar(); // Process user input if (uart_cmd_char(&cmd_state, key) == 1) { //ssc_stats(); } } ssc_dma_start(); fastsource_start(); } }
//------------------------------------------------------------------------------ /// Check console is ready? /// \return 0 not ready, other value means ready and command string length //------------------------------------------------------------------------------ unsigned int DBGU_CommandIsReady() { unsigned char c; static char *p = gpConsoleBuffer; int escflag = 0; char * p_buf = gpConsoleBuffer; static int n = 0; // buffer index int plen = 0; // prompt length static int col=0; // output column cnt unsigned int cmdLen; plen = strlen(GS_SHELL_PROMPT); //right beginning of a new command input if(col == 0) col = plen; Tag_for_CombinedKey: if(DBGU_IsRxReady()) { c = DBGU_GetChar(); // // Special character handling // switch (c) { case '\r': // Enter case '\n': *p = '\0'; cmdLen = p - p_buf; p = gpConsoleBuffer; n = 0; //clear buffer index as 0 col = 0; // this is set for indicate next time input considered as new command gDBGUPromptFlag = 1;//DBGU_puts ("\r\n"); return cmdLen; case '\0': // nul return 0; case 0x03: // ^C - break //p_buf[0] = '\0'; // discard input return 0; case 0x15: // ^U - erase line while (col > plen) { DBGU_puts (gpEraseSeq); --col; } p = p_buf; n = 0; return 0; case 0x17: // ^W - erase word p=DBGU_RemoveCharFromBuf(p_buf, p, &col, &n, plen); while ((n > 0) && (*p != ' ')) { p=DBGU_RemoveCharFromBuf(p_buf, p, &col, &n, plen); } return 0; case 0x08: // ^H - backspace case 0x7F: // DEL - backspace p=DBGU_RemoveCharFromBuf(p_buf, p, &col, &n, plen); return 0; case 0x1b: // arrow, home flag escflag = 1; goto Tag_for_CombinedKey;//in window hyperterminal, arrow and home flag // keys are combined 1b + x case 'D': //ignore arrow,home key case 'C': case 'H': case 'A': case 'B': if(escflag) { escflag = 0; return 0; } default: // // Must be a normal character then // if (n < DBGU_CMDBUFSIZE-2) { if (c == '\t') { // expand TABs DBGU_puts (gpTabSeq+(col&07)); col += 8 - (col&07); } else { ++col; // echo input DBGU_PutChar (c); } *p++ = c; ++n; } else { // Buffer full DBGU_PutChar ('\a'); } } } return 0; }
//------------------------------------------------------------------------------ /// Application entry point. Configures the DBGU, PIT, TC0, LEDs and buttons /// and makes LED\#1 blink in its infinite loop, using the Wait function. /// \return Unused (ANSI-C compatibility). //------------------------------------------------------------------------------ int main(void) { // DBGU configuration TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); TRACE_INFO_WP("\n\r"); TRACE_INFO("Getting new Started Project --\n\r"); TRACE_INFO("%s\n\r", BOARD_NAME); TRACE_INFO("Compiled: %s %s --\n\r", __DATE__, __TIME__); //Configure Reset Controller AT91C_BASE_RSTC->RSTC_RMR= 0xa5<<24; // Configure EMAC PINS PIO_Configure(emacRstPins, PIO_LISTSIZE(emacRstPins)); // Execute reset RSTC_SetExtResetLength(0xd); RSTC_ExtReset(); // Wait for end hardware reset while (!RSTC_GetNrstLevel()); TRACE_INFO("init Flash\n\r"); flash_init(); TRACE_INFO("init Timer\n\r"); // Configure timer 0 ticks=0; extern void ISR_Timer0(); AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF; AT91C_BASE_TC0->TC_SR; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK | AT91C_TC_CPCTRG; AT91C_BASE_TC0->TC_RC = 375; AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; AIC_ConfigureIT(AT91C_ID_TC0, AT91C_AIC_PRIOR_LOWEST, ISR_Timer0); AIC_EnableIT(AT91C_ID_TC0); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // Configure timer 1 extern void ISR_Timer1(); AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC1); AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; //Stop clock AT91C_BASE_TC1->TC_IDR = 0xFFFFFFFF; //Disable Interrupts AT91C_BASE_TC1->TC_SR; //Read Status register AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV4_CLOCK | AT91C_TC_CPCTRG; // Timer1: 2,666us = 48MHz/128 AT91C_BASE_TC1->TC_RC = 0xffff; AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS; AIC_ConfigureIT(AT91C_ID_TC1, 1, ISR_Timer1); AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; led_init(); TRACE_INFO("init EEprom\n\r"); eeprom_init(); rb_reset(&TTY_Rx_Buffer); rb_reset(&TTY_Tx_Buffer); input_handle_func = analyze_ttydata; LED_OFF(); LED2_OFF(); LED3_OFF(); spi_init(); fht_init(); tx_init(); #ifdef HAS_ETHERNET ethernet_init(); #endif TRACE_INFO("init USB\n\r"); CDCDSerialDriver_Initialize(); USBD_Connect(); wdt_enable(WDTO_2S); fastrf_on=0; display_channel = DISPLAY_USB; TRACE_INFO("init Complete\n\r"); checkFrequency(); // Main loop while (1) { CDC_Task(); Minute_Task(); RfAnalyze_Task(); #ifdef HAS_FASTRF FastRF_Task(); #endif #ifdef HAS_RF_ROUTER rf_router_task(); #endif #ifdef HAS_ASKSIN rf_asksin_task(); #endif #ifdef HAS_MORITZ rf_moritz_task(); #endif #ifdef HAS_RWE rf_rwe_task(); #endif #ifdef HAS_MBUS rf_mbus_task(); #endif #ifdef HAS_MAICO rf_maico_task(); #endif #ifdef HAS_ETHERNET Ethernet_Task(); #endif #ifdef DBGU_UNIT_IN if(DBGU_IsRxReady()){ unsigned char volatile * const ram = (unsigned char *) AT91C_ISRAM; unsigned char x; x=DBGU_GetChar(); switch(x) { case 'd': puts("USB disconnect\n\r"); USBD_Disconnect(); break; case 'c': USBD_Connect(); puts("USB Connect\n\r"); break; case 'r': //Configure Reset Controller AT91C_BASE_RSTC->RSTC_RMR=AT91C_RSTC_URSTEN | 0xa5<<24; break; case 'S': USBD_Disconnect(); my_delay_ms(250); my_delay_ms(250); //Reset *ram = 0xaa; AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_PROCRST | AT91C_RSTC_PERRST | AT91C_RSTC_EXTRST | 0xA5<<24; while (1); break; default: rb_put(&TTY_Tx_Buffer, x); } } #endif if (USBD_GetState() == USBD_STATE_CONFIGURED) { if( USBState == STATE_IDLE ) { CDCDSerialDriver_Read(usbBuffer, DATABUFFERSIZE, (TransferCallback) UsbDataReceived, 0); LED3_ON(); USBState=STATE_RX; } } if( USBState == STATE_SUSPEND ) { TRACE_INFO("suspend !\n\r"); USBState = STATE_IDLE; } if( USBState == STATE_RESUME ) { TRACE_INFO("resume !\n\r"); USBState = STATE_IDLE; } } }