Ejemplo n.º 1
0
void get_mac_addr(uint8_t *mac_buf) {
	PINSEL_CFG_Type PinCfg;
	I2C_M_SETUP_Type transferMCfg;

	uint8_t eeprom_addr = EEPROM_ADDR;

	/* Configure I2C0 */
	PinCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
	PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
	PinCfg.Funcnum = 1;
	PinCfg.Pinnum = 27;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);
	// Initialize Slave I2C peripheral
	/* Set up clock and power for I2C0 module */
	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, ENABLE);
	/* As default, peripheral clock for I2C0 module
	 * is set to FCCLK / 2 */
	CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2C0, CLKPWR_PCLKSEL_CCLK_DIV_2);


	transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
	transferMCfg.tx_data = &eeprom_addr;
	transferMCfg.tx_length = 1;
	transferMCfg.rx_data = mac_buf;
	transferMCfg.rx_length = MAC_ADDR_SIZE;
	transferMCfg.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C0, &transferMCfg, I2C_TRANSFER_POLLING);

	/** deinitialize I2C0 */
	LPC_I2C0->I2CONCLR = I2C_I2CONCLR_I2ENC;
	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, DISABLE);
}
Ejemplo n.º 2
0
/*********************************************************************//**
 * @brief		c_entry: Main CAN program body
 * @param[in]	none
 * @return 		int
 **********************************************************************/
