Tim Fernandez-Hart
Published © CC BY

Multiprocessing on Xilinx MPSoC

Run different applications on separate processors concurrently whilst sharing data.

IntermediateProtip1 hour2,448
Multiprocessing on Xilinx MPSoC

Things used in this project

Story

Read more

Code

helloworld_0.c

C/C++
#include <stdio.h>
#include <sleep.h>
#include "xil_io.h"
#include "platform.h"
#include "xil_cache.h"

// Flag to determine who is reading and writing the shared number
#define CORE_FLAG (*(volatile unsigned long *)(0xFFFC0000)) 
//Shared memory Addresses
#define SHARED_MEMORY_BASE 0X200000


int main()
{
    init_platform();

    int n = 1;
    int shared_number = 0;
    int temp_num = 9;
    int *transmit_ptr = (int*) SHARED_MEMORY_BASE;

    print("CPU0: init_platform\n\r");
    CORE_FLAG = 0;

    Xil_Out32(transmit_ptr, shared_number);


    while(1){
        // Read current value print it
        temp_num = Xil_In32(transmit_ptr);

        printf("0: number is currently: %d \n", (int)temp_num);

        // Add 4 to the value and save it back to DDR
        temp_num += 4;
        Xil_DCacheFlushRange(transmit_ptr, sizeof(int));
        Xil_Out32(transmit_ptr, temp_num);

        sleep(1);

        CORE_FLAG = 1;
        while(CORE_FLAG == 1){
        }
    }

    cleanup_platform();
    return 0;
}

helloworld_1

C/C++
#include <stdio.h>
#include <sleep.h>
#include "xil_io.h"
#include "platform.h"
#include "xil_cache.h"


#define CORE_FLAG (*(volatile unsigned long *)(0xFFFC0000)) 
#define SHARED_MEMORY_BASE 0X200000

int main()
{
    int shared_number;
    int temp_num;
    int *transmit_ptr = (int*) SHARED_MEMORY_BASE;

    init_platform();
    print("CPU1: init_platform\n\r");


    while(1){
        while(CORE_FLAG == 0){
        };
        temp_num = Xil_In32(transmit_ptr);
        printf("1: number is currently: %d \n", (int)temp_num);
        temp_num += 1;
        Xil_DCacheFlushRange(transmit_ptr, sizeof(int));
        Xil_Out32(transmit_ptr, temp_num);


     //   print("ARM core 1\n");
        sleep(1);
        CORE_FLAG = 0;
    }

    cleanup_platform();
    return 0;
}

Credits

Tim Fernandez-Hart
2 projects • 6 followers
Contact
Thanks to xb100.

Comments

Please log in or sign up to comment.