Example #1
0
/*
 ***************************************************************************
 *  Module Name: BufferBuild
 *     Filename: CANTransceive.c
 *       Author: Jim Harris
 *     Revision: 1.0
 *    Rev. Date: September 12, 2008
 *    Mod. Time: 14:33
 *
 * Requirements:
 *
 *  Description: This module will build the CAN buffer from the various
 *                pieces of data collected.
 *
 * Rev. History:
 *    Rev 0.0   August 21,2008 jharris
 *        Initial code written
 *    Rev 1.0
 *        Cleaned up all comments/look-and-feel for release
 *        Added standard disclaimer
 ***************************************************************************
*/
void  CANSend8(unsigned int CANTXByte1, unsigned int CANTXByte2)
  {
#if (UEZ_PROCESSOR==NXP_LPC2478)
    /* Let's build up the CAN message buffer */
    if (!G_canConfigured)
        CANConfigure();

#if 0
          /* First, we build up the first long word, which will be CAN message bytes 1-4 */
    CANTXByte1 = 0x00; // R_Temp;  /* First byte is the Remote Temperature Reading */
    CANTXByte1 = CANTXByte1 | (/*L_Temp*/0x11 << 8);  /* Second byte is the Local Temperature Reading */
    CANTXByte1 = CANTXByte1 | (/*ADCdataR36*/0x22 << 16); /* Third byte is the reading of R36 */
    CANTXByte1 = CANTXByte1 | (/*ADCdataR37*/0x33 << 24); /* Fourth byte is the reading of R37 */

        /* Next, we build up the second long word, which will be CAN message bytes 5-8 */
    CANTXByte2 = 0x00; // ADCdataR38;  /* First byte is the reading of R38 */
    CANTXByte2 = CANTXByte2 | (0x00 /*ButtonsRead*/ << 8); /* Second byte is the status of the 4 pushbuttons */
    CANTXByte2 = CANTXByte2 | (0x00 << 16); /* Third byte is for LED status...from CAN board, is NULL */
    CANTXByte2 = CANTXByte2 | (0x00 << 24); /* Fourth byte is for Piezo Frequency...from CAN board, is NULL */
#endif

          C1TDA1  =      CANTXByte1;      /* First 4 bytes of the CAN message */
          C1TDB1  =      CANTXByte2;      /* Next 4 bytes of the CAN Message */
          C1CMR        =      0x00000021;      /* Transmit the message */
#endif // (UEZ_PROCESSOR==NXP_LPC2478)
#if (UEZ_PROCESSOR==NXP_LPC1788)
    /* Let's build up the CAN message buffer */
    if (!G_canConfigured)
        CANConfigure();

          LPC_CAN1->TDA1  =      CANTXByte1;      /* First 4 bytes of the CAN message */
          LPC_CAN1->TDB1  =      CANTXByte2;      /* Next 4 bytes of the CAN Message */
          LPC_CAN1->CMR        =      0x00000021;      /* Transmit the message */
#endif // (UEZ_PROCESSOR==NXP_LPC2478)
  }/* BufferBuild */
