1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: 18: 19: 20: 21:
22:
23: #include "sdisk.h"
24:
25: 26: 27:
28: EXPORT void sdSendEvt(DrvTab *drv, W kind)
29: {
30: W i;
31: DiskEvt evt;
32: ER er;
33:
34: evt.h.evttyp = (kind == TDE_EJECT && drv->OpenCnt != 0) ?
35: TDE_ILLEJECT : kind;
36: evt.h.devid = drv->DevId;
37:
38:
39: evt.info = 0;
40: for (i = 0; i <= drv->nSUnit; i++) {
41: if (drv->s.SUnit[i].OpenCnt > 0) evt.info |= 1 << i;
42: }
43:
44:
45: er = tk_snd_mbf(drv->MbfId, (void*)&evt, sizeof(evt), TMO_EVENT);
46: }
47:
48: 49: 50:
51: EXPORT void sdSetUpAccFn(DrvTab *drv)
52: {
53: switch(drv->Spec.accif) {
54: case MEM_ACCIF:
55: drv->Abort = memAbort;
56: drv->ReadWrite = memReadWrite;
57: drv->Format = memFormat;
58: drv->Identify = memIdentify;
59: drv->DiskInit = memDiskInit;
60: drv->Misc = memMisc;
61: drv->DiskFmt = DiskFmt_MEM;
62: drv->IntHdr = NULL;
63: break;
64: case ATA_ACCIF:
65: drv->Abort = ataAbort;
66: drv->ReadWrite = ataReadWrite;
67: drv->Format = ataFormat;
68: drv->Identify = ataIdentify;
69: drv->DiskInit = ataDiskInit;
70: drv->Misc = ataMisc;
71: drv->DiskFmt = DiskFmt_STD;
72: drv->IntHdr = ataIntHdr;
73: break;
74: case MMC_ACCIF:
75: drv->Abort = mmcAbort;
76: drv->ReadWrite = mmcReadWrite;
77: drv->Format = mmcFormat;
78: drv->Identify = mmcIdentify;
79: drv->DiskInit = mmcDiskInit;
80: drv->Misc = mmcMisc;
81: drv->DiskFmt = DiskFmt_STD;
82: drv->IntHdr = NULL;
83: break;
84: }
85: }
86:
87: 88: 89:
90: EXPORT void sdMakeDiskInfo(DrvTab *drv, DiskInfo *inf)
91: {
92: MEMSET(inf, 0, sizeof(DiskInfo));
93: inf->format = drv->DiskFmt;
94: inf->protect = drv->Spec.readonly ? TRUE : FALSE;
95: inf->removable = drv->Spec.eject;
96: inf->blocksize = drv->SecSize;
97: inf->blockcont = drv->s.SUnit[drv->CurSUnit].EndBlock -
98: drv->s.SUnit[drv->CurSUnit].StartBlock;
99: }
100:
101: 102: 103:
104: EXPORT ER sdRegistDevice(DrvTab *drv)
105: {
106: ER er, err;
107: GDefDev ddev;
108: DiskInfo diskinfo;
109:
110: 111:
112: er = (*(drv->DiskInit))(drv);
113:
114:
115: sdMakeDiskInfo(drv, &diskinfo);
116:
117:
118: ddev = *GDI_ddev(drv->Gdi);
119: ddev.drvatr = (drv->Spec.lockreq) ? TDA_LOCKREQ : 0;
120:
121: switch(drv->Spec.accif) {
122: case MEM_ACCIF: ddev.devatr = (drv->Spec.readonly) ?
123: TDK_DISK_ROM : TDK_DISK_RAM;
124: break;
125: case ATA_ACCIF: ddev.devatr = TDK_DISK_HD;
126: break;
127: case MMC_ACCIF: ddev.devatr = TDK_DISK_FLA;
128: break;
129: default: ddev.devatr = TDK_DISK_UNDEF;
130: }
131:
132: ddev.devatr |= (drv->DrvNo & 0x3F) << 16;
133: ddev.devatr |= (drv->Spec.eject) ? TD_REMOVABLE : 0;
134: ddev.devatr |= (drv->Spec.readonly) ? TD_PROTECT : 0;
135:
136: ddev.blksz = drv->SecSize;
137: ddev.nsub = drv->nSUnit;
138:
139:
140: err = GRedefDevice(&ddev, drv->Gdi);
141: if (err < E_OK) goto E_EXIT;
142: return er;
143: E_EXIT:
144: return err;
145: }
146:
147: 148: 149:
150: EXPORT UW sdGetMsec(void)
151: {
152: SYSTIM ctm;
153: UW ct;
154:
155: tk_get_otm(&ctm);
156:
157: ct = ctm.lo;
158: return (ct == 0) ? 1 : ct;
159: }
160:
161: 162: 163:
164: EXPORT BOOL sdChkTmout(UW *tm, UW tmo, W delay)
165: {
166: UW ct;
167:
168: ct = sdGetMsec();
169: if (*tm == 0) *tm = ct;
170: else if (ct - *tm >= tmo) return TRUE;
171:
172: tk_dly_tsk(delay);
173: return FALSE;
174: }