Esempio n. 1
0
void CreateFileCount()
{
BYTE i=0;
//fCreateNew=1;
FileCreated=0;	//penanda  file create baru, file sebelumnya diabaikan
	while(i<10)
		{
			
			MyFileName[5]=i+0x30;

		if(!FileSearch(MyFileName))	//jika nama file tidak ditemukan,
			{
			UartSendString("try new file : ");
			UartSendString(MyFileName);
			UartSendString("\n");
			break;
			}
			i++;
		}
	if(i>9)return;
	
	if(FileInit(MyFileName)==FIL_OK)
		{
			FileCreated=1;
		}
//fCreateNew=0;
}
Esempio n. 2
0
void acoral_fs_init(void)
{
    DiskInit();
    FileInit();	

    fs_mutex=acoral_mutex_create(0,NULL);
    acoral_mount("disk","A:",NULL,0,NULL);
}
void PlatformInit() { 
  StdioInit();
  ERRORassert();
  TimerInit();
  ERRORassert();
  FileInit();
  if (IsError) {
    ERRORprint();
    fprintf(stderr, "Error during FileInit, no File I/O\n");
  } 
}
//*****************************************************************************
//
// This is the callback from the MSC driver.
//
// \param ui32Instance is the driver instance which is needed when communicating
// with the driver.
// \param ui32Event is one of the events defined by the driver.
// \param pvData is a pointer to data passed into the initial call to register
// the callback.
//
// This function handles callback events from the MSC driver.  The only events
// currently handled are the MSC_EVENT_OPEN and MSC_EVENT_CLOSE.  This allows
// the main routine to know when an MSC device has been detected and
// enumerated and when an MSC device has been removed from the system.
//
// \return None
//
//*****************************************************************************
static void
MSCCallback(tUSBHMSCInstance *ps32Instance, uint32_t ui32Event, void *pvData)
{
    //
    // Determine the event.
    //
    switch(ui32Event)
    {
        //
        // Called when the device driver has successfully enumerated an MSC
        // device.
        //
        case MSC_EVENT_OPEN:
        {
            //
            // Proceed to the enumeration state.
            //
            g_eState = STATE_DEVICE_ENUM;

            break;
        }

        //
        // Called when the device driver has been unloaded due to error or
        // the device is no longer present.
        //
        case MSC_EVENT_CLOSE:
        {
            //
            // Go back to the "no device" state and wait for a new connection.
            //
            g_eState = STATE_NO_DEVICE;

            //
            // Re-initialize the file system.
            //
            FileInit();

            break;
        }

        default:
        {
            break;
        }
    }
}
Esempio n. 5
0
//*****************************************************************************
//
// Initializes the USB stack for mass storage.
//
//*****************************************************************************
void
USBStickInit(void)
{
    //
    // Enable the uDMA controller and set up the control table base.
    // The uDMA controller is used by the USB library.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    MAP_uDMAEnable();
    MAP_uDMAControlBaseSet(g_psDMAControlTable);

    //
    // Initially wait for device connection.
    //
    g_iState = eSTATE_NO_DEVICE;

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open an instance of the mass storage class driver.
    //
    g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Run initial pass through USB host stack.
    //
    USBHCDMain();

    //
    // Initialize the file system.
    //
    FileInit();
}
Esempio n. 6
0
int main() {
    Init();
    FileInit();
    Order = -1;

    //work
    while (Order != 0) {
        ReadInit();
        switch (Order) {
            case 1 : addstu(); break;
            case 2 : addact(); break;
            case 3 : qstu(); break;
            case 4 : qact(); break;
            case 5 : qc(); break;
            case 0 : break;
            default : printf("Unknown Order\n");break;
        }
    }

    // free the memory
    EndFree();
    return 0;
}
Esempio n. 7
0
extern void GUImain( void )
/*************************/
{
    int                 argc = 0;
    char                **argv = NULL;
    char                *dir;
    char                *drive;
    char                *inf_name;
    char                *tmp_path;
    char                *arc_name;
    char                *new_inf;
    char                current_dir[_MAX_PATH];
    bool                ret = FALSE;
    dlg_state           state;

    GUIMemOpen();
    GUIGetArgs( &argv, &argc );
#if defined( __NT__ )
    if( CheckWin95Uninstall( argc, argv ) ) return;
#endif
#ifdef __WINDOWS__
    if( CheckForSetup32( argc, argv ) ) return;
#endif

    // initialize paths and env. vbls.

    if( !SetupPreInit() ) return;
    if( !GetDirParams( argc, argv, &inf_name, &tmp_path, &arc_name ) ) return;
    if( !SetupInit() ) return;
    GUIDrainEvents();   // push things along
    FileInit( arc_name );
    InitGlobalVarList();
    strcpy( current_dir, tmp_path );
    while( InitInfo( inf_name, tmp_path ) ) {

        ret = DoMainLoop( &state );

        if( state == DLG_DONE ) break;
//        if( CancelSetup == TRUE || !ret ) break;
        if( CancelSetup == TRUE ) break;
//        if( !ret ) break;

        // look for another SETUP.INF
        if( GetVariableByName( "SetupPath" ) == NO_VAR ) {
            if( DirParamStack( &inf_name, &tmp_path, Stack_IsEmpty ) == FALSE ) {  // "IsEmpty"?
                DirParamStack( &inf_name, &tmp_path, Stack_Pop ); // "Pop"
                CloseDownMessage( ret );
                CancelSetup = FALSE;
                ret = TRUE;
            } else {
                CloseDownMessage( ret );
                break;
            }
        } else {
            if( GetVariableIntVal( "IsMultiInstall" ) ) {
                // push current script on stack
                DirParamStack( &inf_name, &tmp_path, Stack_Push ); // "Push"
            }
            new_inf = GUIMemAlloc( _MAX_PATH );
            drive = GUIMemAlloc( _MAX_DRIVE );
            dir = GUIMemAlloc( _MAX_PATH );
            if( new_inf == NULL || drive == NULL || dir == NULL ) {
                GUIMemFree( new_inf );
                GUIMemFree( drive );
                GUIMemFree( dir );
                break;
            }
            // construct new path relative to previous
            ReplaceVars( new_inf, GetVariableStrVal( "SetupPath" ) );
            _splitpath( current_dir, drive, dir, NULL, NULL );
            _makepath( inf_name, drive, dir, new_inf, NULL );

            _splitpath( inf_name, drive, dir, NULL, NULL );
            _makepath( tmp_path, drive, dir, NULL, NULL );
//          strcpy( current_dir, tmp_path );

            GUIMemFree( new_inf );
            GUIMemFree( drive );
            GUIMemFree( dir );
        } /* if */

        FreeGlobalVarList( FALSE );
        FreeDefaultDialogs();
        FreeAllStructs();
        ConfigModified = FALSE;
    } /* while */


    FileFini();
    FreeGlobalVarList( TRUE );
    FreeDefaultDialogs();
    FreeAllStructs();
    FreeDirParams( &inf_name, &tmp_path, &arc_name );
    CloseDownProgram();
}
Esempio n. 8
0
void main(void)
{
	Int16  temp_cnt;

	ICR = 0xff2e;	/* IDLE Control Register */
					/* mem port, io port and cpu idle active */

	/* Peripheral_Reset  */
	CSL_SYSCTRL_REGS->PSRCR = 0x0020;

	CSL_SYSCTRL_REGS->PCGCR1 = 0x0000;
	CSL_SYSCTRL_REGS->PCGCR2 = 0x0000;
	CSL_SYSCTRL_REGS->PRCR = 0x00bf;

/* VERY IMPORTANT !!! */
/* PPMODE1 (SPI, GPIO, UART, and I2S2):
    7 signals of the SPI module,
    6 GPIO signals(GP[17:12]),
    4 signals of the UART module,
    4 signals of the I2S2 module

   SP1MODE2 (GP[11:6]). 6 GPIO signals (GP[11:6])
   SP0MODE0 (MMC/SD0). All 6 signals of the MMC/SD0
*/
	CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12)
							|(CSL_SYS_EBSR_SP1MODE_MODE2 << 10)
							|(CSL_SYS_EBSR_SP0MODE_MODE0 << 8);

	asm("	bit(ST1, #ST1_INTM) = #1");

	INTR_init();
	PLL_init(3658);		// system clock set to 120MHz
	TIMER_init();
	EZDSP5535_GPIO_init();
	EZDSP5535_I2C_init();		/* Initialize I2C */

	Audio_init(7);				/* Initialise to bandwidth=7kHz */

	EZDSP5535_LCD_init();
	LCD_print("G722.1 Receiver  ", 17, 0);
	LCD_print("16kbps  ", 8, 1);
	EZDSP5535_SPI_init();
	Si446x_Init();

	EZDSP5535_SAR_init();
	DiskInit();
	FileInit();

	AddFileDriver(SDCammand, NULL);

	asm("	bit(ST1, #ST1_INTM) = #0");

	bApi_Set_Receive();
	while(1) {
		if(gpioIsrStatus == 1) {
			temp_cnt = SPI_recvData(spibuffer);

			gpioIsrStatus = 0;
			CSL_GPIO_REGS->IOINTFLG1 = 0x0800;
		}

		if(spiIsrStatus == 1) {
//			SpiWriteByte(CMD_FIFO_INFO, 0);
			SpiWriteByte(CMD_GET_INT_STATUS, 0);
			bApi_Set_Receive();
			if(audioProcessing())	continue;

			spiIsrStatus = 0;
		}

		fileProcessing();

		asm("	idle");
	}

