Ejemplo n.º 1
0
//*****************************************************************************
//
// CheckBoardRevision uses PD1 with a weak pull down resistor to detect the
// development board hardware revision. Code for the LM4F board can run on the
// TM4C, but not vice versa. This function checks for the board verion and
// warns the user if they are using the wrong board / software.
//
// The EK-LM4F232 (green) board uses an analog accelorometer. The DK-TM4C123G
//(red) board uses a digitial I2C 9 axis accel, mag, gyro.
//
//*****************************************************************************
void
CheckBoardRevision(void)
{
    uint32_t ui32BoardType;
    tContext sDisplayContext;
    //
    // Check if board is TM4C123G (red) or LM4F232 (green). This code
    // should not be run on green board.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    MAP_GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN);
    MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1,
                         GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD);
    ui32BoardType=MAP_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_1);
    if(ui32BoardType==0)
    {
        //
        // The board is green, print error message and hang.
        //
        CFAL96x64x16Init();
        GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
        GrContextForegroundSet(&sDisplayContext, ClrWhite);
        GrContextFontSet(&sDisplayContext, g_psFontFixed6x8);
        GrStringDrawCentered(&sDisplayContext, "ERROR:", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 4, 0);
        GrStringDrawCentered(&sDisplayContext, "Due to different", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 20, false);
        GrStringDrawCentered(&sDisplayContext, "hardware this", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 30, false);
        GrStringDrawCentered(&sDisplayContext, "code cannot run", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 40, false);
        GrStringDrawCentered(&sDisplayContext, "on this board", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 50, false);
        GrStringDrawCentered(&sDisplayContext, "Try diff code.", -1,
                             GrContextDpyWidthGet(&sDisplayContext) / 2, 60, false);
        while(1)
        {
            // Hang here.
        }
    }
    else
    {
        //
        // The board is red, exit & continue as normal.
        //
        return ;
    }
}
Ejemplo n.º 2
0
//*****************************************************************************
//
// Initialize the display.  This function is specific to the  EK-LM4F232 board
// and contains nothing directly relevant to the timer configuration or
// operation.
//
//*****************************************************************************
void
InitDisplay(void)
{
    tRectangle sRect;

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

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "edge-count", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Initialize timer status display.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDraw(&g_sContext, "Countdown:", -1, 8, 26, 0);
    GrStringDraw(&g_sContext, "Interrupts:", -1, 8, 36, 0);
}
Ejemplo n.º 3
0
//*****************************************************************************
//
// Set up the OLED Graphical Display
//
//*****************************************************************************
void
InitGraphics(void)
{
    tRectangle sRect;

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

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

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    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_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "CAN Example", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);
}
Ejemplo n.º 4
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    uint_fast32_t ui32Retcode;

    //
    // 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 SysTick for a 100Hz interrupt.  The FatFs driver wants a 10 ms
    // tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Configure and enable uDMA
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlDelay(10);
    ROM_uDMAControlBaseSet(&sDMAControlTable[0]);
    ROM_uDMAEnable();

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

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

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = DISPLAY_BANNER_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_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-dev-msc", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 5, 0);

    //
    // Initialize the idle timeout and reset all flags.
    //
    g_ui32IdleTimeout = 0;
    g_ui32Flags = 0;

    //
    // Initialize the state to idle.
    //
    g_eMSCState = MSC_DEV_DISCONNECTED;

    //
    // Draw the status bar and set it to idle.
    //
    UpdateStatus("Disconnected", 1);

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

    //
    // Set the USB pins to be controlled by the USB controller.
    //
    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);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDMSCInit(0, &g_sMSCDevice);

    //
    // Determine whether or not an SDCard is installed.  If not, print a
    // warning and have the user install one and restart.
    //
    ui32Retcode = disk_initialize(0);

    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    if(ui32Retcode != RES_OK) {
        GrStringDrawCentered(&g_sContext, "No SDCard Found", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 16, 0);
        GrStringDrawCentered(&g_sContext, "Please insert",
                             -1, GrContextDpyWidthGet(&g_sContext) / 2, 26, 0);
        GrStringDrawCentered(&g_sContext, "a card and",
                             -1, GrContextDpyWidthGet(&g_sContext) / 2, 36, 0);
        GrStringDrawCentered(&g_sContext, "reset the board.",
                             -1, GrContextDpyWidthGet(&g_sContext) / 2, 46, 0);
    } else {
        GrStringDrawCentered(&g_sContext, "SDCard Found",  -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 30, 0);
    }

    //
    // Drop into the main loop.
    //
    while(1) {
        switch(g_eMSCState) {
            case MSC_DEV_READ: {
                //
                // Update the screen if necessary.
                //
                if(g_ui32Flags & FLAG_UPDATE_STATUS) {
                    UpdateStatus("Reading", 0);
                    g_ui32Flags &= ~FLAG_UPDATE_STATUS;
                }

                //
                // If there is no activity then return to the idle state.
                //
                if(g_ui32IdleTimeout == 0) {
                    UpdateStatus("Idle", 0);
                    g_eMSCState = MSC_DEV_IDLE;
                }

                break;
            }
            case MSC_DEV_WRITE: {
                //
                // Update the screen if necessary.
                //
                if(g_ui32Flags & FLAG_UPDATE_STATUS) {
                    UpdateStatus("Writing", 0);
                    g_ui32Flags &= ~FLAG_UPDATE_STATUS;
                }

                //
                // If there is no activity then return to the idle state.
                //
                if(g_ui32IdleTimeout == 0) {
                    UpdateStatus("Idle", 0);
                    g_eMSCState = MSC_DEV_IDLE;
                }
                break;
            }
            case MSC_DEV_DISCONNECTED: {
                //
                // Update the screen if necessary.
                //
                if(g_ui32Flags & FLAG_UPDATE_STATUS) {
                    UpdateStatus("Disconnected", 0);
                    g_ui32Flags &= ~FLAG_UPDATE_STATUS;
                }
                break;
            }
            case MSC_DEV_IDLE: {
                break;
            }
            default: {
                break;
            }
        }
    }
}
//*****************************************************************************
//
// 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;
            }
        }
    }
}
Ejemplo n.º 6
0
//*****************************************************************************
//
// This function initializes the ADC hardware in preparation for data
// acquisition.
//
//*****************************************************************************
void
AcquireInit(void)
{
    unsigned long ulChan;

    //
    // Enable the ADC peripherals and the associated GPIO port
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

    ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);

    ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |GPIO_PIN_7 | GPIO_PIN_3);
    ROM_GPIOPinTypeADC(GPIO_PORTP_BASE, GPIO_PIN_0);

