示例#1
0
文件: platform.c 项目: zhanjun/elua
u32 platform_uart_setup( unsigned id, u32 baud, int databits, int parity, int stopbits )
{
    u32 config;

    MAP_GPIOPinTypeUART(uart_gpio_base [ id ], uart_gpio_pins[ id ]);

    switch( databits )
    {
    case 5:
        config = UART_CONFIG_WLEN_5;
        break;
    case 6:
        config = UART_CONFIG_WLEN_6;
        break;
    case 7:
        config = UART_CONFIG_WLEN_7;
        break;
    default:
        config = UART_CONFIG_WLEN_8;
        break;
    }
    config |= ( stopbits == PLATFORM_UART_STOPBITS_1 ) ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO;
    if( parity == PLATFORM_UART_PARITY_EVEN )
        config |= UART_CONFIG_PAR_EVEN;
    else if( parity == PLATFORM_UART_PARITY_ODD )
        config |= UART_CONFIG_PAR_ODD;
    else
        config |= UART_CONFIG_PAR_NONE;

    MAP_UARTConfigSetExpClk( uart_base[ id ], MAP_SysCtlClockGet(), baud, config );
    MAP_UARTConfigGetExpClk( uart_base[ id ], MAP_SysCtlClockGet(), &baud, &config );
    return baud;
}
示例#2
0
文件: platform.c 项目: zhanjun/elua
int platform_init()
{
    // Set the clocking to run from PLL
#if defined( FORLM3S9B92 ) || defined( FORLM3S9D92 )
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
#else
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
#endif

    // Setup PIO
    pios_init();

    // Setup SSIs
    spis_init();

    // Setup UARTs
    uarts_init();

    // Setup timers
    timers_init();

    // Setup PWMs
    pwms_init();

#ifdef BUILD_ADC
    // Setup ADCs
    adcs_init();
#endif

#ifdef BUILD_CAN
    // Setup CANs
    cans_init();
#endif

    // Setup system timer
    cmn_systimer_set_base_freq( MAP_SysCtlClockGet() );
    cmn_systimer_set_interrupt_freq( SYSTICKHZ );

    // Setup ethernet (TCP/IP)
    eth_init();

    // Common platform initialization code
    cmn_platform_init();

    // Virtual timers
    // If the ethernet controller is used the timer is already initialized, so skip this sequence
#if VTMR_NUM_TIMERS > 0 && !defined( BUILD_UIP )
    // Configure SysTick for a periodic interrupt.
    MAP_SysTickPeriodSet( MAP_SysCtlClockGet() / SYSTICKHZ );
    MAP_SysTickEnable();
    MAP_SysTickIntEnable();
    MAP_IntMasterEnable();
#endif

    // All done
    return PLATFORM_OK;
}
示例#3
0
void hw_delay(unsigned long uS)
{
    TN_INTSAVE_DATA
    tn_disable_interrupt();
    MAP_SysCtlDelay(MAP_SysCtlClockGet() / 1000000 * uS / 3); // The loop takes 3 cycles/loop
    tn_enable_interrupt();
}
示例#4
0
void rt_hw_console_init(void)
{
	struct rt_lm3s_serial* serial;

	serial = &serial1;

	serial->parent.type = RT_Device_Class_Char;

	serial->hw_base = UART0_BASE;
	serial->baudrate = 115200;

	rt_memset(serial->rx_buffer, 0, sizeof(serial->rx_buffer));
	serial->read_index = serial->save_index = 0;

	/* enable UART0 clock */
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	/* set UART0 pinmux */
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	/* Configure the UART for 115,200, 8-N-1 operation. */
	MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), serial->baudrate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	serial->parent.init 	= rt_serial_init;
	serial->parent.open 	= rt_serial_open;
	serial->parent.close    = rt_serial_close;
	serial->parent.read 	= rt_serial_read;
	serial->parent.write    = rt_serial_write;
	serial->parent.control  = rt_serial_control;
	serial->parent.user_data= RT_NULL;

	rt_device_register(&serial->parent, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
}
示例#5
0
void purpinsMotors::configureQEI() {

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	//
	// Set GPIO C5 and C6 as QEI pins.
	//
	MAP_GPIOPinConfigure(GPIO_PC5_PHA1);
	MAP_GPIOPinConfigure(GPIO_PC6_PHB1);
	MAP_GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);

	//
	// Set GPIO D6 and D7 as QEI pins.
	//
	MAP_GPIOPinConfigure(GPIO_PD6_PHA0);
	MAP_GPIOPinConfigure(GPIO_PD7_PHB0);
	MAP_GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);

	MAP_QEIConfigure(QEI0_BASE,
			(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP
					| QEI_CONFIG_NO_RESET), 1200);
	MAP_QEIConfigure(QEI1_BASE,
			(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP
					| QEI_CONFIG_NO_RESET), 1200);

	MAP_QEIEnable(QEI0_BASE);
	MAP_QEIEnable(QEI1_BASE);

	MAP_QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1,
			MAP_SysCtlClockGet() / QEILOOPFREQUENCY);
	MAP_QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1,
			MAP_SysCtlClockGet() / QEILOOPFREQUENCY);

	QEIIntRegister(QEI1_BASE, motorsRightQEIHandler);
	QEIIntRegister(QEI0_BASE, motorsLeftQEIHandler);

	MAP_IntEnable(INT_QEI0);
	MAP_IntEnable(INT_QEI1);

	MAP_QEIIntEnable(QEI0_BASE, QEI_INTTIMER);
	MAP_QEIIntEnable(QEI1_BASE, QEI_INTTIMER);
	MAP_QEIVelocityEnable(QEI0_BASE);
	MAP_QEIVelocityEnable(QEI1_BASE);
}
示例#6
0
文件: rfid.c 项目: mukris/rfid
static void prvSetupSPI(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
	// set the SSI clock to the PIOSC clock
	SSIClockSourceSet(SSI2_BASE, SSI_CLOCK_SYSTEM);
	SSIConfigSetExpClk(SSI2_BASE, MAP_SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);
	MAP_SSIEnable(SSI2_BASE);
}
示例#7
0
void init_hardware()
{
    // Set SysTick timer period (TN_SYS_TICK_FQ_HZ)
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    ///////////
    MAP_SysTickDisable();
    MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / TN_SYS_TICK_FQ_HZ);
    MAP_SysTickIntEnable();
    MAP_SysTickEnable();
}
示例#8
0
void configureUART(){
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Set GPIO A0 and A1 as UART pins.
	//
	MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
	MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
	MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTStdioConfig(0,115200,MAP_SysCtlClockGet());
}
示例#9
0
void SysTimerConfig(void)
{
    /// Enable TIMER0
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    /// Configure TIMER0
    MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
    MAP_TimerLoadSet(TIMER0_BASE,TIMER_A, MAP_SysCtlClockGet()/100);
    MAP_TimerEnable(TIMER0_BASE, TIMER_A);
    /// \todo Set it statically?
    TimerIntRegister(TIMER0_BASE, TIMER_A, SysTimerHandler);
    MAP_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}
