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_UART1
00048 #define NUT_IRQPRI_UART1 4
00049 #endif
00050
00051 static int Uart1IrqCtl(int cmd, void *param);
00052
00053 IRQ_HANDLER sig_UART1 = {
00054 #ifdef NUT_PERFMON
00055 0,
00056 #endif
00057 NULL,
00058 NULL,
00059 Uart1IrqCtl
00060 };
00061
00065 static void Uart1IrqEntry(void) __attribute__ ((naked));
00066 void Uart1IrqEntry(void)
00067 {
00068 IRQ_ENTRY();
00069 #ifdef NUT_PERFMON
00070 sig_UART1.ir_count++;
00071 #endif
00072 if (sig_UART1.ir_handler) {
00073 (sig_UART1.ir_handler) (sig_UART1.ir_arg);
00074 }
00075 IRQ_EXIT();
00076 }
00077
00093 static int Uart1IrqCtl(int cmd, void *param)
00094 {
00095 int rc = 0;
00096 u_int *ival = (u_int *)param;
00097 int enabled = inr(AIC_IMR) & _BV(US1_ID);
00098
00099
00100 if (enabled) {
00101 outr(AIC_IDCR, _BV(US1_ID));
00102 }
00103
00104 switch(cmd) {
00105 case NUT_IRQCTL_INIT:
00106
00107 outr(AIC_SVR(US1_ID), (unsigned int)Uart1IrqEntry);
00108
00109 outr(AIC_SMR(US1_ID), AIC_SRCTYPE_INT_EDGE_TRIGGERED | NUT_IRQPRI_UART1);
00110
00111 outr(AIC_ICCR, _BV(US1_ID));
00112 break;
00113 case NUT_IRQCTL_STATUS:
00114 if (enabled) {
00115 *ival |= 1;
00116 }
00117 else {
00118 *ival &= ~1;
00119 }
00120 break;
00121 case NUT_IRQCTL_ENABLE:
00122 enabled = 1;
00123 break;
00124 case NUT_IRQCTL_DISABLE:
00125 enabled = 0;
00126 break;
00127 case NUT_IRQCTL_GETPRIO:
00128 *ival = inr(AIC_SMR(US1_ID)) & AIC_PRIOR;
00129 break;
00130 case NUT_IRQCTL_SETPRIO:
00131 outr(AIC_SMR(US1_ID), (inr(AIC_SMR(US1_ID)) & ~AIC_PRIOR) | *ival);
00132 break;
00133 #ifdef NUT_PERFMON
00134 case NUT_IRQCTL_GETCOUNT:
00135 *ival = (u_int)sig_UART1.ir_count;
00136 sig_UART1.ir_count = 0;
00137 break;
00138 #endif
00139 default:
00140 rc = -1;
00141 break;
00142 }
00143
00144
00145 if (enabled) {
00146 outr(AIC_IECR, _BV(US1_ID));
00147 }
00148 return rc;
00149 }