Ejemplo n.º 1
0
/*********************************************************************//**
 * @brief 		Assign Capture Signals
 *                - CT16B0_CAP0 : PIO0_2
 *                - CT16B1_CAP0 : PIO1_8
 *                - CT32B0_CAP0 : PIO1_5
 *                - CT32B1_CAP0 : PIO1_0
 * @param[in]	TIMx Pointer to timer/counter device, can be LPC_TMR16B0,
 *                   LPC_TMR16B1, LPC_TMR32B0, LPC_TMR32B1 
 * @return 		None
 **********************************************************************/
void TIM_CapturePins(TMR_TypeDef *TIMx)
{
    CHECK_PARAM(PARAM_TIMx(TIMx));

    if        (TIMx == LPC_TMR16B0) {  /** CT16B0_CAP0 */
        IOCON_SetPinFunc(IOCON_PIO0_2, PIO0_2_FUN_CT16B0_CAP0);

    } else if (TIMx == LPC_TMR16B1) {  /** CT16B1_CAP0 */
        IOCON_SetPinFunc(IOCON_PIO1_8, PIO1_8_FUN_CT16B1_CAP0);
            
    } else if (TIMx == LPC_TMR32B0) {  /** CT32B0_CAP0 */
        IOCON_SetPinFunc(IOCON_PIO1_5, PIO1_5_FUN_CT32B0_CAP0); 
               
    } else if (TIMx == LPC_TMR32B1) {  /** CT32B1_CAP0 */
        IOCON_SetPinFunc(IOCON_PIO1_0, PIO1_0_FUN_CT32B1_CAP0);        
    }
}
Ejemplo n.º 2
0
/********************************************************************//**
 * @brief 		Init ADC AD input pins, pins assign:
 *                AD0 - PIO0_11
 *                AD1 - PIO1_0
 *                AD2 - PIO1_1
 *                AD3 - PIO1_2
 *                AD4 - PIO1_3
 *                AD5 - PIO1_4
 *                AD6 - PIO1_10
 *                AD7 - PIO1_11
 *              NOTE:AD0,AD1,AD2,AD3,AD4 are multiplexed with JTAG pins(SW)
 *
 * @param[in]	* @param[in]	Channel channel number           
 *
 * @return		None
 *********************************************************************/
