conteepread.c
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**************************************************************************
* *
* Copyright (C) 1995, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "osint.h"
#include "controller.h"
#include "siint.h"
#pragma pack (8)
#if __GNUC__
OSPifRam __osEepPifRam __attribute__((aligned (16)));
#else
OSPifRam __osEepPifRam; /* EEPROM RAM buffer */
#endif
int __osEepromRead16K;
static void __osPackEepReadData(u8);
/*
* This call issues a read eeprom command to pif to read
* 8 bytes from eeprom.
* A value of 0 is returned if the calls succeed, otherwise
* -1 is returned
*/
s32
osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer)
{
s32 ret = 0;
int i=0;
u16 type;
u8 *ptr = (u8 *)(&__osEepPifRam);
OSContStatus sdata;
__OSContEepromFormat eepromformat;
/* Block to get resource token */
__osSiGetAccess();
/* Need to make sure EEPROM is not busy before write */
ret = __osEepStatus(mq, &sdata);
type = (u16)(sdata.type & (u16)(CONT_EEPROM | CONT_EEP16K));
if (ret == 0) {
switch(type) {
case (u16)CONT_EEPROM :
if(address >= EEPROM_MAXBLOCKS) {
ret = -1;
}
break;
case (u16)(CONT_EEPROM | CONT_EEP16K) :
if(address >= EEP16K_MAXBLOCKS) {
ret = -1;
} else {
__osEepromRead16K = 1;
}
break;
default:
ret = CONT_NO_RESPONSE_ERROR;
}
}
if (ret != 0) {
__osSiRelAccess();
return(ret);
}
while (sdata.status & CONT_EEPROM_BUSY) {
__osEepStatus(mq, &sdata);
}
/* Set up request command format for eeprom */
__osPackEepReadData(address);
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
/* trigger pifmacro */
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
__osContLastCmd = CONT_EEPROM_READ;
(void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
for (i = 0; i < MAXCONTROLLERS; i++)
ptr++;
eepromformat = *((__OSContEepromFormat *)ptr);
#ifndef _HW_VERSION_1
ret = (s32)((eepromformat.rxsize & CON_ERR_MASK) >> 4);
#endif
if (ret == 0) {
for (i = 0; i < EEPROM_BLOCK_SIZE ; i++)
*buffer++ = eepromformat.data[i];
}
__osSiRelAccess();
return(ret);
}
static void
__osPackEepReadData(u8 address)
{
u8 *ptr = (u8 *)(&__osEepPifRam);
__OSContEepromFormat eepromformat;
int i;
/* clear pif ram */
#if 0
for (i = 0; i < PIFRAMSIZE-1 ; i++)
__osEepPifRam.ramarray[i] = 0xff;
#endif
#ifndef _HW_VERSION_1
__osEepPifRam.pifstatus = CONT_FORMAT;
#else
__osEepPifRam.pifstatus = 0;
#endif
/* Setup eeprom format */
eepromformat.txsize = 2;
eepromformat.rxsize = 8;
eepromformat.cmd = CONT_EEPROM_READ;
eepromformat.address = address;
#if 0
for (i = 0; i < EEPROM_BLOCK_SIZE ; i++)
eepromformat.data[i] = 0;
#endif
for (i = 0; i < MAXCONTROLLERS; i++)
*ptr++ = 0;
*((__OSContEepromFormat *)ptr) = eepromformat;
#ifndef _HW_VERSION_1
ptr += sizeof(eepromformat);
*((u8 *)ptr) = FORMAT_END;
#endif
}