//------------------------------------------------------------------------------ // Function: System_Init // Description: One time initialization at statup //------------------------------------------------------------------------------ static void SystemInit(void) { const uint8_t EQTable[] = {0x8A,0xAA,0x1A,0x2A}; while( (RegisterRead(REG__BSM_STAT)& BIT__BOOT_DONE )== 0) //wait done DEBUG_PRINT(("BIT__BOOT_DONE = 0; \n")); if((RegisterRead(REG__BSM_STAT)& BIT__BOOT_ERROR)!=0) DEBUG_PRINT(("First Boot error! \n")); RegisterModify(REG__HPD_HW_CTRL,MSK__INVALIDATE_ALL, SET); //disable auto HPD conf at RESET TurnAudioMute(ON); TurnVideoMute(ON); #if(PEBBLES_ES1_STARTER_CONF==ENABLE) RegisterWrite(REG__TERMCTRL2, VAL__45OHM); //1.term default value RegisterWrite(REG__FACTORY_A87,0x43); //2.Set PLL mode to internal and set selcalrefg to F RegisterWrite(REG__FACTORY_A81,0x18); //Set PLL zone to auto and set Div20 to 1 RegisterWrite(REG__DRIVE_CNTL,0x64); //3.change output strength, RegisterWrite(REG__FACTORY_ABB,0x04); //4.desable DEC_CON RegisterWriteBlock(REG__FACTORY_A92,(uint8_t *)&EQTable[0],4);//5.Repgrogram EQ table RegisterWrite(REG__FACTORY_AB5,0x40); //EnableEQ RegisterWrite(REG__FACTORY_9E5, 0x02); //6. DLL by pass RegisterWrite(REG__FACTORY_A89,0x00); //7. configure the PLLbias RegisterWrite(REG__FACTORY_00E,0x40); //for ES1.1 conf only #endif CEC_Init(); //set recommended values RegisterWrite(REG__AACR_CFG1, CONF__AACR_CFG1_VALUE); //pll config #1 RegisterWrite(REG__CBUS_PAD_SC, VAL__SC_CONF); //CBUS slew rate RegisterWrite(REG__SRST, BIT__SWRST_AUTO); //enable auto sw reset RegisterWrite(REG__INFM_CLR,BIT__CLR_GBD|BIT__CLR_ACP); //clr GBD & ACP RegisterWrite(REG__ECC_HDCP_THRES, CONF__HDCPTHRESH & 0xff); //HDCP threshold low uint8_t RegisterWrite(REG__ECC_HDCP_THRES+1, (CONF__HDCPTHRESH>>8) & 0xff); //HDCP threshold high uint8_t AutoVideoSetup(); AutoAudioSetup(); SetupInterruptMasks(); InitializePortSwitch(); TurnPowerDown(OFF); RegisterModify(REG__HPD_HW_CTRL,MSK__INVALIDATE_ALL, CLEAR); //CLEAR disable auto HPD conf /* Inti Hdmi Info frame related chip registers and data */ HdmiInitIf (); }
/** * @brief Configures the CEC peripheral. * @param None * @retval None */ void CEC_Config(void) { CEC_InitTypeDef CEC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable CEC clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC , ENABLE); /* Enable CEC_LINE_GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* Configure CEC_LINE_GPIO as Output open drain */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable the CEC global Interrupt (with higher priority) */ NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure CEC */ CEC_InitStructure.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard; CEC_InitStructure.CEC_RxTolerance = CEC_RxTolerance_Standard; CEC_InitStructure.CEC_StopReception = CEC_StopReception_Off; CEC_InitStructure.CEC_BitRisingError = CEC_BitRisingError_Off; CEC_InitStructure.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off; CEC_InitStructure.CEC_BRDNoGen = CEC_BRDNoGen_Off; CEC_InitStructure.CEC_SFTOption = CEC_SFTOption_Off; CEC_Init(&CEC_InitStructure); /* Set the CEC initiator address */ CEC_OwnAddressConfig(MyLogicalAddress1); #if defined (DEVICE_2) /* Set the CEC initiator address 2 */ CEC_OwnAddressConfig(MyLogicalAddress2); #endif #if defined (DEVICE_1) /* Activate CEC interrupts associated to the set of TX flags */ CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE); /* Activate CEC interrupts associated to the set of TX error */ CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_TXUDR|CEC_IT_ARBLST,ENABLE); #elif defined (DEVICE_2) /* Activate CEC interrupts associated to the set of RX flags */ CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE); /* Activate CEC interrupts associated to the set of RX error */ CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE|CEC_IT_RXOVR,ENABLE); #endif /* Enable CEC */ CEC_Cmd(ENABLE); }
/** * @brief Configures the CEC peripheral. * @param None * @retval None */ static void CEC_Config(void) { CEC_InitTypeDef CEC_InitStruct; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* DeInitialize CEC to reinitialize from scratch */ CEC_DeInit(); /* Enable CEC clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC, ENABLE); /* Enable CEC_LINE_GPIO clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); /* Configure CEC_LINE_GPIO as Output open drain */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6 , GPIO_AF3_CEC); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable the CEC global Interrupt (with higher priority) */ NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure CEC */ CEC_InitStruct.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard; CEC_InitStruct.CEC_RxTolerance = CEC_RxTolerance_Standard; CEC_InitStruct.CEC_StopReception = CEC_StopReception_Off; CEC_InitStruct.CEC_BitRisingError = CEC_BitRisingError_Off; CEC_InitStruct.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off; CEC_InitStruct.CEC_BRDNoGen = CEC_BRDNoGen_On; CEC_InitStruct.CEC_SFTOption = CEC_SFTOption_Off; CEC_Init(& CEC_InitStruct); /* Configure Own Address */ CEC_OwnAddressConfig(MyOwnAddress); /* Enable Listen Mode */ CEC_ListenModeCmd(ENABLE); /* Activate CEC interrupts associated to the set of TX flags */ CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE); /* Activate CEC interrupts associated to the set of RX flags */ CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE); /* Activate CEC interrupts associated to the set of TX error */ CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_ARBLST,ENABLE); /* Activate CEC interrupts associated to the set of RX error */ CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE,ENABLE); /* Enable CEC */ CEC_Cmd(ENABLE); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* RCC configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* GPIO configuration */ GPIO_Configuration(); /* Configure the CEC peripheral */ CEC_InitStructure.CEC_BitTimingMode = CEC_BitTimingStdMode; CEC_InitStructure.CEC_BitPeriodMode = CEC_BitPeriodStdMode; CEC_Init(&CEC_InitStructure); /* Set Prescaler value for APB1 clock PCLK1 = 24MHz */ CEC_SetPrescaler(0x4AF); /* Set the CEC initiator address */ CEC_OwnAddressConfig(MY_DEVICE_ADDRESS); /* Activate CEC interrupts associated to the set of RBTF,RERR, TBTF, TERR flags */ CEC_ITConfig(ENABLE); /* Enable CEC */ CEC_Cmd(ENABLE); /* If a frame has been received */ while(ReceivedFrame == 0) { } /* Check the received data with the send ones */ TransferStatus = Buffercmp(TransmitBuffer, ReceiveBuffer, ByteNumber); /* TransferStatus = PASSED, if the data transmitted from CEC Device1 and received by CEC Device2 are the same */ /* TransferStatus = FAILED, if the data transmitted from CEC Device1 and received by CEC Device2 are different */ if (TransferStatus == PASSED) { /* OK */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } while(1) { } }