2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 #ifndef PORTHARDWARE_H
30 #define PORTHARDWARE_H
32 #include "FreeRTOSConfig.h"
34 /*-----------------------------------------------------------*/
36 #define CLR_INT( FLAG_REG, FLAG_MASK ) \
43 : "i" ( _SFR_MEM_ADDR( FLAG_REG ) ), "i" ( ( uint8_t ) ( FLAG_MASK ) ) \
46 #if ( configUSE_TIMER_INSTANCE == 0 )
48 #define TICK_INT_vect TCB0_INT_vect
49 #define INT_FLAGS TCB0_INTFLAGS
50 #define INT_MASK TCB_CAPT_bm
54 TCB0.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
55 TCB0.INTCTRL = TCB_CAPT_bm; \
56 TCB0.CTRLA = TCB_ENABLE_bm; \
59 #elif ( configUSE_TIMER_INSTANCE == 1 )
61 #define TICK_INT_vect TCB1_INT_vect
62 #define INT_FLAGS TCB1_INTFLAGS
63 #define INT_MASK TCB_CAPT_bm
67 TCB1.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
68 TCB1.INTCTRL = TCB_CAPT_bm; \
69 TCB1.CTRLA = TCB_ENABLE_bm; \
72 #elif ( configUSE_TIMER_INSTANCE == 2 )
74 #define TICK_INT_vect TCB2_INT_vect
75 #define INT_FLAGS TCB2_INTFLAGS
76 #define INT_MASK TCB_CAPT_bm
80 TCB2.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
81 TCB2.INTCTRL = TCB_CAPT_bm; \
82 TCB2.CTRLA = TCB_ENABLE_bm; \
85 #elif ( configUSE_TIMER_INSTANCE == 3 )
87 #define TICK_INT_vect TCB3_INT_vect
88 #define INT_FLAGS TCB3_INTFLAGS
89 #define INT_MASK TCB_CAPT_bm
93 TCB3.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
94 TCB3.INTCTRL = TCB_CAPT_bm; \
95 TCB3.CTRLA = TCB_ENABLE_bm; \
98 #elif ( configUSE_TIMER_INSTANCE == 4 )
100 #define TICK_INT_vect RTC_CNT_vect
101 #define INT_FLAGS RTC_INTFLAGS
102 #define INT_MASK RTC_OVF_bm
104 /* Hertz to period for RTC setup */
105 #define RTC_PERIOD_HZ( x ) ( 32768 * ( ( 1.0 / x ) ) )
106 #define TICK_init() \
108 while( RTC.STATUS > 0 ) {; } \
109 RTC.CTRLA = RTC_PRESCALER_DIV1_gc | 1 << RTC_RTCEN_bp; \
110 RTC.PER = RTC_PERIOD_HZ( configTICK_RATE_HZ ); \
111 RTC.INTCTRL |= 1 << RTC_OVF_bp; \
114 #else /* if ( configUSE_TIMER_INSTANCE == 0 ) */
119 #error Invalid timer setting.
120 #endif /* if ( configUSE_TIMER_INSTANCE == 0 ) */
122 /*-----------------------------------------------------------*/
124 #endif /* PORTHARDWARE_H */