int c_entry(void) { /* Main Program */
	PINSEL_CFG_Type PinCfg;

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();
	print_menu();

	/* Pin configuration
	 * CAN1: select P0.0 as RD1. P0.1 as TD1
	 * CAN2: select P2.7 as RD2, P2.8 as RD2
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 0;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 1;
	PINSEL_ConfigPin(&PinCfg);

	PinCfg.Pinnum = 7;
	PinCfg.Portnum = 2;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 8;
	PINSEL_ConfigPin(&PinCfg);

	//Initialize CAN1 & CAN2
	CAN_Init(LPC_CAN1, 125000);
	CAN_Init(LPC_CAN2, 125000);

	//Enable Interrupt
	CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE);

	//Enable CAN Interrupt
	NVIC_EnableIRQ(CAN_IRQn);

	_DBG_("CAN test Bypass Mode function...");
	_DBG_("Press '1' to initialize CAN message...");_DBG_("");
	while(_DG !='1');
	CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
	CAN_InitMessage();
	PrintMessage(&TXMsg);
	_DBG_("Message ID and data will be increased continuously...");

	_DBG_("Press '2' to start CAN operation...");
	while(_DG !='2');

	/** To test Bypass Mode: we send infinite messages to CAN2 and check
	 * receive process via COM1
	 */
	CAN_SendMsg(LPC_CAN1, &TXMsg);

	while (1);
}
Ejemplo n.º 3
0
static void init_ssp(void)
{
	SSP_CFG_Type SSP_ConfigStruct;
	PINSEL_CFG_Type PinCfg;

	/*
	 * Initialize SPI pin connect
	 * P0.7 - SCK;
	 * P0.8 - MISO
	 * P0.9 - MOSI
	 * P2.2 - SSEL - used as GPIO
	 */
	PinCfg.Funcnum = 2;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 0;
	PinCfg.Pinnum = 7;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 8;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 9;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Funcnum = 0;
	PinCfg.Portnum = 2;
	PinCfg.Pinnum = 2;
	PINSEL_ConfigPin(&PinCfg);

	SSP_ConfigStructInit(&SSP_ConfigStruct);

	// Initialize SSP peripheral with parameter given in structure above
	SSP_Init(LPC_SSP1, &SSP_ConfigStruct);

	// Enable SSP peripheral
	SSP_Cmd(LPC_SSP1, ENABLE);
}
Ejemplo n.º 4
0
void USART_Init(void)
{
    UART_CFG_Type UARTConfigStruct;
    UART_FIFO_CFG_Type UARTFIFOConfigStruct;

    PINSEL_ConfigPin(0,2,1);
    PINSEL_ConfigPin(0,3,1);

    UART_ConfigStructInit(&UARTConfigStruct);

    UART_Init(USART_ID, &UARTConfigStruct);

    UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
#if     USART_FIFO_LEVEL == 1
    UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV0;
#elif   USART_FIFO_LEVEL == 4
    UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV1;
#elif   USART_FIFO_LEVEL == 8
    UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV2;
#elif   USART_FIFO_LEVEL == 14
    UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV3;
#endif

    UART_FIFOConfig(USART_ID, &UARTFIFOConfigStruct);


    UART_TxCmd(USART_ID, ENABLE);
    UART_IntConfig(USART_ID, UART_INTCFG_RBR, ENABLE);
    UART_IntConfig(USART_ID, UART_INTCFG_RLS, ENABLE);
    UART_IntConfig(USART_ID, UART_INTCFG_THRE, ENABLE);

    NVIC_SetPriority(USART_IRQ, ((0x01<<3)|0x01));

    NVIC_EnableIRQ(USART_IRQ);
}
Ejemplo n.º 5
0
void serial_init(void) {
	PINSEL_CFG_Type PinCfg;
	UART_CFG_Type UARTConfigStruct;
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;

	//Init pins
	PinCfg.Funcnum = PINSEL_FUNC_1;
	PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
	PinCfg.Portnum = PINSEL_PORT_0;
	PinCfg.Pinnum = PINSEL_PIN_2;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = PINSEL_PIN_3;
	PINSEL_ConfigPin(&PinCfg);
		
	//Init UART Configuration parameter structure to default state: 115200,8,1,N
	UART_ConfigStructInit(&UARTConfigStruct);
	UARTConfigStruct.Baud_rate = 115200;

	//Init FIFOConfigStruct using defaults
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	//Start the devices USB serial
	UART_Init((LPC_UART_TypeDef *)LPC_UART0, &UARTConfigStruct);
	UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &UARTFIFOConfigStruct);
	UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE);
}
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
	PINSEL_CFG_Type PinCfg;

	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	PinCfg.Pinnum = 10;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 11;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 12;
	PINSEL_ConfigPin(&PinCfg);

    /* is Input */
    GPIO_SetDir(2, (1<<10), 0);
    GPIO_SetDir(2, (1<<11), 0);
    GPIO_SetDir(2, (1<<12), 0);

	/* Enable system update tick timer */
	GPIO_SetDir(LED1_GPIO_PORT_NUM,(1<<LED1_GPIO_BIT_NUM),1); // output
	GPIO_SetDir(LED2_GPIO_PORT_NUM,(1<<LED2_GPIO_BIT_NUM),1); // output

	init_timer( 0, TIMER0_INTERVAL );

	Serial_Init(115200, false);
	LEDs_Init();
	USB_Init();

	/* Create a stdio stream for the serial port for stdin and stdout */
	Serial_CreateStream(NULL);

	//USB_Init();
}
Ejemplo n.º 7
0
Archivo: uart.c Proyecto: nedos/ddk-arm
void uart0_shutdown(void)
{

    puts("");

    UART_CFG_Type UARTConfigStruct;
    PINSEL_CFG_Type PinCfg;

    PinCfg.Portnum = UART0_PORTNUM;
    PinCfg.Pinnum = UART0_TX_PINNUM;
    PinCfg.Funcnum = 0;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = UART0_RX_PINNUM;
    PINSEL_ConfigPin(&PinCfg);

    GPIO_SetDir(UART0_PORTNUM, (1<<UART0_TX_PINNUM), 1);
    GPIO_SetValue(UART0_PORTNUM, (1<<UART0_TX_PINNUM));

    UART_TxCmd((LPC_UART_TypeDef *)CONSOLE_UART_PORT, DISABLE);

    UART_IntConfig((LPC_UART_TypeDef *)CONSOLE_UART_PORT, UART_INTCFG_RBR, DISABLE);
    NVIC_DisableIRQ(UART0_IRQn);
}
Ejemplo n.º 8
0
SMB380_Status_t SMB380_Init(void)
{
    unsigned char Data[2];

    //Init I2C module as master
    PINSEL_ConfigPin (2, 14, 2);
    PINSEL_ConfigPin (2, 15, 2);
    I2C_Init(I2C_1, SMB380_SPEED);
    I2C_Cmd(I2C_1,I2C_MASTER_MODE, ENABLE);

    Data[0] = 0x14;
    SMB380_ReadWrite(&Data[0], 1, NULL, 0);
    SMB380_ReadWrite(NULL, 0, &Data[1], 1);

    Data[1] &= ~(0x1F<<0);
    Data[1] |= (0x08<<0);
    //I2C_MasterWrite(SMB380_ADDR, &Data[0], 2);
    SMB380_ReadWrite(&Data[0], 2, NULL, 0);


    Data[0] = 0x15;
    SMB380_ReadWrite(&Data[0], 1, NULL, 0);
    SMB380_ReadWrite(NULL, 0, &Data[1], 1);

    Data[1] &= ~(3<<1);
    Data[1] |= ((1<<5) | (1<<0));
    SMB380_ReadWrite(&Data[0], 2, NULL, 0);

    return SMB380_PASS;
}
Ejemplo n.º 9
0
/* enable FPGA EN_CORE and EN_IO */
void io_init_fpga_pwrenable(void)
{
    uint32_t i=0;

    PinCfg.Funcnum      = 0;
    PinCfg.OpenDrain    = 0;
    PinCfg.Pinmode      = 0;


    // 1V5 core voltage
    PinCfg.Pinnum       = FPGA_CORE_EN_PIN;
    PinCfg.Portnum      = FPGA_CORE_EN_PORT;
    PINSEL_ConfigPin(&PinCfg);
    GPIO_SetDir(FPGA_CORE_EN_PORT, FPGA_CORE_EN, POUT);
    fpga_pwr_enable_core_low();

    // 3V3 IO voltage
    PinCfg.Pinnum       = FPGA_IO_EN_PIN;
    PinCfg.Portnum      = FPGA_IO_EN_PORT;
    PINSEL_ConfigPin(&PinCfg);
    GPIO_SetDir(FPGA_IO_EN_PORT, FPGA_IO_EN, POUT);
    fpga_pwr_enable_io_low();

    return;
}
Ejemplo n.º 10
0
/*******************************************************************************
* Function Name  : TP_Init
* Description    : TSC2046 Initialization
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TP_Init(void) 
{
    SSP_CFG_Type SSP_ConfigStruct;
	/*
	 * Initialize SPI pin connect
	 * P2.23 - TP_CS - used as GPIO
	 * P2.22 - SCK
	 * P2.26 - MISO
	 * P2.27 - MOSI
	 */

	PINSEL_ConfigPin(2, 23, 0);
	PINSEL_ConfigPin(2, 22, 2);
	PINSEL_ConfigPin(2, 26, 2);
	PINSEL_ConfigPin(2, 27, 2);

    /* P0.16 CS is output */
    GPIO_SetDir(TP_CS_PORT_NUM, (1<<TP_CS_PIN_NUM), 1);
	GPIO_SetValue(TP_CS_PORT_NUM, (1<<TP_CS_PIN_NUM));  

  	PINSEL_ConfigPin(2, 11, 0);	  
	GPIO_SetDir(2, (1<<11), 0);	  /* P2.11 TP_INT is input */

	/* initialize SSP configuration structure to default */
	SSP_ConfigStructInit(&SSP_ConfigStruct);

	SSP_ConfigStruct.ClockRate = 250000;
	SSP_ConfigStruct.CPHA = SSP_CPHA_FIRST;	   //SSP_CPHA_SECOND   SSP_CPHA_FIRST
	SSP_ConfigStruct.CPOL = SSP_CPOL_HI;		  //SSP_CPOL_LO	  SSP_CPOL_HI

	/* Initialize SSP peripheral with parameter given in structure above */
	SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
	/* Enable SSP peripheral */
	SSP_Cmd(LPC_SSP0, ENABLE);
}
Ejemplo n.º 11
0
void analogSensorsInit(void)
{

	// pin configuration for AirSpeed Sensor
	PINSEL_CFG_Type airPin_intStr;
	// pin configuration for UltraSonic Distance Sensor
	PINSEL_CFG_Type usonicPin_intStr;

	//Setup Air Speed Sensor Pin
	airPin_intStr.Funcnum   = AIR_PIN_FUNC;
	airPin_intStr.OpenDrain = PINSEL_PINMODE_NORMAL;
	airPin_intStr.Pinmode   = PINSEL_PINMODE_PULLUP;
	airPin_intStr.Pinnum    = AIR_PIN;
	airPin_intStr.Portnum   = AIR_PORT;
	PINSEL_ConfigPin(&airPin_intStr);

	//UltraSonic Sensor Pin
	usonicPin_intStr.Funcnum   = USON_PIN_FUNC;
	usonicPin_intStr.OpenDrain = PINSEL_PINMODE_NORMAL;
	usonicPin_intStr.Pinmode   = PINSEL_PINMODE_PULLUP;
	usonicPin_intStr.Pinnum    = USON_PIN;
	usonicPin_intStr.Portnum   = USON_PORT;
	PINSEL_ConfigPin(&usonicPin_intStr);

	// set AD Conversion speed
	ADC_Init(LPC_ADC, 200000);
	// disable the interrupt
	ADC_IntConfig (LPC_ADC, ADC_ADGINTEN, SET);
	// enable the ADC channels
	ADC_ChannelCmd(LPC_ADC, AIR_CHAN, ENABLE);
	ADC_ChannelCmd(LPC_ADC, USON_CHAN, ENABLE);
}
Ejemplo n.º 12
0
Bool ADC_init()
{
	PINSEL_CFG_Type PinCfg1;
	PinCfg1.Funcnum = 1;
	PinCfg1.OpenDrain = 0;
	PinCfg1.Pinmode = 0;
	PinCfg1.Pinnum = 25;
	PinCfg1.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg1);

	PINSEL_CFG_Type PinCfg2;
	PinCfg2.Funcnum = 1;
	PinCfg2.OpenDrain = 0;
	PinCfg2.Pinmode = 0;
	PinCfg2.Pinnum = 24;
	PinCfg2.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg2);

	PINSEL_CFG_Type PinCfg3;
	PinCfg3.Funcnum = 1;
	PinCfg3.OpenDrain = 0;
	PinCfg3.Pinmode = 0;
	PinCfg3.Pinnum = 23;
	PinCfg3.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg3);

	ADC_Init(LPC_ADC, 10000);

	return TRUE;
}
Ejemplo n.º 13
0
void Init_LCD_Pins(void)
{
    // Configure other pins used by the ILI9341 LCD
    // P0.2 = CS, P0.3 = Reset, P0.21 = DC
    PINSEL_CFG_Type LCDPin;
    LCDPin.Portnum = LCD_CS_PORT;
    LCDPin.Pinnum = LCD_CS_PIN;
    LCDPin.Funcnum = PINSEL_FUNC_0; // Use as GPIO
    LCDPin.OpenDrain = PINSEL_PINMODE_NORMAL;
    LCDPin.Pinmode = PINSEL_PINMODE_PULLUP;
    PINSEL_ConfigPin(&LCDPin);
    LCDPin.Portnum = LCD_RESET_PORT;
    LCDPin.Pinnum = LCD_RESET_PIN;
    PINSEL_ConfigPin(&LCDPin);
    LCDPin.Portnum = LCD_DC_PORT;
    LCDPin.Pinnum = LCD_DC_PIN;
    PINSEL_ConfigPin(&LCDPin);

    // Declare LCD pins as output, disable pin masking
    GPIO_SetDir(LCD_CS_PORT, (1 << LCD_CS_PIN), GPIO_DIR_OUTPUT); 	// CS
    GPIO_SetDir(LCD_RESET_PORT, (1 << LCD_RESET_PIN), GPIO_DIR_OUTPUT); 	// Reset
    GPIO_SetDir(LCD_DC_PORT, (1 << LCD_DC_PIN), GPIO_DIR_OUTPUT); 	// DC

    // Initialize CS to 1
	LCD_CS(1);
}
Ejemplo n.º 14
0
void spi_configure (tPinDef SClk, tPinDef Mosi, tPinDef Miso, tPinDef SSel)
{
  PINSEL_CFG_Type PinCfg;

  /*
   * Initialize SPI pin connect
   */
   
  /* SSEL as GPIO, pull-up mounted */
  PinCfg.Funcnum   = PINSEL_FUNC_0;
  PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
  PinCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinCfg.Portnum   = SSel.port;
  PinCfg.Pinnum    = SSel.pin_number;
  GPIO_SetDir(SSel.port, _BV(SSel.pin_number), 1);
  PINSEL_ConfigPin(&PinCfg);

  /* SCK alternate function 0b10 */
  PinCfg.Funcnum   = PINSEL_FUNC_2;
  PinCfg.Pinmode   = PINSEL_PINMODE_PULLDOWN;
  PinCfg.Portnum   = SClk.port;
  PinCfg.Pinnum    = SClk.pin_number;
  PINSEL_ConfigPin(&PinCfg);

  /* MISO */
  PinCfg.Pinmode   = PINSEL_PINMODE_PULLUP;
  PinCfg.Portnum   = Miso.port;
  PinCfg.Pinnum    = Miso.pin_number;
  PINSEL_ConfigPin(&PinCfg);

  /* MOSI */
  PinCfg.Portnum   = Mosi.port;
  PinCfg.Pinnum    = Mosi.pin_number;
  PINSEL_ConfigPin(&PinCfg);
 }
