Ejemplo n.º 1
0
int main(void)
{
	unsigned int SystemCoreClock = 48000000UL;
	
	// Set system frequency to 48MHz
	SystemFrequency = ConfigurePLL(12000000UL, SystemCoreClock);
		
	// Enable clock to IO Configuration block.  Needed for UART, SPI, I2C, etc...
	SYSCON_SYSAHBCLKCTRL_IOCON(SYSAHBCLKCTRL_ENABLE);

	rt_hw_uart_init();
	rt_uart_init();
	rt_uart_open();
	
	char buffer[256];
	char str[] = "hi.\r\n";
	rt_uart_write(str, 5);
	
	while (1)
	{
		// echo back what was read
		int sz = rt_uart_read(buffer, 256);
		rt_uart_write(buffer, sz);
	}
}
Ejemplo n.º 2
0
/******************************************************************************
** Function name:		TargetResetInit
**
** Descriptions:		Initialize the target board before running the main() 
**						function; User may change it as needed, but may not 
**						deleted it.
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void TargetResetInit(void)
{
	MEMMAP	=	0x1;

	ConfigurePLL();

    return;
}
Ejemplo n.º 3
0
/******************************************************************************
** Function name:		TargetResetInit
**
** Descriptions:		Initialize the target board before running the main()
**						function; User may change it as needed, but may not
**						deleted it.
**
** parameters:			None
** Returned value:		None
**
******************************************************************************/
void TargetResetInit(void)
{

// mthomas
#if 0
#ifdef __DEBUG_RAM
    MEMMAP = 0x2;			/* remap to internal RAM */
#endif

#ifdef __DEBUG_FLASH
    MEMMAP = 0x1;			/* remap to internal flash */
#endif
#endif

#ifdef __DEBUG_RAM
    MEMMAP = 0x2;			/* remap to internal RAM */
#else
    MEMMAP = 0x1;			/* remap to internal flash */
#endif


#if USE_USB
	PCONP |= 0x80000000;		/* Turn On USB PCLK */
#endif
	/* Configure PLL, switch from IRC to Main OSC */
	ConfigurePLL();

  /* Set system timers for each component */
#if (Fpclk / (Fcclk / 4)) == 1
    PCLKSEL0 = 0x00000000;	/* PCLK is 1/4 CCLK */
    PCLKSEL1 = 0x00000000;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
    PCLKSEL0 = 0xAAAAAAAA;	/* PCLK is 1/2 CCLK */
    PCLKSEL1 = 0xAAAAAAAA;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
    PCLKSEL0 = 0x55555555;	/* PCLK is the same as CCLK */
    PCLKSEL1 = 0x55555555;
#endif

    /* Set memory accelerater module*/
    MAMCR = 0;
#if Fcclk < 20000000
    MAMTIM = 1;
#else
#if Fcclk < 40000000
    MAMTIM = 2;
#else
    MAMTIM = 3;
#endif
#endif
    MAMCR = 2;

    GPIOResetInit();

    return;
}
Ejemplo n.º 4
0
void init_clock (void){
	ConfigurePLL();
}
Ejemplo n.º 5
0
int main(void)
{
    // Set system frequency to 48MHz
    SystemFrequency = ConfigurePLL(12000000UL, 48000000UL);

    // Enable clock to IO Configuration block.  Needed for UART, SPI, I2C, etc...
    SYSCON_SYSAHBCLKCTRL_IOCON(SYSAHBCLKCTRL_ENABLE);

    SysTick_Config(SystemFrequency/1000 - 1); // Generate interrupt each 1 ms

    // set direction on port 0_7 (pin 28) to output
    GPIO0_DIR(7, GPIO_OUTPUT);
    GPIO0_DATA(7, 1);  // turn on diagnostic led

    // pin 17 (1_8) is connected to /CS1 on display
    IOCON->PIO1_8.FUNC = PIO1_8_FUNC_GPIO;
    GPIO1_DIR(8, GPIO_OUTPUT);

    // pin 18 (1_9) is connected to A0 on display
    IOCON->PIO1_9.FUNC = PIO1_9_FUNC_GPIO;
    GPIO1_DIR(9, GPIO_OUTPUT);

    // pin 26 (0_3) is connected to /RST on display
    IOCON->PIO0_3.FUNC = PIO0_3_FUNC_GPIO;
    //IOCON->PIO0_3.MODE = MODE_PULLUP_RESISTOR;
    GPIO0_DIR(3, GPIO_OUTPUT);

    // configure display lines
    DispReset(DISP_RESET);
    DispSelect(DISP_DESELECT);
    //DispMode(DISP_CMD_MODE);

    //
    // Configure SPI 0
    //

    // Power on SSP 0
    SYSCON->SYSAHBCLKCTRL.SSP0 = 1;

    // reset the device
    SYSCON->PRESETCTRL.SSP0_RST_N = 0;	// assert reset
    SYSCON->PRESETCTRL.SSP0_RST_N = 1;	// de-assert reset

    // setup clock divisor for SSP0 device
    SYSCON->SSP0CLKDIV = 2;

    // pin 1 - PIO0_8, set to MISO
    // pin 2 - PIO0_9, set to MOSI
    // pin 6 - PIO0_6, set to SCK0
    // pin 25 - PIO0_2, set to SSEL0

    IOCON->PIO0_8.FUNC = PIO0_8_FUNC_MISO;
    IOCON->PIO0_9.FUNC = PIO0_9_FUNC_MOSI;
    IOCON->SCK_LOC.SCKLOC = SCK0_LOC_PIO0_6;
    IOCON->PIO0_6.FUNC = PIO0_6_FUNC_SCK0;
    IOCON->PIO0_2.FUNC = PIO0_2_FUNC_SSEL;

    // setup data clock rate (CPDVSR=2):
    //   SCR=23 = 500Khz
    //   SCR=11 = 1Mhz
    //   SCR=5  = 2Mhz
    // Serial Clock Rate = PCLK / (CPSDVSR * [SCR+1])
    SSP0CON->CPSR.CPSDVSR = 2;
    SSP0CON->CR0.SCR = 11;

    SSP0CON->CR0.DSS = SSP_CR0_DSS_8BIT;
    SSP0CON->CR0.FRF = SSP_CR0_FRF_SPI;
    SSP0CON->CR0.CPOL = SSP_CR0_CPOL_CLOCK_LOW;
    SSP0CON->CR0.CPHA = SSP_CR0_CPHA_AWAY_FROM;

    SSP0CON->CR1.MS = SSP_CR1_MS_MASTER;

    // empty out FIFO
    volatile uint32_t data;
    for (int i = 0; i < SPI_FIFOSIZE; ++i)
    {
        data = SSP0CON->DR;
    }

    // enable SPI controller
    SSP0CON->CR1.SSE = 1;


    //test_display();

    // pin 4 (0_11) is connected to ~SEL on DAC
    IOCON->PIO0_11.FUNC = PIO0_11_FUNC_GPIO;
    GPIO0_DIR(11, GPIO_OUTPUT);
    GPIO0_DATA(11, 1);	// set to hi to deselect the DAC

    Delay(1);
    GPIO0_DATA(11, 0);	// set to low to select the DAC
    Delay(1);
    int j = 257;
    SSP0CON->DR = j >> 8;
    SSP0CON->DR = j & 0xFF;
    Delay(1);
    GPIO0_DATA(11, 1);	// set to hi
    Delay(1);

    int res100 = 0;
    while (1)
    {
        // pin 9 (1_0) is connected to FET gating 10 Ohm current measurement
        IOCON->PIO1_0.FUNC = PIO1_0_FUNC_GPIO;
        GPIO1_DIR(0, GPIO_OUTPUT);
        GPIO1_DATA(0, res100);	// set to high to select

        Delay(3000);
        res100 = res100 ? 0 : 1;
    }

#if 0
    while (1)
    {
        for (int j = 0; j < 4096; ++j)
        {
            Delay(1);
            GPIO0_DATA(11, 0);	// set to low to select the DAC
            Delay(1);
            SSP0CON->DR = j >> 8;

// 			Delay(1);
// 			GPIO0_DATA(11, 1);	// set to hi
// 			Delay(1);
// 			GPIO0_DATA(11, 0);	// set to low to select the DAC
// 			Delay(1);

            SSP0CON->DR = j & 0xFF;
            Delay(1);
            GPIO0_DATA(11, 1);	// set to hi
            Delay(1);
        }
    }
#endif
}
Ejemplo n.º 6
0
int main(void)
{
	// Set system frequency to 48MHz
	SystemFrequency = ConfigurePLL(12000000UL, 48000000UL);

	// Enable clock to IO Configuration block.  Needed for UART, SPI, I2C, etc...
	SYSCON_SYSAHBCLKCTRL_IOCON(SYSAHBCLKCTRL_ENABLE);
	
  SysTick_Config(SystemFrequency/10000 - 1); // Generate interrupt each .1 ms
	
	// set direction on port 0_7 (pin 28) to output
	GPIO0_DIR(7, GPIO_OUTPUT);	
	GPIO0_DATA(7, 1);  // turn on diagnostic led

	GPIO1_DIR(4, GPIO_OUTPUT);	// configure port 1_5 (pin 14) for output
	GPIO1_DIR(5, GPIO_OUTPUT);	// configure port 1_5 (pin 14) for output

	// PWM output (pin 1) is tied to 1,2EN on H-bridge (SN754410 Quad Half H-bridge)	// 
	SetupPWM();

	MotorDir(0, 0);	// turn on braking at 100%
	MotorPower(0, 100);

	// motor details:
	// 120:1 gearbox
	// 8 teeth on motor gear
	// 32 teeth on gear with optical wheel
	// 4 edges per rot of optical wheel
	// 8/32*120*4 = 106.666 edges per rev
	// At 5.5V max speed with just 2 gears,
	// pulse width is avg 9.5 ms.
	//
	// a full stop should be no edge for about 150ms
	// and motor on brake.
	//
	
	g_motorPos = 0;
	g_motorStop = 0;
	g_motorTime = 0;
	g_motorInc = 0;
	
	// setup interrupts on PIO1_0
	IOCON_PIO1_0_MODE(PIO1_0_MODE_PULLDOWN_RESISTOR);
	GPIO1_DIR(0, GPIO_INPUT);	
	GPIO1_IS(0, GPIO_EDGE_SENSITIVE);
	GPIO1_IBE(0, GPIO_BOTH_EDGES);
	GPIO1_IE(0, GPIO_INTERRUPT_ENABLE);

  NVIC_EnableIRQ(EINT1_IRQn);

	U64 time1, time2, oldTime;
	int pos, oldPos;
	oldTime = 0xFFFFFFFFFFFFFFFF;
	U64 systickcnt;
	int desiredMotorInc;		// g_motorInc can only be changed when in a stopped state

	while (1)
	{
		FlashLED();
		desiredMotorInc = g_motorInc = 1;
		g_motorStop = 100;
		MotorDir(0, 1);
		MotorPower(0, 100);

		while (1)
		{
			do {
				time1 = g_motorTime;
				pos = g_motorPos;
				time2 = g_motorTime;
			} while (time1 != time2);

			if (pos > g_motorStop)
			{
				desiredMotorInc = -1;
			}
			else if (pos < g_motorStop)
			{
				desiredMotorInc = 1;
			}

			systickcnt = SysTickCnt;
			if ((systickcnt - time2) > 200 /*ms*/)
			{
				// stopped
				if (pos ==  g_motorStop)
				{
					break;	//achieved goal pos and we are stopped
				}
				
				if (desiredMotorInc != g_motorInc)
				{
					g_motorInc = desiredMotorInc;		// g_motorInc must always be 1 or -1, otherwise we lose track of position
					// change direction and turn power back on
					MotorDir(0, desiredMotorInc);
					MotorPower(0, 20);
				}
			}
		}

		FlashLED();
		desiredMotorInc = g_motorInc = -1;
		g_motorStop = 0;
		MotorDir(0, -1);
		MotorPower(0, 100);

		while (1)
		{
			do {
				time1 = g_motorTime;
				pos = g_motorPos;
				time2 = g_motorTime;
			} while (time1 != time2);

			if (pos > g_motorStop)
			{
				desiredMotorInc = -1;
			}
			else if (pos < g_motorStop)
			{
				desiredMotorInc = 1;
			}

			systickcnt = SysTickCnt;
			if ((systickcnt - time2) > 200 /*ms*/)
			{
				// stopped
				if (pos ==  g_motorStop)
				{
					break;	//achieved goal pos and we are stopped
				}
				
				if (desiredMotorInc != g_motorInc)
				{
					g_motorInc = desiredMotorInc;		// g_motorInc must always be 1 or -1, otherwise we lose track of position
					// change direction and turn power back on
					MotorDir(0, desiredMotorInc);
					MotorPower(0, 20);
				}
			}
		}

	}
}