void ADC_PinsInit(uint8_t channel)
{    
	uint32_t pin;
	CHECK_PARAM(PARAM_ADC_CHANNEL_SELECTION(channel));
    // alexk: CHECK_PARAM(PARAM_ADMODE(mod));

    /* Set AD function */
    switch(channel) {
    case 0:         /* AD Channel 0:  PIO0_11 */
        IOCON_SetPinFunc(IOCON_PIO0_11, PIO0_11_FUN_AD0);
        pin = IOCON_PIO0_11;
        break;
    case 1:         /* AD Channel 1:  PIO1_0  */
        IOCON_SetPinFunc(IOCON_PIO1_0, PIO1_0_FUN_AD1);
        pin = IOCON_PIO1_0;
        break;
    case 2:         /* AD Channel 2:  PIO1_1  */
        IOCON_SetPinFunc(IOCON_PIO1_1, PIO1_1_FUN_AD2);        
        pin = IOCON_PIO1_1;
        break;
    case 3:         /* AD Channel 3:  PIO1_2  */
        IOCON_SetPinFunc(IOCON_PIO1_2, PIO1_2_FUN_AD3);
        pin = IOCON_PIO1_2;
        break;
    case 4:         /* AD Channel 4:  PIO1_3  */
        IOCON_SetPinFunc(IOCON_PIO1_3, PIO1_3_FUN_AD4);
        pin = IOCON_PIO1_3;
        break;
    case 5:         /* AD Channel 5:  PIO1_4  */
        IOCON_SetPinFunc(IOCON_PIO1_4, PIO1_4_FUN_AD5);
        pin = IOCON_PIO1_4;
        break;
    case 6:         /* AD Channel 6:  PIO1_10 */
        IOCON_SetPinFunc(IOCON_PIO1_10, PIO1_10_FUN_AD6);
        pin = IOCON_PIO1_10;
        break;
    case 7:         /* AD Channel 7:  PIO1_11  */
        IOCON_SetPinFunc(IOCON_PIO1_11, PIO1_11_FUN_AD7);
        pin = IOCON_PIO1_11;
        break;
    default: return;
    };

   	*(uint32_t *)((uint32_t)&(LPC_IOCON->PIO2_6) + pin) &= ~ADC_PINS_MODE_MASK;
}
Ejemplo n.º 3
0
/*********************************************************************//**
 * @brief 		Assign External Match Output Pins
 * @param[in]	TIMx Pointer to timer/counter device, can be LPC_TMR16B0,
 *                   LPC_TMR16B1, LPC_TMR32B0, LPC_TMR32B1, pins assgign: 
 *                  16-bit Counter/Timer 0
 *                      - MAT0 : PIO0_8
 *                      - MAT1 : PIO0_9
 *                      - MAT2 : PIO0_10
 *                      - MAT3 : None pin out
 *                  16-bit Counter/Timer 1
 *                      - MAT0 : PIO1_9
 *                      - MAT1 : PIO1_10
 *                      - MAT2 : None pin out
 *                      - MAT3 : None pin out
 *                  32-bit Counter/Timer 0
 *                      - MAT0 : PIO1_6
 *                      - MAT1 : PIO1_7
 *                      - MAT2 : PIO0_1
 *                      - MAT3 : PIO0_11
 *                  32-bit Counter/Timer 1
 *                      - MAT0 : PIO1_1
 *                      - MAT1 : PIO1_2
 *                      - MAT2 : PIO1_3
 *                      - MAT3 : PIO1_4
 * @param[in]	matFlag, external Match Output, can be:
 *                   - TIM_PINS_MAT0 : External Match Output 0
 *                   - TIM_PINS_MAT1 : External Match Output 1 
 *                   - TIM_PINS_MAT2 : External Match Output 2 
 *                   - TIM_PINS_MAT3 : External Match Output 3
 * @return 		None
 **********************************************************************/