Ejemplo n.º 15
0
void uart_init() {

	UART_CFG_Type cfg;
	UART_FIFO_CFG_Type fifo_cfg;

	UART_ConfigStructInit(&cfg);
	cfg.Baud_rate = 57600;

	PINSEL_CFG_Type PinCfg;

	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 2;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 3;
	PINSEL_ConfigPin(&PinCfg);

	UART_Init(LPC_UART0, &cfg);

	UART_FIFOConfigStructInit(&fifo_cfg);

	UART_FIFOConfig(LPC_UART0, &fifo_cfg);

	UART_TxCmd(LPC_UART0, ENABLE);

}
Ejemplo n.º 16
0
void LED_Init (void)
{
	PINSEL_CFG_Type PinCfg;

	uint8_t temp;

	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	for (temp = 2; temp <= 6; temp++){
		PinCfg.Pinnum = temp;
		PINSEL_ConfigPin(&PinCfg);
	}

	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 29;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 31;
	PINSEL_ConfigPin(&PinCfg);

	// Set direction to output
	GPIO_SetDir(2, LED2_MASK, 1);
	GPIO_SetDir(1, LED1_MASK, 1);

	/* Turn off all LEDs */
	GPIO_ClearValue(2, LED2_MASK);
	GPIO_ClearValue(1, LED1_MASK);
}
Ejemplo n.º 17
0
void LED_Init (void)
{
	PINSEL_CFG_Type PinCfg;

	uint8_t temp;

	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 2;
	for (temp = 2; temp <= 6; temp++){
		PinCfg.Pinnum = temp;
		PINSEL_ConfigPin(&PinCfg);
	}

	PinCfg.Funcnum = 0;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 29;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 31;
	PINSEL_ConfigPin(&PinCfg);


	// Set direction to output
	LPC_GPIO2->FIODIR |= LED2_MASK;
	LPC_GPIO1->FIODIR |= LED1_MASK;

	/* Turn off all LEDs */
	LPC_GPIO2->FIOCLR = LED2_MASK;
	LPC_GPIO1->FIOCLR = LED1_MASK;
}
Ejemplo n.º 18
0
Archivo: uart.c Proyecto: nedos/ddk-arm
void uart2_init(const uint32_t BaudRate, const bool DoubleSpeed)
{
    UART_CFG_Type UARTConfigStruct;
    PINSEL_CFG_Type PinCfg;

    PinCfg.Portnum = UART2_PORTNUM;
    PinCfg.Pinnum = UART2_TX_PINNUM;
    PinCfg.Funcnum = UART2_FUNCNUM;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = UART2_RX_PINNUM;
    PINSEL_ConfigPin(&PinCfg);

    /* Initialize UART Configuration parameter structure to default state:
     * Baudrate = 9600bps
     * 8 data bit
     * 1 Stop bit
     * None parity
     */
    UART_ConfigStructInit(&UARTConfigStruct);
    // Re-configure baudrate
    UARTConfigStruct.Baud_rate = BaudRate;

    // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
    UART_Init((LPC_UART_TypeDef *)FPGA_UART_PORT, &UARTConfigStruct);

    // Enable UART Transmit
    UART_TxCmd((LPC_UART_TypeDef *)FPGA_UART_PORT, ENABLE);

    UART_IntConfig((LPC_UART_TypeDef *)FPGA_UART_PORT, UART_INTCFG_RBR, ENABLE);
    NVIC_EnableIRQ(UART2_IRQn);
}
Ejemplo n.º 19
0
void sio_init(void)
{
	//LPC_USART_3
	PINSEL_CFG_Type PinSelCfg;
	UART_CFG_Type UartCFG_Struct;
	UART_FIFO_CFG_Type UART_FIFO_CFG_Struct;


	// P4_28
	PinSelCfg.Portnum = PINSEL_PORT_4;
	PinSelCfg.Pinnum = PINSEL_PIN_28;
	PinSelCfg.Funcnum = PINSEL_FUNC_3;
	PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP;
	PINSEL_ConfigPin(&PinSelCfg);
	// P4_29
	PinSelCfg.Pinnum = PINSEL_PIN_29;
	PINSEL_ConfigPin(&PinSelCfg);

	uartDataToSend.currPtr = 0;
	uartDataToSend.lastPtr = 0;
	/* Initialize UART Configuration parameter structure to default state:
	 * Baudrate = 9600bps
	 * 8 data bit
	 * 1 Stop bit
	 * None parity
	*/
	UART_ConfigStructInit(&UartCFG_Struct);

	/* Set Baudrate to 115200 */
	UartCFG_Struct.Baud_rate = 115200;

	/* Initialize UART3 peripheral with given to corresponding parameter */
	UART_Init(SERIAL_USART, &UartCFG_Struct);

	/* Initialize FIFOConfigStruct to default state:
	 * 				- FIFO_DMAMode = DISABLE
	 * 				- FIFO_Level = UART_FIFO_TRGLEV0
	 * 				- FIFO_ResetRxBuf = ENABLE
	 * 				- FIFO_ResetTxBuf = ENABLE
	 * 				- FIFO_State = ENABLE
	 */
	UART_FIFOConfigStructInit(&UART_FIFO_CFG_Struct);

	/* Initialize FIFO for UART3 peripheral */
	UART_FIFOConfig(SERIAL_USART, &UART_FIFO_CFG_Struct);

	/*  Enable UART Transmit */
	UART_TxCmd(SERIAL_USART, ENABLE);

	UART_IntConfig(SERIAL_USART, UART_INTCFG_THRE, ENABLE);

	NVIC_SetPriorityGrouping(UART3_PriorGrup);
	NVIC_SetPriority(UART3_IRQn, UART3_Prior);

	NVIC_EnableIRQ(UART3_IRQn);


}
Ejemplo n.º 20
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	PINSEL_CFG_Type PinCfg;
	TIM_TIMERCFG_Type TIM_ConfigStruct;
	TIM_MATCHCFG_Type TIM_MatchConfigStruct;

	// Conifg P1.28 as MAT0.0
	PinCfg.Funcnum = 3;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);

	/* P3.26 as STCLK */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Portnum = 3;
	PinCfg.Pinnum = 26;
	PINSEL_ConfigPin(&PinCfg);

	// Initialize timer 0, prescale count time of 10uS
	TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	TIM_ConfigStruct.PrescaleValue	= 10;

	// use channel 0, MR0
	TIM_MatchConfigStruct.MatchChannel = 0;
	// Disable interrupt when MR0 matches the value in TC register
	TIM_MatchConfigStruct.IntOnMatch   = TRUE;
	//Enable reset on MR0: TIMER will reset if MR0 matches it
	TIM_MatchConfigStruct.ResetOnMatch = TRUE;
	//Stop on MR0 if MR0 matches it
	TIM_MatchConfigStruct.StopOnMatch  = FALSE;
	//Toggle MR0.0 pin if MR0 matches it
	TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
	// Set Match value, count value of 10 (10 * 10uS = 100uS --> 10KHz)
	TIM_MatchConfigStruct.MatchValue   = 10;

	TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
	TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
	TIM_Cmd(LPC_TIM0,ENABLE);

	GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output

	//Use P0.0 to test System Tick interrupt
	/* Initialize System Tick with 10ms time interval
	 * Frequency input = 10kHz /2 = 5kHz
	 * Time input = 10ms
	 */
	SYSTICK_ExternalInit(5000, 10);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
