]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX200_RX231-RSK_Renesas_e2studio/src/Full_Demo/IntQueueTimer.c
c0f42b77ad9b2cdc535e7008b4677af014f8edf0
[freertos] / FreeRTOS / Demo / RX200_RX231-RSK_Renesas_e2studio / src / Full_Demo / IntQueueTimer.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * This file contains the non-portable and therefore RX62N specific parts of\r
30  * the IntQueue standard demo task - namely the configuration of the timers\r
31  * that generate the interrupts and the interrupt entry points.\r
32  */\r
33 \r
34 /* Scheduler includes. */\r
35 #include "FreeRTOS.h"\r
36 #include "task.h"\r
37 \r
38 /* Demo includes. */\r
39 #include "IntQueueTimer.h"\r
40 #include "IntQueue.h"\r
41 \r
42 /* Hardware specifics. */\r
43 #include "iodefine.h"\r
44 \r
45 #define tmrTIMER_0_1_FREQUENCY  ( 2000UL )\r
46 #define tmrTIMER_2_3_FREQUENCY  ( 2407UL )\r
47 \r
48 void vInitialiseTimerForIntQueueTest( void )\r
49 {\r
50         /* Ensure interrupts do not start until full configuration is complete. */\r
51         portENTER_CRITICAL();\r
52         {\r
53                 /* Give write access. */\r
54                 SYSTEM.PRCR.WORD = 0xa502;\r
55 \r
56                 /* Cascade two 8bit timer channels to generate the interrupts. \r
57                 8bit timer unit 1 (TMR0 and TMR1) and 8bit timer unit 2 (TMR2 and TMR3 are\r
58                 utilised for this test. */\r
59 \r
60                 /* Enable the timers. */\r
61                 SYSTEM.MSTPCRA.BIT.MSTPA5 = 0;\r
62                 SYSTEM.MSTPCRA.BIT.MSTPA4 = 0;\r
63 \r
64                 /* Enable compare match A interrupt request. */\r
65                 TMR0.TCR.BIT.CMIEA = 1;\r
66                 TMR2.TCR.BIT.CMIEA = 1;\r
67 \r
68                 /* Clear the timer on compare match A. */\r
69                 TMR0.TCR.BIT.CCLR = 1;\r
70                 TMR2.TCR.BIT.CCLR = 1;\r
71 \r
72                 /* Set the compare match value. */\r
73                 TMR01.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );\r
74                 TMR23.TCORA = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / tmrTIMER_0_1_FREQUENCY ) -1 ) / 8 );\r
75 \r
76                 /* 16 bit operation ( count from timer 1,2 ). */\r
77                 TMR0.TCCR.BIT.CSS = 3;\r
78                 TMR2.TCCR.BIT.CSS = 3;\r
79         \r
80                 /* Use PCLK as the input. */\r
81                 TMR1.TCCR.BIT.CSS = 1;\r
82                 TMR3.TCCR.BIT.CSS = 1;\r
83         \r
84                 /* Divide PCLK by 8. */\r
85                 TMR1.TCCR.BIT.CKS = 2;\r
86                 TMR3.TCCR.BIT.CKS = 2;\r
87 \r
88                 /* Enable TMR 0, 2 interrupts. */\r
89                 TMR0.TCR.BIT.CMIEA = 1;\r
90                 TMR2.TCR.BIT.CMIEA = 1;\r
91 \r
92                 /* Set interrupt priority and enable. */\r
93                 IPR( TMR0, CMIA0 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 1;\r
94                 IR( TMR0, CMIA0 ) = 0U;\r
95                 IEN( TMR0, CMIA0 ) = 1U;\r
96 \r
97                 /* Do the same for TMR2, but to vector 129. */\r
98                 IPR( TMR2, CMIA2 ) = configMAX_SYSCALL_INTERRUPT_PRIORITY - 2;\r
99                 IR( TMR2, CMIA2 ) = 0U;\r
100                 IEN( TMR2, CMIA2 ) = 1U;\r
101         }\r
102         portEXIT_CRITICAL();\r
103 }\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 #pragma interrupt r_tmr_cmia0_interrupt(vect=VECT(TMR0,CMIA0))\r
107 void r_tmr_cmia0_interrupt( void )\r
108 {\r
109         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 #pragma interrupt r_tmr_cmia2_interrupt(vect=VECT(TMR2,CMIA2))\r
114 void r_tmr_cmia2_interrupt( void )\r
115 {\r
116         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
117 }\r
118 \r
119 \r
120 \r
121 \r