/********************************************************************************* * _start() - startup code *********************************************************************************/ void _Core0_start(void) { uint32 pcxi; uint16 cpuWdtPassword = IfxScuWdt_getCpuWatchdogPasswordInline(&MODULE_SCU.WDTCPU[0]); IFX_CFG_CPU_CSTART_PRE_C_INIT_HOOK(0); /*Test Stack, CSA and Cache */ /* Load user stack pointer */ __setareg(sp, __USTACK(0)); __dsync(); /* Set the PSW to its reset value in case of a warm start,clear PSW.IS */ __mtcr(CPU_PSW, IFXCSTART0_PSW_DEFAULT); /* Set the PCXS and PCXO to its reset value in case of a warm start */ pcxi = __mfcr(CPU_PCXI); pcxi &= IFXCSTART0_PCX_O_S_DEFAULT; /*0xfff00000; */ __mtcr(CPU_PCXI, pcxi); /*enable/disable program cache depending on the configuration */ IfxCpu_setProgramCache(IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_PCACHE); /*enable/disable data cache depending on the configuration */ IfxCpu_setDataCache(IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_DCACHE); /* Clear the ENDINIT bit in the WDT_CON0 register, inline funtion */ IfxScuWdt_clearCpuEndinitInline(&MODULE_SCU.WDTCPU[0], cpuWdtPassword); /* Load Base Address of Trap Vector Table. */ __mtcr(CPU_BTV, (uint32)__TRAPTAB(0)); /* Load Base Address of Interrupt Vector Table. we will do this later in the program */ __mtcr(CPU_BIV, (uint32)__INTTAB(0)); /* Load interupt stack pointer. */ __mtcr(CPU_ISP, (uint32)__ISTACK(0)); IfxScuWdt_setCpuEndinitInline(&MODULE_SCU.WDTCPU[0], cpuWdtPassword); /* initialize SDA base pointers */ __setareg(a0, __SDATA1(0)); __setareg(a1, __SDATA2(0)); /* These to be un commented if A8 and A9 are required to be initialized */ __setareg(a8, __SDATA3(0)); __setareg(a9, __SDATA4(0)); /* Setup the context save area linked list. */ IfxCpu_initCSA((uint32 *)__CSA(0), (uint32 *)__CSA_END(0)); /*Initialize the context save area for CPU0 */ { /*CPU and safety watchdogs are enabled by default, C initialization functions are not servicing the watchdogs */ uint16 safetyWdtPassword = IfxScuWdt_getSafetyWatchdogPassword(); IfxScuWdt_disableCpuWatchdog(cpuWdtPassword); IfxScuWdt_disableSafetyWatchdog(safetyWdtPassword); Ifx_C_Init(); /*Initialization of C runtime variables */ IfxScuWdt_enableCpuWatchdog(cpuWdtPassword); IfxScuWdt_enableSafetyWatchdog(safetyWdtPassword); } /*Initialize the clock system */ IFXCPU_CSTART_CCU_INIT_HOOK(); /*Call main function of Cpu0 */ __non_return_call(core0_main); }
int core0_main(void) { udp_pcb_t * udp; ip_addr_t addr; pbuf_t *p = (void*)0;//(pbuf_t *)pbuf_alloc_special(MEMP_PBUF); uint16 idx; uint16 total; /* * !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!! * Enable the watchdog in the demo if it is required and also service the watchdog periodically * */ IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword()); IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword()); /* Initialise the application state */ g_AppCpu0.info.pllFreq = IfxScuCcu_getPllFrequency(); g_AppCpu0.info.cpuFreq = IfxScuCcu_getCpuFrequency(IfxCpu_getCoreId()); g_AppCpu0.info.sysFreq = IfxScuCcu_getSpbFrequency(); g_AppCpu0.info.stmFreq = IfxStm_getFrequency(&MODULE_STM0); report.position = 0; IfxPort_Io_initModule(&conf); for (idx = 0; idx < conf.size; idx++) { IfxPort_Io_ConfigPin *tbl = &conf.pinTable[idx]; IfxPort_setPinHigh(tbl->pin->port, tbl->pin->pinIndex); // P33.0 = 0 } initStm0(); /* Enable the global interrupts of this CPU */ IfxCpu_enableInterrupts(); /* Demo init */ wMultican_init(); Ifx_Lwip_Config config; IP4_ADDR(&config.ipAddr, 192, 168, 7, 123); IP4_ADDR(&config.netMask, 255, 255, 255, 0); IP4_ADDR(&config.gateway, 192, 168, 7, 6); MAC_ADDR(&config.ethAddr, 0x00, 0x20, 0x30, 0x40, 0x50, 0x60); Ifx_Lwip_init(&config); addr.addr8[3] = 6; addr.addr8[2] = 7; addr.addr8[1] = 168; addr.addr8[0] = 192; /* background endless loop */ IfxPort_setPinHigh(&MODULE_P33, 6); // P33.0 = 0 total = Ifx_g_Eth.config.phyLink(); if (total == 1) { report.phy_link = 1; } else { report.phy_link = 0; } ethRam = NULL_PTR; udp = udp_new(); while (TRUE) { Ifx_Lwip_pollTimerFlags(); Ifx_Lwip_pollReceiveFlags(); if (total != Ifx_g_Eth.config.phyLink()) { total = Ifx_g_Eth.config.phyLink(); if (total == 1) { IfxPort_setPinLow(&MODULE_P33, 6); netif_set_up(&Ifx_g_Lwip.netif); IfxEth_startTransmitter(Ifx_g_Lwip.netif.state); } else { netif_set_down(&Ifx_g_Lwip.netif); IfxPort_setPinHigh(&MODULE_P33, 6); } } report.phy_link = total; report.mdio_stat = IfxEth_Phy_Pef7071_MIIState(); report.ethRam = ethRam!=NULL?1:0; wMultiCanNode0Demo_run(report, 0); if ((stat & 0x0003) != 0x01) { IfxPort_setPinLow(&MODULE_P33, 7); } else { IfxPort_setPinHigh(&MODULE_P33, 7); } if (Ifx_g_Eth.config.phyLink() && (ethRam = IfxEth_getTransmitBuffer(&Ifx_g_Eth))) { p = (pbuf_t *)memp_malloc(MEMP_PBUF); if (p != NULL) { p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)ethRam)); p->len = 100; p->tot_len = p->len; p->next = NULL; p->ref = 1; p->type = PBUF_REF; udp_sendto_if(udp, p, &addr, 5001, &Ifx_g_Lwip.netif); pbuf_free(p); IfxPort_setPinLow(&MODULE_P33, 8); // P33.0 = 0 } } else { IfxPort_setPinHigh(&MODULE_P33, 8); // P33.0 = 0 } REGRESSION_RUN_STOP_PASS; } udp_remove(udp); return 0; }