Ejemplo n.º 21
0
/*
*@描述:初始化串口
*@参数:void
*@返回:无
*/
void InitUart(void)
{
	// UART Configuration structure variable
	UART_CFG_Type UARTConfigStruct;
	// UART FIFO configuration Struct variable
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;
	// Pin configuration for UART0
	PINSEL_CFG_Type PinCfg;
	/*
	 * Initialize UART pin connect
	 */
	PinCfg.OpenDrain = UARTOpendrain;
	PinCfg.Pinmode = UARTPinMode;
	PinCfg.Portnum = UARTPortTX;
	PinCfg.Pinnum = UARTPinTX;
	PinCfg.Funcnum = UARTFuncTX;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Portnum = UARTPortRX;
	PinCfg.Pinnum = UARTPinRX;
	PinCfg.Funcnum = UARTFuncRX;
	PINSEL_ConfigPin(&PinCfg);
	/* Initialize UART Configuration parameter structure to default state:
	 * Baudrate = 9600bps
	 * 8 data bit
	 * 1 Stop bit
	 * None parity
	 */
	UART_ConfigStructInit(&UARTConfigStruct);
	// Re-configure baudrate to 57600bps
	UARTConfigStruct.Baud_rate = 57600;
	// Initialize UART peripheral with given to corresponding parameter
	UART_Init((LPC_UART_TypeDef *)_LPC_UART, &UARTConfigStruct);
	/* Initialize FIFOConfigStruct to default state:
	 * 				- FIFO_DMAMode = DISABLE
	 * 				- FIFO_Level = UART_FIFO_TRGLEV0
	 * 				- FIFO_ResetRxBuf = ENABLE
	 * 				- FIFO_ResetTxBuf = ENABLE
	 * 				- FIFO_State = ENABLE
	 */
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
	UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV3;//8 character 
	// Initialize FIFO for UART0 peripheral
	UART_FIFOConfig((LPC_UART_TypeDef *)_LPC_UART, &UARTFIFOConfigStruct);


	// Enable UART Transmit
	UART_TxCmd((LPC_UART_TypeDef *)_LPC_UART, ENABLE);

    /* Enable UART Rx interrupt */
	UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RBR, ENABLE);
	/* Enable UART line status interrupt */
	UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RLS, DISABLE);
	/* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(_UART_IRQ, ((0x01<<3)|0x01));
	/* Enable Interrupt for UART channel */
    NVIC_EnableIRQ(_UART_IRQ);
	BufInit(&bufSerialRec);
	
}
Ejemplo n.º 22
0
void uart_init(void)
{
	// UART Configuration structure variable
	UART_CFG_Type UARTConfigStruct;
	// UART FIFO configuration Struct variable
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;
	// Pin configuration for UART
	PINSEL_CFG_Type PinCfg;

	/*
	* Initialize UART3 pin connect: P4.28 -> TXD3; P4.29 -> RXD3
	* or P0.2 -> TXD0, P0.3 -> RXD0
	*/
	PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
#if DBG_UART_NUM == 3	
	PinCfg.Funcnum = PINSEL_FUNC_3;
	PinCfg.Portnum = 4;
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 29;
	PINSEL_ConfigPin(&PinCfg);
#else
	PinCfg.Funcnum = PINSEL_FUNC_1;
	PinCfg.Portnum = 0;
	PinCfg.Pinnum = 2;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 3;
	PINSEL_ConfigPin(&PinCfg);
#endif	

	/* Initialize UART Configuration parameter structure to default state:
		* Baudrate = as below
		* 8 data bit
		* 1 Stop bit
		* None parity
		*/
	UART_ConfigStructInit(&UARTConfigStruct);
	UARTConfigStruct.Baud_rate = 115200;

	// Initialize UART peripheral with given to corresponding parameter
	UART_Init(DBG_UART, &UARTConfigStruct);

	/* Initialize FIFOConfigStruct to default state:
	*                              - FIFO_DMAMode = DISABLE
	*                              - FIFO_Level = UART_FIFO_TRGLEV0
	*                              - FIFO_ResetRxBuf = ENABLE
	*                              - FIFO_ResetTxBuf = ENABLE
	*                              - FIFO_State = ENABLE
	*/
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	// Initialize FIFO for UART peripheral
	UART_FIFOConfig(DBG_UART, &UARTFIFOConfigStruct);

	// Enable UART Transmit
	UART_TxCmd(DBG_UART, ENABLE);
}
Ejemplo n.º 23
0
/*********************************************************************//**
 * @brief 		Client Hardware Initialize
 * @param[in] 	None
 * @return 		None
 ***********************************************************************/
