Changeset 8d989c5 in rtems


Ignore:
Timestamp:
Oct 1, 2019, 11:48:27 AM (3 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
7685b48
Parents:
47e5c1d
git-author:
Sebastian Huber <sebastian.huber@…> (10/01/19 11:48:27)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/02/19 05:01:36)
Message:

score: Install timecounter according to quality

This makes it possible to install higher quality timecounter in
plug-and-play systems and helps to override the clock driver provided
timecounter in some test scenarios.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/kern_tc.c

    r47e5c1d r8d989c5  
    13951395        if (tc->tc_quality < 0)
    13961396                return;
     1397#endif /* __rtems__ */
    13971398        if (tc->tc_quality < timecounter->tc_quality)
    13981399                return;
     
    14001401            tc->tc_frequency < timecounter->tc_frequency)
    14011402                return;
     1403#ifndef __rtems__
    14021404        (void)tc->tc_get_timecount(tc);
    14031405        (void)tc->tc_get_timecount(tc);
  • testsuites/sptests/sptimecounter01/init.c

    r47e5c1d r8d989c5  
    11/*
    2  * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2015, 2019 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    3030const char rtems_test_name[] = "SPTIMECOUNTER 1";
    3131
     32#define TEST_QUAL 1234
     33
     34#define TEST_FREQ 1000000
     35
    3236typedef struct {
    33   struct timecounter tc_soft;
    34   u_int tc_soft_counter;
     37  struct timecounter tc;
     38  uint32_t counter;
     39  struct timecounter tc_2;
     40  uint32_t counter_2;
    3541} test_context;
    3642
    3743static test_context test_instance;
    3844
    39 static uint32_t test_get_timecount_soft(struct timecounter *tc)
     45static uint32_t test_get_timecount(struct timecounter *tc)
    4046{
    4147  test_context *ctx;
    4248
    43   ctx = RTEMS_CONTAINER_OF(tc, test_context, tc_soft);
    44   ++ctx->tc_soft_counter;
    45 
    46   return ctx->tc_soft_counter;
     49  ctx = RTEMS_CONTAINER_OF(tc, test_context, tc);
     50  ++ctx->counter;
     51
     52  return ctx->counter;
     53}
     54
     55static uint32_t test_get_timecount_2(struct timecounter *tc)
     56{
     57  test_context *ctx;
     58
     59  ctx = RTEMS_CONTAINER_OF(tc, test_context, tc_2);
     60  ++ctx->counter_2;
     61
     62  return ctx->counter_2;
     63}
     64
     65static void test_install(test_context *ctx)
     66{
     67  struct timecounter *tc;
     68  struct timecounter *tc_2;
     69  uint32_t c;
     70  uint32_t c_2;
     71
     72  tc = &ctx->tc;
     73  tc_2 = &ctx->tc_2;
     74  c = ctx->counter;
     75  c_2 = ctx->counter_2;
     76
     77  tc_2->tc_get_timecount = test_get_timecount_2;
     78  tc_2->tc_counter_mask = 0x0fffffff;
     79  tc_2->tc_frequency = TEST_FREQ - 1;
     80  tc_2->tc_quality = TEST_QUAL;
     81  _Timecounter_Install(tc_2);
     82  assert(ctx->counter == c);
     83  assert(ctx->counter_2 == c_2);
     84
     85  tc_2->tc_get_timecount = test_get_timecount_2;
     86  tc_2->tc_counter_mask = 0x0fffffff;
     87  tc_2->tc_frequency = TEST_FREQ - 1;
     88  tc_2->tc_quality = TEST_QUAL + 1;
     89  _Timecounter_Install(tc_2);
     90  assert(ctx->counter == c + 1);
     91  assert(ctx->counter_2 == c_2 + 1);
     92
     93  tc->tc_get_timecount = test_get_timecount;
     94  tc->tc_counter_mask = 0x0fffffff;
     95  tc->tc_frequency = TEST_FREQ;
     96  tc->tc_quality = TEST_QUAL + 1;
     97  _Timecounter_Install(tc);
     98  assert(ctx->counter == c + 2);
     99  assert(ctx->counter_2 == c_2 + 2);
    47100}
    48101
    49102void boot_card(const char *cmdline)
    50103{
    51   test_context *ctx = &test_instance;
    52   struct timecounter *tc_soft = &ctx->tc_soft;
    53   uint64_t soft_freq = 1000000;
     104  test_context *ctx;
     105  struct timecounter *tc;
    54106  struct bintime bt;
    55107  struct timeval tv;
    56108  struct timespec ts;
    57109
     110  ctx = &test_instance;
     111  tc = &ctx->tc;
     112
    58113  TEST_BEGIN();
    59114
     
    121176  assert(bt.frac == 0);
    122177
    123   ctx->tc_soft_counter = 0;
    124   tc_soft->tc_get_timecount = test_get_timecount_soft;
    125   tc_soft->tc_counter_mask = 0x0fffffff;
    126   tc_soft->tc_frequency = soft_freq;
    127   tc_soft->tc_quality = 1234;
    128   _Timecounter_Install(tc_soft);
    129   assert(ctx->tc_soft_counter == 1);
    130 
    131   rtems_bsd_binuptime(&bt);
    132   assert(ctx->tc_soft_counter == 2);
     178  ctx->counter = 0;
     179  tc->tc_get_timecount = test_get_timecount;
     180  tc->tc_counter_mask = 0x0fffffff;
     181  tc->tc_frequency = TEST_FREQ;
     182  tc->tc_quality = TEST_QUAL;
     183  _Timecounter_Install(tc);
     184  assert(ctx->counter == 1);
     185
     186  rtems_bsd_binuptime(&bt);
     187  assert(ctx->counter == 2);
    133188
    134189  assert(bt.sec == 1);
    135190  assert(bt.frac == 18446744073708);
    136191
    137   ctx->tc_soft_counter = 0xf0000000 | 1;
    138   rtems_bsd_binuptime(&bt);
    139   assert(ctx->tc_soft_counter == (0xf0000000 | 2));
     192  ctx->counter = 0xf0000000 | 1;
     193  rtems_bsd_binuptime(&bt);
     194  assert(ctx->counter == (0xf0000000 | 2));
    140195
    141196  assert(bt.sec == 1);
     
    143198
    144199  /* Ensure that the fraction overflows and the second remains constant */
    145   ctx->tc_soft_counter = (0xf0000000 | 1) + soft_freq;
    146   rtems_bsd_binuptime(&bt);
    147   assert(ctx->tc_soft_counter == (0xf0000000 | 2) + soft_freq);
     200  ctx->counter = (0xf0000000 | 1) + TEST_FREQ;
     201  rtems_bsd_binuptime(&bt);
     202  assert(ctx->counter == (0xf0000000 | 2) + TEST_FREQ);
    148203  assert(bt.sec == 1);
    149204  assert(bt.frac == 18446742522092);
    150205
     206  test_install(ctx);
     207
    151208  TEST_END();
    152209
Note: See TracChangeset for help on using the changeset viewer.