// UCP.h
// Sample header file for UCP memory allocation
//
// Author : Yang Kai 2020/12/17

#ifndef __UCP_H
#define __UCP_H

#include <ucps.h>

// section attribute
#define __DM0 __attribute__((section(".DM0")))
#define __DM1 __attribute__((section(".DM1")))
#define __DM2 __attribute__((section(".DM2")))
#define __DM3 __attribute__((section(".DM3")))

// vector type
typedef int          v16s32 __attribute__((__vector_size__(64)));
typedef unsigned int v16u32 __attribute__((__vector_size__(64)));

// routines
void* addri2d(void* iaddr);
void* addrd2i(void* daddr);

// Macros of DMx DADDR RANGE
#define DM0_DADDR_START 0x00000000 // 256K
#define DM0_DADDR_END   0x0003FFFF
#define DM1_DADDR_START 0x00040000 // 256K
#define DM1_DADDR_END   0x0007FFFF
#define DM2_DADDR_START 0x00080000 // 128K
#define DM2_DADDR_END   0x0009FFFF
#define DM3_DADDR_START 0x000C0000 // 128K
#define DM3_DADDR_END   0x000DFFFF

// Macros for DMx IADDR RANGE
#define DM0_IADDR_START 0x00200000 // 256K
#define DM0_IADDR_END   0x0023FFFF
#define DM1_IADDR_START 0x00280000 // 256K
#define DM1_IADDR_END   0x002BFFFF
#define DM2_IADDR_START 0x00300000 // 128K
#define DM2_IADDR_END   0x0031FFFF
#define DM3_IADDR_START 0x00380000 // 128K
#define DM3_IADDR_END   0x0039FFFF

#define DM0ADDR(x) ((unsigned int)(x) - DM0_IADDR_START + DM0_DADDR_START)
#define DM1ADDR(x) ((unsigned int)(x) - DM1_IADDR_START + DM1_DADDR_START)
#define DM2ADDR(x) ((unsigned int)(x) - DM2_IADDR_START + DM2_DADDR_START)
#define DM3ADDR(x) ((unsigned int)(x) - DM3_IADDR_START + DM3_DADDR_START)


#endif // __UCP_H