void ClientHardwareInit(void)
{
	// UART Configuration structure variable
	UART_CFG_Type uart_config;
	// UART FIFO Configuration Struct variable
	UART_FIFO_CFG_Type uart_fifo;
	// Pin configuration for UART0
	PINSEL_CFG_Type pin;
    
    // Initialize UART0 pin connect
	pin.Funcnum = PINSEL_FUNC_1;
	pin.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
	pin.Pinmode = PINSEL_PINMODE_PULLUP;
	pin.Pinnum = PINSEL_PIN_2;
	pin.Portnum = PINSEL_PORT_0;
	PINSEL_ConfigPin(&pin);
	pin.Pinnum = PINSEL_PIN_3;
	PINSEL_ConfigPin(&pin);

	// Initialize UART Configration parameter structure to default state:
	// Baudrate = 9600bps
	// 8 data bit
	// 1 stop bit
	// None parity
	UART_ConfigStructInit(&uart_config);

	// Set baudrate to 115200 */
	uart_config.Baud_rate = 115200;
	// Initialize UART0 peripheral with give to corresponding parameter */
	UART_Init((LPC_UART_TypeDef *)LPC_UART0, &uart_config);

	// Initialize FIFOConfigStruct to default state:
	// 				- FIFO_DMAMode = DISABLE
	// 				- FIFO_Level = UART_FIFO_TRGLEV0
	// 				- FIFO_ResetRxBuf = ENABLE
	// 				- FIFO_ResetTxBuf = ENABLE
	// 				- FIFO_State = ENABLE
	UART_FIFOConfigStructInit(&uart_fifo);
    
	// Initialize FIFO for UART0 peripheral
	UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &uart_fifo);

	// Enable UART Transmit
	UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE);

	// Enable UART Rx interrupt
	UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RBR, ENABLE);

	// Enable UART line status interrupt
	UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RLS, ENABLE);
    
	// preemption = 1, sub-priority = 1
	NVIC_SetPriority(UART0_IRQn, ((0x01 << 3) | 0x01));
    
	// Enable Interrupt for UART0 channel
	NVIC_EnableIRQ(UART0_IRQn);
}
Ejemplo n.º 24
0
void pinsel_uart3(void){
	PINSEL_CFG_Type PinCfg;
	PinCfg.Funcnum = 2;
	PinCfg.Pinnum = 0;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 1;
	PINSEL_ConfigPin(&PinCfg);
}
Ejemplo n.º 25
0
void xl_UART_Config(unsigned char port)
{
   UART_CFG_Type      UARTConfigStruct;
   UART_FIFO_CFG_Type UARTFIFOConfigStruct;
   
   UART_ConfigStructInit(&UARTConfigStruct);
   UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
   
   switch(port)
   {
      case 0:
           PINSEL_ConfigPin(0,2,1);
           PINSEL_ConfigPin(0,3,1);
           UARTConfigStruct.Baud_rate  = 115200;
           
           UART_Init( (UART_ID_Type)port, &UARTConfigStruct );
           UART_FIFOConfig( (UART_ID_Type)port, &UARTFIFOConfigStruct );
           UART_TxCmd( (UART_ID_Type)port, ENABLE );      
           
           UART_IntConfig(UART_0, UART_INTCFG_RBR, ENABLE);
           UART_IntConfig(UART_0, UART_INTCFG_RLS, ENABLE);           
           
           NVIC_SetPriority(UART0_IRQn, ((0x02<<3)|0x02));
	          NVIC_EnableIRQ(UART0_IRQn);          
           break;
           
      case 2:      
           PINSEL_ConfigPin(0,10,1);
           PINSEL_ConfigPin(0,11,1);
           
           /**  */
           PINSEL_ConfigPin(1, 19, 6); 
           UARTConfigStruct.Baud_rate = 9600;
           
           UART_Init( (UART_ID_Type)port, &UARTConfigStruct );
           
           LPC_UART2->RS485CTRL  = 0x31;
           LPC_UART2->RS485DLY   = 0x10;
           
           UART_FIFOConfig( (UART_ID_Type)port, &UARTFIFOConfigStruct );
           UART_TxCmd( (UART_ID_Type)port, ENABLE );
                     
           UART_IntConfig(UART_2, UART_INTCFG_RBR, ENABLE);
           UART_IntConfig(UART_2, UART_INTCFG_RLS, ENABLE); 
           
//           NVIC_SetPriority(UART2_IRQn, ((0x02<<3)|0x03));
	         	NVIC_DisableIRQ(UART2_IRQn);      
           break;
           
     default:
           break;
   }
   

}
Ejemplo n.º 26
0
/*********************************************************************//**
 * @brief 		Initialize and Configure SPI device
 * @param[in] 	SPIx	SPI peripheral definition, should be LPC_SPI
 * @return 		None
 ***********************************************************************/
