Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 605bdf68df0f239ac2c74b752cc65b3e3bbe4275 authored by dependabot[bot] on 01 November 2024, 13:22:26 UTC, committed by GitHub on 01 November 2024, 13:22:26 UTC
Bump libopencm3 from `1f3abd4` to `201f5bc`
Bumps [libopencm3](https://github.com/libopencm3/libopencm3) from `1f3abd4` to `201f5bc`.
- [Commits](https://github.com/libopencm3/libopencm3/compare/1f3abd43763fa39d23e737602b6d0011a45c70b2...201f5bcfb3fa70ee34818152463e7139f24db377)

---
updated-dependencies:
- dependency-name: libopencm3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
1 parent 3200c9e
  • Files
  • Changes
  • 91eae56
  • /
  • common
  • /
  • test.c
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:605bdf68df0f239ac2c74b752cc65b3e3bbe4275
directory badge Iframe embedding
swh:1:dir:d376b3f4e65914f88ce37b5814b27eec41c0664d
content badge Iframe embedding
swh:1:cnt:1a24c275f002b0964f126b4a61f63238365aa70a
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
test.c
// SPDX-License-Identifier: Apache-2.0 or CC0-1.0
#include <hal.h>
#include <randombytes.h>
#include <sendfn.h>
#include <stdint.h>

#if defined(SRAM_TIMING_TEST)
#define TEST_BLOCK_SIZE 4096

/* Don't use opencm3 here, since not all platforms might use opencm3, but all
   have these DWT registers */
#define DWT_CTRL           (*(volatile uint32_t*)(0xE0001000u + 0x00))
#define DWT_CYCCNT         (*(volatile uint32_t*)(0xE0001000u + 0x04))
#define DWT_CTRL_CYCCNTENA (1 << 0)
#define SCS_DEMCR          (*(volatile uint32_t*)(0xE000E000u + 0xDFC))
#define SCS_DEMCR_TRCENA   (1 << 24)
/* Need a really precise cycle counter. */
static void cyccnt_enable()
{
	SCS_DEMCR |= SCS_DEMCR_TRCENA;
	DWT_CYCCNT = 0;
	DWT_CTRL |= DWT_CTRL_CYCCNTENA;
}
static inline void cyccnt_start()
{
	DWT_CYCCNT = 0;
}
static inline uint32_t cyccnt_get()
{
  return DWT_CYCCNT;
}

__attribute__((noinline))
static uint32_t test_load(volatile unsigned* ram_block)
{
  asm volatile("cpsid if");
  cyccnt_start();
#define NL "\n\t"
  asm volatile("_MEMLOOP%=:" NL
               "ldr r12, [%0], #4" NL
               "cmp %0, %1" NL
               "bne _MEMLOOP%=" NL
               :"+r" (ram_block): "r" (ram_block + (TEST_BLOCK_SIZE / sizeof(unsigned))): "r12", "cc");
  uint32_t result = cyccnt_get();
  asm volatile("cpsie if");
  return result;
}

__attribute__((noinline))
static uint32_t test_unalignedload(volatile void* ram_block)
{
  volatile unsigned char* ram_block8 = ram_block;
  ram_block8 += 2;
  asm volatile("cpsid if");
  cyccnt_start();
#define NL "\n\t"
  asm volatile("_MEMLOOP%=:" NL
               "ldr r12, [%0], #4" NL
               "cmp %0, %1" NL
               "blt _MEMLOOP%=" NL
               :"+r" (ram_block8): "r" (ram_block8 + TEST_BLOCK_SIZE): "r12", "cc");
  uint32_t result = cyccnt_get();
  asm volatile("cpsie if");
  return result;
}

__attribute__((noinline))
static uint32_t test_store(volatile unsigned* ram_block)
{
  cyccnt_start();
#define NL "\n\t"
  asm volatile("_MEMLOOP%=:" NL
               "str r12, [%0], #4" NL
               "cmp %0, %1" NL
               "bne _MEMLOOP%=" NL
               :"+r" (ram_block): "r" (ram_block + (TEST_BLOCK_SIZE / sizeof(unsigned))): "r12", "cc");
  return cyccnt_get();
}

__attribute__((noinline))
static uint32_t test_loadstore(volatile unsigned* ram_block)
{
  cyccnt_start();
#define NL "\n\t"
  asm volatile("_MEMLOOP%=:" NL
               "str r12, [%0]" NL
               "add r12, r12, #1" NL
               "ldr r12, [%0], #4" NL
               "cmp %0, %1" NL
               "bne _MEMLOOP%=" NL
               :"+r" (ram_block): "r" (ram_block + (TEST_BLOCK_SIZE / sizeof(unsigned))): "r12", "cc");
  return cyccnt_get();
}

static void memory_timing_test(void)
{
  cyccnt_enable();
#define RAMBLK(BLK)                                                       \
  static volatile unsigned ram ## BLK ## _block[TEST_BLOCK_SIZE / sizeof(unsigned) + 1] __attribute__((section(".ram" #BLK)))

#define TEST(BLK) \
  test_load(ram ## BLK ## _block); \
  test_unalignedload(ram ## BLK ## _block);  \
  test_store(ram ## BLK ## _block); \
  test_loadstore(ram ## BLK ## _block); \
  send_unsigned("ram" #BLK " load", test_load(ram ## BLK ## _block)); \
  send_unsigned("ram" #BLK " unalignedload", test_unalignedload(ram ## BLK ## _block));   \
  send_unsigned("ram" #BLK " store", test_store(ram ## BLK ## _block)); \
  send_unsigned("ram" #BLK " loadstore", test_loadstore(ram ## BLK ## _block));

  static volatile unsigned ram1_block[TEST_BLOCK_SIZE / sizeof(unsigned) + 1];
  TEST(1);
#if defined(HAS_SRAM2)
  RAMBLK(2);
  TEST(2);
#endif
#if defined(HAS_SRAM3)
  RAMBLK(3);
  TEST(3);
#endif
#if defined(HAS_CCM)
  static volatile unsigned ramccm_block[TEST_BLOCK_SIZE / sizeof(unsigned) + 1] __attribute__((section(".ccmram")));
  TEST(ccm);
#endif
}
#endif

#ifndef CLOCK_TEST
#define CLOCK_TEST CLOCK_BENCHMARK
#endif

void stacktest(size_t size)
{
  volatile uint32_t mem[size] __attribute__((unused));
  for (unsigned i = 0; i < size; ++i) {
    mem[i] = 0;
  }
}

int main(void)
{
  hal_setup(CLOCK_TEST);
  hal_send_str("Hello world");
  send_unsigned("Stack Size", hal_get_stack_size());
  unsigned rnd;
  randombytes((unsigned char*) &rnd, sizeof(unsigned));
  send_unsigned("Random number", rnd);
  size_t stack;
  hal_spraystack();
  stacktest(100);
  stack = hal_checkstack();
  send_unsigned("stackusage1", stack);
  hal_spraystack();
  stacktest(200);
  stack = hal_checkstack();
  send_unsigned("stackusage2", stack);
#if defined(SRAM_TIMING_TEST)
  memory_timing_test();
#endif
  return 0;
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top