1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: #include <sys/machine.h>
15: #ifdef CPU_RZA2M
16: 17: 18: 19: 20:
21: #include <tk/tkernel.h>
22: #include <tk/syslib.h>
23:
24: #if USE_PTMR
25:
26: typedef struct {
27: UW baddr;
28: UINT mode;
29: UW limit;
30: FP ptmrhdr;
31: PRI intpri;
32:
33: void *exinf;
34: } T_PTMRCB;
35:
36: T_PTMRCB ptmrcb[TK_MAX_PTIMER] = {
37: { OSTM1_BASE, -1, 0, (FP)NULL, INTPRI_OSTM1, 0 },
38: { OSTM2_BASE, -1, 0, (FP)NULL, INTPRI_OSTM2, 0 },
39: };
40:
41: #define OSTMn_CMP(n) (ptmrcb[n].baddr + OSTMnCMP)
42: #define OSTMn_CNT(n) (ptmrcb[n].baddr + OSTMnCNT)
43: #define OSTMn_TE(n) (ptmrcb[n].baddr + OSTMnTE)
44: #define OSTMn_TS(n) (ptmrcb[n].baddr + OSTMnTS)
45: #define OSTMn_TT(n) (ptmrcb[n].baddr + OSTMnTT)
46: #define OSTMn_CTL(n) (ptmrcb[n].baddr + OSTMnCTL)
47:
48: 49: 50:
51: LOCAL void ptmr_int_main( UINT intno, T_PTMRCB *p_cb)
52: {
53: ClearInt( intno);
54:
55: if( p_cb->ptmrhdr != NULL) {
56: (*p_cb->ptmrhdr)( p_cb->exinf);
57: }
58:
59: if( p_cb->mode == TA_ALM_PTMR) {
60: DisableInt( intno);
61: out_b( OSTMn_TT((intno==INTNO_OSTM1)?0:1), 1);
62: }
63:
64: EndOfInt(intno);
65: }
66:
67: LOCAL void ptmr1_inthdr( UINT intno ) { ptmr_int_main( intno, &ptmrcb[0]); }
68: LOCAL void ptmr2_inthdr( UINT intno ) { ptmr_int_main( intno, &ptmrcb[1]); }
69:
70: LOCAL void (* const inthdr_tbl[])() = {
71: ptmr1_inthdr, ptmr2_inthdr
72: };
73:
74: LOCAL const UINT intno_tbl[] = {
75: INTNO_OSTM1, INTNO_OSTM2
76: };
77:
78: 79: 80:
81: EXPORT ER StartPhysicalTimer( UINT ptmrno, UW limit, UINT mode)
82: {
83: T_DINT dint;
84: UINT intno;
85: ER err;
86:
87:
88: if(( ptmrno == 0 || ptmrno > TK_MAX_PTIMER )
89: || ( limit == 0 ) || ( mode > TA_CYC_PTMR )) return E_PAR;
90:
91: ptmrno--;
92: ptmrcb[ptmrno].limit = limit;
93: ptmrcb[ptmrno].mode = mode;
94:
95:
96: out_b( OSTMn_TT(ptmrno), 1);
97: out_w( OSTMn_CMP(ptmrno), limit);
98:
99:
100: intno = intno_tbl[ptmrno];
101: dint.intatr = TA_HLNG;
102: dint.inthdr = inthdr_tbl[ptmrno];
103: err = tk_def_int( intno, &dint);
104: if(err != E_OK) {
105: return err;
106: }
107: EnableInt( intno, ptmrcb[ptmrno].intpri);
108:
109:
110: out_b(OSTMn_CTL(ptmrno), 0);
111:
112:
113: out_b(OSTMn_TS(ptmrno), 1);
114:
115: return E_OK;
116: }
117:
118: EXPORT ER StopPhysicalTimer( UINT ptmrno )
119: {
120:
121: if( ptmrno == 0 || ptmrno > TK_MAX_PTIMER ) return E_PAR;
122:
123: ptmrno--;
124:
125:
126: DisableInt( intno_tbl[ptmrno]);
127: out_b( OSTMn_TT(ptmrno), 1);
128:
129: return E_OK;
130: }
131:
132:
133: IMPORT ER GetPhysicalTimerCount( UINT ptmrno, UW *p_count )
134: {
135:
136: if( ptmrno == 0 || ptmrno > TK_MAX_PTIMER ) return E_PAR;
137:
138: ptmrno--;
139:
140:
141: *p_count = ptmrcb[ptmrno].limit - in_w( OSTMn_CNT(ptmrno)) ;
142:
143: return E_OK;
144: }
145:
146:
147: EXPORT ER DefinePhysicalTimerHandler( UINT ptmrno, CONST T_DPTMR *pk_dptmr )
148: {
149:
150: if( ptmrno == 0 || ptmrno > TK_MAX_PTIMER ) return E_PAR;
151:
152: ptmrno--;
153:
154:
155: if(pk_dptmr != NULL) {
156: ptmrcb[ptmrno].ptmrhdr = pk_dptmr->ptmrhdr;
157: ptmrcb[ptmrno].exinf = pk_dptmr->exinf;
158: } else {
159: ptmrcb[ptmrno].ptmrhdr = NULL;
160: }
161:
162: return E_OK;
163: }
164:
165:
166: EXPORT ER GetPhysicalTimerConfig(UINT ptmrno, T_RPTMR *pk_rptmr)
167: {
168:
169: if( ptmrno == 0 || ptmrno > TK_MAX_PTIMER ) return E_PAR;
170:
171: pk_rptmr->ptmrclk = PTMCLK;
172: pk_rptmr->maxcount = PTMR_MAX_CNT;
173: pk_rptmr->defhdr = TRUE;
174:
175: return E_OK;
176: }
177:
178: #endif
179: #endif