Пример #1
0
static void configAllPins(void)
{
    /* PWM */
    configPin(1, 18, 0, 0, 2);      /* PWM 1 */
    configPin(1, 20, 0, 0, 2);      /* PWM 2 */
    configPin(3, 26, 0, 0, 3);      /* PWM 3 */
    configPin(1, 23, 0, 0, 2);      /* PWM 4 */
    configPin(1, 24, 0, 0, 2);      /* PWM 5 */
    configPin(2, 5, 0, 0, 1);       /* PWM 6 */

    /* Motor Control */
    configPin(1, 21, 0, 0, 1);      /* ABORT */
    configPin(1, 19, 0, 0, 1);      /* MC0_A0 */
    configPin(1, 25, 0, 0, 1);      /* MC0_A1 */
    configPin(1, 28, 0, 0, 1);      /* MC0_A2 */
    configPin(1, 22, 0, 0, 1);      /* MC0_B0 */
    configPin(1, 26, 0, 0, 1);      /* MC0_B1 */
    configPin(1, 29, 0, 0, 1);      /* MC0_B2 */
//    configPin()     /* P0_4 */
//    configPin()     /* P0_5 */
//    configPin()     /* P0_19 */

    /* Analog */
    configPin(0, 23, 0, 0, 1);      /* AD0_0 */
    configPin(0, 24, 0, 0, 1);      /* AD0_1 */
    configPin(0, 25, 0, 0, 1);      /* AD0_2 */
    configPin(0, 26, 0, 0, 1);      /* AD0_3 */
    configPin(1, 31, 0, 0, 3);      /* AD0_5 */
    configPin(0, 3, 0, 0, 2);       /* AD0_6 */
    configPin(0, 2, 0, 0, 2);       /* AD0_7 */

    /* SPI1 */
    configPin(0, 6, 0, 0, 2);       /* CS1 */
    configPin(0, 7, 0, 0, 2);       /* CLK1 */
    configPin(0, 8, 0, 0, 2);       /* MISO1 */
    configPin(0, 9, 0, 0, 2);       /* MOSI1 */
//    configPin()     /* P1_27 */
//    configPin()     /* P3_25 */
//    configPin()     /* P2_10 */
//    configPin()     /* P0_20 */
//    configPin()     /* P2_8 */
//    configPin()     /* P4_28 */
//    configPin()     /* P4_29 */

    /* UART */
    configPin(2, 0, 0, 0, 2);     /* TX1 */
    configPin(2, 1, 0, 0, 2);     /* RX1 */
    configPin(2, 7, 0, 0, 2);     /* RTS1 */
    configPin(2, 2, 0, 0, 2);     /* CTS1 */
    configPin(0, 10, 0, 0, 1);    /* TX2 */
    configPin(0, 11, 0, 0, 1);    /* RX2 */
    configPin(0, 0, 0, 0, 2);     /* TX3 */
    configPin(0, 1, 0, 0, 2);     /* RX3 */

    /* I2C */
    configPin(0, 27, 0, 0, 1);     /* SDA0 */
    configPin(0, 28, 0, 0, 1);     /* SCL0 */

    /* SPI0 */
    configPin(0, 17, 0, 0, 2);     /* MISO */
    configPin(0, 18, 0, 0, 2);     /* MOSI */
    configPin(0, 15, 0, 0, 2);     /* CS0 */
    configPin(0, 16, 0, 0, 2);     /* CLK */
//    configPin();     /* P2_6 */

    /* CAN */
    configPin(0, 21, 0, 0, 3);     /* CANH */
    configPin(0, 22, 0, 0, 3);     /* CANL */
//    configPin()     /* P2_3 */
//    configPin()     /* P2_4 */
}
Пример #2
0
/*
 * Put pins back in their initial state to simulate a reset condition without
 * disconnecting USB
 */
