1##
2##   ______                              _
3##  / _____)             _              | |
4## ( (____  _____ ____ _| |_ _____  ____| |__
5##  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
6##  _____) ) ____| | | || |_| ____( (___| | | |
7## (______/|_____)_|_|_| \__)_____)\____)_| |_|
8## (C)2013-2017 Semtech
9##  ___ _____ _   ___ _  _____ ___  ___  ___ ___
10## / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
11## \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
12## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
13## embedded.connectivity.solutions.==============
14##
15## License:  Revised BSD License, see LICENSE.TXT file included in the project
16## Authors:  Johannes Bruder (STACKFORCE), Miguel Luis (Semtech)
17##
18project(mac)
19cmake_minimum_required(VERSION 3.6)
20
21#---------------------------------------------------------------------------------------
22# Options
23#---------------------------------------------------------------------------------------
24
25# Allow selection of region
26option(REGION_EU868 "Region EU868" ON)
27option(REGION_US915 "Region US915" OFF)
28option(REGION_CN779 "Region CN779" OFF)
29option(REGION_EU433 "Region EU433" OFF)
30option(REGION_AU915 "Region AU915" OFF)
31option(REGION_AS923 "Region AS923" OFF)
32option(REGION_CN470 "Region CN470" OFF)
33option(REGION_KR920 "Region KR920" OFF)
34option(REGION_IN865 "Region IN865" OFF)
35option(REGION_RU864 "Region RU864" OFF)
36set(REGION_LIST REGION_EU868 REGION_US915 REGION_CN779 REGION_EU433 REGION_AU915 REGION_AS923 REGION_CN470 REGION_KR920 REGION_IN865 REGION_RU864)
37
38# AS923 Channel Plan
39set(REGION_AS923_DEFAULT_CHANNEL_PLAN_LIST CHANNEL_PLAN_GROUP_AS923_1 CHANNEL_PLAN_GROUP_AS923_2 CHANNEL_PLAN_GROUP_AS923_3 CHANNEL_PLAN_GROUP_AS923_4 CHANNEL_PLAN_GROUP_AS923_1_JP_CH24_CH38_LBT CHANNEL_PLAN_GROUP_AS923_1_JP_CH24_CH38_DC CHANNEL_PLAN_GROUP_AS923_1_JP_CH37_CH61_LBT_DC)
40set(REGION_AS923_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_GROUP_AS923_1 CACHE STRING "Default channel plan for AS923 is CHANNEL_PLAN_GROUP_AS923_1")
41set_property(CACHE REGION_AS923_DEFAULT_CHANNEL_PLAN PROPERTY STRINGS ${REGION_AS923_DEFAULT_CHANNEL_PLAN_LIST})
42
43# CN470 Channel Plan
44set(REGION_CN470_DEFAULT_CHANNEL_PLAN_LIST CHANNEL_PLAN_20MHZ_TYPE_A CHANNEL_PLAN_20MHZ_TYPE_B CHANNEL_PLAN_26MHZ_TYPE_A CHANNEL_PLAN_26MHZ_TYPE_B)
45set(REGION_CN470_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_20MHZ_TYPE_A CACHE STRING "Default channel plan for CN470 is CHANNEL_PLAN_20MHZ_TYPE_A")
46set_property(CACHE REGION_CN470_DEFAULT_CHANNEL_PLAN PROPERTY STRINGS ${REGION_CN470_DEFAULT_CHANNEL_PLAN_LIST})
47
48
49#---------------------------------------------------------------------------------------
50# Target
51#---------------------------------------------------------------------------------------
52set( MAC_BUILD_SOURCES
53     ${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCommon.c
54     ${CMAKE_CURRENT_SOURCE_DIR}/region/Region.c
55     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMac.c
56     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacAdr.c
57     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacClassB.c
58     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacCommands.c
59     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacConfirmQueue.c
60     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacCrypto.c
61     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacParser.c
62     ${CMAKE_CURRENT_SOURCE_DIR}/LoRaMacSerializer.c )
63
64if(REGION_AS923 STREQUAL ON)
65set( MAC_BUILD_SOURCES
66    ${MAC_BUILD_SOURCES}
67    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionAS923.c" )
68endif()
69
70if(REGION_AU915 STREQUAL ON)
71set( MAC_BUILD_SOURCES
72     ${MAC_BUILD_SOURCES}
73     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionAU915.c" )
74endif()
75
76if(REGION_CN470 STREQUAL ON)
77set( MAC_BUILD_SOURCES
78     ${MAC_BUILD_SOURCES}
79     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN470.c"
80     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN470A20.c"
81     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN470B20.c"
82     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN470A26.c"
83     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN470B26.c" )
84endif()
85
86if(REGION_CN779 STREQUAL ON)
87set( MAC_BUILD_SOURCES
88    ${MAC_BUILD_SOURCES}
89    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionCN779.c" )
90endif()
91
92if(REGION_EU433 STREQUAL ON)
93set( MAC_BUILD_SOURCES
94    ${MAC_BUILD_SOURCES}
95    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionEU433.c" )
96endif()
97
98if(REGION_EU868 STREQUAL ON)
99set( MAC_BUILD_SOURCES
100    ${MAC_BUILD_SOURCES}
101    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionEU868.c" )
102endif()
103
104if(REGION_IN865 STREQUAL ON)
105set( MAC_BUILD_SOURCES
106    ${MAC_BUILD_SOURCES}
107    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionIN865.c" )
108endif()
109
110if(REGION_KR920 STREQUAL ON)
111set( MAC_BUILD_SOURCES
112    ${MAC_BUILD_SOURCES}
113    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionKR920.c" )
114endif()
115
116if(REGION_RU864 STREQUAL ON)
117set( MAC_BUILD_SOURCES
118    ${MAC_BUILD_SOURCES}
119    "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionRU864.c" )
120endif()
121
122if(REGION_US915 STREQUAL ON)
123set( MAC_BUILD_SOURCES
124     ${MAC_BUILD_SOURCES}
125     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionBaseUS.c"
126     "${CMAKE_CURRENT_SOURCE_DIR}/region/RegionUS915.c" )
127endif()
128
129add_library(${PROJECT_NAME} OBJECT EXCLUDE_FROM_ALL ${MAC_BUILD_SOURCES})
130
131# Loops through all regions and add compile time definitions for the enabled ones.
132foreach( REGION ${REGION_LIST} )
133    if(${REGION})
134        target_compile_definitions(${PROJECT_NAME} PUBLIC -D"${REGION}")
135    endif()
136endforeach()
137
138# Applies AS923 channel plan
139target_compile_definitions(${PROJECT_NAME} PRIVATE -DREGION_AS923_DEFAULT_CHANNEL_PLAN=${REGION_AS923_DEFAULT_CHANNEL_PLAN})
140
141# Applies CN470 channel plan
142target_compile_definitions(${PROJECT_NAME} PRIVATE -DREGION_CN470_DEFAULT_CHANNEL_PLAN=${REGION_CN470_DEFAULT_CHANNEL_PLAN})
143
144
145# Add define if class B is supported
146target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${CLASSB_ENABLED}>:LORAMAC_CLASSB_ENABLED>)
147
148# SecureElement NVM
149if(${SECURE_ELEMENT} MATCHES SOFT_SE)
150    target_compile_definitions(${PROJECT_NAME} PRIVATE -DSOFT_SE)
151endif()
152
153add_dependencies(${PROJECT_NAME} board)
154
155target_include_directories( ${PROJECT_NAME} PUBLIC
156    ${CMAKE_CURRENT_SOURCE_DIR}
157    ${CMAKE_CURRENT_SOURCE_DIR}/region
158    $<TARGET_PROPERTY:system,INTERFACE_INCLUDE_DIRECTORIES>
159    $<TARGET_PROPERTY:radio,INTERFACE_INCLUDE_DIRECTORIES>
160    $<TARGET_PROPERTY:board,INTERFACE_INCLUDE_DIRECTORIES>
161)
162
163set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11)
164