/*
 * This is a simple program to test multi-core microblaze SoC
 */

#include <stdio.h>
//#include "xuartlite_l.h"
#include "xparameters.h"
#include "xil_cache.h"

#include "multicore.h"

void print(char *str);

unsigned long getCurrentCoreID()
{
    /* Query the USER1 bits in the PVR to determine the current core's ID. */
    pvr_t pvr_data;
    microblaze_get_pvr(&pvr_data);
    unsigned long core_id = (unsigned long) (pvr_data.pvr[0] & 0xFF);
    return core_id;
}

void enable_caches()
{
#if XPAR_MICROBLAZE_USE_ICACHE
	microblaze_enable_icache();
#endif
#if XPAR_MICROBLAZE_USE_DCACHE
	microblaze_enable_dcache();
#endif
}

void disable_caches()
{
#if XPAR_MICROBLAZE_USE_ICACHE
	microblaze_disable_icache();
#endif
#if XPAR_MICROBLAZE_USE_DCACHE
	microblaze_disable_dcache();
#endif
}

int main()
{
    enable_caches();

    print("Core 0: Hello World!\n\r");

    disable_caches();

    return 0;
}

void core_1_thread(void *parameter)
{
    unsigned long core_id = getCurrentCoreID();

    printf("Core %d: Hello World!\r\n", core_id);

    while (1) { /* thread never returns */ };
}

void core_2_thread(void *parameter)
{
    unsigned long core_id = getCurrentCoreID();

    printf("Core %d: Hello World!\r\n", core_id);

    while (1) { /* thread never returns */ };
}

void core_3_thread(void *parameter)
{
    unsigned long core_id = getCurrentCoreID();

    printf("Core %d: Hello World!\r\n", core_id);

    while (1) { /* thread never returns */ };
}