int _resetConfig(uint8_t * args)
{
    int i;

    /* P0.0 - P0.11 */
    for (i = 0; i < 12; i++)
        configPin(0, i, 0, 0, 0);

    /*
     * P0.15 - P0.28
     * intentionally skip P0.29 (USB+) and P0.30 (USB-)
     */
    for (i = 15; i < 29; i++)
        configPin(0, i, 0, 0, 0);

    /*
     * P1.0, P1.1, P1.4, P1.8, P1.9, P1.10
     */
    configPin(1, 0, 0, 0, 0);
    configPin(1, 1, 0, 0, 0);
    configPin(1, 4, 0, 0, 0);
    configPin(1, 8, 0, 0, 0);
    configPin(1, 9, 0, 0, 0);
    configPin(1, 10, 0, 0, 0);

    /*
     * P1.14 - P1.31
     */
    for (i = 14; i < 32; i++)
        configPin(1, i, 0, 0, 0);

    /*
     * P2.0 - P2.8
     * intentionally skip P2.9 (USB_CONNECT)
     */
    for (i = 0; i < 9; i++)
        configPin(2, i, 0, 0, 0);

    /*
     * P2.10 - P2.14
     */
    for (i = 10; i < 15; i++)
        configPin(2, i, 0, 0, 0);

    /*
     * Intentionally skip P3.25 (LED)
     * P3.26
     */
    configPin(3, 26, 0, 0, 0);

    /* P4.28, P4.29 */
    configPin(4, 28, 0, 0, 0);
    configPin(4, 29, 0, 0, 0);

    return 0;
}
Пример #3
0
void boardInit() {
  SysTick_Config(SystemCoreClock/1000 - 1); 

  /*
    A note about interrupt priorities

    A smaller numeric priority means that the priority is higher, thus
    the most important interrupt has priority 0, the least import 31.

    If an interrupt arrives while servicing an interrupt with a lower
    priority, then the lesser interrupt is interrupted to service the
    high priority one, if the high priority interrupt is of a different
    preemption priority group.

    IOW: an IRQ in PP group 3 will be interrupted if an IRQ arrives with
    PP group 2,1 or 0.

    The sub priority is only used to order the interrupts at the same PE
    level.

    NVIC_SetPriorityGrouping is used here to divide the 32 levels of
    IRQ priorities into 8 preemption groups and 4 sub priorities.
  */
  NVIC_SetPriorityGrouping(4);   
  for (int i=0;i<35;i++) {
    NVIC_SetPriority(i, GROUP_PRIORITY_DEFAULT);    
  }
  NVIC_SetPriority(TIMER2_IRQn, GROUP_PRIORITY_STEPPER);
  NVIC_SetPriority(SysTick_IRQn, GROUP_PRIORITY_1000HZ); 
  NVIC_SetPriority(TIMER3_IRQn, GROUP_PRIORITY_100HZ);
  NVIC_SetPriority(USB_IRQn, GROUP_PRIORITY_USB);
  
  initUARTs();
  initADC();
  initPWM();
  
  // Motor drivers are active low, so let's disable all of them, until the drivers turn them on:
  GPIO_SET(IO_X_ENABLE);
  GPIO_SET(IO_Y_ENABLE);
  GPIO_SET(IO_Z_ENABLE);
  GPIO_SET(IO_A_ENABLE); 
   
  /*
    Set the simple I/O configuration for all the pins we use,    
    this will ensure that all pins have had its function selected
  */
  for (int i=0;i<ALL_PINS_SIZE;i++) {
    configPin(ALL_PINS[i]);
  }

  /*
    Set up timer3 to poke the "slow" 100Hz maintainance routine
   */    

  TIM_TIMERCFG_Type timerCfg;
  timerCfg.PrescaleOption = TIM_PRESCALE_USVAL;
  timerCfg.PrescaleValue  = 1000; // 1 ms interval
  TIM_Init(LPC_TIM3, TIM_TIMER_MODE, &timerCfg);

  TIM_MATCHCFG_Type timerMatch;
  timerMatch.MatchChannel = 0;
  timerMatch.IntOnMatch   = TRUE;
  timerMatch.ResetOnMatch = TRUE;
  timerMatch.StopOnMatch  = FALSE;
  timerMatch.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
  timerMatch.MatchValue   = 10-1;
  TIM_ConfigMatch(LPC_TIM3,&timerMatch);

  NVIC_EnableIRQ(TIMER3_IRQn);
  TIM_Cmd(LPC_TIM3,ENABLE);
  
  initAPI();
}