1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: #include <sys/machine.h>
15: #ifdef CPU_TMPM367FDFG
16:
17: #include <tk/tkernel.h>
18: #include "../../adc.h"
19: #include "../../../include/dev_def.h"
20: #if DEV_ADC_ENABLE
21: 22: 23: 24: 25:
26:
27: 28: 29:
30: const LOCAL UW ba[DEV_ADC_UNITNM] = { ADA_BASE, ADB_BASE };
31:
32: 33: 34:
35: LOCAL struct {
36: ID wait_tskid;
37: } ll_devcb[DEV_ADC_UNITNM];
38:
39:
40: 41: 42:
43: void adc_inthdr( UINT intno)
44: {
45: INT unit;
46:
47: unit = (intno == INTNO_INTADA? DEV_ADC_UNIT0: DEV_ADC_UNIT1);
48: tk_wup_tsk(ll_devcb[unit].wait_tskid);
49: }
50:
51: 52: 53:
54: LOCAL UW adc_convert( UINT unit, INT ch, INT size, UW *buf )
55: {
56: UW addr, rtn;
57:
58: if(ch < 0 || ch >= ADC_CH_NUM) return E_PAR;
59:
60: ll_devcb[unit].wait_tskid = tk_get_tid();
61:
62: if( size == 1) {
63:
64: out_w( ba[unit] + ADxMOD3, ADMD_CHFIX_SINGLE);
65: out_w( ba[unit] + ADxMOD2, ch);
66:
67: } else if(( ch + size ) <= ADC_CH_NUM ) {
68:
69: out_w( ba[unit] + ADxMOD3, ADMD_CHSCAN_SINGLE);
70: out_w( ba[unit] + ADxMOD4, ch | ((size-1)<<4));
71:
72: } else {
73: return (UW)E_PAR;
74: }
75:
76: tk_can_wup(TSK_SELF);
77: out_w( ba[unit] + ADxMOD0, ADxMOD0_ADS);
78:
79: rtn = (UW)tk_slp_tsk(unit?DEVCNF_ADCB_INTPRI:DEVCNF_ADCA_TMOSCAN);
80: if(rtn == E_OK) {
81: addr = ba[unit] + ADxREG00 + (ch<<2);
82: rtn = size;
83: while( size-- > 0) {
84: *buf++ = in_w( addr) & 0x0000FFF;
85: addr += 4;
86: }
87: in_w( ba[unit] + ADxMOD5);
88: }
89:
90: return rtn;
91: }
92:
93:
94: 95: 96:
97: EXPORT W dev_adc_llctl( UW unit, INT cmd, UW p1, UW p2, UW *pp)
98: {
99: W rtn = (W)E_OK;
100:
101: switch(cmd) {
102: case LLD_ADC_OPEN:
103: if(unit == DEV_ADC_UNIT0) {
104: out_w(ba[unit] + ADxCLK, DEVCNF_ADCA_CLK);
105: EnableInt(INTNO_INTADA, DEVCNF_ADCA_INTPRI);
106: } else {
107: out_w(ba[unit] + ADxCLK, DEVCNF_ADCB_CLK);
108: EnableInt(INTNO_INTADB, DEVCNF_ADCB_INTPRI);
109: }
110: out_w(ba[unit] + ADxMOD1, ADxMOD1_DACON);
111: break;
112:
113: case LLD_ADC_CLOSE:
114: DisableInt((unit?INTNO_INTADB:INTNO_INTADA));
115: out_w(ba[unit] + ADxMOD1, 0);
116: break;
117:
118: case LLD_ADC_READ:
119: rtn = adc_convert(unit, p1, p2, pp);
120: break;
121:
122: case LLD_ADC_RSIZE:
123: rtn = ADC_CH_NUM - p1;
124: if(rtn < 0 ) rtn = 0;
125: break;
126:
127: }
128:
129: return rtn;
130: }
131:
132: 133: 134:
135: EXPORT ER dev_adc_llinit( T_ADC_DCB *p_dcb)
136: {
137: const T_DINT dint = {
138: .intatr = TA_HLNG,
139: .inthdr = adc_inthdr,
140: };
141: ER err;
142:
143:
144: err = tk_def_int((p_dcb->unit?INTNO_INTADB:INTNO_INTADA), &dint);
145:
146: return err;
147: }
148:
149: #endif
150: #endif