Esempio n. 1
0
int main()
{
	reset_reason = scuPostReset(CLKCR_M32_P64);

	enablePin(1, 0, GPIO_OUT_PP);  // LED
	enablePin(1, 1, GPIO_OUT_PP);  // LED
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // P2.1 alt6 is USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);  // P2.2 is the debug serial input

	// If we can't configure the serial port then hang.
	unsigned int ch0_cbase = usicConfigure(0, USIC_PROTO_ASC);
	while (ch0_cbase == 0) {
		asm("wfi");
	}
	usicFifoEnable(0);

	configureCCU();
	// Clock = 64MHz so 8000000 - 1 is 8 systicks/second.
	systickEnable(8000000 - 1);
	enable_interrupts();

	// Start CCU slices 0 and 1 simultaneously.
	ccuStartSlices(BIT1 | BIT0);

	usicBufferedSendCh0("Ready.\r\n");
	while(1)
	{
		asm("wfi");
	}

	return 0;
}
Esempio n. 2
0
void boardInit(void)
{
    SIM_SCGC5 |= 0x00000400; //enable Port B clock
    SIM_SCGC5 |= 0x00000200; //enable Port A clock
    SIM_SCGC5 |= 0x00001000; //enable Port D clock

    PORTB_PCR19 |= (uint32_t)0x00000100; //Configure portB19 as GPIO (GREEN)
    GPIOB_PDDR |= (uint32_t)0x00080000; //Configure portB19 as output

    PORTA_PCR12 |= (uint32_t)0x000A0102; //Configure portA12 as GPIO with falling edge interrupt and pullup enabled.
    GPIOA_PDDR &= ~(uint32_t)(1<<12); //Configure portA12 as input.

    PORTB_PCR18 |= (uint32_t)0x00000100; //Configure portB18 as GPIO (RED)
    GPIOB_PSOR |= (uint32_t)0x00040000;
    GPIOB_PDDR |= (uint32_t)0x00040000; //Configure portB18 as output

    PORTD_PCR1 |= (uint32_t)0x00000100; //Configure portD1 as GPIO (BLUE)
    FGPIOD_PSOR |= (uint32_t)0x00000002;
    FGPIOD_PDDR |= (uint32_t)0x00000002; //Configure portD1 as output

    //SIM_SCGC6 |= (uint8_t) 0x00800000; // Enable PIT clock

    SIM_SOPT2 |= 0x01000000; // Set TPM to use the MCGFLLCLK as a clock source
    // MCGFLLCLK is either 24MHz or 23 986 176Hz
    SIM_SCGC6 |= 0x01000000; // Enable TPM0 clock

    uart0Config();
    uart0Enable();

    llwuConfigure();
    vllsEnable();
    vllsConfigure(1);

    PMC_REGSC = 0x08;

    systickConfigure();

    interruptSetPriority(30,0); //Port A ISR
    interruptEnable(30);

    interruptSetPriority(7,0); // Configure LLWU interrupt as highest priority.
    interruptEnable(7); //Enable LLWU interrupt.

    systickEnable();

    rtcInit();
    rtcStart();

    interruptSetPriority(21,0); // Configure RTC Seconds interrupt as highest priority.
    interruptEnable(21); //Enable RTC Seconds interrupt.

    i2cInit();
    interruptSetPriority(9,3); // Configure I2C interrupt as Lowest priority.
    interruptEnable(9); //Enable I2C interrupt.

    interruptSetPriority(22,3); // Configure PIT interrupt as Lowest priority.
    interruptEnable(9); //Enable PIT interrupt.
}
Esempio n. 3
0
int main()
{
	// Changing this clock speed also requires a change to the argument
	// to systickEnable().
	scuPostReset(CLKCR_M8_P8);

	// Configure GPIO
	enablePin(1, 0, GPIO_OUT_PP_ALT6);  // LED is ACMP1.OUT
	enablePin(1, 1, GPIO_OUT_PP);       // LED
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // P2.1 alt6 is USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);     // P2.2 is the debug serial input
	// enablePin(2, 8, GPIO_IN_FLOAT);     // P2.8 ACMP0.INN (Vref/2)
	// enablePin(2, 9, GPIO_OUT_PP);       // P2.9 ACMP0.INP
	enablePin(2, 6, GPIO_IN_FLOAT);     // P2.6 ACMP1.INN
	enablePin(2, 7, GPIO_IN_FLOAT);     // P2.7 ACMP1.INP (Vref/2)
	enablePin(2, 11, GPIO_OUT_PP);      // P2.11 ACMP.Vref
	clearPin(1, 1);

	// 1Hz (8MHz / 8M)
	systickEnable(8000000 - 1);

	// Configure ACMP
	acmpEnable();
	// ACMP1 enabled with 15mv hysteresis and INP is Vref/2
	acmpConfigure(1, ACMP_CMP_EN |
	                 // ACMP_CMP1_DIV_EN |
	                 ACMP_CMP_HYST_ADJ_15);
	// ACMP0 enabled with 15mv hysteresis and INN is Vref/2
	//acmpConfigure(0, ACMP_CMP_EN |
	//                 ACMP_CMP0_SEL |
	//                 ACMP_CMP_HYST_ADJ_15);

	// Turn on Vref
	clearPin(2, 11);  // Vref
	// Turn off ACMP inputs
	// clearPin(2, 6);  // ACMP1.INN
	// clearPin(2, 7);  // ACMP1.INP

	enable_interrupts();

	while(1)
	{
		asm("wfi");
	}
	return 0;
}
Esempio n. 4
0
int main()
{
	scuPostReset(CLKCR_M32_P64);

	// On board LEDs.
	enablePin(1, 0, GPIO_OUT_PP);
	enablePin(1, 1, GPIO_OUT_PP);

	// Pins used for USIC channel 0 ASC mode.
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);     // debug serial input
	clearPin(1, 0);
	clearPin(1, 1);

	// Pins used for USIC channel 1 SSC mode.
	enablePin(0, 6, GPIO_IN_FLOAT);  // DX0C in
	enablePin(0, 7, GPIO_OUT_PP_ALT7);  // data out
	enablePin(0, 8, GPIO_OUT_PP_ALT7);  // sclk out
	enablePin(0, 9, GPIO_OUT_PP_ALT7);  // chip select out

	ch0_cbase = usicConfigure(0, USIC_PROTO_ASC);
	ch1_cbase = usicConfigure(1, USIC_PROTO_SSC);
	while (ch0_cbase == 0 || ch1_cbase == 0) {
		asm("wfi");
	}
	usicFifoEnable(0);

        systickEnable(8000000 - 1);

	enable_interrupts();

	usicBufferedSendCh0("Ready.\r\n");
	while(1)
	{
		asm("wfi");
	}
	return 0;
}
Esempio n. 5
0
int main()
{
	scuPostReset(CLKCR_M32_P64);

	enablePin(1, 0, GPIO_OUT_PP);  // LED
	enablePin(1, 1, GPIO_OUT_PP);  // LED
	enablePin(2, 1, GPIO_OUT_PP_ALT6);  // P2.1 alt6 is USIC0_CH0_DOUT0
	enablePin(2, 2, GPIO_IN_FLOAT);  // P2.2 is the debug serial input

	// Capture compare unit config
	ccuEnable(GCTRL_SUSCFG_ROLLOVER);
	// Slice 0: 40kHz 50% PWM.
	// Event 1: active high, rising edge, input I (SCU)
	// Clear the timer (STRM) and start on event 1
	// Transfer shadow registers on timer clear
	ccuConfigureSlice(0,
	    ccuEvent1(EVIS_INyI, EVEM_RISING, EVLM_HIGH, EVLPFM_0),
	    STRTS_EV1,
	    CMOD_COMPARE | CLST_ENABLE | STRM_BOTH,
	    PSC_FCCU_16,  // Prescaler: 64MHz / 16 = 4MHz
	    99, 50,  // 40kHz 50%
	    0, 0,    // No interrupts
	    0);      // Passive level low
	// Slice 1: Capture.
	// Event 0: 3 clock LPF, active high, rising edge, input B (P0.7)
	// Capture on event 0.
	// Event 1: active high, rising edge, input I (SCU.GSC40)
	// Clear the timer (STRM) and start on event 1.
	ccuConfigureSlice(1,
	    ccuEvent0(EVIS_INyB, EVEM_RISING, EVLM_HIGH, EVLPFM_3) |
	    ccuEvent1(EVIS_INyI, EVEM_RISING, EVLM_HIGH, EVLPFM_0),
	    CAP0S_EV0 | STRTS_EV1,
	    CMOD_CAPTURE | STRM_BOTH,
	    PSC_FCCU_16,  // Prescaler: 64MHz / 16 = 4MHz
	    0xffff, 0xffff,
	    INTE_E0AE_ENABLE,
	    SRS_E0SR_SR0,  // Event 0 generates interrupt SR0
	    0);  // Passive level low
	// CCU40 OUT0 is connected to P0.0, P0.5, P0.6, P1.0, P2.0.
	// P0.6: open drain PWM output. (CCU4.OUT0)
	// P1.0: push pull PWM output (LED). (CCU4.OUT0)
	// P0.7 pull up input to CCU slice 1 trigger capture.
	enablePin(1, 0, GPIO_OUT_PP_ALT2);  // LED P1.0 alt2 is CCU4.OUT0
	enablePin(0, 6, GPIO_OUT_PP_ALT4);  // P0.6 alt4 is CCU4.OUT0
	enablePin(0, 7, GPIO_IN_PU);

	// Clock = 64MHz so 8000000 - 1 is 8 systicks/second.
	systickEnable(8000000 - 1);

	enable_interrupts();

	// Start CCU slices 0 and 1
	ccuStartSlices(BIT1 | BIT0);

	while(1)
	{
		asm("wfi");
	}

	return 0;
}