示例#10
0
    StellarisIO()
        : magic(gMagic)
    {
        MAP_FPULazyStackingEnable();

        /* Set clock to PLL at 50MHz */
        MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

        MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / (1000*10)); // 1us
        MAP_SysTickIntEnable();
        MAP_SysTickEnable();
    }
示例#11
0
文件: enc28j60.c 项目: mota37/Modbus
/**
 * Write value to PHY address.
 * Reading procedure is described in ENC28J60 datasheet
 * section 3.3.
 */
void enc_phy_write(uint8_t addr, uint16_t value) {
	WRITE_REG(ENC_MIREGADR, addr);
	WRITE_REG(ENC_MIWRL, value & 0xFF);
	WRITE_REG(ENC_MIWRH, value >> 8);

	MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));

	uint8_t stat;
	do {
		stat = READ_MREG(ENC_MISTAT);
	} while (stat & ENC_MISTAT_BUSY);
}
示例#12
0
void purpinsMotors::configurePWM(){

	//Configure PWM Clock
	MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_2);

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

	pwmPeriod = MAP_SysCtlClockGet() / 2 / PWM_FREQUENCY; //PWM frequency

	MAP_GPIOPinConfigure(GPIO_PF1_M1PWM5);
	MAP_GPIOPinConfigure(GPIO_PF2_M1PWM6);
	MAP_GPIOPinConfigure(GPIO_PF3_M1PWM7);
	MAP_GPIOPinConfigure(GPIO_PC4_M0PWM6);

	MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
	MAP_GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);


	//gen 3 for m0pwm6
	MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	//gen 3 for m1pwm6 and m1pwm7
	MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
	//gen 2 for m1pwm5
	MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

	//Set the Period (expressed in clock ticks)
	MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, pwmPeriod);
	MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, pwmPeriod);
	MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, pwmPeriod);

	//Set PWM duty-0%
	MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5 , 0);
	MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6 , 0);
	MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7 , 0);
	MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_6 , 0);

	// Enable the PWM generators
	MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_2);
	MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_3);
	MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_3);


	// Turn on the Output pins
	MAP_PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
	MAP_PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT, true);
	MAP_PWMOutputState(PWM1_BASE, PWM_OUT_7_BIT, true);
	MAP_PWMOutputState(PWM0_BASE, PWM_OUT_6_BIT, true);
}
示例#13
0
void hw_timer0a_set_timeout(unsigned long uS)
{
#ifdef DEBUG
    if (uS > 1000000)
    {
        dbg_puts("uS > 1000000");
        dbg_trace();
        tn_halt();
    }
#endif // DEBUG

    MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, MAP_SysCtlClockGet() / 1000000 * uS);
}
示例#14
0
/*---------------------------------------------------------------------------*/
void
watchdog_reboot(void)
{
#if WATCHDOG_ENABLED == 1
	watchdog_start();
	if(MAP_WatchdogLockState(WATCHDOG0_BASE) == true)
	{
		MAP_WatchdogUnlock(WATCHDOG0_BASE);
	}
	MAP_WatchdogReloadSet(WATCHDOG0_BASE, (MAP_SysCtlClockGet() / 4)); // 250ms
	while(1); //loop
#endif
}
示例#15
0
void hw_timer1a_start_once(unsigned long uS)
{
#ifdef DEBUG
    if (uS > 1000000)
    {
        dbg_puts("uS > 1000000");
        dbg_trace();
        tn_halt();
    }
#endif // DEBUG

    MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, MAP_SysCtlClockGet() / 1000000 * uS);
    MAP_TimerEnable(TIMER1_BASE, TIMER_A);
}
示例#16
0
   /*          via the HCI_COMClose() function.                         */
