Changeset 9a49a96 in rtems


Ignore:
Timestamp:
Sep 5, 2008, 1:24:26 PM (11 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, 4.9, master
Children:
cf594ad7
Parents:
18039f10
Message:

Improved parameter checks for bit rate function.

Location:
c/src/lib/libbsp/powerpc/gen5200
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/powerpc/gen5200/ChangeLog

    r18039f10 r9a49a96  
     12008-09-04      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * include/mscan-base.h, mscan/mscan-base.c, mscan/mscan.c,
     4        mscan/mscan_int.h: Improved parameter checks for bit rate function.
     5
    162008-09-03      Joel Sherrill <joel.sherrill@oarcorp.com>
    27
  • c/src/lib/libbsp/powerpc/gen5200/include/mscan-base.h

    r18039f10 r9a49a96  
    3232 */
    3333
    34 #define MSCAN_BIT_RATE_DEFAULT 100000
     34#define MSCAN_BIT_RATE_MIN 10000
     35
     36#define MSCAN_BIT_RATE_MAX 1000000
     37
     38#define MSCAN_BIT_RATE_DEFAULT 125000
    3539
    3640#define MSCAN_FILTER_NUMBER_MIN 0
     
    232236} mscan_context;
    233237
    234 void mscan_enable( mscan *m, unsigned bit_rate);
     238bool mscan_enable( mscan *m, unsigned bit_rate);
    235239
    236240void mscan_disable( mscan *m);
     
    238242void mscan_interrupts_disable( mscan *m);
    239243
    240 void mscan_set_bit_rate( mscan *m, unsigned bit_rate);
     244bool mscan_set_bit_rate( mscan *m, unsigned bit_rate);
    241245
    242246void mscan_initialization_mode_enter( mscan *m, mscan_context *context);
  • c/src/lib/libbsp/powerpc/gen5200/mscan/mscan-base.c

    r18039f10 r9a49a96  
    140140 * in [bits/s].
    141141 */
    142 void mscan_set_bit_rate( mscan *m, unsigned can_bit_rate)
     142bool mscan_set_bit_rate( mscan *m, unsigned can_bit_rate)
    143143{
    144144  mscan_context context;
    145   uint32_t prescale_val = 0;
     145  unsigned prescale_val = 0;
    146146  uint8_t tq_no,
    147147    tseg_1,
     
    149149    sseg;
    150150
     151  if (can_bit_rate < MSCAN_BIT_RATE_MIN || can_bit_rate > MSCAN_BIT_RATE_MAX) {
     152    return false;
     153  }
     154
    151155  /* Enter initialization mode */
    152156  mscan_initialization_mode_enter( m, &context);
     
    154158  /* get optimized prescaler value */
    155159  prescale_val = prescaler_calculation(can_bit_rate, IPB_CLOCK, &tq_no);
     160
     161  /* Check prescaler value */
     162  if (prescale_val > 64) {
     163    /* Leave initialization mode */
     164    mscan_initialization_mode_leave( m, &context);
     165   
     166    return false;
     167  }
    156168
    157169  /* get time segment length from time segment table */
     
    186198  /* Leave initialization mode */
    187199  mscan_initialization_mode_leave( m, &context);
     200
     201  return true;
    188202}
    189203
     
    281295 * The module is set to listen only mode.
    282296 */
    283 void mscan_enable( mscan *m, unsigned bit_rate)
    284 {
     297bool mscan_enable( mscan *m, unsigned bit_rate)
     298{
     299  bool s = true;
     300
    285301  /* Disable the module */
    286302  mscan_disable( m);
     
    296312
    297313  /* Set bit rate and leave initialization mode */
    298   mscan_set_bit_rate( m, bit_rate);
     314  s = mscan_set_bit_rate( m, bit_rate);
    299315
    300316  /* Clear all flags */
     
    303319  /* Disable interrupts */
    304320  mscan_interrupts_disable( m);
     321
     322  return s;
    305323}
    306324
  • c/src/lib/libbsp/powerpc/gen5200/mscan/mscan.c

    r18039f10 r9a49a96  
    496496
    497497  /* perform all can bit time settings */
    498   mscan_set_bit_rate(m, CAN_BIT_RATE);
     498  (void) mscan_set_bit_rate(m, MSCAN_BIT_RATE_DEFAULT);
    499499
    500500  /* Enter initialization mode */
     
    11861186      /* set can bitrate */
    11871187    case MSCAN_SET_BAUDRATE:
    1188 
    1189       /* check bitrate settings */
    1190       if (((ctrl_parms->ctrl_can_bitrate) >= CAN_BIT_RATE_MIN)
    1191           && ((ctrl_parms->ctrl_can_bitrate) <= CAN_BIT_RATE_MAX)) {
    1192 
    1193         /* perform all can bit time settings */
    1194         mscan_set_bit_rate(m, ctrl_parms->ctrl_can_bitrate);
    1195 
    1196         /* enable ints. */
    1197         mscan_interrupts_enable(m);
    1198 
    1199         /* wait for bus sync. */
    1200         mpc5200_mscan_wait_sync(m);
    1201 
    1202         return RTEMS_SUCCESSFUL;
    1203       } else {
    1204 
     1188      /* perform all can bit time settings */
     1189      if (!mscan_set_bit_rate(m, ctrl_parms->ctrl_can_bitrate)) {
    12051190        return RTEMS_UNSATISFIED;
    12061191      }
     1192
     1193      /* enable ints. */
     1194      mscan_interrupts_enable(m);
     1195
     1196      /* wait for bus sync. */
     1197      mpc5200_mscan_wait_sync(m);
    12071198
    12081199      break;
  • c/src/lib/libbsp/powerpc/gen5200/mscan/mscan_int.h

    r18039f10 r9a49a96  
    3939#define MSCAN_NORMAL_MODE            4
    4040#define MSCAN_SLEEP_MODE             8
    41 
    42 #define CAN_BIT_RATE_MAX         1000000
    43 #define CAN_BIT_RATE_MIN         100000
    44 #define CAN_BIT_RATE             100000
    4541
    4642#define MSCAN_RX_BUFF_NOACTIVE   (0 << 4)
Note: See TracChangeset for help on using the changeset viewer.