]> git.sur5r.net Git - freertos/blob - Demo/RX200_RX210-RSK_Renesas/RTOSDemo/switches.c
Add an RX210 demo project.
[freertos] / Demo / RX200_RX210-RSK_Renesas / RTOSDemo / switches.c
1 /* Kernel includes. */\r
2 #include "FreeRTOS.h"\r
3 #include "task.h"\r
4 #include "semphr.h"\r
5 \r
6 #include "iodefine.h"\r
7 \r
8 extern xQueueHandle SwitchQueue;\r
9 \r
10 // IRQ1\r
11 #pragma interrupt (Excep_IRQ1(vect=65))\r
12 void Excep_IRQ1(void);\r
13 \r
14 // IRQ3\r
15 #pragma interrupt (Excep_IRQ3(vect=67))\r
16 void Excep_IRQ3(void);\r
17 \r
18 // IRQ4\r
19 #pragma interrupt (Excep_IRQ4(vect=68))\r
20 void Excep_IRQ4(void);\r
21 \r
22 \r
23 \r
24 void SwitchSetup(void)\r
25 {\r
26         /* Configure SW 1-3 pin settings */\r
27     PORT3.PDR.BIT.B1 = 0;               /* Switch 1 - Port 3.1 - IRQ1 */\r
28     PORT3.PDR.BIT.B3 = 0;               /* Switch 2 - Port 3.3 - IRQ3 */\r
29     PORT3.PDR.BIT.B4 = 0;               /* Switch 3 - Port 3.4 - IRQ4 */\r
30 \r
31         PORT3.PMR.BIT.B1 = 1;\r
32         PORT3.PMR.BIT.B3 = 1;\r
33         PORT3.PMR.BIT.B4 = 1;\r
34         \r
35         MPC.PWPR.BIT.B0WI = 0;          // Writing to the PFSWE bit is enabled\r
36         MPC.PWPR.BIT.PFSWE = 1;         // Writing to the PFS register is enabled\r
37         MPC.P31PFS.BIT.ISEL = 1;\r
38         MPC.P33PFS.BIT.ISEL = 1;\r
39         MPC.P34PFS.BIT.ISEL = 1;\r
40 \r
41         /* IRQ1 */\r
42         ICU.IER[0x08].BIT.IEN1 = 1;     \r
43         ICU.IPR[65].BIT.IPR = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
44         ICU.IR[65].BIT.IR = 0;\r
45         ICU.IRQCR[1].BIT.IRQMD = 1;     // falling edge\r
46         \r
47         /* IRQ3 */\r
48         ICU.IER[0x08].BIT.IEN3 = 1;     \r
49         ICU.IPR[67].BIT.IPR = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
50         ICU.IR[67].BIT.IR = 0;\r
51         ICU.IRQCR[3].BIT.IRQMD = 1;     // falling edge\r
52 \r
53         /* IRQ4 */\r
54         ICU.IER[0x08].BIT.IEN4 = 1;     \r
55         ICU.IPR[68].BIT.IPR = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
56         ICU.IR[68].BIT.IR = 0;\r
57         ICU.IRQCR[4].BIT.IRQMD = 1;     // falling edge\r
58         \r
59 }\r
60 \r
61 void Excep_IRQ1(void)\r
62 {\r
63         portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
64         static portTickType PreviousCount = 0;\r
65         portTickType CurrentCount;\r
66         static unsigned char ID_Switch1 = 1;\r
67         \r
68         CurrentCount = xTaskGetTickCount();\r
69         \r
70         if( (CurrentCount - PreviousCount) > (125 / portTICK_RATE_MS) )\r
71         {\r
72                 xQueueSendToBackFromISR( SwitchQueue, &ID_Switch1, &xHigherPriorityTaskWoken);\r
73         }\r
74         PreviousCount = CurrentCount;\r
75     portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
76 }\r
77 \r
78 void Excep_IRQ3(void)\r
79 {\r
80         static portTickType PreviousCount = 0;\r
81         portTickType CurrentCount;\r
82 \r
83         portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
84         static unsigned char ID_Switch2 = 2;\r
85 \r
86         CurrentCount = xTaskGetTickCount();\r
87         \r
88         if( (CurrentCount - PreviousCount) > (250 / portTICK_RATE_MS) )\r
89         {\r
90                 xQueueSendToBackFromISR( SwitchQueue, &ID_Switch2, &xHigherPriorityTaskWoken);\r
91         }\r
92         PreviousCount = CurrentCount;\r
93     portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
94 }\r
95 \r
96 void Excep_IRQ4(void)\r
97 {\r
98         static portTickType PreviousCount = 0;\r
99         portTickType CurrentCount;\r
100 \r
101         portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
102         static unsigned char ID_Switch3 = 3;\r
103         \r
104         CurrentCount = xTaskGetTickCount();\r
105         \r
106         if( (CurrentCount - PreviousCount) > (125 / portTICK_RATE_MS) )\r
107         {\r
108                 xQueueSendToBackFromISR( SwitchQueue, &ID_Switch3, &xHigherPriorityTaskWoken);\r
109         }\r
110         PreviousCount = CurrentCount;\r
111     portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
112 }