void SPI_Config (LPC_SPI_TypeDef *SPIx)
{
	// Pin configuration for SPI
	PINSEL_CFG_Type PinCfg;

	// SPI Configuration structure variable
	SPI_CFG_Type SPI_ConfigStruct;

	if(SPIx == LPC_SPI)
	{
		/*
		 * Initialize SPI pin connect
		 * P0.15 - SCK;
		 * P0.16 - SSEL - used as GPIO
		 * P0.17 - MISO
		 * P0.18 - MOSI
		 */
		PinCfg.Funcnum = 3;
		PinCfg.OpenDrain = 0;
		PinCfg.Pinmode = 0;
		PinCfg.Portnum = 0;
		PinCfg.Pinnum = 15;
		PINSEL_ConfigPin(&PinCfg);
		PinCfg.Pinnum = 17;
		PINSEL_ConfigPin(&PinCfg);
		PinCfg.Pinnum = 18;
		PINSEL_ConfigPin(&PinCfg);
		PinCfg.Pinnum = 16;
		PinCfg.Funcnum = 0;
		PINSEL_ConfigPin(&PinCfg);
	}
/*
	SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND;
	SPI_ConfigStruct.CPOL = SPI_CPOL_LO;
	SPI_ConfigStruct.ClockRate = SPI_CLOCK;
	SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST;
	SPI_ConfigStruct.Databit = SPI_DATABIT_8;
	SPI_ConfigStruct.Mode = SPI_MASTER_MODE;*/

	// initialize SPI configuration structure to default
	SPI_ConfigStructInit(&SPI_ConfigStruct);

	SPI_ConfigStruct.ClockRate = 3000000;
	SPI_ConfigStruct.Databit = SPI_DATABIT_8;

	// Initialize SPI peripheral with parameter given in structure above
	SPI_Init(LPC_SPI, &SPI_ConfigStruct);

	CS_Init();     // Chip Select Init

	Buffer_Init(); // Empty Buffer
}
Ejemplo n.º 27
0
static void SpiInit(void)
{
  // Init : SPI Enable, Master, Clock rate

#if 0
#ifdef USE_RF12
    // use clk/8 (2x 1/16th) to avoid exceeding RF12's SPI specs of 2.5 MHz when both are used together
    SPCR = _BV(SPE) | _BV(MSTR);
#else
    SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR0);