void TIM_MatchPins(TMR_TypeDef *TIMx, uint8_t matFlag)
{
    CHECK_PARAM(PARAM_TIMx(TIMx));
    CHECK_PARAM(PARAM_TIM_MAT_PINS(matFlag));
    
    // 16-bit counter/timer 0 external Match Output 
    if (TIMx == LPC_TMR16B0) {
        switch(matFlag) {
        case TIM_PINS_MAT0:
            IOCON_SetPinFunc(IOCON_PIO0_8, PIO0_8_FUN_CT16B0_MAT0); break;
        case TIM_PINS_MAT1:
            IOCON_SetPinFunc(IOCON_PIO0_9, PIO0_9_FUN_CT16B0_MAT1); break;
        case TIM_PINS_MAT2:
            IOCON_SetPinFunc(IOCON_PIO0_10, PIO0_10_FUN_CT16B0_MAT2); break;
        case TIM_PINS_MAT3:
            break;
        }    
    
    // 16-bit counter/timer 1 external Match Output 
    } else
    if (TIMx == LPC_TMR16B1) {
        switch(matFlag) {
        case TIM_PINS_MAT0:
            IOCON_SetPinFunc(IOCON_PIO1_9, PIO1_9_FUN_CT16B1_MAT0); break;
        case TIM_PINS_MAT1:
            IOCON_SetPinFunc(IOCON_PIO1_10, PIO1_10_FUN_CT16B1_MAT1); break;
        case TIM_PINS_MAT2:            
        case TIM_PINS_MAT3:
            break;
        }
    
    // 32-bit counter/timer 0 external Match Output 
    } else
    if (TIMx == LPC_TMR32B0) {
        switch(matFlag) {
        case TIM_PINS_MAT0:
            IOCON_SetPinFunc(IOCON_PIO1_6, PIO1_6_FUN_CT32B0_MAT0); break;
        case TIM_PINS_MAT1:
            IOCON_SetPinFunc(IOCON_PIO1_7, PIO1_7_FUN_CT32B0_MAT1); break;
        case TIM_PINS_MAT2:            
            IOCON_SetPinFunc(IOCON_PIO0_1, PIO0_1_FUN_CT32B0_MAT2); break;
        case TIM_PINS_MAT3:
            IOCON_SetPinFunc(IOCON_PIO0_11, PIO0_11_FUN_CT32B0_MAT3); break;
       }
    
    // 32-bit counter/timer 1 external Match Output 
    } else
    if (TIMx == LPC_TMR32B1) {
        switch(matFlag) {
        case TIM_PINS_MAT0:
            IOCON_SetPinFunc(IOCON_PIO1_1, PIO1_1_FUN_CT32B1_MAT0); break;
        case TIM_PINS_MAT1:
            IOCON_SetPinFunc(IOCON_PIO1_2, PIO1_2_FUN_CT32B1_MAT1); break;
        case TIM_PINS_MAT2:            
            IOCON_SetPinFunc(IOCON_PIO1_3, PIO1_3_FUN_CT32B1_MAT2); break;
        case TIM_PINS_MAT3:
            IOCON_SetPinFunc(IOCON_PIO1_4, PIO1_4_FUN_CT32B1_MAT3); break;
       }
    } 
        
}
Ejemplo n.º 4
0
int main()
{
    UART_CFG_Type uart_config;
    UART_FIFO_CFG_Type uart_fifo_config;
    TIM_TIMERCFG_Type timer_config;
    TIM_MATCHCFG_Type timer_match;
    OS_TID uart_task_id = 0;
    OS_TID activity_task_id = 0;
    uint32_t reset_flags = 0;

    reset_flags = LPC_SYSCON->SYSRSTSTAT;

    SEQ_Initialize();
    PROTO_Reset();
    PROTO_SetHandlers(g_protocol_handlers);

    SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);

    // Reset pin
    IOCON_SetPinFunc(IOCON_PIO0_0, PIO0_0_FUN_RESET);

    // Status LED pin
    ACTIVITY_SET_PIN();
    GPIO_SetDir(ACTIVITY_PORT, ACTIVITY_PIN, 1);
    GPIO_ResetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    // Timer activity LED pin
    TIMER_ACTIVITY_SET_PIN();
    GPIO_SetDir(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN, 1);
    GPIO_ResetBits(TIMER_ACTIVITY_PORT, TIMER_ACTIVITY_PIN);

    // RGB control
    RED_SET_PIN();
    GREEN_SET_PIN();
    BLUE_SET_PIN();
    GPIO_SetDir(RED_PORT, RED_PIN, 1);
    GPIO_SetDir(GREEN_PORT, GREEN_PIN, 1);
    GPIO_SetDir(BLUE_PORT, BLUE_PIN, 1);
    GPIO_ResetBits(RED_PORT, RED_PIN);
    GPIO_ResetBits(GREEN_PORT, GREEN_PIN);
    GPIO_ResetBits(BLUE_PORT, BLUE_PIN);

    timer_config.PrescaleOption = TIM_PRESCALE_TICKVAL;
    timer_config.PrescaleValue = 1;
    TIM_Init(LPC_TMR32B0, TIM_TIMER_MODE, &timer_config);

    timer_match.MatchChannel = 0;
    timer_match.IntOnMatch = ENABLE;
    timer_match.StopOnMatch = DISABLE;
    timer_match.ResetOnMatch = ENABLE;
    timer_match.ExtMatchOutputType = 0;
    timer_match.MatchValue = SystemCoreClock / (TICKS_PER_SECOND * 256);
    TIM_ConfigMatch(LPC_TMR32B0, &timer_match);

    TIM_Cmd(LPC_TMR32B0, ENABLE);
    NVIC_EnableIRQ(TIMER_32_0_IRQn);

    // UART
    IOCON_SetPinFunc(IOCON_PIO1_6, PIO1_6_FUN_RXD);   /* UART RXD - PIO1_6 */
    IOCON_SetPinFunc(IOCON_PIO1_7, PIO1_7_FUN_TXD);   /* UART RXD - PIO1_7 */

    uart_config.Baud_rate = 115200;
    uart_config.Databits = UART_DATABIT_8;
    uart_config.Parity = UART_PARITY_NONE;
    uart_config.Stopbits = UART_STOPBIT_1;

    UART_Init(LPC_UART, &uart_config);

    uart_fifo_config.FIFO_Level = UART_FIFO_TRGLEV0;
    uart_fifo_config.FIFO_ResetRxBuf = ENABLE;
    uart_fifo_config.FIFO_ResetTxBuf = ENABLE;
    UART_FIFOConfig(LPC_UART, &uart_fifo_config);

    UART_TxCmd(LPC_UART, ENABLE);

    // SPI
    CL632_Init();
    // Select page 0 and no paging access
    CL632_SpiWriteByte(0x00, 0x00);
    CL632_SpiWriteByte(0x00, 0x00);

    // LCD
    // LCD backlite control
    LCD_BACKLITE_SET_PIN();
    GPIO_SetDir(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN, 1);
    GPIO_ResetBits(LCD_BACKLITE_PORT, LCD_BACKLITE_PIN);

    // LCD Data bus
    LCD_DATA_SET_PINS();
    GPIO_SetDir(LCD_DATA_PORT, LCD_DATA_BUS, 1);
    GPIO_ResetBits(LCD_DATA_PORT, LCD_DATA_BUS);

    LCD_RS_SET_PIN();
    GPIO_SetDir(LCD_RS_PORT, LCD_RS_PIN, 1);
    GPIO_ResetBits(LCD_RS_PORT, LCD_RS_PIN);

    LCD_RW_SET_PIN();
    GPIO_SetDir(LCD_RW_PORT, LCD_RW_PIN, 1);
    GPIO_ResetBits(LCD_RW_PORT, LCD_RW_PIN);

    LCD_E_SET_PIN();
    GPIO_SetDir(LCD_E_PORT, LCD_E_PIN, 1);
    GPIO_ResetBits(LCD_E_PORT, LCD_E_PIN);

    KS0066_PowerUpDelay();
    KS0066_FunctionSet();
    KS0066_WaitForIdle();
    KS0066_DisplayOnOffControl(KS0066_DISPCTL_DISPLAY_ON);
    KS0066_WaitForIdle();
    KS0066_ClearDisplay();
    KS0066_WaitForIdle();

    CoInitOS();
    GPIO_SetBits(ACTIVITY_PORT, ACTIVITY_PIN);

    uart_task_id = CoCreateTask(uartTask, NULL, UART_TASK_PRIORITY,
            GetStackTop(uartTaskStack), GetStackSize(uartTaskStack));

    activity_task_id = CoCreateTask(activityTask, NULL, ACTIVITY_TASK_PRIORITY,
            GetStackTop(activityTaskStack), GetStackSize(activityTaskStack));

    if (uart_task_id == E_CREATE_FAIL || activity_task_id == E_CREATE_FAIL) {
        UART_PrintString("INIT ERROR");
        UART_PrintString(kNewLine);
    }

    if (reset_flags & 0x01)
        UART_PrintString("RST:PU");
    else if (reset_flags & 0x02)
        UART_PrintString("RST:RST");
    else if (reset_flags & 0x04)
        UART_PrintString("RST:WDT");
    else if (reset_flags & 0x08)
        UART_PrintString("RST:BOD");
    else if (reset_flags & 0x10)
        UART_PrintString("RST:SOFT");
    else
        UART_PrintString("RST");

    UART_PrintString(kNewLine);

    PrintVersionString(UART_WriteChar);
    UART_PrintString(kNewLine);
    func_printf_nofloat(UART_WriteChar, "COOS:%d\r\n", CoGetOSVersion());

    KS0066_WriteString("V:" __DATE__ " " __TIME__, KS0066_WRAP_FLAG);

    CoStartOS();

    //while (1) {
    //}

    return 0;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: inf3ct3d/fmtr
