Beispiel #1
0
void main()
{
    systemInit();
	
    //Among other things, allocates byte arrays for sending commands.
    dynamixel_init();

    // Oooh. what's this?
    setDigitalOutput(param_arduino_DTR_pin, LOW);
    ioTxSignals(0);

    //usbInit();
    uart1Init();
    uart1SetBaudRate(param_baud_rate);

    
	
    // Initial setting of serial mode
    updateSerialMode();

    // Set up P1_5 to be the radio's TX debug signal.
    // P1DIR |= (1<<5);
    // IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode)

	// P1DIR |= 0x20; //Enable pin P1_5
	
    while(1)
    {
	uint32 ms;
	uint16 now;
	uint16 speed;
		
	updateSerialMode();
	boardService();
	updateLeds();
	errorService();

	// Code for oscillating a servo back and forth
	ms = getMs();		// Get current time in ms
	now = ms % (uint32)10000; 	// 10 sec for a full swing
	if(now >= (uint16)5000){				// Goes from 0ms...5000ms
		now = (uint16)10000 - now;			// then 5000ms...0ms
	}
	speed = interpolate(now, 0, 5000, 100, 900); // speed is really the position.
	
	ax12SetGOAL_POSITION(32, speed);

	delayMs(30);
    }
}
Beispiel #2
0
int main(void)
{
    NVIC_SetPriorityGrouping(3);

    /* enable GPIO */
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;

    act::mode(GPIO_OUTPUT);
    stat::mode(GPIO_OUTPUT);
    error::mode(GPIO_OUTPUT);
    error::high();
    estop::mode(GPIO_INPUT);

    /* setup ethernet */
    phy_rst::mode(GPIO_OUTPUT_2MHz);
    phy_rst::high(); // release reset line

    eth_mii_crs::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_rx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mdio::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_col::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rx_dv::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mii_rxd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rx_er::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_tx_en::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mdc::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_txd2::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_tx_clk::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd0::mode(GPIO_ALTERNATE | GPIO_AF_ETH);
    eth_mii_rxd1::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    eth_mii_txd3::mode(GPIO_ALTERNATE | GPIO_AF_ETH);

    /* Initialize Table */
    register_table.model_number = 302;
    register_table.version = 0;
    register_table.id = 253;
    register_table.baud_rate = 34; // 57600????
    register_table.last_packet = 0;
    register_table.system_time = 0;
    register_table.led = 0;

    dynamixel_init();

    /* setup analog */
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN | RCC_APB2ENR_ADC3EN;
    adc1.init(VOLTAGE_SENSE_ANALOG_CHANNEL,
              CURRENT_SENSE_ANALOG_CHANNEL);
    voltage_sense::mode(GPIO_INPUT_ANALOG);
    current_sense::mode(GPIO_INPUT_ANALOG);

    /* setup systick */
    SysTick_Config(SystemCoreClock/1000);
    NVIC_SetPriority(SysTick_IRQn,2);
    NVIC_EnableIRQ(SysTick_IRQn);

    Ethernet_Init();
    LwIP_Init();
    if (!netapp_init())
        while(1);

    __enable_irq();

    /* done with setup, turn off err led */
    error::low();

    while(1)
    {
        /* check if any packet received */
        if (ETH_CheckFrameReceived())
        {
            /* process received ethernet packet */
            LwIP_Pkt_Handle();
        }
        LwIP_Periodic_Handle(register_table.system_time);
    }
}