1 |
2 |
dimamali |
/*****************************************************************************/
|
2 |
|
|
/* This file is a part of the GRLIB VHDL IP LIBRARY */
|
3 |
|
|
/* Copyright (C) 2004 GAISLER RESEARCH */
|
4 |
|
|
|
5 |
|
|
/* This program is free software; you can redistribute it and/or modify */
|
6 |
|
|
/* it under the terms of the GNU General Public License as published by */
|
7 |
|
|
/* the Free Software Foundation; either version 2 of the License, or */
|
8 |
|
|
/* (at your option) any later version. */
|
9 |
|
|
|
10 |
|
|
/* See the file COPYING for the full details of the license. */
|
11 |
|
|
/*****************************************************************************/
|
12 |
|
|
|
13 |
|
|
#include "rmapapi.h"
|
14 |
|
|
|
15 |
|
|
int build_rmap_hdr(struct rmap_pkt *pkt, char *hdr, int *size)
|
16 |
|
|
{
|
17 |
|
|
int i;
|
18 |
|
|
int type;
|
19 |
|
|
int write;
|
20 |
|
|
int srcspalen;
|
21 |
|
|
if ((pkt->type != readcmd) && (pkt->type != writecmd) && (pkt->type != rmwcmd) &&
|
22 |
|
|
(pkt->type != readrep) && (pkt->type != writerep) && (pkt->type != rmwrep)) {
|
23 |
|
|
return 1;
|
24 |
|
|
}
|
25 |
|
|
if ((pkt->verify != yes) && (pkt->verify != no)) {
|
26 |
|
|
return 1;
|
27 |
|
|
}
|
28 |
|
|
if ((pkt->ack != yes) && (pkt->ack != no)) {
|
29 |
|
|
return 2;
|
30 |
|
|
}
|
31 |
|
|
if ((pkt->incr != yes) && (pkt->incr != no)) {
|
32 |
|
|
return 3;
|
33 |
|
|
}
|
34 |
|
|
if ( (pkt->dstspalen < 0) || (pkt->dstspalen > 228) ) {
|
35 |
|
|
return 4;
|
36 |
|
|
}
|
37 |
|
|
if ( (pkt->srcspalen < 0) || (pkt->srcspalen > 12) ) {
|
38 |
|
|
return 5;
|
39 |
|
|
}
|
40 |
|
|
if( (pkt->destkey < 0) || (pkt->destkey > 255) ) {
|
41 |
|
|
return 6;
|
42 |
|
|
}
|
43 |
|
|
if( (pkt->destaddr < 0) || (pkt->destaddr > 255) ) {
|
44 |
|
|
return 7;
|
45 |
|
|
}
|
46 |
|
|
if( (pkt->destkey < 0) || (pkt->destkey > 255) ) {
|
47 |
|
|
return 8;
|
48 |
|
|
}
|
49 |
|
|
if( (pkt->srcaddr < 0) || (pkt->srcaddr > 255) ) {
|
50 |
|
|
return 9;
|
51 |
|
|
}
|
52 |
|
|
if( (pkt->tid < 0) || (pkt->tid > 65535) ) {
|
53 |
|
|
return 10;
|
54 |
|
|
}
|
55 |
|
|
if( (pkt->len < 0) || (pkt->len > 16777215) ) {
|
56 |
|
|
return 11;
|
57 |
|
|
}
|
58 |
|
|
if( (pkt->status < 0) || (pkt->status > 12) ) {
|
59 |
|
|
return 12;
|
60 |
|
|
}
|
61 |
|
|
if ((pkt->type == writecmd) || (pkt->type == writerep)) {
|
62 |
|
|
write = 1;
|
63 |
|
|
} else {
|
64 |
|
|
write = 0;
|
65 |
|
|
}
|
66 |
|
|
if ((pkt->type == writecmd) || (pkt->type == readcmd) || (pkt->type == rmwcmd)) {
|
67 |
|
|
type = 1;
|
68 |
|
|
*size = pkt->dstspalen + 15;
|
69 |
|
|
srcspalen = pkt->srcspalen/4;
|
70 |
|
|
if ( (pkt->srcspalen % 4) != 0) {
|
71 |
|
|
srcspalen = srcspalen + 1;
|
72 |
|
|
}
|
73 |
|
|
*size = srcspalen * 4 + *size;
|
74 |
|
|
for(i = 0; i < pkt->dstspalen; i++) {
|
75 |
|
|
hdr[i] = pkt->dstspa[i];
|
76 |
|
|
}
|
77 |
|
|
hdr[pkt->dstspalen] = (char)pkt->destaddr;
|
78 |
|
|
hdr[pkt->dstspalen+1] = (char)0x01;
|
79 |
|
|
hdr[pkt->dstspalen+2] = (char)0;
|
80 |
|
|
hdr[pkt->dstspalen+2] = hdr[pkt->dstspalen+2] | (type << 6) |
|
81 |
|
|
(write << 5) | (pkt->verify << 4) | (pkt->ack << 3) | (pkt->incr << 2) | srcspalen;
|
82 |
|
|
hdr[pkt->dstspalen+3] = (char)pkt->destkey;
|
83 |
|
|
for(i = 0; i < pkt->srcspalen; i++) {
|
84 |
|
|
hdr[pkt->dstspalen+3+i] = pkt->srcspa[i];
|
85 |
|
|
}
|
86 |
|
|
hdr[pkt->dstspalen+4+pkt->srcspalen] = (char)pkt->srcaddr;
|
87 |
|
|
hdr[pkt->dstspalen+5+pkt->srcspalen] = (char)((pkt->tid >> 8) & 0xFF);
|
88 |
|
|
hdr[pkt->dstspalen+6+pkt->srcspalen] = (char)(pkt->tid & 0xFF);
|
89 |
|
|
hdr[pkt->dstspalen+7+pkt->srcspalen] = (char)0;
|
90 |
|
|
hdr[pkt->dstspalen+8+pkt->srcspalen] = (char)((pkt->addr >> 24) & 0xFF);
|
91 |
|
|
hdr[pkt->dstspalen+9+pkt->srcspalen] = (char)((pkt->addr >> 16) & 0xFF);
|
92 |
|
|
hdr[pkt->dstspalen+10+pkt->srcspalen] = (char)((pkt->addr >> 8) & 0xFF);
|
93 |
|
|
hdr[pkt->dstspalen+11+pkt->srcspalen] = (char)(pkt->addr & 0xFF);
|
94 |
|
|
hdr[pkt->dstspalen+12+pkt->srcspalen] = (char)((pkt->len >> 16) & 0xFF);
|
95 |
|
|
hdr[pkt->dstspalen+13+pkt->srcspalen] = (char)((pkt->len >> 8) & 0xFF);
|
96 |
|
|
hdr[pkt->dstspalen+14+pkt->srcspalen] = (char)(pkt->len & 0xFF);
|
97 |
|
|
} else {
|
98 |
|
|
type = 0;
|
99 |
|
|
if (pkt->type == writerep) {
|
100 |
|
|
*size = pkt->srcspalen + 7;
|
101 |
|
|
} else {
|
102 |
|
|
*size = pkt->srcspalen + 11;
|
103 |
|
|
}
|
104 |
|
|
srcspalen = pkt->srcspalen/4;
|
105 |
|
|
if ( (pkt->srcspalen % 4) != 0) {
|
106 |
|
|
srcspalen = srcspalen + 1;
|
107 |
|
|
}
|
108 |
|
|
for(i = 0; i < pkt->srcspalen; i++) {
|
109 |
|
|
hdr[i] = pkt->srcspa[i];
|
110 |
|
|
}
|
111 |
|
|
hdr[pkt->srcspalen] = (char)pkt->srcaddr;
|
112 |
|
|
hdr[pkt->srcspalen+1] = (char)0x01;
|
113 |
|
|
hdr[pkt->srcspalen+2] = (char)0;
|
114 |
|
|
hdr[pkt->srcspalen+2] = hdr[pkt->srcspalen+2] | (type << 6) |
|
115 |
|
|
(write << 5) | (pkt->verify << 4) | (pkt->ack << 3) | (pkt->incr << 2) | srcspalen;
|
116 |
|
|
hdr[pkt->srcspalen+3] = (char)pkt->status;
|
117 |
|
|
hdr[pkt->srcspalen+4] = (char)pkt->destaddr;
|
118 |
|
|
hdr[pkt->srcspalen+5] = (char)((pkt->tid >> 8) & 0xFF);
|
119 |
|
|
hdr[pkt->srcspalen+6] = (char)(pkt->tid & 0xFF);
|
120 |
|
|
if (pkt->type != writerep) {
|
121 |
|
|
hdr[pkt->srcspalen+7] = (char)0;
|
122 |
|
|
hdr[pkt->srcspalen+8] = (char)((pkt->len >> 16) & 0xFF);
|
123 |
|
|
hdr[pkt->srcspalen+9] = (char)((pkt->len >> 8) & 0xFF);
|
124 |
|
|
hdr[pkt->srcspalen+10] = (char)(pkt->len & 0xFF);
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
return 0;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|