1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: 17: 18: 19: 20:
21:
22: #include "clkdrv.h"
23: #include "svc/ifem1d512.h"
24:
25:
26: IMPORT ER IICup(W ch, BOOL start);
27: IMPORT ER IICXfer(W ch, UH *cmddata, W words);
28:
29:
30: IMPORT ER SPIup(W ch, BOOL start);
31: IMPORT ER SPIXfer(W cs, UB *xmit, UB *recv, W len);
32:
33:
34: LOCAL INT em1d512_iicspi_svcentry(void *par, W fn)
35: {
36: H8IO_EM1D512_IICXFER_PARA *iic;
37: H8IO_EM1D512_SPIXFER_PARA *spi;
38: INT er;
39:
40: switch (fn) {
41: case H8IO_EM1D512_IICXFER_FN:
42: iic = par;
43: er = IICXfer(iic->ch, iic->cmddat, iic->words);
44: break;
45: case H8IO_EM1D512_SPIXFER_FN:
46: spi = par;
47: er = SPIXfer(spi->cs, spi->xmit, spi->recv, spi->len);
48: break;
49: default:
50: er = E_ILUSE;
51: break;
52: }
53:
54: return er;
55: }
56:
57:
58: EXPORT ER em1d512_iicspi_svc(BOOL start)
59: {
60: ER er;
61: T_DSSY dssy;
62: static BOOL initialized = FALSE;
63:
64: er = E_OK;
65: if (!start) {
66: if ( initialized == FALSE ) goto fin0;
67: goto fin3;
68: }
69: if ( initialized != FALSE ) goto fin0;
70:
71: er = IICup(0, TRUE);
72: er |= IICup(1, TRUE);
73: if (er < E_OK) goto fin1;
74:
75: er = SPIup(0, TRUE);
76: er |= SPIup(1, TRUE);
77: er |= SPIup(2, TRUE);
78: if (er < E_OK) goto fin2;
79:
80:
81: dssy.ssyatr = TA_NULL;
82: dssy.ssypri = H8IO_PRI;
83: dssy.svchdr = (FP)em1d512_iicspi_svcentry;
84: dssy.breakfn = NULL;
85: dssy.startupfn = NULL;
86: dssy.cleanupfn = NULL;
87: dssy.eventfn = NULL;
88: dssy.resblksz = 0;
89: er = tk_def_ssy(H8IO_SVC, &dssy);
90: if (er < E_OK) goto fin3;
91:
92: initialized = TRUE;
93: er = E_OK;
94: goto fin0;
95:
96: fin3:
97: tk_def_ssy(H8IO_SVC, NULL);
98: fin2:
99: SPIup(2, FALSE);
100: SPIup(1, FALSE);
101: SPIup(0, FALSE);
102: fin1:
103: IICup(1, FALSE);
104: IICup(0, FALSE);
105: fin0:
106: return er;
107: }