blob: e9d4ddc6d888656881c5e2c61dff84d7b1ae5d9b [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.
*/
#include "hw/top_matcha/sw/autogen/top_matcha.h"
#include "sw/device/examples/testdata/hps_images/hps_images.h"
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/dif/dif_uart.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
#include "sw/device/lib/testing/test_framework/status.h"
#include "sw/device/lib/testing/test_framework/test_util.h"
OTTF_DEFINE_TEST_CONFIG();
static dif_uart_t smc_uart;
void _ottf_main(void) {
test_status_set(kTestStatusInTest);
init_uart(TOP_MATCHA_SMC_UART_BASE_ADDR, &smc_uart);
LOG_INFO("[SMC] Start from SMC");
// Create an array with the pointers to the image frame
// Cast the type from unsigned char into uint32_t
const uint32_t *const hps_image_frame[] = {
(const uint32_t *)hps_0, (const uint32_t *)hps_1, (const uint32_t *)hps_2,
(const uint32_t *)hps_3, (const uint32_t *)hps_4, (const uint32_t *)hps_5,
(const uint32_t *)hps_6};
const unsigned int hps_image_frame_byte_len[] = {
hps_0_len, hps_1_len, hps_2_len, hps_3_len,
hps_4_len, hps_5_len, hps_6_len};
const uint32_t golden_checksum[] = {0x0d42e16c, 0x687bc994, 0x7d6ff262,
0xd852fbab, 0x1b119323, 0xc911c378,
0x7725c13a};
unsigned int kNumOfFrames = 7;
mmio_region_t ml_hps_base =
mmio_region_from_addr(TOP_MATCHA_RAM_ML_DMEM_BASE_ADDR + 0x300000);
mmio_region_t ml_checksum_base =
mmio_region_from_addr(TOP_MATCHA_RAM_ML_DMEM_BASE_ADDR + 0x380000);
uintptr_t frame_base_offset = 0;
for (uint32_t frame_idx = 0; frame_idx < kNumOfFrames; frame_idx++) {
// Load HPS images 0-6 into ML DMEM.
// Read HPS images 0-6 from ML DMEM and compute checksum.
CHECK(hps_image_frame_byte_len[frame_idx] % sizeof(uint32_t) == 0,
"The frame is not word align");
for (uintptr_t word_idx = 0;
word_idx < hps_image_frame_byte_len[frame_idx] / sizeof(uint32_t);
word_idx++) {
uintptr_t offset = word_idx * sizeof(uint32_t);
mmio_region_write32(ml_hps_base, offset + frame_base_offset,
hps_image_frame[frame_idx][word_idx]);
}
uint32_t checksum = 0;
uint32_t mem_val, golden_val;
for (uintptr_t word_idx = 0;
word_idx < hps_image_frame_byte_len[frame_idx] / sizeof(uint32_t);
word_idx++) {
uintptr_t offset = word_idx * sizeof(uint32_t);
mem_val = mmio_region_read32(ml_hps_base, offset + frame_base_offset);
golden_val = hps_image_frame[frame_idx][word_idx];
checksum += mem_val;
CHECK(mem_val == hps_image_frame[frame_idx][word_idx],
"Data at offset 0x%x - Expected: 0x%08x | Actual: 0x%08x", offset,
golden_val, mem_val);
}
frame_base_offset += hps_image_frame_byte_len[frame_idx];
// Write checksum into ML DMEM.
mmio_region_write32(ml_checksum_base, 0, checksum);
CHECK(checksum == golden_checksum[frame_idx],
"Checksum is wrong - Expected: 0x%08x | Actual: 0x%08x",
golden_checksum[frame_idx], checksum);
}
test_status_set(kTestStatusPassed);
asm volatile("wfi");
}