//	RemoveFileDriver(SDCammand);
}
Esempio n. 9
0
//*****************************************************************************
//
// The main application loop.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Status, i32Idx;
    uint32_t ui32SysClock, ui32PLLRate;
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set the part pin out appropriately for this device.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Initialize the hub port status.
    //
    for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++)
    {
        g_psHubStatus[i32Idx].bConnected = false;
    }

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open the Keyboard interface.
    //
    KeyboardOpen();
    MSCOpen(ui32SysClock);

    //
    // Open a hub instance and provide it with the memory required to hold
    // configuration descriptors for each attached device.
    //
    USBHHubOpen(HubCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Tell the USB library the CPU clock and the PLL frequency.
    //
    USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-host-hub");

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) /
                         GrFontMaxWidthGet(g_psFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                           (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                           GrFontHeightGet(g_psFontFixed6x8);

    //
    // Initial update of the screen.
    //
    UpdateStatus(0);
    UpdateStatus(1);
    UpdateStatus(2);
    UpdateStatus(3);

    g_ui32CmdIdx = 0;
    g_ui32CurrentLine = 0;

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        WriteString("> ");

        //
        // Is there a command waiting to be processed?
        //
        while((g_ui32Flags & FLAG_CMD_READY) == 0)
        {
            //
            // Call the YSB library to let non-interrupt code run.
            //
            USBHCDMain();

            //
            // Call the keyboard and mass storage main routines.
            //
            KeyboardMain();
            MSCMain();
        }

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32Status = CmdLineProcess(g_pcCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(i32Status == CMDLINE_BAD_CMD)
        {
            WriteString("Bad command!\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32Status == CMDLINE_TOO_MANY_ARGS)
        {
            WriteString("Too many arguments for command processor!\n");
        }
        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(i32Status != 0)
        {
            WriteString("Command returned error code\n");
            WriteString((char *)StringFromFresult((FRESULT)i32Status));
            WriteString("\n");
        }

        //
        // Reset the command flag and the command index.
        //
        g_ui32Flags &= ~FLAG_CMD_READY;
        g_ui32CmdIdx = 0;
    }
}
//*****************************************************************************
//
// The program main function.  It performs initialization, then runs a loop to
// process USB activities and operate the user interface.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32DriveTimeout;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the system clock to run at 50MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Configure the required pins for USB operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure SysTick for a 100Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable the uDMA controller and set up the control table base.
    // The uDMA controller is used by the USB library.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    ROM_uDMAEnable();
    ROM_uDMAControlBaseSet(g_psDMAControlTable);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the buttons driver.
    //
    ButtonsInit();

    //
    // Initialize two offscreen displays and assign the palette.  These
    // buffers are used by the slide menu widget to allow animation effects.
    //
    GrOffScreen4BPPInit(&g_sOffscreenDisplayA, g_pui8OffscreenBufA, 96, 64);
    GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayA, g_pui32Palette, 0,
                              NUM_PALETTE_ENTRIES);
    GrOffScreen4BPPInit(&g_sOffscreenDisplayB, g_pui8OffscreenBufB, 96, 64);
    GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayB, g_pui32Palette, 0,
                              NUM_PALETTE_ENTRIES);

    //
    // Show an initial status screen
    //
    g_pcStatusLines[0] = "Waiting";
    g_pcStatusLines[1] = "for device";
    ShowStatusScreen(g_pcStatusLines, 2);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sFileMenuWidget);

    //
    // Initially wait for device connection.
    //
    g_eState = STATE_NO_DEVICE;

    //
    // Initialize the USB stack for host mode.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open an instance of the mass storage class driver.
    //
    g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the drive timeout.
    //
    ui32DriveTimeout = USBMSC_DRIVE_RETRY;

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Initialize the USB controller for host operation.
    //
    USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // Enter an infinite loop to run the user interface and process USB
    // events.
    //
    while(1)
    {
        uint32_t ui32LastTickCount = 0;

        //
        // Call the USB stack to keep it running.
        //
        USBHCDMain();

        //
        // Process any messages in the widget message queue.  This keeps the
        // display UI running.
        //
        WidgetMessageQueueProcess();

        //
        // Take action based on the application state.
        //
        switch(g_eState)
        {
            //
            // A device has enumerated.
            //
            case STATE_DEVICE_ENUM:
            {
                //
                // Check to see if the device is ready.  If not then stay
                // in this state and we will check it again on the next pass.
                //
                if(USBHMSCDriveReady(g_psMSCInstance) != 0)
                {
                    //
                    // Wait about 500ms before attempting to check if the
                    // device is ready again.
                    //
                    ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3));

                    //
                    // Decrement the retry count.
                    //
                    ui32DriveTimeout--;

                    //
                    // If the timeout is hit then go to the
                    // STATE_TIMEOUT_DEVICE state.
                    //
                    if(ui32DriveTimeout == 0)
                    {
                        g_eState = STATE_TIMEOUT_DEVICE;
                    }

                    break;
                }

                //
                // Getting here means the device is ready.
                // Reset the CWD to the root directory.
                //
                g_pcCwdBuf[0] = '/';
                g_pcCwdBuf[1] = 0;

                //
                // Set the initial directory level to the root
                //
                g_ui32Level = 0;

                //
                // We need to reset the indexes of the root menu to 0, so that
                // it will start at the top of the file list, and reset the
                // slide menu widget to start with the root menu.
                //
                g_psFileMenus[g_ui32Level].ui32CenterIndex = 0;
                g_psFileMenus[g_ui32Level].ui32FocusIndex = 0;
                SlideMenuMenuSet(&g_sFileMenuWidget, &g_psFileMenus[g_ui32Level]);

                //
                // Initiate a directory change to the root.  This will
                // populate a menu structure representing the root directory.
                //
                if(ProcessDirChange("/", g_ui32Level))
                {
                    //
                    // If there were no errors reported, we are ready for
                    // MSC operation.
                    //
                    g_eState = STATE_DEVICE_READY;

                    //
                    // Set the Device Present flag.
                    //
                    g_ui32Flags = FLAGS_DEVICE_PRESENT;

                    //
                    // Request a repaint so the file menu will be shown
                    //
                    WidgetPaint(WIDGET_ROOT);
                }

                break;
            }

            //
            // If there is no device then just wait for one.
            //
            case STATE_NO_DEVICE:
            {
                if(g_ui32Flags == FLAGS_DEVICE_PRESENT)
                {
                    //
                    // Show waiting message on screen
                    //
                    g_pcStatusLines[0] = "Waiting";
                    g_pcStatusLines[1] = "for device";
                    ShowStatusScreen(g_pcStatusLines, 2);

                    //
                    // Clear the Device Present flag.
                    //
                    g_ui32Flags &= ~FLAGS_DEVICE_PRESENT;
                }
                break;
            }

            //
            // An unknown device was connected.
            //
            case STATE_UNKNOWN_DEVICE:
            {
                //
                // If this is a new device then change the status.
                //
                if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
                {
                    //
                    // Clear the screen and indicate that an unknown device
                    // is present.
                    //
                    g_pcStatusLines[0] = "Unknown";
                    g_pcStatusLines[1] = "device";
                    ShowStatusScreen(g_pcStatusLines, 2);
                }

                //
                // Set the Device Present flag.
                //
                g_ui32Flags = FLAGS_DEVICE_PRESENT;

                break;
            }

            //
            // The connected mass storage device is not reporting ready.
            //
            case STATE_TIMEOUT_DEVICE:
            {
                //
                // If this is the first time in this state then print a
                // message.
                //
                if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
                {
                    //
                    //
                    // Clear the screen and indicate that an unknown device
                    // is present.
                    //
                    g_pcStatusLines[0] = "Device";
                    g_pcStatusLines[1] = "Timeout";
                    ShowStatusScreen(g_pcStatusLines, 2);
                }

                //
                // Set the Device Present flag.
                //
                g_ui32Flags = FLAGS_DEVICE_PRESENT;

                break;
            }

            //
            // The device is ready and in use.
            //
            case STATE_DEVICE_READY:
            {
                //
                // Process occurrence of timer tick.  Check for user input
                // once each tick.
                //
                if(g_ui32SysTickCount != ui32LastTickCount)
                {
                    uint8_t ui8ButtonState;
                    uint8_t ui8ButtonChanged;

                    ui32LastTickCount = g_ui32SysTickCount;

                    //
                    // Get the current debounced state of the buttons.
                    //
                    ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0);

                    //
                    // If select button or right button is pressed, then we
                    // are trying to descend into another directory
                    //
                    if(BUTTON_PRESSED(SELECT_BUTTON,
                                      ui8ButtonState, ui8ButtonChanged) ||
                       BUTTON_PRESSED(RIGHT_BUTTON,
                                      ui8ButtonState, ui8ButtonChanged))
                    {
                        uint32_t ui32NewLevel;
                        uint32_t ui32ItemIdx;
                        char *pcItemName;

                        //
                        // Get a pointer to the current menu for this CWD.
                        //
                        tSlideMenu *psMenu = &g_psFileMenus[g_ui32Level];

                        //
                        // Get the highlighted index in the current file list.
                        // This is the currently highlighted file or dir
                        // on the display.  Then get the name of the file at
                        // this index.
                        //
                        ui32ItemIdx = SlideMenuFocusItemGet(psMenu);
                        pcItemName = psMenu->psSlideMenuItems[ui32ItemIdx].pcText;

                        //
                        // Make sure we are not yet past the maximum tree
                        // depth.
                        //
                        if(g_ui32Level < MAX_SUBDIR_DEPTH)
                        {
                            //
                            // Potential new level is one greater than the
                            // current level.
                            //
                            ui32NewLevel = g_ui32Level + 1;

                            //
                            // Process the directory change to the new
                            // directory.  This function will populate a menu
                            // structure with the files and subdirs in the new
                            // directory.
                            //
                            if(ProcessDirChange(pcItemName, ui32NewLevel))
                            {
                                //
                                // If the change was successful, then update
                                // the level.
                                //
                                g_ui32Level = ui32NewLevel;

                                //
                                // Now that all the prep is done, send the
                                // KEY_RIGHT message to the widget and it will
                                // "slide" from the previous file list to the
                                // new file list of the CWD.
                                //
                                SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT);

                            }
                        }
                    }

                    //
                    // If the UP button is pressed, just pass it to the widget
                    // which will handle scrolling the list of files.
                    //
                    if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged))
                    {
                        SendWidgetKeyMessage(WIDGET_MSG_KEY_UP);
                    }

                    //
                    // If the DOWN button is pressed, just pass it to the widget
                    // which will handle scrolling the list of files.
                    //
                    if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged))
                    {
                        SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN);
                    }

                    //
                    // If the LEFT button is pressed, then we are attempting
                    // to go up a level in the file system.
                    //
                    if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged))
                    {
                        uint32_t ui32NewLevel;

                        //
                        // Make sure we are not already at the top of the
                        // directory tree (at root).
                        //
                        if(g_ui32Level)
                        {
                            //
                            // Potential new level is one less than the
                            // current level.
                            //
                            ui32NewLevel = g_ui32Level - 1;

                            //
                            // Process the directory change to the new
                            // directory.  This function will populate a menu
                            // structure with the files and subdirs in the new
                            // directory.
                            //
                            if(ProcessDirChange("..", ui32NewLevel))
                            {
                                //
                                // If the change was successful, then update
                                // the level.
                                //
                                g_ui32Level = ui32NewLevel;

                                //
                                // Now that all the prep is done, send the
                                // KEY_LEFT message to the widget and it will
                                // "slide" from the previous file list to the
                                // new file list of the CWD.
                                //
                                SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
                            }
                        }
                    }
                }
                break;
            }
            //
            // Something has caused a power fault.
            //
            case STATE_POWER_FAULT:
            {
                //
                // Clear the screen and show a power fault indication.
                //
                g_pcStatusLines[0] = "Power";
                g_pcStatusLines[1] = "fault";
                ShowStatusScreen(g_pcStatusLines, 2);
                break;
            }

            default:
            {
                break;
            }
        }
    }
}
Esempio n. 11
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    FRESULT FileResult;
    tRectangle sRect;

    //
    // Initially wait for device connection.
    //
    g_eState = STATE_NO_DEVICE;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Enable Clocking to the USB controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Set the USB pins to be controlled by the USB controller.
    //
    GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4);

    //
    // The LM3S3748 board uses a USB mux that must be switched to use the
    // host connecter and not the device connecter.
    //
    GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN);
    GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_HOST);

    //
    // Turn on USB Phy clock.
    //
    SysCtlUSBPLLEnable();

    //
    // Set the system tick to fire 100 times per second.
    //
    SysTickPeriodSet(SysCtlClockGet()/100);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Enable the uDMA controller and set up the control table base.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    uDMAEnable();
    uDMAControlBaseSet(g_sDMAControlTable);

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = SPLASH_HEIGHT - 1;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);

    GrStringDrawCentered(&g_sContext, "usb_host_msc", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Set the color to white and select the 20 point font.
    //
    GrContextForegroundSet(&g_sContext, FILE_COLOR);

    GrStringDraw(&g_sContext, "No Device",
        100, 0, TOP_HEIGHT, 1);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers);

    //
    // Open an instance of the mass storage class driver.
    //
    g_ulMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USB_HOST_PWREN_HIGH);

    //
    // Initialize the host controller.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the pushbuttons.
    //
    ButtonsInit();

    //
    // Set the auto repeat rates for the up and down buttons.
    //
    ButtonsSetAutoRepeat(UP_BUTTON, 50, 15);
    ButtonsSetAutoRepeat(DOWN_BUTTON, 50, 15);

    //
    // Current directory is "/"
    //
    g_DirData.szPWD[0] = '/';
    g_DirData.szPWD[1] = 0;

    //
    // Initialize the file system.
    //
    FileInit();

    while(1)
    {
        USBHCDMain();

        switch(g_eState)
        {
            case STATE_DEVICE_ENUM:
            {
                //
                // Reset the root directory.
                //
                g_DirData.szPWD[0] = '/';
                g_DirData.szPWD[1] = 0;

                //
                // Open the root directory.
                //
                FileResult = f_opendir(&g_DirData.DirState, g_DirData.szPWD);

                //
                // Wait for the root directory to open successfully.  The MSC
                // device can enumerate before being read to be accessed, so
                // there may be some delay before it is ready.
                //
                if(FileResult == FR_OK)
                {
                    //
                    // Reset the directory state.
                    //
                    g_DirData.ulIndex = 0;
                    g_DirData.ulSelectIndex = 0;
                    g_DirData.ulValidValues = 0;
                    g_eState = STATE_DEVICE_READY;

                    //
                    // Ignore buttons pressed before being ready.
                    //
                    g_ulButtons = 0;

                    //
                    // Update the screen if the root dir opened successfully.
                    //
                    DirUpdate();
                    UpdateWindow();
                }
                else if(FileResult != FR_NOT_READY)
                {
                    // some kind of error
                }

                //
                // Set the Device Present flag.
                //
                g_ulFlags = FLAGS_DEVICE_PRESENT;

                break;
            }

            //
            // This is the running state where buttons are checked and the
            // screen is updated.
            //
            case STATE_DEVICE_READY:
            {
                //
                // Down button pressed and released.
                //
                if(g_ulButtons & BUTTON_DOWN_CLICK)
                {
                    //
                    // Update the screen and directory state.
                    //
                    MoveDown();

                    //
                    // Clear the button pressed event.
                    //
                    g_ulButtons &= ~BUTTON_DOWN_CLICK;
                }

                //
                // Up button pressed and released.
                //
                if(g_ulButtons & BUTTON_UP_CLICK)
                {
                    //
                    // Update the screen and directory state.
                    //
                    MoveUp();

                    //
                    // Clear the button pressed event.
                    //
                    g_ulButtons &= ~BUTTON_UP_CLICK;
                }

                //
                // Select button pressed and released.
                //
                if(g_ulButtons & BUTTON_SELECT_CLICK)
                {
                    //
                    // If this was a directory go into it.
                    //
                    SelectDir();

                    //
                    // Clear the button pressed event.
                    //
                    g_ulButtons &= ~BUTTON_SELECT_CLICK;
                }
                break;
            }

            //
            // If there is no device then just wait for one.
            //
            case STATE_NO_DEVICE:
            {
                if(g_ulFlags == FLAGS_DEVICE_PRESENT)
                {
                    //
                    // Clear the screen and indicate that there is no longer
                    // a device present.
                    //
                    ClearTextBox();
                    GrStringDraw(&g_sContext, "No Device",
                         100, 0, TOP_HEIGHT, 1);

                    //
                    // Clear the Device Present flag.
                    //
                    g_ulFlags &= ~FLAGS_DEVICE_PRESENT;
                }
                break;
            }

            //
            // An unknown device was connected.
            //
            case STATE_UNKNOWN_DEVICE:
            {
                //
                // If this is a new device then change the status.
                //
                if((g_ulFlags & FLAGS_DEVICE_PRESENT) == 0)
                {
                    //
                    // Clear the screen and indicate that an unknown device is
                    // present.
                    //
                    ClearTextBox();
                    GrStringDraw(&g_sContext, "Unknown Device",
                         100, 0, TOP_HEIGHT, 1);
                }

                //
                // Set the Device Present flag.
                //
                g_ulFlags = FLAGS_DEVICE_PRESENT;

                break;
            }

            //
            // Something has caused a power fault.
            //
            case STATE_POWER_FAULT:
            {
                break;
            }

            default:
            {
                break;
            }
        }
    }
}
Esempio n. 12
0
int main (void)
{
	int answer;

	CreatorInfo();

	while (true)
		{
			printf("================== MENU ==================\n");
			printf("1. Input the database;\n");
			printf("2. Supplement to the database;\n");
			printf("3. Edit the database;\n");
			printf("4. Delete the element in the database;\n");
			printf("5. Output the database;\n");
			printf("6. Output the worst students list;\n");
			printf("7. Output the teachers-docents list;\n");
			printf("8. Output the totall budget of faculties;\n");
			printf("0. Exit.\n\n");

			scanf("%d", &answer);

			switch (answer)
				{
					case INPUT:
						{
							FileInit();
							break;
						}
					case SUPPLEMENT:
						{
							FileSupplement();
							break;
						}
					case EDIT:
						{
							FileEditing();
							break;
						}
					case DELETE:
						{
							FileDelete();
							break;
						}
					case OUTPUT:
						{
							FileOutput();
							break;
						}
					case VIEWSTUD:
						{
							LowestScore();
							break;
						}
					case VIEWTEACH:
						{
							Docents();
							break;
						}
					case BUDGET:
						{
							TotallBudget();
							break;
						}
					case EXIT:
						{
							exit (false);
							break;
						}
					default:
						printf("Something went wrong...\n");
				}
		}
}
Esempio n. 13
0
//*****************************************************************************
//
// The program main function.  It performs initialization, then runs
// a command processing loop to read commands from the console.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32DriveTimeout;
    uint32_t ui32SysClock;
    tContext sContext;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL |
                                       SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "usb-host-msc");

    //
    // Configure SysTick for a 100Hz interrupt.
    //
    ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable the uDMA controller and set up the control table base.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    ROM_uDMAEnable();
    ROM_uDMAControlBaseSet(g_sDMAControlTable);

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit(ui32SysClock);

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);

    //
    // Set some initial strings.
    //
    ListBoxTextAdd(&g_sDirList, "Waiting for device...");

    //
    // Issue the initial paint request to the widgets then immediately call
    // the widget manager to process the paint message.  This ensures that the
    // display is drawn as quickly as possible and saves the delay we would
    // otherwise experience if we processed the paint message after mounting
    // and reading the SD card.
    //
    WidgetPaint(WIDGET_ROOT);
    WidgetMessageQueueProcess();

    //
    // Initially wait for device connection.
    //
    g_eState = STATE_NO_DEVICE;

    //
    // Initialize the USB stack for host mode.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open an instance of the mass storage class driver.
    //
    g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the drive timeout.
    //
    ui32DriveTimeout = USBMSC_DRIVE_RETRY;

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Initialize the USB controller for host operation.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // Enter an (almost) infinite loop for reading and processing commands from
    // the user.
    //
    while(1)
    {
        //
        // Call the USB stack to keep it running.
        //
        USBHCDMain();

        //
        // Process any messages in the widget message queue.  This keeps the
        // display UI running.
        //
        WidgetMessageQueueProcess();

        switch(g_eState)
        {
            case STATE_DEVICE_ENUM:
            {
                //
                // Take it easy on the Mass storage device if it is slow to
                // start up after connecting.
                //
                if(USBHMSCDriveReady(g_psMSCInstance) != 0)
                {
                    //
                    // Wait about 500ms before attempting to check if the
                    // device is ready again.
                    //
                    ROM_SysCtlDelay(ui32SysClock / (3 * 2));

                    //
                    // Decrement the retry count.
                    //
                    ui32DriveTimeout--;

                    //
                    // If the timeout is hit then go to the
                    // STATE_TIMEOUT_DEVICE state.
                    //
                    if(ui32DriveTimeout == 0)
                    {
                        g_eState = STATE_TIMEOUT_DEVICE;
                    }
                    break;
                }

                //
                // Getting here means the device is ready.
                // Reset the CWD to the root directory.
                //
                g_cCwdBuf[0] = '/';
                g_cCwdBuf[1] = 0;

                //
                // Set the initial directory level to the root
                //
                g_ui32Level = 0;

                //
                // Fill the list box with the files and directories found.
                //
                if(!PopulateFileListBox(true))
                {
                    //
                    // If there were no errors reported, we are ready for
                    // MSC operation.
                    //
                    g_eState = STATE_DEVICE_READY;
                }

                //
                // Set the Device Present flag.
                //
                g_ui32Flags = FLAGS_DEVICE_PRESENT;
                break;
            }

            //
            // If there is no device then just wait for one.
            //
            case STATE_NO_DEVICE:
            {
                if(g_ui32Flags == FLAGS_DEVICE_PRESENT)
                {
                    //
                    // Empty the list box on the display.
                    //
                    ListBoxClear(&g_sDirList);
                    ListBoxTextAdd(&g_sDirList, "Waiting for device...");
                    WidgetPaint((tWidget *)&g_sDirList);

                    //
                    // Clear the Device Present flag.
                    //
                    g_ui32Flags &= ~FLAGS_DEVICE_PRESENT;
                }
                break;
            }

            //
            // An unknown device was connected.
            //
            case STATE_UNKNOWN_DEVICE:
            {
                //
                // If this is a new device then change the status.
                //
                if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
                {
                    //
                    // Clear the screen and indicate that an unknown device
                    // is present.
                    //
                    ListBoxClear(&g_sDirList);
                    ListBoxTextAdd(&g_sDirList, "Unknown device.");
                    WidgetPaint((tWidget *)&g_sDirList);
                }
                //
                // Set the Device Present flag.
                //
                g_ui32Flags = FLAGS_DEVICE_PRESENT;
                break;
            }

            //
            // The connected mass storage device is not reporting ready.
            //
            case STATE_TIMEOUT_DEVICE:
            {
                //
                // If this is the first time in this state then print a
                // message.
                //
                if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
                {
                    //
                    // Clear the screen and indicate that an unknown device
                    // is present.
                    //
                    ListBoxClear(&g_sDirList);
                    ListBoxTextAdd(&g_sDirList, "Device Timeout.");
                    WidgetPaint((tWidget *)&g_sDirList);
                }

                //
                // Set the Device Present flag.
                //
                g_ui32Flags = FLAGS_DEVICE_PRESENT;
                break;
            }

            //
            // Something has caused a power fault.
            //
            case STATE_POWER_FAULT:
            {
                break;
            }
            default:
            {
                break;
            }
        }
    }
}
Esempio n. 14
0
//The Main function of program
int main(int argc, char *argv[])
{
#ifdef _DEBUG
//Handle the system signal.
	SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
#endif

	if (argc > 0)
	{
		std::shared_ptr<wchar_t> wPath(new wchar_t[MAX_PATH]());
	//Path initialization and Winsock initialization.
		MultiByteToWideChar(CP_ACP, NULL, argv[0], MBSTOWCS_NULLTERMINATE, wPath.get(), MAX_PATH);
		if (FileInit(wPath.get()) == EXIT_FAILURE)
			return EXIT_FAILURE;
		wPath.reset();

	//Windows Firewall Test in first start.
		if (argc > 1 && strlen(argv[1U]) == strlen("--FirstStart") && memcmp(argv[1], ("--FirstStart"), strlen("--FirstStart")) == 0)
		{
			if (FirewallTest(AF_INET6) == EXIT_FAILURE && FirewallTest(AF_INET) == EXIT_FAILURE)
			{
				PrintError(WINSOCK_ERROR, L"Windows Firewall Test error", NULL, nullptr, NULL);

				WSACleanup();
				return EXIT_FAILURE;
			}
			else {
				return EXIT_SUCCESS;
			}
		}
	}
	else {
		return EXIT_FAILURE;
	}

//Read configuration file and WinPcap initialization.
	if (Parameter.ReadParameter() == EXIT_FAILURE)
	{
		WSACleanup();
		return EXIT_FAILURE;
	}
	std::thread CaptureInitializationThread(CaptureInit);
	CaptureInitializationThread.detach();

//Get Localhost DNS PTR Records.
	std::thread IPv6LocalAddressThread(LocalAddressToPTR, AF_INET6);
	std::thread IPv4LocalAddressThread(LocalAddressToPTR, AF_INET);
	IPv6LocalAddressThread.detach();
	IPv4LocalAddressThread.detach();

//DNSCurve initialization
	if (Parameter.DNSCurve && DNSCurveParameter.Encryption)
	{
		randombytes_set_implementation(&randombytes_salsa20_implementation);
		DNSCurveInit();
	}
	
//Read IPFilter, start DNS Cache monitor(Timer type) and read Hosts.
	if (Parameter.FileRefreshTime > 0)
	{
		if (Parameter.OperationMode == LISTEN_CUSTOMMODE)
		{
			std::thread IPFilterThread(&Configuration::ReadIPFilter, std::ref(Parameter));
			IPFilterThread.detach();
		}

		if (Parameter.CacheType != 0)
		{
			std::thread DNSCacheTimerThread(DNSCacheTimerMonitor, Parameter.CacheType);
			DNSCacheTimerThread.detach();
		}

		std::thread HostsThread(&Configuration::ReadHosts, std::ref(Parameter));
		HostsThread.detach();
	}

//Service initialization and start service.
	SERVICE_TABLE_ENTRYW ServiceTable[] = {{LOCAL_SERVICENAME, (LPSERVICE_MAIN_FUNCTIONW)ServiceMain}, {nullptr, NULL}};
	if (!StartServiceCtrlDispatcherW(ServiceTable))
	{
		PrintError(SYSTEM_ERROR, L"Service start error", GetLastError(), nullptr, NULL);

		WSACleanup();
		return EXIT_FAILURE;
	}

	WSACleanup();
	return EXIT_SUCCESS;
}
Esempio n. 15
0
void main(void)
{
	Int16  *samples;
	HANDLE FHandle = Not_Open_FILE;
	Int16  *out_words = &rawOutWords[1];
	Uint8  *byte16 = &RfByte[2];	
	Int16  mlt_coefs[DCT_LENGTH];
	Int16  mag_shift[2];
	Int16  old_mag_shift[2];
	Uint16 number_of_bits_per_frame;
	Uint16 number_of_bytes_per_frame;
	Uint16 number_of_16bit_words_per_frame;
	Int16  offset;
	Int16  key;
	Uint16 chn;		// left and right channel, 0 or 1
	Int16  sent_buffer_cnt = 0;
	Uint8  *sent_buffer;
	
	ICR = 0xff2e;	/* IDLE Control Register */
					/* mem port, io port and cpu idle active */

	DSP_zero(xmt_l, DCT_LENGTH);
	DSP_zero(xmt_r, DCT_LENGTH);
	/* Peripheral_Reset  */
	CSL_SYSCTRL_REGS->PSRCR = 0x0020;

	CSL_SYSCTRL_REGS->PCGCR1 = 0x0000;
	CSL_SYSCTRL_REGS->PCGCR2 = 0x0000;
	CSL_SYSCTRL_REGS->PRCR = 0x00bf;

	CSL_SYSCTRL_REGS->EBSR = (CSL_SYS_EBSR_PPMODE_MODE1 << 12)
							| (0 << 8) | (2 << 10);//GPIO(11-6)
	asm("	bit(ST1, #ST1_INTM) = #1");

	number_of_bits_per_frame = (Uint16)(BITRATE * 20);	// BITRATE in kbps
	number_of_bytes_per_frame = (Uint16)(number_of_bits_per_frame>>3);
	number_of_16bit_words_per_frame = (Uint16)(number_of_bits_per_frame>>4);

	INTR_init();
	PLL_init();
	TIMER_init();
	EZDSP5535_GPIO_init();
	DMA_audio_init(DCT_LENGTH);

	EZDSP5535_I2C_init();		/* Initialize I2C */
	aic3204_init(6);			/* Initialize codec */
	EZDSP5535_LCD_init();
	EZDSP5535_I2S_init();		/* Initialize I2S */
	LCD_print("G722.1 Send       ", 17, 0);
	LCD_print("16kbps  ", 8, 1);
	EZDSP5535_SPI_init();
	Si446x_Init();
	EZDSP5535_SAR_init();
	DiskInit();
	FileInit();
	AddFileDriver(SDCammand, NULL);

	sam2coef_init();
	coef2sam_init();
	rawOutWords[0] = 0x6b21;
	RfByte[0] = 0x21; RfByte[1] = 0x6b;		// little-endian

	old_mag_shift[0] = 0;
	old_mag_shift[1] = 0;
	asm("	bit(ST1, #ST1_INTM) = #0");

	SpiWriteByte(CMD_GET_INT_STATUS, 0);	// clear interrupt pending
	while(1) {
		if(pingpong >= 0) {
			offset = (pingpong>>1) * DCT_LENGTH;
/*******************************************************************
 * LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT
 *******************************************************************/
			chn = LEFT;
			samples = &rcv_l[offset];		// Read frame of samples from mem.
			// Convert input samples to rmlt coefs
			mag_shift[chn] = samples_to_rmlt_coefs(samples, mlt_coefs, chn);
			// Encode the mlt coefs
			encoder(number_of_bits_per_frame, mlt_coefs, mag_shift[chn], out_words);
			byte16 = &RfByte[2];
			byte16[-2] = 0x6b; byte16[-1] = 0x20;
			DSP_word2byte(byte16, out_words, number_of_16bit_words_per_frame);
			
			// process the out_words into decoder_mlt_coefs
			decoder(out_words, mlt_coefs, &mag_shift[chn], &old_mag_shift[chn]);

			samples = &xmt_l[offset];		// Write frame of output samples
			// convert the decoder_mlt_coefs to samples
			rmlt_coefs_to_samples(mlt_coefs, samples, mag_shift[chn], chn);

/*******************************************************************
 * RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT 
 *******************************************************************/
			chn = RIGHT;
			samples = &rcv_r[offset];		// Read frame of samples from mem.
			// Convert input samples to rmlt coefs
			mag_shift[chn] = samples_to_rmlt_coefs(samples, mlt_coefs, chn);
			// Encode the mlt coefs
			encoder(number_of_bits_per_frame, mlt_coefs, mag_shift[chn], out_words);

			byte16 = &RfByte[number_of_bytes_per_frame + 4];
			byte16[-2] = 0x6b; byte16[-1] = 0x21;
			DSP_word2byte(byte16, out_words, number_of_16bit_words_per_frame);

			// process the out_words into decoder_mlt_coefs
			decoder(out_words, mlt_coefs, &mag_shift[chn], &old_mag_shift[chn]);

			samples = &xmt_r[offset];		// Write frame of output samples
			// convert the decoder_mlt_coefs to samples
			rmlt_coefs_to_samples(mlt_coefs, samples, mag_shift[chn], chn);

			if (FHandle != Not_Open_FILE)	// Write output bitstream
				FileWrite(RfByte, 2*number_of_bytes_per_frame+4, FHandle);

			pingpong = -1;
			sent_buffer = RfByte;
			sent_buffer_cnt = 0;
		}
		if(spiIsrStatus == 1) {
			bApi_Set_Send(43);
			spiIsrStatus = 0;
		}
		if(sent_buffer_cnt < 2) {
			if(gpioIsrStatus == 1) {
				SPI_sendData(sent_buffer, number_of_bytes_per_frame+2);
				sent_buffer += number_of_bytes_per_frame+2;
				sent_buffer_cnt++;
				gpioIsrStatus = 0;
				CSL_GPIO_REGS->IOINTFLG1 = 0x0800;
			}
		}

//		key = EZDSP5535_SAR_getKey();
		key = -1;
		if(key == SW1)
		if(FHandle == Not_Open_FILE)
		{
			LCD_print("RECORDING......", 15, 0);
			FHandle = FileOpen("A:\\VOICE000.TXT", FILE_FLAGS_WRITE);
		}
		if(key == SW2)
		if(FHandle != Not_Open_FILE)
		{
			LCD_print("SAVE VOICE000.DAT", 17, 0); 
			FileClose(FHandle);
			AllCacheWriteBack();
			FHandle = Not_Open_FILE;
		}
		asm("	idle");
	}