Changeset 3f60fb4f in rtems for c/src


Ignore:
Timestamp:
03/04/11 16:03:46 (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, 5, master
Children:
8179916
Parents:
c0640a2
Message:

2011-03-04 Till Straumann <strauman@…>

PR 1738/bsps

  • clock/clock.c, include/bsp.h, network/network.c: system clock driver programs the PIT w/o assuming the CPU clock frequency being a power of two.
Location:
c/src/lib/libbsp/m68k/uC5282
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/m68k/uC5282/ChangeLog

    rc0640a2 r3f60fb4f  
     12011-03-04      Till Straumann <strauman@slac.stanford.edu>
     2
     3        PR 1738/bsps
     4        * clock/clock.c, include/bsp.h, network/network.c: system clock driver
     5        programs the PIT w/o assuming the CPU clock frequency being a power
     6        of two.
     7
    182011-02-17      Till Straumann <strauman@slac.stanford.edu>
    29
  • c/src/lib/libbsp/m68k/uC5282/clock/clock.c

    rc0640a2 r3f60fb4f  
    2727 * Place in static RAM so updates don't hit the SDRAM
    2828 */
    29 extern int __SRAMBASE[];
    30 #define IDLE_COUNTER      __SRAMBASE[0]
    31 #define FILTERED_IDLE     __SRAMBASE[1]
    32 #define MAX_IDLE_COUNT    __SRAMBASE[2]
    33 #define USEC_PER_TICK     __SRAMBASE[3]
     29#define IDLE_COUNTER    __SRAMBASE.idle_counter
     30#define FILTERED_IDLE   __SRAMBASE.filtered_idle
     31#define MAX_IDLE_COUNT  __SRAMBASE.max_idle_count
     32#define PITC_PER_TICK   __SRAMBASE.pitc_per_tick
     33#define NSEC_PER_PITC   __SRAMBASE.nsec_per_pitc
    3434#define FILTER_SHIFT    6
    3535
     
    3838    int i = MCF5282_PIT3_PCNTR;
    3939    if (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF)
    40         i = MCF5282_PIT3_PCNTR - USEC_PER_TICK;
    41     return (USEC_PER_TICK - i) * 1000;
     40        i = MCF5282_PIT3_PCNTR - PITC_PER_TICK;
     41    return (PITC_PER_TICK - i) * NSEC_PER_PITC;
    4242}
    4343
     
    4949#define Clock_driver_support_at_tick()                                       \
    5050    do {                                                                     \
    51         int idle = IDLE_COUNTER;                                             \
     51        unsigned idle = IDLE_COUNTER;                                        \
    5252        IDLE_COUNTER = 0;                                                    \
    5353        if (idle > MAX_IDLE_COUNT)                                           \
     
    7676 * Set up the clock hardware
    7777 *
    78  * Prescale so that it counts in microseconds
    79  * System clock frequency better be 2**n (1<=n<=16) MHz!
     78 * f_pit = f_clk / 2^(preScaleCode+1) / N  = 1/(us_per_tick/us_per_s)
     79 *
     80 * N = f_clk / 2^(preScaleCode+1) * us_per_tick / us_per_s
     81 *
     82 * ns_per_pit_clk = ns_per_s / (f_clk / 2^(preScaleCode+1))
     83 *                = ns_per_s * 2^(preScaleCode+1) / f_clk;
    8084 */
    8185#define Clock_driver_support_initialize_hardware()                       \
    8286    do {                                                                 \
     87                unsigned long long N;                                            \
    8388        int level;                                                       \
    84         int preScaleCode = -2;                                           \
    85         int preScaleDivisor = bsp_get_CPU_clock_speed() / 1000000;       \
    86         while (preScaleDivisor) {                                        \
    87             preScaleDivisor >>= 1;                                       \
    88             preScaleCode++;                                              \
    89         }                                                                \
    90         IDLE_COUNTER = 0;                                                \
    91         FILTERED_IDLE = 0;                                               \
     89        int preScaleCode = 0;                                            \
     90                N  = bsp_get_CPU_clock_speed();                                  \
     91                N *= rtems_configuration_get_microseconds_per_tick();            \
     92                N /= 2*1000000; /* min_prescale * us_per_s */                    \
     93                while ( N > 0x10000 ) {                                          \
     94                        preScaleCode++;                                              \
     95                        N >>= 1;                                                     \
     96                }                                                                \
     97                PITC_PER_TICK  = N;                                              \
     98                N  = 2000000000ULL << preScaleCode;                              \
     99                N /= bsp_get_CPU_clock_speed();                                  \
     100                NSEC_PER_PITC  = N;                                              \
     101        IDLE_COUNTER   = 0;                                              \
     102        FILTERED_IDLE  = 0;                                              \
    92103        MAX_IDLE_COUNT = 0;                                              \
    93104        bsp_allocate_interrupt(PIT3_IRQ_LEVEL, PIT3_IRQ_PRIORITY);       \
     
    102113                            MCF5282_PIT_PCSR_PIE |                       \
    103114                            MCF5282_PIT_PCSR_RLD;                        \
    104         USEC_PER_TICK = rtems_configuration_get_microseconds_per_tick(); \
    105         MCF5282_PIT3_PMR = USEC_PER_TICK - 1;                            \
     115        MCF5282_PIT3_PMR = PITC_PER_TICK - 1;                            \
    106116        MCF5282_PIT3_PCSR = MCF5282_PIT_PCSR_PRE(preScaleCode) |         \
    107117                            MCF5282_PIT_PCSR_PIE |                       \
     
    115125Thread bsp_idle_thread(uint32_t ignored)
    116126{
    117     for(;;)
    118         __asm__ volatile ("addq.l #1,__SRAMBASE"); /* Atomic increment */
     127  /* Atomic increment */
     128  for(;;)
     129    __asm__ volatile ("addq.l #1,%0"::"m"(IDLE_COUNTER));
    119130}
    120131
  • c/src/lib/libbsp/m68k/uC5282/include/bsp.h

    rc0640a2 r3f60fb4f  
    135135#define BSP_IDLE_TASK_BODY bsp_idle_thread
    136136
     137/*
     138 * SRAM. The BSP uses SRAM for maintaining some clock-driver data
     139 *       and for ethernet descriptors (and the initial stack during
     140 *       early boot).
     141 */
     142
     143typedef struct mcf5282BufferDescriptor_ {
     144    volatile uint16_t   status;
     145    uint16_t                    length;
     146    volatile void      *buffer;
     147} mcf5282BufferDescriptor_t;
     148
     149extern struct {
     150        uint32_t                  idle_counter;
     151        uint32_t                  filtered_idle;
     152        uint32_t                  max_idle_count;
     153        uint32_t                  pitc_per_tick;
     154        uint32_t                  nsec_per_pitc;
     155        uint32_t                  pad[3]; /* align to 16-bytes for descriptors */
     156        mcf5282BufferDescriptor_t fec_descriptors[];
     157        /* buffer descriptors are allocated from here */
     158
     159    /* initial stack is at top of SRAM (start.S)  */
     160} __SRAMBASE;
     161
    137162#ifdef __cplusplus
    138163}
  • c/src/lib/libbsp/m68k/uC5282/network/network.c

    rc0640a2 r3f60fb4f  
    8181    #error "Driver must have MCLBYTES > RBUF_SIZE"
    8282#endif
    83 
    84 typedef struct mcf5282BufferDescriptor_ {
    85     volatile uint16_t   status;
    86     uint16_t                    length;
    87     volatile void      *buffer;
    88 } mcf5282BufferDescriptor_t;
    8983
    9084/*
     
    198192 * Allow some space at the beginning for other diagnostic counters
    199193 */
    200 extern char __SRAMBASE[];
    201194static mcf5282BufferDescriptor_t *
    202195mcf5282_bd_allocate(unsigned int count)
    203196{
    204     static mcf5282BufferDescriptor_t *bdp = (mcf5282BufferDescriptor_t *)(__SRAMBASE+16);
     197    static mcf5282BufferDescriptor_t *bdp = __SRAMBASE.fec_descriptors;
    205198    mcf5282BufferDescriptor_t *p = bdp;
    206199
Note: See TracChangeset for help on using the changeset viewer.