Ejemplo n.º 1
0
void init(void)
{
  // Enable output for led
  //DDRB |= _BV(DDB7);
  
  //enable AD converter
  adc_init();

  //enable communication to PC over USB
  HostInit();
  
  //enable communications with gps
  GpsInit();
  
  
  //DebugInit();

  //enable global interrupts 
  sei (); 
}
Ejemplo n.º 2
0
/* HostGetHostFromHash
 *
 * Hash retrieval function for hosts. Looks up the hash bucket containing the
 * host pointer. Then compares the packet with the found host to see if it is
 * the host we need. If it isn't, walk the list until the right host is found.
 *
 * returns a *LOCKED* host or NULL
 */
Host *HostGetHostFromHash (Address *a)
{
    Host *h = NULL;

    /* get the key to our bucket */
    uint32_t key = HostGetKey(a);
    /* get our hash bucket and lock it */
    HostHashRow *hb = &host_hash[key];
    HRLOCK_LOCK(hb);

    /* see if the bucket already has a host */
    if (hb->head == NULL) {
        h = HostGetNew(a);
        if (h == NULL) {
            HRLOCK_UNLOCK(hb);
            return NULL;
        }

        /* host is locked */
        hb->head = h;
        hb->tail = h;

        /* got one, now lock, initialize and return */
        HostInit(h,a);

        HRLOCK_UNLOCK(hb);
        return h;
    }

    /* ok, we have a host in the bucket. Let's find out if it is our host */
    h = hb->head;

    /* see if this is the host we are looking for */
    if (HostCompare(h, a) == 0) {
        Host *ph = NULL; /* previous host */

        while (h) {
            ph = h;
            h = h->hnext;

            if (h == NULL) {
                h = ph->hnext = HostGetNew(a);
                if (h == NULL) {
                    HRLOCK_UNLOCK(hb);
                    return NULL;
                }
                hb->tail = h;

                /* host is locked */

                h->hprev = ph;

                /* initialize and return */
                HostInit(h,a);

                HRLOCK_UNLOCK(hb);
                return h;
            }

            if (HostCompare(h, a) != 0) {
                /* we found our host, lets put it on top of the
                 * hash list -- this rewards active hosts */
                if (h->hnext) {
                    h->hnext->hprev = h->hprev;
                }
                if (h->hprev) {
                    h->hprev->hnext = h->hnext;
                }
                if (h == hb->tail) {
                    hb->tail = h->hprev;
                }

                h->hnext = hb->head;
                h->hprev = NULL;
                hb->head->hprev = h;
                hb->head = h;

                /* found our host, lock & return */
                SCMutexLock(&h->m);
                (void) HostIncrUsecnt(h);
                HRLOCK_UNLOCK(hb);
                return h;
            }
        }
    }

    /* lock & return */
    SCMutexLock(&h->m);
    (void) HostIncrUsecnt(h);
    HRLOCK_UNLOCK(hb);
    return h;
}
Ejemplo n.º 3
0
//--------------------------------------------------------------------
// Main Init function
//--------------------------------------------------------------------
void init(void)
{
  uint16_t dummy = 0;
  int16_t ret;

  LED_ERROR_ON;

  //enable AD converter
  adc_init();

  ResetImu();

  //enable communication to PC over USB
  HostInit();
  
  //enable communication to the bus
  BusInit();
  
  //enable communications with gps
  GpsInit();
  
  InitLeds();
  
  XbeeInit();

  //timer for sending out estop status
  timer3_init();
  //timer3_set_overflow_callback(SendEstopStatus);
  timer3_set_overflow_callback(globalTimerOverflow);  

  timer4_init();
  timer4_set_compa_callback(Rs485ResponseTimeout);
  timer4_disable_compa_callback();

  timer1_init();
  timer1_set_compa_callback(EncodersRequestFcn);

  //generate the request packets:
  encoderRequestRawPacketSize = DynamixelPacketWrapData(MMC_MOTOR_CONTROLLER_DEVICE_ID,
                          MMC_MOTOR_CONTROLLER_ENCODERS_REQUEST,
                          &dummy,sizeof(dummy),
                          encoderRequestRawPacket,
                          encoderRequestRawPacketMaxSize);

  Servo1Init(GlobalTimerGetTime());


  //buzzer port
  BUZZER_DDR |= _BV(BUZZER_PIN);

  //enable global interrupts 
  sei();
  
  DDRL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  PORTL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  //PORTL |= _BV(PL3);
  
  /*
  TCCR5A |= _BV(WGM51) | _BV(WGM50);
  TCCR5B |= _BV(WGM52) | _BV(WGM53);
  OCR5A = 2000;
  TCCR5A |= _BV(COM5A0);
  TCCR5A |= _BV(COM5B0);
  TCCR5A |= _BV(COM5C0);
  */

  LED_ERROR_OFF;
}
//*****************************************************************************
//
// main routine.
//
//*****************************************************************************
int
main(void)
{
    tLPMFeature sLPMFeature;

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

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

    //
    // Configure the UART.
    //
    UARTStdioConfig(0, 115200, g_ui32SysClock);

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

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

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

    //
    // Configure USB for OTG operation.
    //
    USBOTGInit(g_ui32SysClock, ModeCallback);

    sLPMFeature.ui32HIRD = 500;
    sLPMFeature.ui32Features = USBLIB_FEATURE_LPM_EN |
                               USBLIB_FEATURE_LPM_RMT_WAKE;
    USBHCDFeatureSet(0, USBLIB_FEATURE_LPM, &sLPMFeature);

    //
    // Initialize the host stack.
    //
    HostInit();

    //
    // Initialize the device stack.
    //
    DeviceInit();

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

    //
    // Set the new state so that the screen updates on the first
    // pass.
    //
    g_ui32NewState = 1;

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

        //
        // Handle deferred state change.
        //
        if(g_ui32NewState)
        {
            g_ui32NewState =0;

            //
            // Update the status area of the screen.
            //
            ClearMainWindow();

            //
            // Update the status bar with the new mode.
            //
            switch(g_iCurrentMode)
            {
                case eUSBModeHost:
                {
                    UpdateStatus("Host Mode", 0, true);
                    break;
                }
                case eUSBModeDevice:
                {
                    UpdateStatus("Device Mode", 0, true);
                    break;
                }
                case eUSBModeNone:
                {
                    UpdateStatus("Idle Mode\n", 0, true);
                    break;
                }
                default:
                {
                    break;
                }
            }
        }

        if(g_iCurrentMode == eUSBModeDevice)
        {
            DeviceMain();
        }
        else if(g_iCurrentMode == eUSBModeHost)
        {
            HostMain();
        }
    }
}
Ejemplo n.º 5
0
//*****************************************************************************
//
// Capture one sequence of DEVCTL register values during a session request.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

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

    //
    // Set the pinout appropriately for this board.
    //
    PinoutSet();

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

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

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    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_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "OTG Example", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

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

    //
    // Open the UART for I/O
    //
    UARTStdioInit(0);