void BTPSAPI HCITR_COMReconfigure(unsigned int HCITransportID, HCI_Driver_Reconfigure_Data_t *DriverReconfigureData)
{
   long                          BaudRate;

   /* Check to make sure that the specified Transport ID is valid.      */
   if((DriverReconfigureData) && (HCITransportID == TRANSPORT_ID) && (HCITransportOpen))
   {
      /* Change the UART baud rate.                                     */
      if(DriverReconfigureData->ReconfigureCommand == HCI_COMM_DRIVER_RECONFIGURE_DATA_COMMAND_CHANGE_PARAMETERS)
      {
         BaudRate = (long)DriverReconfigureData->ReconfigureData;
         MAP_UARTConfigSetExpClk(UartContext.Base, MAP_SysCtlClockGet(), BaudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
      }
   }
}
示例#17
0
文件: gps.c 项目: tuzhikov/SURD
void GPS_init()
{

    dbg_printf("Initializing GPS module...");

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART);

    MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
    MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    MAP_UARTConfigSetExpClk(UART_BASE, MAP_SysCtlClockGet(), UART_SPEED, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    MAP_UARTDisable(UART_BASE);
    MAP_UARTTxIntModeSet(UART_BASE, UART_TXINT_MODE_EOT);
    MAP_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_TX);
    MAP_IntEnable(INT_UART);
    MAP_UARTEnable(UART_BASE);
    MAP_UARTFIFODisable(UART_BASE);

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    //
    MAP_IntEnable(INT_GPIOG);
    // Настроить прерывания на PPS
    MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE);
    MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7);
    //

    if (tn_task_create(&task_GPS_tcb, &task_GPS_func, TASK_GPS_PRI,
        &task_GPS_stk[TASK_GPS_STK_SZ - 1], TASK_GPS_STK_SZ, 0,
        TN_TASK_START_ON_CREATION) != TERR_NO_ERR)
    {
        dbg_puts("tn_task_create(&task_GPS_tcb) error");
        goto err;
    }

    // Настроить прерывания на PPS
    //MAP_IntEnable(INT_GPIOG);
    //MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE);
    //MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7);

    dbg_puts("[done]");

    return;