#endif
    SPSR |= _BV(SPI2X);
#else
  // LPC17xx config

  PINSEL_CFG_Type pin_config = 
  {
    .Portnum = DECODE_PORTNUM(SPI_SCK),
    .Pinmode = PINSEL_PINMODE_TRISTATE,
    .OpenDrain = PINSEL_PINMODE_NORMAL
  };

  SSP_CFG_Type  ssp_config =
  {
        .CPHA           = SSP_CPHA_FIRST,
        .CPOL           = SSP_CPOL_HI,
        .ClockRate      = SSP_CLK,
        .Databit        = SSP_DATABIT_8,
        .Mode           = SSP_MASTER_MODE,
        .FrameFormat    = SSP_FRAME_SPI
    };

    // setup IO pins for SSP peripheral function
    pin_config.Funcnum = 2; // second alternate function
    pin_config.Pinnum = DECODE_BITNUM(SPI_MISO);
    PINSEL_ConfigPin(&pin_config);

    pin_config.Pinnum = DECODE_BITNUM(SPI_MOSI);
    PINSEL_ConfigPin(&pin_config);
    
    pin_config.Pinnum = DECODE_BITNUM(SPI_SCK);
    PINSEL_ConfigPin(&pin_config);

    pin_config.Funcnum = 0; // GPIO control
    pin_config.Pinnum = DECODE_BITNUM(SPI_SSEL);
    PINSEL_ConfigPin(&pin_config);

    // Initialize the SSP
    SSP_Init(SSP, &ssp_config);
    SSP_Cmd(SSP, ENABLE);
#endif
}
Ejemplo n.º 28
0
/*********************************************************************//**
 * @brief 		Configuration for Match register
 * @param[in]	TIMx Pointer to timer device
 * @param[in]   TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
 * 					- MatchChannel : choose channel 0 or 1
 * 					- IntOnMatch	 : if SET, interrupt will be generated when MRxx match
 * 									the value in TC
 * 					- StopOnMatch	 : if SET, TC and PC will be stopped whenM Rxx match
 * 									the value in TC
 * 					- ResetOnMatch : if SET, Reset on MR0 when MRxx match
 * 									the value in TC
 * 					-ExtMatchOutputType: Select output for external match
 * 						 +	 0:	Do nothing for external output pin if match
 *						 +   1:	Force external output pin to low if match
 *						 + 	 2: Force external output pin to high if match
 *						 + 	 3: Toggle external output pin if match
 *					MatchValue: Set the value to be compared with TC value
 * @return 		None
 **********************************************************************/
