Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <arch/arm.h>
00045 #include <dev/irqreg.h>
00046
00047 #ifndef NUT_IRQPRI_SYS
00048 #define NUT_IRQPRI_SYS 0
00049 #endif
00050
00051 SYSIRQ_HANDLER syssig_DBGU;
00052 SYSIRQ_HANDLER syssig_MC;
00053 SYSIRQ_HANDLER syssig_PIT;
00054 SYSIRQ_HANDLER syssig_PMC;
00055 SYSIRQ_HANDLER syssig_RSTC;
00056 SYSIRQ_HANDLER syssig_RTT;
00057 SYSIRQ_HANDLER syssig_WDT;
00058
00059
00060 static int SystemIrqCtl(int cmd, void *param);
00061
00062 IRQ_HANDLER sig_SYS = {
00063 #ifdef NUT_PERFMON
00064 0,
00065 #endif
00066 NULL,
00067 NULL,
00068 SystemIrqCtl
00069 };
00070
00074 static void SystemIrqEntry(void) __attribute__ ((naked));
00075 void SystemIrqEntry(void)
00076 {
00077 IRQ_ENTRY();
00078 #ifdef NUT_PERFMON
00079 sig_SYS.ir_count++;
00080 #endif
00081 if (syssig_DBGU.sir_enabled && syssig_DBGU.sir_handler) {
00082
00083 (syssig_DBGU.sir_handler) (syssig_DBGU.sir_arg);
00084 }
00085 if (syssig_MC.sir_enabled && syssig_MC.sir_handler) {
00086
00087 (syssig_MC.sir_handler) (syssig_MC.sir_arg);
00088 }
00089 if (syssig_PMC.sir_enabled && syssig_PMC.sir_handler) {
00090
00091 (syssig_PMC.sir_handler) (syssig_PMC.sir_arg);
00092 }
00093 if (syssig_RSTC.sir_enabled && syssig_RSTC.sir_handler) {
00094
00095 (syssig_RSTC.sir_handler) (syssig_RSTC.sir_arg);
00096 }
00097 if (syssig_RTT.sir_enabled && syssig_RTT.sir_handler) {
00098
00099 (syssig_RTT.sir_handler) (syssig_RTT.sir_arg);
00100 }
00101 if (syssig_WDT.sir_enabled && syssig_WDT.sir_handler) {
00102
00103 (syssig_WDT.sir_handler) (syssig_WDT.sir_arg);
00104 }
00105 if ((inr(PIT_MR) & PIT_PITIEN) != 0 && (inr(PIT_SR) & PIT_PITS) != 0) {
00106 if (syssig_PIT.sir_handler) {
00107
00108 (syssig_PIT.sir_handler) (syssig_PIT.sir_arg);
00109 }
00110 inr(PIT_PIVR);
00111 }
00112 IRQ_EXIT();
00113 }
00114
00130 static int SystemIrqCtl(int cmd, void *param)
00131 {
00132 int rc = 0;
00133 unsigned int *ival = (unsigned int *)param;
00134 int_fast8_t enabled = inr(AIC_IMR) & _BV(SYSC_ID);
00135
00136
00137 if (enabled) {
00138 outr(AIC_IDCR, _BV(SYSC_ID));
00139 }
00140
00141 switch(cmd) {
00142 case NUT_IRQCTL_INIT:
00143
00144 outr(AIC_SVR(SYSC_ID), (unsigned int)SystemIrqEntry);
00145
00146 outr(AIC_SMR(SYSC_ID), AIC_SRCTYPE_INT_LEVEL_SENSITIVE | NUT_IRQPRI_SYS);
00147
00148 outr(AIC_ICCR, _BV(SYSC_ID));
00149 break;
00150 case NUT_IRQCTL_STATUS:
00151 if (enabled) {
00152 *ival |= 1;
00153 }
00154 else {
00155 *ival &= ~1;
00156 }
00157 break;
00158 case NUT_IRQCTL_ENABLE:
00159 enabled = 1;
00160 break;
00161 case NUT_IRQCTL_DISABLE:
00162 enabled = 0;
00163 break;
00164 case NUT_IRQCTL_GETPRIO:
00165 *ival = inr(AIC_SMR(SYSC_ID)) & AIC_PRIOR;
00166 break;
00167 case NUT_IRQCTL_SETPRIO:
00168 outr(AIC_SMR(SYSC_ID), (inr(AIC_SMR(SYSC_ID)) & ~AIC_PRIOR) | *ival);
00169 break;
00170 #ifdef NUT_PERFMON
00171 case NUT_IRQCTL_GETCOUNT:
00172 *ival = (unsigned int)sig_SYS.ir_count;
00173 sig_SYS.ir_count = 0;
00174 break;
00175 #endif
00176 default:
00177 rc = -1;
00178 break;
00179 }
00180
00181
00182 if (enabled) {
00183 outr(AIC_IECR, _BV(SYSC_ID));
00184 }
00185 return rc;
00186 }
00187
00195 int NutSysIrqEnable(SYSIRQ_HANDLER * sysirq)
00196 {
00197 sysirq->sir_enabled = 1;
00198
00199 return SystemIrqCtl(NUT_IRQCTL_ENABLE, NULL);
00200 }
00201
00209 int NutSysIrqDisable(SYSIRQ_HANDLER * sysirq)
00210 {
00211 sysirq->sir_enabled = 0;
00212
00213 return 0;
00214 }
00215
00235 int NutRegisterSysIrqHandler(SYSIRQ_HANDLER * sysirq, void (*handler) (void *), void *arg)
00236 {
00237 int rc;
00238
00239
00240 NutSysIrqDisable(sysirq);
00241
00242
00243 rc = SystemIrqCtl(NUT_IRQCTL_INIT, NULL);
00244
00245 if (rc == 0) {
00246
00247 sysirq->sir_arg = arg;
00248 sysirq->sir_handler = handler;
00249 }
00250 return rc;
00251 }