int main ()
{
	//int i, j;
//	TIM_TIMERCFG_Type timer_config;
//	TIM_MATCHCFG_Type match_config;
	UART_CFG_Type cfg;
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;

	/******************** GPIO **********************************/
	SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_GPIO, ENABLE);
	GPIO_SetDir(PORT0, GPIO_Pin_7, 1);
	GPIO_SetDir(PORT3, GPIO_Pin_3, 0);

	IOCON_SetPinMode(IOCON_PIO3_3, PIN_MODE_PullUp);
	IOCON_SetPinMode(IOCON_PIO0_7, PIN_MODE_PullUp);
	/*************************************************************/

	/******************* LCD ***********************************/
	lcd_init();
	lcd_string(" ** Flow Meter ** ", 1);
	/************************************************************/

	/****************** 32 bit Counter ****************************/
	IOCON_SetPinFunc(IOCON_PIO1_5, PIO1_5_FUN_CT32B0_CAP0);
	SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_CT32B0, ENABLE);
	LPC_TMR32B0->CTCR = (1<<0);

//	LPC_TMR32B0->TCR = (1<<1);
//	LPC_TMR32B0->TCR = (1<<0);
	/***************************************************************/

	/****************** External Interrupt on GPIO *********************/
	gpio_init_config ();
	GPIO_EventInit(&gpio_int_struct);
	GPIO_PortIntCmd(PORT3, ENABLE);
	/*******************************************************************/

	/*************************** UART **************************************/
	/* Assign UART Pins */
	UART_PinsInit();

	cfg.Baud_rate = 115200;
	cfg.Parity = UART_PARITY_NONE;
	cfg.Databits = UART_DATABIT_8;
	cfg.Stopbits = UART_STOPBIT_1;
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	UART_Init(LPC_UART, &cfg);
	UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);

	/* Enable Transmit */
	UART_TxCmd(LPC_UART,ENABLE);


	/************************************************************************/

	/******************************** SPI *********************************/
	DAC_SPI1_Config ();
	/***********************************************************************/

	/************************ 32 Bit Timer1 ******************************/
	NVIC_EnableIRQ(TIMER_32_1_IRQn);
	/* Configure Timer Prescale */
	timer_config.PrescaleOption = TIM_PRESCALE_TICKVAL;
	/* We have a 48MHz clock, so a prescale of 48000 will mean the main timer ticks every millisecond. */
	timer_config.PrescaleValue = 11999;
	/* Init! */
	TIM_Init(LPC_TMR32B1, TIM_TIMER_MODE, &timer_config);
	/* COnfigure Timer Match */
	/* Match on channel 0 */
	match_config.MatchChannel = 0;
	/* Interrupt on match */
	match_config.IntOnMatch =   TIM_INT_ON_MATCH(0);
	/* Reset the timer on match */
	match_config.ResetOnMatch = TIM_RESET_ON_MATCH(0);
	/* Match on a count of 75, so interrupt every 75 milliseconds */
	match_config.MatchValue = 4000U;
	/*  Config the match */
	TIM_ConfigMatch(LPC_TMR32B1, &match_config);
	/* Clear the timer, and then start it */
	TIM_Cmd(LPC_TMR32B1, TIM_RESET);
	TIM_Cmd(LPC_TMR32B1, TIM_ENABLE);
	/******************************************************************/
	while(1)
	{
		// DAC_SPI1_Write(0x0E8B); // 3V
		//DAC_SPI1_Write(0x09b2); // 2V
		//DAC_SPI1_Write(0x04D9); // 1V
		//UART_Send(LPC_UART, (uint8_t *)"Hello, World!\n", sizeof("Hello, World!\n") - 1, NONE_BLOCKING);
		//_delay_ms(1000);

		Flow_Uart_Send (1, 5);
		_delay_ms(1);
		Flow_Uart_Send (20, 5);
		_delay_ms(1);
		Flow_Uart_Send (300, 5);
		_delay_ms(1);
		Flow_Uart_Send (4000, 5);
		_delay_ms(1);
		Flow_Uart_Send (50000, 5);

		//idle
	}
}