//    ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
    //ROM_ADCR

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6;
    ADCSequenceDisable(ADC0_BASE,SEQUENCER);

    ROM_ADCSequenceConfigure(ADC0_BASE, SEQUENCER, ADC_TRIGGER_TIMER, 0);

    for(ulChan = 0; ulChan < 2; ulChan++)
    {
        unsigned long ulChCtl;


        if (ulChan ==1)
        {

            ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH1|ADC_CTL_IE | ADC_CTL_END);
        }
        else if(ulChan==0)
        {
        	ulChCtl = ADC_CTL_CH0;
        	ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH0);
        }


    }

    ADCHardwareOversampleConfigure(ADC0_BASE, 1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER );

    //100 micro
    unsigned long freq=SAMPLING_FREQUENCY;
    unsigned long period=(2*ROM_SysCtlClockGet()/(freq));

    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A,period);
    ROM_TimerControlTrigger(TIMER0_BASE, TIMER_A, true);

    //ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    //ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() /2);




    CFAL96x64x16Init();
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    sRect1.sXMin = 0;
    sRect1.sYMin = 0;
    sRect1.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect1.sYMax = 23;

    sRect2.sXMin = 0;
    sRect2.sYMin = 23;
    sRect2.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect2.sYMax = GrContextDpyHeightGet(&sDisplayContext) - 1;


	snprintf(text,sizeof(text),"STart");


    GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect1);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);
    GrContextFontSet(&sDisplayContext, g_pFontCm12);
    GrStringDrawCentered(&sDisplayContext,text, -1,
                         GrContextDpyWidthGet(&sDisplayContext) / 2, 10, 0);

    //GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    //GrRectFill(&sDisplayContext, &sRect1);
    //GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);

    /*GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect2);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    GrRectDraw(&sDisplayContext, &sRect2);
*/
    compute_filter();
    maxi1=0;
    maxi2=0;
    max1=0;
    max2=0;
    res=0;
    res1=0;
    g_ulADCCount=0;
    buffer_index=0;
    ulLastADCCount=0;

}
Ejemplo n.º 7
0
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint_fast32_t ui32TxCount;
    uint_fast32_t ui32RxCount;
    tRectangle sRect;
    char pcBuffer[16];

    //
    // 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 clocking to run from the PLL at 50MHz
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

#ifdef DEBUG
    //
    // Configure the UART for debug output.
    //
    ConfigureUART();
