/******************************************************************** * INITIALIZATION * ******************************************************************/ void ENC2_Init(void) { debug_entry; //Set default bank currentBank = 0; init_SPI2(); DeassertChipSelect_2(); ENCX24J600_Reset(); delay_loop_ms (100); ENCX24J600_Unreset (); // Perform a reliable reset ENC2_SendSystemReset(); // Initialize RX tracking variables and other control state flags nextPacketPointer = RXSTART; // Set up TX/RX/UDA buffer addresses ENC2_WriteReg(ETXST, TXSTART); ENC2_WriteReg(ERXST, RXSTART); ENC2_WriteReg(ERXTAIL, RAMSIZE - 2); ENC2_WriteReg(EUDAST, USSTART); ENC2_WriteReg(EUDAND, USEND); // If promiscuous mode is set, than allow accept all packets #ifdef PROMISCUOUS_MODE ENC2_WriteReg(ERXFCON, (ERXFCON_CRCEN | ERXFCON_RUNTEN | ERXFCON_UCEN | ERXFCON_NOTMEEN | ERXFCON_MCEN)); dd #endif // Set PHY Auto-negotiation to support 10BaseT Half duplex, // 10BaseT Full duplex, 100BaseTX Half Duplex, 100BaseTX Full Duplex, // and symmetric PAUSE capability ENC2_WritePHYReg(PHANA, PHANA_ADPAUS0 | PHANA_AD10FD | PHANA_AD10 | PHANA_AD100FD | PHANA_AD100 | PHANA_ADIEEE0); // Enable RX packet reception ENC2_BFSReg(ECON1, ECON1_RXEN); // KUKU, supaya GPIO aktif untuk deteck packet ENC2_WriteReg(EIE, EIE_INTIE | EIE_LINKIE | EIE_PKTIE | EIE_TXABTIE | EIE_RXABTIE); debug_leave; }
void InitApp(void) { /* Setup analog functionality and port direction */ //IO configuration (pull-up CN interrupts enable // IEC1bits.CNIE=1; // IPC4bits.CNIP=1; /* Initialize peripherals */ init_peripheral_pin_select(); uart1_Initialize(19200); init_timer2(); init_timer3(); init_SPI1(); init_SPI2(); }
void systemInit(void) { GPIO_InitTypeDef GPIO_InitStructure; //uint32_t i; //GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = LED0_PIN | LED1_PIN | LED2_PIN| LED3_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOE, &GPIO_InitStructure); #ifdef BUZZER { RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Pin = BEEP_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOD, &GPIO_InitStructure); }; #endif // uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]); // This is needed because some shit inside Keil startup f***s with SystemCoreClock, setting it back to 72MHz even on HSI. SystemCoreClockUpdate(); // Turn on clocks for stuff we use RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_TIM5 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_SPI2 | RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3 , ENABLE); RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1 | RCC_APB2Periph_SPI1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_DMA2, ENABLE); RCC_ClearFlag(); /*/ Make all GPIO in by default to save power and reduce noise GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); // Turn off JTAG port 'cause we're using the GPIO for leds GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // Configure gpio for (i = 0; i < gpio_count; i++) { GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode; GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure); }*/ LED0_OFF; LED1_OFF; LED2_OFF; LED3_OFF; BEEP_OFF; // Init cycle counter cycleCounterInit(); // SysTick SysTick_Config(SystemCoreClock / 1000); // Configure the rest of the stuff #ifndef FY90Q i2cInit(I2C2); init_SPI1(); init_SPI2(); #endif // sleep for 100ms delay(100); }