void TIM_ConfigMatch(TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
{
	CHECK_PARAM(PARAM_TIMx(TIMx));
	CHECK_PARAM(PARAM_TIM_EXTMATCH_OPT(TIM_MatchConfigStruct->ExtMatchOutputType));
	uint32_t timer = TIM_ConverPtrToTimeNum(TIMx) ;
	//	TIMx->MR[TIM_MatchConfigStruct->MatchChannel] = TIM_MatchConfigStruct->MatchValue;
	switch(TIM_MatchConfigStruct->MatchChannel)
	{
	case 0:
		TIMx->MR0 = TIM_MatchConfigStruct->MatchValue;
		break;
	case 1:
		TIMx->MR1 = TIM_MatchConfigStruct->MatchValue;
		break;
	}
	//interrupt on MRn
	TIMx->MCR &=~TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);

	if (TIM_MatchConfigStruct->IntOnMatch)
		TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//reset on MRn
	if (TIM_MatchConfigStruct->ResetOnMatch)
		TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	//stop on MRn
	if (TIM_MatchConfigStruct->StopOnMatch)
		TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);

	// match output type

	TIMx->EMR 	&= ~TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
	TIMx->EMR    = TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);

		//pin output configuration
		if (TIM_MatchConfigStruct->ExtMatchOutputType >0)
		{
			if ((timer <2)&& (TIM_MatchConfigStruct->MatchChannel < 2))
			{
				PINSEL_ConfigPin((PINSEL_CFG_Type *)&timer_match_pin[2*timer +TIM_MatchConfigStruct->MatchChannel]);
			}
			if ((timer ==2))
			{
				PINSEL_ConfigPin( (PINSEL_CFG_Type *)&timer_match_pin[2*timer + TIM_MatchConfigStruct->MatchChannel]);
			}
			if ((timer ==3)&&(TIM_MatchConfigStruct->MatchChannel < 2))
			{
				PINSEL_ConfigPin( (PINSEL_CFG_Type *)&timer_match_pin[4*timer + TIM_MatchConfigStruct->MatchChannel]);
			}
		}
}
Ejemplo n.º 29
0
 void RC5_Init(void)
 {


		 reseteo_general=0;  // Esto estaba en el main() antes.


	     //Config P1.26 as CAP0.0
	     PinCfg.Funcnum = PINSEL_FUNC_3;
	     PinCfg.OpenDrain = 0;
	     PinCfg.Pinmode = 0;
	     PinCfg.Portnum = PINSEL_PORT_1;
	     PinCfg.Pinnum = PINSEL_PIN_26;
	     PINSEL_ConfigPin(&PinCfg);

	     //Config P0.24 como GPIO
	     PinCfg.Funcnum=PINSEL_FUNC_0;
	     PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
	     PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
	     PinCfg.Pinnum = PINSEL_PIN_24;
	     PinCfg.Portnum = PINSEL_PORT_0;
	     PINSEL_ConfigPin(&PinCfg);


	     // Initialize timer 0, prescale count time of 1000000uS = 1S lo cambio yo
	     TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
	     TIM_ConfigStruct.PrescaleValue   = 1;

	     // use channel 0, CAPn.0
	     TIM_CaptureConfigStruct.CaptureChannel = 0;
	     // Enable capture on CAPn.0 rising edge
	     TIM_CaptureConfigStruct.RisingEdge = ENABLE;
	     // Enable capture on CAPn.0 falling edge
	     TIM_CaptureConfigStruct.FallingEdge = ENABLE;
	     // Generate capture interrupt
	     TIM_CaptureConfigStruct.IntOnCaption = ENABLE;


	     // Set configuration for Tim_config and Tim_MatchConfig
	     TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
	     TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct);
	     TIM_ResetCounter(LPC_TIM0);


	     /* preemption = 1, sub-priority = 1 */
	     NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
	     /* Enable interrupt for timer 0 */
	     NVIC_EnableIRQ(TIMER0_IRQn);
	     // To start timer 0
	     TIM_Cmd(LPC_TIM0,ENABLE);
} // --> RC5
Ejemplo n.º 30
0
void jtag_init(void)
{
    uint32_t i=0;

    PinCfg.Funcnum      = 0;    // GPIO
    PinCfg.OpenDrain    = 0;
    PinCfg.Pinmode      = 0;

    puts("");
    printf("Init JTAG port pins: TDO, ");

    PinCfg.Portnum      = JTAG_TDOPORT;
    PinCfg.Pinnum       = JTAG_TDOPIN;
    PINSEL_ConfigPin(&PinCfg);

    printf("TDI, ");
    PinCfg.Portnum      = JTAG_TDIPORT;
    PinCfg.Pinnum       = JTAG_TDIPIN;
    PINSEL_ConfigPin(&PinCfg);

    printf("TMS, ");
    PinCfg.Portnum      = JTAG_TMSPORT;
    PinCfg.Pinnum       = JTAG_TMSPIN;
    PINSEL_ConfigPin(&PinCfg);

    printf("TRST, ");
    PinCfg.Portnum      = JTAG_TRSTPORT;
    PinCfg.Pinnum       = JTAG_TRSTPIN;
    PINSEL_ConfigPin(&PinCfg);

    printf("TCK - done\n");
    PinCfg.Portnum      = JTAG_TCKPORT;
    PinCfg.Pinnum       = JTAG_TCKPIN;
    PINSEL_ConfigPin(&PinCfg);

    GPIO_SetDir(JTAG_TDIPORT, JTAG_TDI, 1);
    GPIO_SetDir(JTAG_TDOPORT, JTAG_TDO, 0);
    GPIO_SetDir(JTAG_TMSPORT, JTAG_TMS, 1);
    GPIO_SetDir(JTAG_TCKPORT, JTAG_TCK, 1);
    GPIO_SetDir(JTAG_TRSTPORT, JTAG_TRST, 1);

    GPIO_ClearValue(JTAG_TDIPORT, JTAG_TDI);

    GPIO_ClearValue(JTAG_TMSPORT, JTAG_TMS);
    GPIO_ClearValue(JTAG_TCKPORT, JTAG_TCK);

    GPIO_ClearValue(JTAG_TRSTPORT, JTAG_TRST);
    GPIO_SetValue(  JTAG_TRSTPORT, JTAG_TRST);

    return;
}