本帖最后由 chujunzbdx 于 2016-3-20 20:53 编辑
前一段时间一直在对创龙TMS320C665x 开发板裸机外接设备的接口进行datasheet,从本周一开始进入基于Platform平台库开发。
首先研究基于 ti的Platform平台库开发,首先研究几个基本的函数。
1. 平台初始化
输入外设使能标志
初始化配置参数
原型: Platform_STATUS platform_init(platform_init_flags * p_flags, platform_init_config * p_config);
- #if (PLATFORM_INIT_IN)
- /* Registers to enable or disable memory ECC for L1, L2 and MSMC memories */
- #define L1PEDSTAT 0x01846404
- #define L1PEDCMD 0x01846408
- #define L1PEDADDR 0x0184640C
- #define L2EDSTAT 0x01846004
- #define L2EDCMD 0x01846008
- #define L2EDADDR 0x0184600C
- #define L2EDCPEC 0x01846018
- #define L2EDCNEC 0x0184601C
- #define L2EDCEN 0x01846030
- #define SMCERRAR 0x0BC00008
- #define SMCERRXR 0x0BC0000C
- #define SMEDCC 0x0BC00010
- #define SMCEA 0x0BC00014
- #define SMSECC 0x0BC00018
- /*Enable EDC on MSMC*/
- /* Note: Once MSMC EDC is enabled, error correction stays enabled until
- * the MSMC is reset
- */
- static int MSMC_enableEDC ()
- {
- unsigned int status = 0;
- *(unsigned int *)(SMEDCC) &= 0x7FFFFFFF; //Clear SEN(bit31)=0
- *(unsigned int *)(SMEDCC) |= 0x40000000; //Set ECM(bit30)=1
- /* Check the status */
- status = *(unsigned int *)(SMEDCC);
- if ((status>>30)==0x1)
- /* Enabled */
- return 1;
- /* Failed */
- return 0;
- }
- /*Enable EDC on L1P*/
- static int enableL1PEDC ()
- {
- unsigned int status = 0;
- *(unsigned int *)(L1PEDCMD) = 0x1; //Set EN(bit0)=1
- /* Check the status */
- status = *(unsigned int *)(L1PEDSTAT);
- if ((status<<28) == 0x10000000)
- /* Enabled */
- return 1;
- /* Failed */
- return 0;
- }
- /*Enable EDC on L2*/
- static int enableL2EDC ()
- {
- unsigned int status = 0;
- *(unsigned int *)(L2EDCMD) = 0x1;
- /* Check the status */
- status = *(unsigned int *)(L2EDSTAT);
- if ((status<<28) == 0x10000000)
- /* Enabled */
- return 1;
- /* Failed */
- return 0;
- }
- /*Enable all bits in L2EDCEN*/
- static int enableEDCL2EDCEN ()
- {
- /* Set DL2CEN(bit0),PL2CEN(bit1),DL2SEN(bit2),PL2SEN(bit3),SDMAEN(bit4)=1 */
- *(unsigned int *)(L2EDCEN) |= 0x1F;
- return 1;
- }
- Platform_STATUS platform_init(platform_init_flags * p_flags,
- platform_init_config * p_config)
- {
- CSL_Status status;
- PllcHwSetup pllc_hwSetup;
- PllcHwSetup pllc_hwSetupRead;
- #ifdef PLATFORM_PLL_REINIT
- int loop_count;
- #endif
- /*************************************************************************
- * This routine may be called before BIOS or the application has loaded.
- * Do not try and write debug statements from here.
- ***********************************************************************/
- if ((p_flags == 0) || (p_config == 0)){
- platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- /* Start TCSL so its free running */
- CSL_chipWriteTSCL(0);
- #ifdef PLATFORM_PLL_REINIT
- for (loop_count = 0; loop_count < 10; loop_count++) {
- platform_errno = 0;
- #endif
- /* PLLC module handle structure */
- if (p_flags->pll) {
- /* Set the Core PLL */
- /* Clear local data structures */
- memset(&pllc_hwSetup, 0, sizeof(PllcHwSetup));
- /* Setup PLLC hardware parameters */
- pllc_hwSetup.divEnable = (CSL_BitMask32) (PLLC_DIVEN_PLLDIV2 |
- PLLC_DIVEN_PLLDIV5 |
- PLLC_DIVEN_PLLDIV8) ;
- /* Setup PLLC hardware parameters */
- pllc_hwSetup.pllM =
- (((p_config->pllm) ? p_config->pllm : PLATFORM_PLL1_PLLM_val) - 1);
- pllc_hwSetup.preDiv = PLATFORM_PLL_PREDIV_val - 1;
- pllc_hwSetup.pllDiv2 = PLATFORM_PLLDIV2_val - 1;
- pllc_hwSetup.pllDiv5 = PLATFORM_PLLDIV5_val - 1;
- pllc_hwSetup.pllDiv8 = PLATFORM_PLLDIV8_val - 1;
- pllc_hwSetup.postDiv = PLATFORM_PLL_POSTDIV_val -1;
- /* set Pll */
- status = CorePllcHwSetup (&pllc_hwSetup);
- if (status != CSL_SOK) {
- platform_errno = PLATFORM_ERRNO_PLL_SETUP;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- /* Read back */
- status = CorePllcGetHwSetup (&pllc_hwSetupRead);
- if (status != CSL_SOK) {
- platform_errno = PLATFORM_ERRNO_PLL_SETUP;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- /* Set the DDR3 PLL if DDR flag is set */
- if (p_flags->ddr) {
- status = SetDDR3PllConfig();
- if (status != CSL_SOK) {
- platform_errno = PLATFORM_ERRNO_PLL_SETUP;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- }
- }
-
- /* Initialize DDR3 */
- if (p_flags->ddr) {
- xmc_setup();
- status = DDR3Init();
- if (status != CSL_SOK) {
- platform_errno = PLATFORM_ERRNO_GENERIC;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- }
- #ifdef PLATFORM_PLL_REINIT
- if (!p_flags->pll || !p_flags->ddr) {
- break;
- }
- /* Run DDR3 test */
- if (platform_memory_test(PLL_REINIT_DDR3_TEST_START_ADDR,
- PLL_REINIT_DDR3_TEST_END_ADDR) == Platform_EOK) {
- break;
- }
- }
- platform_init_return_code = loop_count;
- if (loop_count == 10) {
- platform_errno = PLATFORM_ERRNO_GENERIC;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- #endif
- /* Save frequency, its needed by platform_delay */
- if(!platform_mcb.frequency) {
- platform_mcb.frequency = platform_get_frequency();
- }
- PowerUpDomains();
- /* Enable Error Correction for memory */
- if (p_flags->ecc) {
- enableL1PEDC();
- enableEDCL2EDCEN();
- enableL2EDC();
- MSMC_enableEDC();
- }
- if (p_flags->phy) {
- configSerdes();
- }
- return Platform_EOK;
- }
- #endif
复制代码
以上初始化平台使能L1,L2等内存空间,初始化时钟等;
2.配置调试输出
platform_write_configure
函数原型为:
- WRITE_info platform_write_configure (WRITE_info wtype) {
- WRITE_info original;
- IFPRINT(platform_write("platform_write_configure(write_type=%d) called n", wtype));
- original = write_type;
- write_type = wtype;
- return original;
- }
复制代码
3.配置串口初始化
platform_uart_init
原型为
- Platform_STATUS platform_uart_init(void) {
- IFPRINT(platform_write("platform_uart_init called n"));
- UartInit();
- platform_uart_set_baudrate(115200);
- return Platform_EOK;
- }
复制代码
4. 配置串口波特率platform_uart_set_baudrate
函数原型为
- Platform_STATUS platform_uart_set_baudrate(uint32_t baudrate) {
- uint16_t brate;
- IFPRINT(platform_write("platform_uart_set_baudrate(baudrate=%d) called n", baudrate));
- brate = ((Uint16) (PLATFORM_UART_INPUT_CLOCK_RATE/(baudrate * 16)));
- UartSetBaudRate(brate);
- return Platform_EOK;
- }
复制代码
5. 平台串口发送函数
platform_uart_write
原型为
- Platform_STATUS platform_uart_write(uint8_t buf)
- {
- UartWriteData(buf);
- return Platform_EOK;
- }
复制代码
总计 对于基于Platform平台采用创龙的两个函数库:一个是外设驱动库;一个平台库。如下图
0
|
|
|
|
没用创龙的XDS200的仿真器,自己的。
|
|
|
|
|