#endif

    //
    // Not configured initially.
    //
    g_bUSBConfigured = false;

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

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

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-dev-bulk", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Show the various static text elements on the color STN display.
    //
    GrStringDraw(&g_sContext, "Tx bytes:", -1, 0, 32, false);
    GrStringDraw(&g_sContext, "Rx bytes:", -1, 0, 42, false);

    //
    // Enable the GPIO peripheral used for USB, and configure the USB
    // pins.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);

    //
    // Enable the system tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Show the application name on the display and UART output.
    //
    DEBUG_PRINT("\nTiva C Series USB bulk device example\n");
    DEBUG_PRINT("---------------------------------\n\n");

    //
    // Tell the user what we are up to.
    //
    DisplayStatus(&g_sContext, "Configuring USB");

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDBulkInit(0, &g_sBulkDevice);

    //
    // Wait for initial configuration to complete.
    //
    DisplayStatus(&g_sContext, "Waiting for host");

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;

    //
    // Main application loop.
    //
    while(1)
    {

        //
        // Have we been asked to update the status display?
        //
        if(g_ui32Flags & COMMAND_STATUS_UPDATE)
        {
            //
            // Clear the command flag
            //
            g_ui32Flags &= ~COMMAND_STATUS_UPDATE;
            DisplayStatus(&g_sContext, g_pcStatus);
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32TxCount)
        {
            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32TxCount;

            //
            // Update the display of bytes transmitted by the UART.
            //
            usnprintf(pcBuffer, 16, " %d ", ui32TxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 48, 32, true);
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32RxCount)
        {
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32RxCount;

            //
            // Update the display of bytes received by the UART.
            //
            usnprintf(pcBuffer, 16, " %d ", ui32RxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 48, 42, true);
        }
    }
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tUSBMode eLastMode;
    char *pcString;

    //
    // 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);

    //
    // Initially wait for device connection.
    //
    g_eUSBState = STATE_NO_DEVICE;
    eLastMode = USB_MODE_OTG;
    g_eCurrentUSBMode = USB_MODE_OTG;

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    
    //
    // 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 Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Enable clocking to the UART and associated GPIO
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the relevant pins such that UART0 owns them.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Open UART0 for debug output.
    //
    UARTStdioInit(0);

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

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

    //
    // Open an instance of the keyboard driver.  The keyboard does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a keyboard is present.
    //
    g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer,
                                            KEYBOARD_MEMORY_SIZE);

    //
    // 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 OTG operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pHCDPool, HCD_MEMORY_SIZE);

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

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

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = (2 * DISPLAY_BANNER_HEIGHT) - 1;
    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-host-", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);
    GrStringDrawCentered(&g_sContext, "keyboard", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 14, 0);


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

    //
    // 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_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                          (3*(DISPLAY_BANNER_HEIGHT + 1)))/
                          GrFontHeightGet(g_pFontFixed6x8);

    //
    // Open and instance of the keyboard class driver.
    //
    UARTprintf("Host Keyboard Application\n");

    //
    // Initial update of the screen.
    //
    UpdateStatus();

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Tell the OTG library code how much time has passed in
        // milliseconds since the last call.
        //
        USBOTGMain(GetTickms());

        //
        // Has the USB mode changed since last time we checked?
        //
        if(g_eCurrentUSBMode != eLastMode)
        {
            //
            // Remember the new mode.
            //
            eLastMode = g_eCurrentUSBMode;

            switch(eLastMode)
            {
                case USB_MODE_HOST:
                    pcString = "HOST";
                    break;

                case USB_MODE_DEVICE:
                    pcString = "DEVICE";
                    break;

                case USB_MODE_NONE:
                    pcString = "NONE";
                    break;

                default:
                    pcString = "UNKNOWN";
                    break;
            }

            UARTprintf("USB mode changed to %s\n", pcString);
        }

        switch(g_eUSBState)
        {
            //
            // This state is entered when they keyboard is first detected.
            //
            case STATE_KEYBOARD_INIT:
            {
                //
                // Initialized the newly connected keyboard.
                //
                USBHKeyboardInit(g_ulKeyboardInstance);

                //
                // Proceed to the keyboard connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                //
                // Update the screen now that the keyboard has been
                // initialized.
                //
                UpdateStatus();

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                break;
            }
            case STATE_KEYBOARD_UPDATE:
            {
                //
                // If the application detected a change that required an
                // update to be sent to the keyboard to change the modifier
                // state then call it and return to the connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                break;
            }
            case STATE_KEYBOARD_CONNECTED:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is connected.
                //
                break;
            }

            case STATE_UNKNOWN_DEVICE:
            {
                //
                // Nothing to do as the device is unknown.
                //
                break;
            }

            case STATE_NO_DEVICE:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is not connected.
                //
                break;
            }
            default:
            {
                break;
            }
        }
    }
}
Ejemplo n.º 9
0
//*****************************************************************************
//
// Print "Hello World!" to the display.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    UARTprintf("Hello, world!\n");

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

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

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

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

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontCm12);
    GrStringDrawCentered(&sContext, "hello", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 10, 0);

    //
    // Say hello using the Computer Modern 40 point font.
    //
    GrContextFontSet(&sContext, g_psFontCm12/*g_psFontFixed6x8*/);
    GrStringDrawCentered(&sContext, "Hello World!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         ((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24,
                         0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // We are finished. Hang around doing nothing.
    //
    while(1) {
    }
}
Ejemplo n.º 10
0
//*****************************************************************************
//
// Compute and display a sine wave.
//
//*****************************************************************************
int
main(void)
{
    uint_fast16_t ui16ItemCount = 0;
    uint32_t ui32LastTickCount = 0;

    //
    // 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 clocking to run directly at 50 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Configure SysTick to generate a periodic time tick interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

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

    //
    // Initialize an offscreen display and assign the palette.  This offscreen
    // buffer is needed by the strip chart widget.
    //
    GrOffScreen4BPPInit(&g_sOffscreenDisplay, g_pui8OffscreenBuf, 96, 64);
    GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplay, g_pui32Palette, 0,
                              NUM_PALETTE_ENTRIES);

    //
    // Set the data series buffer pointer to point at the storage where the
    // series data points will be stored.
    //
    g_sSeries.pvData = g_i8SeriesData;

    //
    // Add the series to the strip chart
    //
    StripChartSeriesAdd(&g_sStripChart, &g_sSeries);

    //
    // Add the strip chart to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, &g_sStripChart.sBase);

    //
    // Enter a loop to continuously calculate a sine wave.
    //
    while(1)
    {
        float fElapsedTime;
        float fRadians;
        float fSine;

        //
        // Wait for the next timer tick.
        //
        while(ui32LastTickCount == g_ui32TickCount)
        {
        }
        ui32LastTickCount = g_ui32TickCount;

        //
        // Preparing to add a new data point to the strip chart ...
        // If the number count of items in the strip chart has reached the
        // maximum value, then the data points need to "slide down" in the
        // buffer so new data can be added at the end.
        //
        if(ui16ItemCount == SERIES_LENGTH)
        {
            memmove(&g_i8SeriesData[0], &g_i8SeriesData[1], SERIES_LENGTH - 1);
        }

        //
        // Otherwise, the series data buffer is less than full so just
        // increment the count of data points.
        //
        else
        {
            //
            // Increment the number of items that have been added to the strip
            // chart series data buffer.
            //
            ui16ItemCount++;

            //
            // Since the count of data items has changed, it must be updated in
            // the data series.
            //
            g_sSeries.ui16NumItems = ui16ItemCount;
        }

        //
        // Compute the elapsed time in decimal seconds, in floating point
        // format.
        //
        fElapsedTime = (float)g_ui32TickCount * FSECONDS_PER_TICK;

        //
        // Convert the time to radians.
        //
        fRadians = fElapsedTime * 2.0 * M_PI;

        //
        // Adjust the period of the wave.  This will give us a wave period
        // of 4 seconds, or 0.25 Hz.  This number was chosen arbitrarily to
        // provide a nice looking wave on the display.
        //
        fRadians /= 4.0;

        //
        // Compute the sine.  Multiply by 0.5 to reduce the amplitude.
        //
        fSine = sinf(fRadians) * 0.5;

        //
        // Finally, save the sine value into the last location in the series
        // data point buffer.  Convert the sine amplitude to display pixels.
        // (Amplitude 1 = 32 pixels)
        //
        g_i8SeriesData[ui16ItemCount - 1] = (int8_t)(fSine * 32.0);

        //
        // Now that a new data point has been added to the series, advance
        // the strip chart.
        //
        StripChartAdvance(&g_sStripChart, 1);

        //
        // Request a repaint and run the widget processing queue.
        //
        WidgetPaint(WIDGET_ROOT);
        WidgetMessageQueueProcess();
    }
}
Ejemplo n.º 11
0
//*****************************************************************************
//
// Run the hibernate example.  Use a loop to put the microcontroller into
// hibernate mode, and to wake up based on time. Also allow the user to cause
// it to hibernate and/or wake up based on button presses.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Idx;
    uint32_t ui32Status = 0;
    uint32_t ui32HibernateCount = 0;
    tContext sContext;
    tRectangle sRect;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    //
    // Initialize the OLED display
    //
    CFAL96x64x16Init();

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

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "hibernate", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

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

    //
    // Set up systick to generate interrupts at 100 Hz.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Enable the Hibernation module.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Print wake cause message on display.
    //
    GrStringDrawCentered(&sContext, "Wake due to:", -1,
                         GrContextDpyWidthGet(&sContext) / 2, Row(2) + 4,
                         true);

    //
    // Check to see if Hibernation module is already active, which could mean
    // that the processor is waking from a hibernation.
    //
    if(HibernateIsActive())
    {
        //
        // Read the status bits to see what caused the wake.
        //
        ui32Status = HibernateIntStatus(0);
        HibernateIntClear(ui32Status);

        //
        // Wake was due to the push button.
        //
        if(ui32Status & HIBERNATE_INT_PIN_WAKE)
        {
            GrStringDrawCentered(&sContext, "BUTTON", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // Wake was due to RTC match
        //
        else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
        {
            GrStringDrawCentered(&sContext, "TIMEOUT", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // Wake is due to neither button nor RTC, so it must have been a hard
        // reset.
        //
        else
        {
            GrStringDrawCentered(&sContext, "RESET", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // If the wake is due to button or RTC, then read the first location
        // from the battery backed memory, as the hibernation count.
        //
        if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))
        {
            HibernateDataGet(&ui32HibernateCount, 1);
        }
    }

    //
    // Enable the Hibernation module.  This should always be called, even if
    // the module was already enabled, because this function also initializes
    // some timing parameters.
    //
    HibernateEnableExpClk(ROM_SysCtlClockGet());

    //
    // If the wake was not due to button or RTC match, then it was a reset.
    //
    if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)))
    {
        //
        // Configure the module clock source.
        //
        HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);

        //
        // Finish the wake cause message.
        //
        GrStringDrawCentered(&sContext, "RESET", -1,
                             GrContextDpyWidthGet(&sContext) / 2,
                             Row(3) + 4, true);

        //
        // Wait a couple of seconds in case we need to break in with the
        // debugger.
        //
        SysTickWait(3 * 100);

        //
        // Allow time for the crystal to power up.  This line is separated from
        // the above to make it clear this is still needed, even if the above
        // delay is removed.
        //
        SysTickWait(15);
    }

    //
    // Print the count of times that hibernate has occurred.
    //
    usnprintf(g_pcBuf, sizeof(g_pcBuf), "Hib count=%4u", ui32HibernateCount);
    GrStringDrawCentered(&sContext, g_pcBuf, -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(1) + 4, true);

    //
    // Print messages on the screen about hibernation.
    //
    GrStringDrawCentered(&sContext, "Select to Hib", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(4) + 4, true);
    GrStringDrawCentered(&sContext, "Wake in 5 s,", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(5) + 4, true);
    GrStringDrawCentered(&sContext, "or press Select", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(6) + 4, true);
    GrStringDrawCentered(&sContext, "for immed. wake.", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(7) + 4, true);

    //
    // Clear the button pressed flag, in case it was held down at the
    // beginning.
    //
    bSelectPressed = 0;

    //
    // Wait for user to press the button.
    //
    while(!bSelectPressed)
    {
        //
        // Wait a bit before looping again.
        //
        SysTickWait(10);
    }

    //
    // Tell user to release the button.
    //
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(4) + 4, true);
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(5) + 4, true);
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(6) + 4, true);
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(7) + 4, true);
    GrStringDrawCentered(&sContext, "Release the", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(5) + 4, true);
    GrStringDrawCentered(&sContext, "button.", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(6) + 4, true);
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(7) + 4, true);

    //
    // Wait for user to release the button.
    //
    while(bSelectPressed)
    {
    }

    //
    // If hibernation count is very large, it may be that there was already
    // a value in the hibernate memory, so reset the count.
    //
    ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount;

    //
    // Increment the hibernation count, and store it in the battery backed
    // memory.
    //
    ui32HibernateCount++;
    HibernateDataSet(&ui32HibernateCount, 1);

    //
    // Clear and enable the RTC and set the match registers to 5 seconds in the
    // future. Set both to same, though they could be set differently, the
    // first to match will cause a wake.
    //
    HibernateRTCSet(0);
    HibernateRTCEnable();
    HibernateRTCMatchSet(0, 5);

    //
    // Set wake condition on pin or RTC match.  Board will wake when 5 seconds
    // elapses, or when the button is pressed.
    //
    HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);

    //
    // Request hibernation.
    //
    HibernateRequest();

    //
    // Give it time to activate, it should never get past this wait.
    //
    SysTickWait(100);

    //
    // Should not have got here, something is wrong.  Print an error message to
    // the user.
    //
    sRect.i16XMin = 0;
    sRect.i16XMax = 95;
    sRect.i16YMin = 0;
    sRect.i16YMax = 63;
    GrContextForegroundSet(&sContext, ClrBlack);
    GrRectFill(&sContext, &sRect);
    GrContextForegroundSet(&sContext, ClrWhite);
    ui32Idx = 0;
    while(g_pcErrorText[ui32Idx])
    {
        GrStringDraw(&sContext, g_pcErrorText[ui32Idx], -1, Col(0),
                     Row(ui32Idx), true);
        ui32Idx++;
    }

    //
    // Wait for the user to press the button, then restart the app.
    //
    bSelectPressed = 0;
    while(!bSelectPressed)
    {
    }

    //
    // Reset the processor.
    //
    ROM_SysCtlReset();

    //
    // Finished.
    //
    while(1)
    {
    }
}
Ejemplo n.º 12
0
//*****************************************************************************
//
// A simple demonstration of the features of the TivaWare Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Idx;
    tRectangle sRect;

    //
    // 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 clocking to run from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

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

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

    //
    // Fill the top 12 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 11;
    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_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "grlib_demo", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 5, 0);

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ui32Idx = 0; ui32Idx <= 8; ui32Idx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((10 - ui32Idx) * 255) / 8) << ClrRedShift) |
                                (((ui32Idx * 255) / 8) << ClrGreenShift)));
        GrLineDraw(&g_sContext, 60, 60, 0, 60 - (5 * ui32Idx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ui32Idx = 1; ui32Idx <= 11; ui32Idx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((11 - ui32Idx) * 255) / 11) <<
                                 ClrGreenShift) |
                                (((ui32Idx * 255) / 11) << ClrBlueShift)));
        GrLineDraw(&g_sContext, 60, 60, (ui32Idx * 5), 20);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(&g_sContext, ClrBlue);
    GrCircleFill(&g_sContext, 80, 30, 15);
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrCircleDraw(&g_sContext, 80, 30, 15);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(&g_sContext, ClrGray);
    sRect.i16XMin = 8;
    sRect.i16YMin = 45;
    sRect.i16XMax = 46;
    sRect.i16YMax = 51;
    GrRectFill(&g_sContext, &sRect);
    GrContextForegroundSet(&g_sContext, ClrWhite);
    sRect.i16XMin += 4;
    sRect.i16YMin += 4;
    sRect.i16XMax += 4;
    sRect.i16YMax += 4;
    GrRectDraw(&g_sContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrStringDraw(&g_sContext, "Strings", -1, 6, 16, 0);
    GrContextForegroundSet(&g_sContext, ClrSilver);
    GrStringDraw(&g_sContext, "Strings", -1, 7, 17, 0);

    //
    // Draw an image.
    //
    GrTransparentImageDraw(&g_sContext, g_pui8Logo, 64, 34, ClrBlack);
#if 0
    GrImageDraw(&g_sContext, g_pui8Logo, 64, 34);
#endif

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 13
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    uint_fast32_t ui32LastTickCount;
    bool bLastSuspend;
    tRectangle sRect;
    tContext sContext;
    int_fast32_t i32CenterX;

    //
    // 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 clocking to run from the PLL at 50MHz.
    //
    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);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Enable the GPIO that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
    ROM_GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0);

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

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

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);
    i32CenterX = GrContextDpyWidthGet(&sContext) / 2;

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "usb-dev-keyboard", -1, i32CenterX, 4, 0);

    //
    // Not configured initially.
    //
    g_bConnected = false;
    g_bSuspended = false;
    bLastSuspend = false;

    //
    // Initialize the USB stack for device mode.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB HID device class driver,
    // initialize the USB
    // controller and connect the device to the bus.
    //
    USBDHIDKeyboardInit(0, &g_sKeyboardDevice);

    //
    // Set the system tick to fire 100 times per second.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // The main loop starts here.  We begin by waiting for a host connection
    // then drop into the main keyboard handling section.  If the host
    // disconnects, we return to the top and wait for a new connection.
    //
    while(1)
    {
        uint8_t ui8Buttons;
        uint8_t ui8ButtonsChanged;

        //
        // Tell the user what we are doing and provide some basic instructions.
        //
        GrStringDrawCentered(&sContext, "    Waiting    ",
                             -1, i32CenterX, 22, 1);
        GrStringDrawCentered(&sContext, " for host ... ", -1,
                             i32CenterX, 32, 1);

        //
        // Wait here until USB device is connected to a host.
        //
        while(!g_bConnected)
        {
        }

        //
        // Update the status.
        //
        GrStringDrawCentered(&sContext, "     Host     ",
                             -1, i32CenterX, 22, 1);
        GrStringDrawCentered(&sContext, " connected ... ",
                             -1, i32CenterX, 32, 1);

        //
        // Enter the idle state.
        //
        g_eKeyboardState = STATE_IDLE;

        //
        // Assume that the bus is not currently suspended if we have just been
        // configured.
        //
        bLastSuspend = false;

        //
        // Keep transferring characters from the UART to the USB host for as
        // long as we are connected to the host.
        //
        while(g_bConnected)
        {
            //
            // Remember the current time.
            //
            ui32LastTickCount = g_ui32SysTickCount;

            //
            // Has the suspend state changed since last time we checked?
            //
            if(bLastSuspend != g_bSuspended)
            {
                //
                // Yes - the state changed so update the display.
                //
                bLastSuspend = g_bSuspended;
                if(bLastSuspend)
                {
                    GrStringDrawCentered(&sContext, "      Bus      ", -1,
                                         i32CenterX, 22, 1);
                    GrStringDrawCentered(&sContext, " suspended ... ", -1,
                                         i32CenterX, 32, 1);
                }
                else
                {
                    GrStringDrawCentered(&sContext, "     Host     ", -1,
                                         i32CenterX, 22, 1);
                    GrStringDrawCentered(&sContext, " connected ... ",
                                         -1, i32CenterX, 32, 1);
                }
            }

            //
            // See if the button was just pressed.
            //
            ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0);
            if(BUTTON_PRESSED(SELECT_BUTTON, ui8Buttons, ui8ButtonsChanged))
            {
                //
                // If the bus is suspended then resume it.  Otherwise, type
                // some "random" characters.
                //
                if(g_bSuspended)
                {
                    USBDHIDKeyboardRemoteWakeupRequest(
                                                   (void *)&g_sKeyboardDevice);
                }
                else
                {
                    SendString("Make the Switch to TI Microcontrollers!");
                }
            }

            //
            // Wait for at least 1 system tick to have gone by before we poll
            // the buttons again.
            //
            while(g_ui32SysTickCount == ui32LastTickCount)
            {
            }
        }
    }
}
//*****************************************************************************
//
// Demonstrate the use of the USB stick update example.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulCount;
    tContext sContext;
    tRectangle sRect;

    //
    // 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);

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

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

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

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

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&sContext, "usb-stick-demo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Indicate what is happening.
    //
    GrStringDrawCentered(&sContext, "Press the", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, 0);
    GrStringDrawCentered(&sContext, "select button to", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, 0);
    GrStringDrawCentered(&sContext, "start the USB", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, 0);
    GrStringDrawCentered(&sContext, "stick updater.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Enable the GPIO module which the select button is attached to.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);

    //
    // Enable the GPIO pin to read the user button.
    //
    ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    ROM_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Wait for the pullup to take effect or the next loop will exist too soon.
    //
    SysCtlDelay(1000);

    //
    // Wait until the select button has been pressed for ~40ms (in order to
    // debounce the press).
    //
    ulCount = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0)
        {
            //
            // Increment the count since the button is pressed.
            //
            ulCount++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being pressed.
            //
            if(ulCount == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is not pressed.
            //
            ulCount = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Wait until the select button has been released for ~40ms (in order to
    // debounce the release).
    //
    ulCount = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) != 0)
        {
            //
            // Increment the count since the button is released.
            //
            ulCount++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being released.
            //
            if(ulCount == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is pressed.
            //
            ulCount = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Indicate that the updater is being called.
    //
    GrStringDrawCentered(&sContext, "The USB stick", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, true);
    GrStringDrawCentered(&sContext, "updater is now", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, true);
    GrStringDrawCentered(&sContext, "waiting for a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, true);
    GrStringDrawCentered(&sContext, "USB stick.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, true);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Call the updater so that it will search for an update on a memory stick.
    //
    (*((void (*)(void))(*(unsigned long *)0x2c)))();

    //
    // The updater should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 15
0
//*****************************************************************************
//
// This example application demonstrates the use of the timers to generate
// periodic interrupts.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

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

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

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

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "timers", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Initialize timer status display.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);
    GrStringDraw(&g_sContext, "Timer 0:", -1, 16, 26, 0);
    GrStringDraw(&g_sContext, "Timer 1:", -1, 16, 36, 0);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Configure the two 32-bit periodic timers.
    //
    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet());
    ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() / 2);

    //
    // Setup the interrupts for the timer timeouts.
    //
    ROM_IntEnable(INT_TIMER0A);
    ROM_IntEnable(INT_TIMER1A);
    ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Enable the timers.
    //
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);
    ROM_TimerEnable(TIMER1_BASE, TIMER_A);

    //
    // Loop forever while the timers run.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tContext sContext;

    //
    // Set the clocking to run at 50 MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    
    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

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

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

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&sContext, "softuart-echo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);
    
    //
    // Initialize the display and write some instructions.
    //
    GrStringDrawCentered(&sContext, "Connect a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, false);
    GrStringDrawCentered(&sContext, "terminal", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, false);
    GrStringDrawCentered(&sContext, "to UART0.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, false);
    GrStringDrawCentered(&sContext, "115000,N,8,1", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, false);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Compute the bit time for 115,200 baud.
    //
    g_ulBitTime = (ROM_SysCtlClockGet() / 115200) - 1;

    //
    // Configure the SoftUART for 8-N-1 operation.
    //
    SoftUARTInit(&g_sUART);
    SoftUARTRxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_0);
    SoftUARTTxGPIOSet(&g_sUART, GPIO_PORTA_BASE, GPIO_PIN_1);
    SoftUARTRxBufferSet(&g_sUART, g_pusRxBuffer,
                        sizeof(g_pusRxBuffer) / sizeof(g_pusRxBuffer[0]));
    SoftUARTTxBufferSet(&g_sUART, g_pucTxBuffer, sizeof(g_pucTxBuffer));
    SoftUARTCallbackSet(&g_sUART, SoftUARTIntHandler);
    SoftUARTConfigSet(&g_sUART,
                      (SOFTUART_CONFIG_WLEN_8 | SOFTUART_CONFIG_STOP_ONE |
                       SOFTUART_CONFIG_PAR_NONE));

    //
    // Configure the timer for the SoftUART transmitter.
    //
    ROM_TimerConfigure(TIMER0_BASE,
                       (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC |
                        TIMER_CFG_B_PERIODIC));
    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ulBitTime);
    ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT);
    ROM_TimerEnable(TIMER0_BASE, TIMER_A);

    //
    // Set the priorities of the interrupts associated with the SoftUART.  The
    // receiver is higher priority than the transmitter, and the receiver edge
    // interrupt is higher priority than the receiver timer interrupt.
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x00);
    ROM_IntPrioritySet(INT_TIMER0B, 0x40);
    ROM_IntPrioritySet(INT_TIMER0A, 0x80);

    //
    // Enable the interrupts associated with the SoftUART.
    //
    ROM_IntEnable(INT_TIMER0A);
    ROM_IntEnable(INT_TIMER0B);
    ROM_IntEnable(INT_GPIOA);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"\033[2JEnter text: ", 16);

    //
    // Enable the SoftUART interrupt.
    //
    SoftUARTIntEnable(&g_sUART, SOFTUART_INT_RX | SOFTUART_INT_RT);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
        //
        // Wait until there are characters available in the receive buffer.
        //
        while(g_ulFlag == 0)
        {
        }
        g_ulFlag = 0;

        //
        // Loop while there are characters in the receive buffer.
        //
        while(SoftUARTCharsAvail(&g_sUART))
        {
            //
            // Read the next character from the UART and write it back to the
            // UART.
            //
            SoftUARTCharPutNonBlocking(&g_sUART,
                                       SoftUARTCharGetNonBlocking(&g_sUART));
        }
    }
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

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

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

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

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = (DISPLAY_BANNER_HEIGHT) - 1;
    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-host-mouse", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Display default information about the mouse
    //
    GrStringDrawCentered(&g_sContext, "Position:", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 16, 0);
    GrStringDrawCentered(&g_sContext, "-,-", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 26, 1);
    GrStringDrawCentered(&g_sContext, "Buttons:", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 36, 0);
    GrStringDrawCentered(&g_sContext, "---", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 46, 1);

    //
    // Fill the bottom rows of the screen with blue to create the status area.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = GrContextDpyHeightGet(&g_sContext) -
                  DISPLAY_BANNER_HEIGHT - 1;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = sRect.i16YMin + DISPLAY_BANNER_HEIGHT;

    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

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

    //
    // Print a no device message a placeholder for the message printed
    // during an event.
    //
    GrStringDrawCentered(&g_sContext, "No Device", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2,
                         sRect.i16YMin + 5, 0);

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

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

    //
    // 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);

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

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

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

    //
    // Initialized the cursor.
    //
    g_ui32Buttons = 0;
    g_i32CursorX = 0;
    g_i32CursorY = 0;

    //
    // Open an instance of the mouse driver.  The mouse does not need
    // to be present at this time, this just saves a place for it and allows
    // the applications to be notified when a mouse is present.
    //
    g_psMouseInstance =
        USBHMouseOpen(MouseCallback, g_pui8Buffer, MOUSE_MEMORY_SIZE);

    //
    // 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 OTG operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Tell the OTG state machine how much time has passed in
        // milliseconds since the last call.
        //
        USBOTGMain(GetTickms());

        switch(g_eUSBState)
        {
            //
            // This state is entered when the mouse is first detected.
            //
            case STATE_MOUSE_INIT:
            {
                //
                // Initialize the newly connected mouse.
                //
                USBHMouseInit(g_psMouseInstance);

                //
                // Proceed to the mouse connected state.
                //
                g_eUSBState = STATE_MOUSE_CONNECTED;

                break;
            }

            case STATE_MOUSE_CONNECTED:
            {
                //
                // Nothing is currently done in the main loop when the mouse
                // is connected.
                //
                break;
            }

            case STATE_NO_DEVICE:
            {
                //
                // The mouse is not connected so nothing needs to be done here.
                //
                break;
            }

            default:
            {
                break;
            }
        }
    }
}
Ejemplo n.º 18
0
//*****************************************************************************
//
// Initialize and operate the data logger.
//
//*****************************************************************************
int
main(void)
{
    tContext sDisplayContext, sBufferContext;
    uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount;
    bool bSkipSplash;
    uint8_t ui8ButtonState, ui8ButtonChanged;
    uint_fast8_t ui8X, ui8Y;


    //
    // 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.
    //
    MAP_FPULazyStackingEnable();

    //
    // Set the clocking to run at 50 MHz.
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ui32SysClock = MAP_SysCtlClockGet();

    //
    // Initialize locals.
    //
    bSkipSplash = false;
    ui32LastTickCount = 0;

    //
    // Initialize the data acquisition module.  This initializes the ADC
    // hardware.
    //
    AcquireInit();

    //
    // Enable access to  the hibernate peripheral.  If the hibernate peripheral
    // was already running then this will have no effect.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Check to see if the hiberate module is already active and if so then
    // read the saved configuration state.  If both are okay, then proceed
    // to check and see if we are logging data using sleep mode.
    //
    if(HibernateIsActive() && !GetSavedState(&g_sConfigState))
    {
        //
        // Read the status of the hibernate module.
        //
        ui32HibIntStatus = HibernateIntStatus(1);

        //
        // If this is a pin wake, that means the user pressed the select
        // button and we should terminate the sleep logging.  In this case
        // we will fall out of this conditional section, and go through the
        // normal startup below, but skipping the splash screen so the user
        // gets immediate response.
        //
        if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE)
        {
            //
            // Clear the interrupt flag so it is not seen again until another
            // wake.
            //
            HibernateIntClear(HIBERNATE_INT_PIN_WAKE);
            bSkipSplash = true;
        }

        //
        // Otherwise if we are waking from hibernate and it was not a pin
        // wake, then it must be from RTC match.  Check to see if we are
        // sleep logging and if so then go through an abbreviated startup
        // in order to collect the data and go back to sleep.
        //
        else if(g_sConfigState.ui32SleepLogging &&
                (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0))
        {
            //
            // Start logger and pass the configuration.  The logger should
            // configure itself to take one sample.
            //
            AcquireStart(&g_sConfigState);
            g_iLoggerState = eSTATE_LOGGING;

            //
            // Enter a forever loop to run the acquisition.  This will run
            // until a new sample has been taken and stored.
            //
            while(!AcquireRun())
            {
            }

            //
            // Getting here means that a data acquisition was performed and we
            // can now go back to sleep.  Save the configuration and then
            // activate the hibernate.
            //
            SetSavedState(&g_sConfigState);

            //
            // Set wake condition on pin-wake or RTC match.  Then put the
            // processor in hibernation.
            //
            HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
            HibernateRequest();

            //
            // Hibernating takes a finite amount of time to occur, so wait
            // here forever until hibernate activates and the processor
            // power is removed.
            //
            for(;;)
            {
            }
        }

        //
        // Otherwise, this was not a pin wake, and we were not sleep logging,
        // so just fall out of this conditional and go through the normal
        // startup below.
        //
    }
    else
    {
        //
        // In this case, either the hibernate module was not already active, or
        // the saved configuration was not valid.  Initialize the configuration
        // to the default state and then go through the normal startup below.
        //
        GetDefaultState(&g_sConfigState);
    }

    //
    // Enable the Hibernate module to run.
    //
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // The hibernate peripheral trim register must be set per silicon
    // erratum 2.1
    //
    HibernateRTCTrimSet(0x7FFF);

    //
    // Start the RTC running.  If it was already running then this will have
    // no effect.
    //
    HibernateRTCEnable();

    //
    // In case we were sleep logging and are now finished (due to user
    // pressing select button), then disable sleep logging so it doesnt
    // try to start up again.
    //
    g_sConfigState.ui32SleepLogging = 0;
    SetSavedState(&g_sConfigState);

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

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

    //
    // Pass the restored state to the menu system.
    //
    MenuSetState(&g_sConfigState);

    //
    // Enable the USB peripheral
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Configure the required pins for USB operation.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

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

    //
    // Initialize the stack to be used with USB stick.
    //
    USBStickInit();

    //
    // Initialize the stack to be used as a serial device.
    //
    USBSerialInit();

    //
    // Initialize the USB controller for dual mode operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the menus module.  This module will control the user
    // interface menuing system.
    //
    MenuInit(WidgetActivated);

    //
    // Configure SysTick to periodically interrupt.
    //
    g_ui32TickCount = 0;
    MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE);
    MAP_SysTickIntEnable();
    MAP_SysTickEnable();

    //
    // Initialize the display context and another context that is used
    // as an offscreen drawing buffer for display animation effect
    //
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    GrContextInit(&sBufferContext, &g_sOffscreenDisplayA);

    //
    // Show the splash screen if we are not skipping it.  The only reason to
    // skip it is if the application was in sleep-logging mode and the user
    // just waked it up with the select button.
    //
    if(!bSkipSplash)
    {
        const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black;

        //
        // Draw the TI logo on the display.  Use an animation effect where the
        // logo will "slide" onto the screen.  Allow select button to break
        // out of animation.
        //
        for(ui8X = 0; ui8X < 96; ui8X++)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0);
        }

        //
        // Leave the logo on the screen for a long duration.  Monitor the
        // buttons so that if the user presses the select button, the logo
        // display is terminated and the application starts immediately.
        //
        while(g_ui32TickCount < 400)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
        }

        //
        // Extended splash sequence
        //
        if(ButtonsPoll(0, 0) & UP_BUTTON)
        {
            for(ui8X = 0; ui8X < 96; ui8X += 4)
            {
                GrImageDraw(&sDisplayContext,
                            g_ppui8Image_Splash[(ui8X / 4) & 3],
                            (int32_t)ui8X - 96L, 0);
                GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0);
                MAP_SysCtlDelay(ui32SysClock / 12);
            }
            MAP_SysCtlDelay(ui32SysClock / 3);
            pui8SplashLogo = g_ppui8Image_Splash[4];
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0);
            MAP_SysCtlDelay(ui32SysClock / 12);
        }

        //
        // Draw the initial menu into the offscreen buffer.
        //
        SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0);

        //
        // Now, draw both the TI logo splash screen (from above) and the initial
        // menu on the screen at the same time, moving the coordinates so that
        // the logo "slides" off the display and the menu "slides" onto the
        // display.
        //
        for(ui8Y = 0; ui8Y < 64; ui8Y++)
        {
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y);
            GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y);
        }
    }

    //
    // Add the menu widget to the widget tree and send an initial paint
    // request.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget);
    WidgetPaint(WIDGET_ROOT);

    //
    // Set the focus handle to the menu widget.  Any button events will be
    // sent to this widget
    //
    g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

    //
    // Forever loop to run the application
    //
    while(1)
    {

        //
        // Each time the timer tick occurs, process any button events.
        //
        if(g_ui32TickCount != ui32LastTickCount)
        {
            //
            // Remember last tick count
            //
            ui32LastTickCount = g_ui32TickCount;

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

            //
            // Pass any button presses through to the widget message
            // processing mechanism.  The widget that has the button event
            // focus (probably the menu widget) will catch these button events.
            //
            if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT);
            }
            if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_UP);
            }
            if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN);
            }
            if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            }
            if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT);
            }
        }

        //
        // Tell the OTG library code how much time has passed in milliseconds
        // since the last call.
        //
        USBOTGMain(GetTickms());

        //
        // Call functions as needed to keep the host or device mode running.
        //
        if(g_iCurrentUSBMode == eUSBModeDevice)
        {
            USBSerialRun();
        }
        else if(g_iCurrentUSBMode == eUSBModeHost)
        {
            USBStickRun();
        }

        //
        // If in the logging state, then call the logger run function.  This
        // keeps the data acquisition running.
        //
        if((g_iLoggerState == eSTATE_LOGGING) ||
           (g_iLoggerState == eSTATE_VIEWING))
        {
            if(AcquireRun() && g_sConfigState.ui32SleepLogging)
            {
                //
                // If sleep logging is enabled, then at this point we have
                // stored the first data item, now save the state and start
                // hibernation.  Wait for the power to be cut.
                //
                SetSavedState(&g_sConfigState);
                HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
                HibernateRequest();
                for(;;)
                {
                }
            }

            //
            // If viewing instead of logging then request a repaint to keep
            // the viewing window updated.
            //
            if(g_iLoggerState == eSTATE_VIEWING)
            {
                WidgetPaint(WIDGET_ROOT);
            }
        }

        //
        // If in the saving state, then save data from flash storage to
        // USB stick.
        //
        if(g_iLoggerState == eSTATE_SAVING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreSave();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the erasing state, then erase the data stored in flash.
        //
        if(g_iLoggerState == eSTATE_ERASING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreErase();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the flash reporting state, then show the report of the amount
        // of used and free flash memory.
        //
        if(g_iLoggerState == eSTATE_FREEFLASH)
        {
            //
            // Report free flash space
            //
            FlashStoreReport();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If we are exiting the clock setting widget, that means that control
        // needs to be given back to the menu system.
        //
        if(g_iLoggerState == eSTATE_CLOCKEXIT)
        {
            //
            // Give the button event focus back to the menu system
            //
            g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

            //
            // Send a button event to the menu widget that means the left
            // key was pressed.  This signals the menu widget to deactivate
            // the current child widget (which was the clock setting wigdet).
            // This will cause the menu widget to slide the clock set widget
            // off the screen and resume control of the display.
            //
            SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // Process any new messages that are in the widget queue.  This keeps
        // the user interface running.
        //
        WidgetMessageQueueProcess();
    }
}
Ejemplo n.º 19
0
//*****************************************************************************
//
// A simple application demonstrating use of the boot loader,
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tContext sContext;
    unsigned long ulSysClock;

    //
    // 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_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ulSysClock = ROM_SysCtlClockGet();

    //
    // Initialize the peripherals that each of the boot loader flavors
    // supports.  Since this example is intended for use with any of the
    // boot loaders and we don't know which is actually in use, we cover all
    // bases and initialize for serial, Ethernet and USB use here.
    //
    SetupForUART();
    SetupForUSB();

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

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

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

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

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&sContext, "boot-demo2", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    GrStringDrawCentered(&sContext, "Press select", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, false);
    GrStringDrawCentered(&sContext, "button to", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, false);
    GrStringDrawCentered(&sContext, "update.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, false);
   
    //
    // Wait for select button to be pressed.
    // 
    while ((ButtonsPoll(0, 0) & SELECT_BUTTON) == 0) 
    {
        ROM_SysCtlDelay(ulSysClock / 1000);
    }

    GrStringDrawCentered(&sContext, "             ", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, true);
    GrStringDrawCentered(&sContext, " Updating... ", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, true);
    GrStringDrawCentered(&sContext, "             ", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, true);

    //
    // Transfer control to the boot loader.
    //
    JumpToBootLoader();

    //
    // The previous function never returns but we need to stick in a return
    // code here to keep the compiler from generating a warning.
    //
    return(0);
}
Ejemplo n.º 20
0
//*****************************************************************************
//
// This is the main application entry function.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32TxCount;
    uint32_t ui32RxCount;
    tRectangle sRect;
    char pcBuffer[16];
    uint32_t ui32Fullness;

    //
    // 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 clocking to run from the PLL at 50MHz
    //
    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);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Not configured initially.
    //
    g_bUSBConfigured = false;

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

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

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    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_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-dev-serial", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Show the various static text elements on the color STN display.
    //
    GrStringDraw(&g_sContext, "Tx #",-1, 0, 12, false);
    GrStringDraw(&g_sContext, "Tx buf", -1, 0, 22, false);
    GrStringDraw(&g_sContext, "Rx #", -1, 0, 32, false);
    GrStringDraw(&g_sContext, "Rx buf", -1, 0, 42, false);
    DrawBufferMeter(&g_sContext, 40, 22);
    DrawBufferMeter(&g_sContext, 40, 42);

    //
    // Enable the UART that we will be redirecting.
    //
    ROM_SysCtlPeripheralEnable(USB_UART_PERIPH);

    //
    // Enable and configure the UART RX and TX pins
    //
    ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH);
    ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH);
    ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN);
    ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN);

    //
    // TODO: Add code to configure handshake GPIOs if required.
    //

    //
    // Set the default UART configuration.
    //
    ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(),
                            DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG);
    ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    //
    // Configure and enable UART interrupts.
    //
    ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false));
    ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE |
                      UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX));

    //
    // Enable the system tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Tell the user what we are up to.
    //
    DisplayStatus(&g_sContext, " Configuring... ");

    //
    // Initialize the transmit and receive buffers.
    //
    USBBufferInit(&g_sTxBuffer);
    USBBufferInit(&g_sRxBuffer);

    //
    // Set the USB stack mode to Device mode with VBUS monitoring.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB library and place the device
    // on the bus.
    //
    USBDCDCInit(0, &g_sCDCDevice);

    //
    // Wait for initial configuration to complete.
    //
    DisplayStatus(&g_sContext, "Waiting for host");

    //
    // Clear our local byte counters.
    //
    ui32RxCount = 0;
    ui32TxCount = 0;

    //
    // Enable interrupts now that the application is ready to start.
    //
    ROM_IntEnable(USB_UART_INT);

    //
    // Main application loop.
    //
    while(1)
    {

        //
        // Have we been asked to update the status display?
        //
        if(g_ui32Flags & COMMAND_STATUS_UPDATE)
        {
            //
            // Clear the command flag
            //
            ROM_IntMasterDisable();
            g_ui32Flags &= ~COMMAND_STATUS_UPDATE;
            ROM_IntMasterEnable();

            DisplayStatus(&g_sContext, g_pcStatus);
        }

        //
        // Has there been any transmit traffic since we last checked?
        //
        if(ui32TxCount != g_ui32UARTTxCount)
        {
            //
            // Take a snapshot of the latest transmit count.
            //
            ui32TxCount = g_ui32UARTTxCount;

            //
            // Update the display of bytes transmitted by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32TxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 40, 12, true);

            //
            // Update the RX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's receive buffer is the UART's
            // transmit buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 22);
        }

        //
        // Has there been any receive traffic since we last checked?
        //
        if(ui32RxCount != g_ui32UARTRxCount)
        {
            //
            // Take a snapshot of the latest receive count.
            //
            ui32RxCount = g_ui32UARTRxCount;

            //
            // Update the display of bytes received by the UART.
            //
            usnprintf(pcBuffer, 16, "%d ", ui32RxCount);
            GrStringDraw(&g_sContext, pcBuffer, -1, 40, 32, true);

            //
            // Update the TX buffer fullness. Remember that the buffers are
            // named relative to the USB whereas the status display is from
            // the UART's perspective. The USB's transmit buffer is the UART's
            // receive buffer.
            //
            ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) /
                          UART_BUFFER_SIZE);

            UpdateBufferMeter(&g_sContext, ui32Fullness, 40, 42);
        }
    }
}
Ejemplo n.º 21
0
//*****************************************************************************
//
// This is the main example program.  It checks to see that the interrupts are
// processed in the correct order when they have identical priorities,
// increasing priorities, and decreasing priorities.  This exercises interrupt
// preemption and tail chaining.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    uint_fast8_t ui8Error;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

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

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "interrupts", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);

    //
    // Put the status header text on the display.
    //
    GrStringDraw(&g_sContext, "Active:", -1, 6, 32, 0);
    GrStringDraw(&g_sContext, "Pending:", -1, 0, 44, 0);

    //
    // Configure the PB0-PB2 to be outputs to indicate entry/exit of one
    // of the interrupt handlers.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
                                               GPIO_PIN_3);
    ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, 0);

    //
    // Set up and enable the SysTick timer.  It will be used as a reference
    // for delay loops in the interrupt handlers.  The SysTick timer period
    // will be set up for one second.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet());
    ROM_SysTickEnable();

    //
    // Reset the error indicator.
    //
    ui8Error = 0;

    //
    // Enable interrupts to the processor.
    //
    ROM_IntMasterEnable();

    //
    // Enable the interrupts.
    //
    ROM_IntEnable(INT_GPIOA);
    ROM_IntEnable(INT_GPIOB);
    ROM_IntEnable(INT_GPIOC);

    //
    // Indicate that the equal interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, "Equal Pri", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 20, 1);

    //
    // Set the interrupt priorities so they are all equal.
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x00);
    ROM_IntPrioritySet(INT_GPIOB, 0x00);
    ROM_IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the LCD.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1))
    {
        ui8Error |= 1;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the decreasing interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, " Decreasing Pri ", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 20, 1);

    //
    // Set the interrupt priorities so that they are decreasing (i.e. C > B >
    // A).
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x80);
    ROM_IntPrioritySet(INT_GPIOB, 0x40);
    ROM_IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the CSTN.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1))
    {
        ui8Error |= 2;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the increasing interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, " Increasing Pri ", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 20, 1);

    //
    // Set the interrupt priorities so that they are increasing (i.e. C < B <
    // A).
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x00);
    ROM_IntPrioritySet(INT_GPIOB, 0x40);
    ROM_IntPrioritySet(INT_GPIOC, 0x80);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the CSTN.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3))
    {
        ui8Error |= 4;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Disable the interrupts.
    //
    ROM_IntDisable(INT_GPIOA);
    ROM_IntDisable(INT_GPIOB);
    ROM_IntDisable(INT_GPIOC);

    //
    // Disable interrupts to the processor.
    //
    ROM_IntMasterDisable();

    //
    // Print out results if error occurred.
    //
    if(ui8Error)
    {
        GrStringDraw(&g_sContext, "Equal: P        ", -1, 0, 32, 1);
        GrStringDraw(&g_sContext, "  Inc: P        ", -1, 0, 44, 1);
        GrStringDraw(&g_sContext, "  Dec: P        ", -1, 0, 56, 1);
        if(ui8Error & 1)
        {
            GrStringDraw(&g_sContext, "F ", -1, 42, 32, 1);
        }
        if(ui8Error & 2)
        {
            GrStringDraw(&g_sContext, "F ", -1, 42, 44, 1);
        }
        if(ui8Error & 4)
        {
            GrStringDraw(&g_sContext, "F ", -1, 42, 56, 1);
        }
    }
    else
    {
        GrStringDrawCentered(&g_sContext, "    Success!    ", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 20, 1);
    }

    //
    // Flush the display.
    //
    GrFlush(&g_sContext);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 22
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tContext sContext;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

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

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

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "uart-echo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Initialize the display and write some instructions.
    //
    GrStringDrawCentered(&sContext, "Connect a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, false);
    GrStringDrawCentered(&sContext, "terminal", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, false);
    GrStringDrawCentered(&sContext, "to UART0.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, false);
    GrStringDrawCentered(&sContext, "115000,N,8,1", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, false);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((uint8_t *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// This example demonstrates the use of the watchdog timer.
//
//*****************************************************************************
int
main(void)
{
    int_fast32_t i32CenterX;
    tRectangle sRect;

    //
    // 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 clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the display and  buttons drivers.
    //
    CFAL96x64x16Init();
    ButtonsInit();

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);
    i32CenterX = GrContextDpyWidthGet(&g_sContext) / 2;

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "watchdog", -1, i32CenterX, 4, 0);

    //
    // Show the state and offer some instructions to the user.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "Feeding", -1, i32CenterX, 14, 1);
    GrStringDrawCentered(&g_sContext, "Watchdog", -1, i32CenterX, 24, 1);
    GrStringDrawCentered(&g_sContext, "Press", -1, i32CenterX, 36, 1);
    GrStringDrawCentered(&g_sContext, "Select", -1, i32CenterX, 46, 1);
    GrStringDrawCentered(&g_sContext, "to stop", -1, i32CenterX, 56, 1);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Set GPIO PG2 as an output.  This drives an LED on the board that will
    // toggle when a watchdog interrupt is processed.
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
    ROM_GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0);

    //
    // Enable the watchdog interrupt.
    //
    ROM_IntEnable(INT_WATCHDOG);

    //
    // Set the period of the watchdog timer.
    //
    ROM_WatchdogReloadSet(WATCHDOG0_BASE, ROM_SysCtlClockGet());

    //
    // Enable reset generation from the watchdog timer.
    //
    ROM_WatchdogResetEnable(WATCHDOG0_BASE);

    //
    // Enable the watchdog timer.
    //
    ROM_WatchdogEnable(WATCHDOG0_BASE);

    //
    // Loop forever while the LED winks as watchdog interrupts are handled.
    //
    while(1)
    {
        //
        // Poll for the select button pressed
        //
        uint8_t ui8Buttons = ButtonsPoll(0, 0);
        if(ui8Buttons & SELECT_BUTTON)
        {
            SelectButtonPressed();
            while(1)
            {
            }
        }
    }
}