blob: a99ec773732893e7aff2bff6f51a0f7276eeed7e [file] [log] [blame]
--
-- Copyright 2023 Google LLC
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
set_project("CHERIoT soundstream demo")
local shodan_dir = os.getenv("ROOTDIR")
if shodan_dir == nil or shodan_dir == '' then
raise("ROOTDIR not set")
end
local cheriot_out_dir = os.getenv("CHERIOT_OUT_DIR")
if cheriot_out_dir == nil or cheriot_out_dir == '' then
raise("CHERIOT_OUT_DIR not set")
end
local sdkdir = path.join(shodan_dir, "sw/cheriot-rtos/sdk")
includes(sdkdir)
set_toolchains("cheriot-clang")
option("board")
set_default("sencha")
local matcha_dir = path.join(shodan_dir, "hw/matcha")
local dif_dir = path.join(matcha_dir, "sw/device/lib/dif")
local dif_autogen_dir = path.join(dif_dir, "autogen")
local opentitan_dir = path.join(shodan_dir, "hw/opentitan-upstream")
local matcha_gen_dir = path.join(cheriot_out_dir, "opentitan-gen/include/opentitan")
-- Support libraries
includes(path.join(sdkdir, "lib"))
includes(path.join(sdkdir, "lib/freestanding"))
local function is_sencha()
return is_config("board", "sencha")
end
-- Each driver operates in a compartment.
compartment("i2s")
add_files("i2s.cc")
add_files(path.join(dif_dir, "dif_i2s.c"),
path.join(dif_autogen_dir, "dif_i2s_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
if is_sencha() then
compartment("mailbox")
add_files("mailbox.cc")
add_files(path.join(dif_dir, "dif_tlul_mailbox.c"),
path.join(dif_autogen_dir, "dif_tlul_mailbox_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
end
compartment("ml_top")
add_files("ml_top.cc")
add_files(path.join(dif_dir, "dif_ml_top.c"),
path.join(dif_autogen_dir, "dif_ml_top_autogen.c"))
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
-- Soundstream application.
compartment("soundstream")
add_files("soundstream.cc", "encode.cc")
add_files(path.join(matcha_dir, "hw/top_matcha/sw/autogen/top_matcha.c"));
add_includedirs(matcha_dir, matcha_gen_dir, opentitan_dir)
add_defines("CHERIOT_NO_AMBIENT_MALLOC")
-- Firmware image.
firmware("soundstream-firmware")
add_deps("i2s", "ml_top")
if is_sencha() then
add_deps("mailbox")
end
add_deps("soundstream")
add_deps("freestanding", "debug")
on_load(function(target)
target:values_set("board", "$(board)")
-- NB: trusted_stack_frames is a guess; +1'd for any
-- compartment error handler usage?
local threads = {
{
compartment = "soundstream",
priority = 1,
entry_point = "entry",
stack_size = 0x1000, -- 4KB
trusted_stack_frames = 5
},
-- NB: stack sizes bumped for logging
{
compartment = "i2s",
priority = 10,
entry_point = "i2s_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
},
{
compartment = "ml_top",
priority = 10,
entry_point = "ml_top_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
},
}
if is_sencha() then
table.insert(threads, {
compartment = "mailbox",
priority = 10,
entry_point = "mailbox_isr",
stack_size = 0x400, -- 512B
trusted_stack_frames = 3
})
end
target:values_set("threads", threads, {expand = false})
end)