err:
    dbg_trace();
    tn_halt();
}
void SetupStdio(void)
{
    //Put these into variables because passing macros to macros isnt fun.
    const unsigned long srcClock = MAP_SysCtlClockGet();
    const unsigned long baud = 115200;

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    MAP_UARTConfigSetExpClk(UART0_BASE, srcClock, baud,
                (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                 UART_CONFIG_WLEN_8));
    MAP_UARTEnable(UART0_BASE);
}
示例#19
0
static void spi_init(void) {
  MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

  // Configure SSI1 for SPI RAM usage
  MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
  MAP_GPIOPinConfigure(GPIO_PB4_SSI2CLK);
  MAP_GPIOPinConfigure(GPIO_PB6_SSI2RX);
  MAP_GPIOPinConfigure(GPIO_PB7_SSI2TX);
  MAP_GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);
  MAP_SSIConfigSetExpClk(SSI2_BASE, MAP_SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
			 SSI_MODE_MASTER, 1000000, 8);
  MAP_SSIEnable(SSI2_BASE);

  unsigned long b;
  while(MAP_SSIDataGetNonBlocking(SSI2_BASE, &b)) {}
}
示例#20
0
void hw_watchdog_init()
{
    // Startup watchdog timer
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
    MAP_WatchdogReloadSet(WATCHDOG0_BASE, MAP_SysCtlClockGet() * 8); // 8s
    MAP_WatchdogResetEnable(WATCHDOG0_BASE);

#ifdef DEBUG
    MAP_WatchdogStallEnable(WATCHDOG0_BASE);
#endif // DEBUG

    MAP_IntEnable(INT_WATCHDOG);
    MAP_WatchdogEnable(WATCHDOG0_BASE); // can not be disabled

    hw_watchdog_clear();
}
示例#21
0
void platform_init(void) {
	/* 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 clock to PLL at 50MHz */
	MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
					   SYSCTL_XTAL_16MHZ);

	/* Enable the GPIO pins for the LED (PF2 & PF3). */
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2);
	/* Enable the system tick. FIXME do we need this? */
	MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND);
	MAP_SysTickIntEnable();
	MAP_SysTickEnable();
}
示例#22
0
void I2CController::setup(GPIOPin sda, GPIOPin scl, speed_t speed, bool doEnableInterrupts, uint32_t defaultTimeout)
{
	RecursiveMutexGuard guard(&_lock);
	_sda = sda;
	_scl = scl;
	_defaultTimeout = defaultTimeout;

	MAP_SysCtlPeripheralEnable(_periph);
	SysCtlPeripheralReset(_periph);

	_sda.enablePeripheral();
	if (_base == I2C0_MASTER_BASE) {
		_sda.mapAsI2C0SDA();
	}
	else if (_base == I2C1_MASTER_BASE) {
		_sda.mapAsI2C1SDA();
	}
	else {
		while(1) { /* we should never get here! */ }
	}
	_sda.configure(GPIOPin::I2C);

	_scl.enablePeripheral();
	if (_base == I2C0_MASTER_BASE) {
		_scl.mapAsI2C0SCL();
	}
	else if (_base == I2C1_MASTER_BASE) {
		_scl.mapAsI2C1SCL();
	}
	else {
		while(1) { /* we should never get here! */ }
	}
	_scl.configure(GPIOPin::I2CSCL);

	I2CMasterInitExpClk(_base, MAP_SysCtlClockGet(), (speed==speed_400kBit) ? 1 : 0);
	I2CMasterEnable(_base);

	if (doEnableInterrupts) enableInterrupts(true, true);

    // Do a dummy receive to make sure you don't get junk on the first receive.
    I2CMasterControl(_base, I2C_MASTER_CMD_SINGLE_RECEIVE);
    waitFinish(1);
}
示例#23
0
u32 platform_spi_setup( unsigned id, int mode, u32 clock, unsigned cpol, unsigned cpha, unsigned databits )
{
  unsigned protocol;

  if( cpol == 0 )
    protocol = cpha ? SSI_FRF_MOTO_MODE_1 : SSI_FRF_MOTO_MODE_0;
  else
    protocol = cpha ? SSI_FRF_MOTO_MODE_3 : SSI_FRF_MOTO_MODE_2;
  mode = mode == PLATFORM_SPI_MASTER ? SSI_MODE_MASTER : SSI_MODE_SLAVE;
  MAP_SSIDisable( spi_base[ id ] );

  MAP_GPIOPinTypeSSI( spi_gpio_base[ id ], spi_gpio_pins[ id ] );

  // FIXME: not sure this is always "right"
  // MAP_GPIOPadConfigSet(spi_gpio_base[ id ], spi_gpio_clk_pin[ id ], GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);

  MAP_SSIConfigSetExpClk( spi_base[ id ], MAP_SysCtlClockGet(), protocol, mode, clock, databits );
  MAP_SSIEnable( spi_base[ id ] );
  return clock;
}
示例#24
0
void systick_init()
{
  //
  // Configure SysTick for a periodic interrupt.
  //
  MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKHZ);
  MAP_SysTickEnable();
  MAP_SysTickIntEnable();

  //MAP_IntEnable(INT_GPIOA);
  MAP_IntEnable(INT_GPIOE);
  MAP_IntMasterEnable();

  MAP_SysCtlPeripheralClockGating(false);

  MAP_GPIOIntTypeSet(GPIO_PORTE_BASE, ENC_INT, GPIO_FALLING_EDGE);
  MAP_GPIOPinIntClear(GPIO_PORTE_BASE, ENC_INT);
  MAP_GPIOPinIntEnable(GPIO_PORTE_BASE, ENC_INT);
  UARTprintf("int enabled\n");
}
示例#25
0
void
watchdog_init(void)
{
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
  delay_us(5);
	/*
	 * Check to see if the registers are locked, and if so, unlock them.
	 * Locking prevents stray access from modifying register content
	 */
	if(MAP_WatchdogLockState(WATCHDOG0_BASE) == true)
	{
		MAP_WatchdogUnlock(WATCHDOG0_BASE);
	}
  MAP_IntEnable(INT_WATCHDOG);

  /* Prevent watchdog reset during debugging */
  MAP_WatchdogStallEnable(WATCHDOG0_BASE);
  /* 2 seconds */
	MAP_WatchdogReloadSet(WATCHDOG0_BASE, (MAP_SysCtlClockGet() * 2));
	MAP_WatchdogResetEnable(WATCHDOG0_BASE);
}
示例#26
0
  void SystemTimer::initialize()
  {
    uint32_t clockRate;

    __counter = 0;

#ifdef CLASS_IS_TM4C123
    clockRate = MAP_SysCtlClockGet();
#else
    clockRate = MAP_SysCtlClockFreqGet();
#endif

    if (clockRate == 66666666 && MCU_CLOCK == CLK80) { // some boards reports the clock frequency incorrectly
      clockRate = 80000000;
    }

    MAP_SysTickPeriodSet(clockRate / 1000);

    MAP_SysTickIntEnable();
    MAP_SysTickEnable();
  }