#endif

    //
    // Determine the number of SysCtlDelay loops required to delay 1mS.
    //
    g_ulClockMS = ROM_SysCtlClockGet() / (3 * 1000);

    //
    // Configure the required pins for USB operation.
    //
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

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

    //
    // Initialize the host stack.
    //
    HostInit();

    //
    // Initialize the device stack.
    //
    DeviceInit();

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

    //
    // Set the new state so that the screen updates on the first
    // pass.
    //
    g_ulNewState = 1;

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

        //
        // Handle deferred state change.
        //
        if(g_ulNewState)
        {
            g_ulNewState =0;

            //
            // Update the status area of the screen.
            //
            ClearMainWindow();

            //
            // Update the status bar with the new mode.
            //
            switch(g_eCurrentUSBMode)
            {
                case USB_MODE_HOST:
                {
                    UpdateStatus("Host Mode", 0, true);
                    break;
                }
                case USB_MODE_DEVICE:
                {
                    UpdateStatus("Device Mode", 0, true);
                    break;
                }
                case USB_MODE_NONE:
                {
                    UpdateStatus("Idle Mode", 0, true);
                    break;
                }
                default:
                {
                    break;
                }
            }

        }

        if(g_eCurrentUSBMode == USB_MODE_DEVICE)
        {
            DeviceMain();
        }
        else if(g_eCurrentUSBMode == USB_MODE_HOST)
        {
            HostMain();
        }
    }
}