Example #2
0
int CANReceive8(unsigned int *aCANByteA, unsigned int *aCANByteB)
{
    unsigned CANrdy = 0;

    if (!G_canConfigured)
        CANConfigure();

#if (UEZ_PROCESSOR==NXP_LPC2478)
    {
        CANrdy = C1GSR&0x00000001;        /* Get status of receiver buffer */
        if (CANrdy != 0) {
          /* We have received a CAN message, so we need to process it */
          CANRCV = pdTRUE;
          *aCANByteA = C1RDA; /* Get the first 4 bytes of the received CAN message */
          *aCANByteB = C1RDB; /* Get the last 4 bytes of the received CAN message */

          C1CMR =   0x00000004; /* Release the receive buffer */      
         }

    }
    return (CANrdy)?1:0;
#elif (UEZ_PROCESSOR==NXP_LPC1788)
    {
        CANrdy = LPC_CAN1->GSR&0x00000001;        /* Get status of receiver buffer */
        if (CANrdy != 0) {
          /* We have received a CAN message, so we need to process it */
          CANRCV = pdTRUE;
          *aCANByteA = LPC_CAN1->RDA; /* Get the first 4 bytes of the received CAN message */
          *aCANByteB = LPC_CAN1->RDB; /* Get the last 4 bytes of the received CAN message */

          LPC_CAN1->CMR =   0x00000004; /* Release the receive buffer */      
         }

    }
    return (CANrdy)?1:0;
#elif (UEZ_PROCESSOR==NXP_LPC4088)
    {
        CANrdy = LPC_CAN1->GSR&0x00000001;        /* Get status of receiver buffer */
        if (CANrdy != 0) {
          /* We have received a CAN message, so we need to process it */
          CANRCV = pdTRUE;
          *aCANByteA = LPC_CAN1->RDA; /* Get the first 4 bytes of the received CAN message */
          *aCANByteB = LPC_CAN1->RDB; /* Get the last 4 bytes of the received CAN message */

          LPC_CAN1->CMR =   0x00000004; /* Release the receive buffer */      
         }

    }
    return (CANrdy)?1:0;
#else
  CANrdy = 0;
  return 0;
#endif //(UEZ_PROCESSOR==NXP_LPC2478)
}/* vCANmsg */
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
    //
    // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is
    // a workaround to allow the PLL to operate reliably.
    //
    if(REVISION_IS_A2)
    {
        SysCtlLDOSet(SYSCTL_LDO_2_75V);
    }

    //
    // Set the clocking to run at 50MHz from the PLL.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_8);

    //
    // Get the system clock speed.
    //
    g_ulSystemClock = SysCtlClockGet();

    //
    // Enable the peripherals used by the application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the GPIOs used to read the state of the on-board push buttons.
    //
    GPIOPinTypeGPIOInput(GPIO_PORTE_BASE,
                         GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPadConfigSet(GPIO_PORTE_BASE,
                     GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
                     GPIO_PIN_TYPE_STD_WPU);

    //
    // Configure the LED, speaker, and UART GPIOs as required.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);

    //
    // Initialize the CAN controller.
    //
    CANConfigure();

    //
    // Intialize the Ethernet Controller and TCP/IP Stack.
    //
    EnetInit();

    //
    // Configure the first UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    UARTEnable(UART0_BASE);

    //
    // Send a welcome message to the UART.
    //
    UARTCharPut(UART0_BASE, 'W');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, 'l');
    UARTCharPut(UART0_BASE, 'c');
    UARTCharPut(UART0_BASE, 'o');
    UARTCharPut(UART0_BASE, 'm');
    UARTCharPut(UART0_BASE, 'e');
    UARTCharPut(UART0_BASE, '\r');
    UARTCharPut(UART0_BASE, '\n');

    //
    // Initialize the OSRAM OLED display.
    //
    RIT128x96x4Init(3500000);

    //
    // Initialize the PWM for generating music and sound effects.
    //
    AudioOn();

    //
    // Configure SysTick to periodically interrupt.
    //
    SysTickPeriodSet(g_ulSystemClock / CLOCK_RATE);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Delay for a bit to allow the initial display flash to subside.
    //
    Delay(CLOCK_RATE / 4);

    //
    // Play the intro music.
    //
    AudioPlaySong(g_pusIntro, sizeof(g_pusIntro) / 2);

    //
    // Display the Texas Instruments logo for five seconds (or twelve seconds
    // if built using gcc).
    //
#if defined(gcc)
    DisplayLogo(g_pucTILogo, 120, 42, 12 * CLOCK_RATE);
#else
    DisplayLogo(g_pucTILogo, 120, 42, 5 * CLOCK_RATE);
#endif

    //
    // Display the Code Composer Studio logo for five seconds.
    //
#if defined(ccs)
    DisplayLogo(g_pucCodeComposer, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the Keil/ARM logo for five seconds.
    //
#if defined(rvmdk) || defined(__ARMCC_VERSION)
    DisplayLogo(g_pucKeilLogo, 128, 40, 5 * CLOCK_RATE);
#endif

    //
    // Display the IAR logo for five seconds.
    //
#if defined(ewarm)
    DisplayLogo(g_pucIarLogo, 102, 61, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeSourcery logo for five seconds.
    //
#if defined(sourcerygxx)
    DisplayLogo(g_pucCodeSourceryLogo, 128, 34, 5 * CLOCK_RATE);
#endif

    //
    // Display the CodeRed logo for five seconds.
    //
#if defined(codered)
    DisplayLogo(g_pucCodeRedLogo, 128, 32, 5 * CLOCK_RATE);
#endif

    //
    // Throw away any button presses that may have occurred while the splash
    // screens were being displayed.
    //
    HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Display the main screen.
        //
        if(MainScreen())
        {
            //
            // The button was pressed, so start the game.
            //
            PlayGame();
        }
        else
        {
            //
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            //
            ScreenSaver();
        }
    }
}