示例#27
0
文件: enc28j60.c 项目: mota37/Modbus
/**
 * Read value from PHY address.
 * Reading procedure is described in ENC28J60 datasheet
 * section 3.3.
 */
uint16_t enc_phy_read(uint8_t addr) {
	/*
	 1. Write the address of the PHY register to read
	 from into the MIREGADR register.*/
	WRITE_REG(ENC_MIREGADR, addr);

	/*2. Set the MICMD.MIIRD bit. The read operation
	 begins and the MISTAT.BUSY bit is set.*/
	WRITE_REG(ENC_MICMD, 0x1);

	/*3. Wait 10.24 μs. Poll the MISTAT.BUSY bit to be
	 certain that the operation is complete. While
	 busy, the host controller should not start any
	 MIISCAN operations or write to the MIWRH
	 register.
	 When the MAC has obtained the register
	 contents, the BUSY bit will clear itself.*/

	/* Assuming that we are running at 1MHz, a single cycle is
	 * 1 us */
	MAP_SysCtlDelay(((MAP_SysCtlClockGet()/3)/1000));

	uint8_t stat;
	do {
		stat = READ_MREG(ENC_MISTAT);
	} while (stat & ENC_MISTAT_BUSY);

	/*4. Clear the MICMD.MIIRD bit.*/
	WRITE_REG(ENC_MICMD, 0x00);

	/*5. Read the desired data from the MIRDL and
	 MIRDH registers. The order that these bytes are
	 accessed is unimportant.
	 */
	uint16_t ret;
	ret = READ_MREG(ENC_MIRDL) & 0xFF;
	ret |= READ_MREG(ENC_MIRDH) << 8;

	return ret;
}
void spi_init(unsigned long bitrate,unsigned long datawidth){
	//SSI
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

	MAP_SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA);
	MAP_SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOC);
	//CS Pin
	MAP_GPIOPinTypeGPIOOutput(CS_PIN_BASE,CS_PIN);

	//CE Pin
	MAP_GPIOPinTypeGPIOOutput(CE_PIN_BASE,CE_PIN);

	/* Configure the SSI0 port */
	MAP_SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER, bitrate, datawidth);
	/* Configure the appropriate pins to be SSI instead of GPIO */
	MAP_GPIOPinTypeSSI(GPIO_PORTA_AHB_BASE, GPIO_PIN_2 |GPIO_PIN_4 | GPIO_PIN_5);
	MAP_SSIEnable(SSI0_BASE);

	ulClockMS = MAP_SysCtlClockGet() / (3 * 1000);
}
示例#29
0
//PWM = PF1/M1PWM5 & PC4/M0PWM6
void configurePWM(void)
{



	//Configure PWM Clock to match system
	MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_2);

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

	//PD6 & PD7 for direction
	MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_INT_PIN_6 |GPIO_INT_PIN_7);
	MAP_GPIOPinWrite(GPIO_PORTD_BASE,GPIO_INT_PIN_6 |GPIO_INT_PIN_7,0);

	ulPeriod = MAP_SysCtlClockGet() / 2 / PWM_FREQUENCY; //PWM frequency


	MAP_GPIOPinConfigure(GPIO_PF1_M1PWM5);
	MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);

	MAP_PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

	//Set the Period (expressed in clock ticks)
	MAP_PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, ulPeriod);

	//Set PWM duty-0%
	MAP_PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5 , 0);

	// Enable the PWM generator
	MAP_PWMGenEnable(PWM1_BASE, PWM_GEN_2);

	// Turn on the Output pins
	MAP_PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);
}
示例#30
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();
    }
}