Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/sm9untitledPlain Text
#include "xparameters.h"
#include "xil_printf.h"
#include "xil_types.h"
#define SIZE_10MB 0xA00000
#define NUM_CPUS 4
#define CPU_ID 0
#define DDR_BASE XPAR_MIG7SERIES_0_BASEADDR
#define MUTEX_BASE XPAR_AXI_MUTEX_0_BASEADDR
#define BARRIER_ADDR (DDR_BASE + SIZE_10MB)
void InitDdr2(int size_to_init)
{
int i;
// Start timer | Auto reload
*(u32*)(XPAR_AXI_TIMER_0_BASEADDR + 0x0) |=
(1 << 7) | (1 << 4);
for(i = 0; i < size_to_init; i++)
{
*((u8*)(XPAR_MIG7SERIES_0_BASEADDR + i)) =
*((u8*)(XPAR_AXI_TIMER_0_BASEADDR + 0x8));
}
// Stop timer
*(u32*)(XPAR_AXI_TIMER_0_BASEADDR + 0x0) &= ~(1 << 7);
}
// Hardware Mutex Lock
void MutexLock(int mutexNumber, int cpuId)
{
u32 mutexValue;
u32 mutexAddress;
mutexAddress = MUTEX_BASE + (256 * mutexNumber);
mutexValue = (cpuId << 1) | 1;
while(1)
{
*(u32*)mutexAddress = mutexValue;
if(*(u32*)mutexAddress == mutexValue)
break;
}
}
// Hardware Mutex Unlock
void MutexUnlock(int mutexNumber, int cpuId)
{
u32 mutexAddress;
u32 mutexValue;
mutexAddress = MUTEX_BASE + (256 * mutexNumber);
mutexValue = (cpuId << 1);
*(u32*)mutexAddress = mutexValue;
}
// One-time barrier
void Sync_all()
{
volatile u32* barrier = (volatile u32*)BARRIER_ADDR;
// Wait until MB0 initializes the barrier
while(*barrier == 0);
// Decrement shared counter atomically
MutexLock(3, XPAR_CPU_ID);
(*barrier)--;
MutexUnlock(3, XPAR_CPU_ID);
// Wait for all processors
while(*barrier != 0);
}
int main()
{
u32 section_size;
u32 start_offset;
u32 end_offset;
xil_printf("\r\n--- Lab 9 ---\r\n");
if(CPU_ID == 0)
{
xil_printf("MB0: Initializare DDR2...\r\n");
InitDdr2(SIZE_10MB);
xil_printf("MB0: Initializare completata\r\n");
// Initialize barrier counter
*(volatile u32*)BARRIER_ADDR = NUM_CPUS;
}
xil_printf("MB%d: Astept bariera\r\n", CPU_ID);
Sync_all();
xil_printf("MB%d: Bariera terminata\r\n", CPU_ID);
section_size = SIZE_10MB / NUM_CPUS;
start_offset = CPU_ID * section_size;
end_offset = start_offset + section_size;
xil_printf("Processor: MB%d\r\n", CPU_ID);
xil_printf("Section size: %d bytes\r\n", section_size);
xil_printf("Start offset: 0x%08x\r\n", start_offset);
xil_printf("End offset: 0x%08x\r\n", end_offset);
while(1)
{
}
return 0;
}2,519 chars · codepastes.com