Changeset 9c2eaca in rtems


Ignore:
Timestamp:
May 4, 2009, 12:53:45 AM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
9a12c7e5
Parents:
81fb3d3
Message:

2009-05-03 Joel Sherrill <joel.sherrill@…>

  • libchip/rtc/ds1375.c, libchip/rtc/mc146818a.c: Fix warnings. Reformat as needed.
Location:
c/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/ChangeLog

    r81fb3d3 r9c2eaca  
     12009-05-03      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libchip/rtc/ds1375.c, libchip/rtc/mc146818a.c: Fix warnings. Reformat
     4        as needed.
     5
    162009-04-29      Chris Johns <chrisj@rtems.org>
    27
  • c/src/libchip/rtc/ds1375.c

    r81fb3d3 r9c2eaca  
    99 *
    1010 *     Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
    11  *         Stanford Linear Accelerator Center, Stanford University.
     11 *      Stanford Linear Accelerator Center, Stanford University.
    1212 *
    1313 * Acknowledgement of sponsorship
     
    1515 * The software was produced by
    1616 *     the Stanford Linear Accelerator Center, Stanford University,
    17  *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
     17 *      under Contract DE-AC03-76SFO0515 with the Department of Energy.
    1818 *
    1919 * Government disclaimer of liability
     
    7171 * Our file descriptors may even be 0..2
    7272 */
    73 #define STDIOSAFE(fmt,args...)          \
    74         do {                                \
    75                 if ( _System_state_Is_up( _System_state_Get() ) ) { \
    76                         fprintf(stderr,fmt,args);   \
    77                 } else {                        \
    78                         printk(fmt,args);           \
    79                 }                               \
    80         } while (0)
     73#define STDIOSAFE(fmt,args...)        \
     74  do {                                \
     75    if ( _System_state_Is_up( _System_state_Get() ) ) { \
     76      fprintf(stderr,fmt,args);   \
     77    } else {                        \
     78      printk(fmt,args);           \
     79    }                               \
     80  } while (0)
    8181 
    8282
    8383STATIC uint8_t ds1375_bcd2bin(uint8_t x)
    8484{
    85 uint8_t h = x & 0xf0;
    86 
    87         /* 8*hi + 2*hi + lo */
    88         return ( h >> 1 ) + ( h >> 3 ) + ( x & 0xf );
     85  uint8_t h = x & 0xf0;
     86
     87  /* 8*hi + 2*hi + lo */
     88  return ( h >> 1 ) + ( h >> 3 ) + ( x & 0xf );
    8989}
    9090
    9191STATIC uint8_t ds1375_bin2bcd(uint8_t x)
    9292{
    93 uint8_t h = x/10;
    94 
    95         return ( h << 4 ) + ( x - ( ( h << 3 ) + ( h << 1 ) ) );
     93  uint8_t h = x/10;
     94
     95  return ( h << 4 ) + ( x - ( ( h << 3 ) + ( h << 1 ) ) );
    9696}
    9797
     
    104104 *             _REG and _OFF happen to be identical).
    105105 */
    106 
    107 
    108 #define DS1375_SEC_REG  0x0
    109 #define DS1375_SEC_OFF  (DS1375_SEC_REG-DS1375_SEC_REG)
     106#define DS1375_SEC_REG  0x0
     107#define DS1375_SEC_OFF  (DS1375_SEC_REG-DS1375_SEC_REG)
    110108/* Extract seconds and convert to binary */
    111 #define DS1375_SEC(x)   ds1375_bcd2bin( ((x)[DS1375_SEC_OFF]) & 0x7f )
    112 
    113 #define DS1375_MIN_REG  0x1
    114 #define DS1375_MIN_OFF  (DS1375_MIN_REG-DS1375_SEC_REG)
     109#define DS1375_SEC(x)  ds1375_bcd2bin( ((x)[DS1375_SEC_OFF]) & 0x7f )
     110
     111#define DS1375_MIN_REG  0x1
     112#define DS1375_MIN_OFF  (DS1375_MIN_REG-DS1375_SEC_REG)
    115113/* Extract minutes and convert to binary */
    116 #define DS1375_MIN(x)   ds1375_bcd2bin( ((x)[DS1375_MIN_OFF]) & 0x7f )
    117 
    118 #define DS1375_HR_REG   0x2
    119 #define DS1375_HR_OFF   (DS1375_HR_REG-DS1375_SEC_REG)
    120 #define DS1375_HR_1224  (1<<6)
    121 #define DS1375_HR_AMPM  (1<<5)
     114#define DS1375_MIN(x)  ds1375_bcd2bin( ((x)[DS1375_MIN_OFF]) & 0x7f )
     115
     116#define DS1375_HR_REG  0x2
     117#define DS1375_HR_OFF  (DS1375_HR_REG-DS1375_SEC_REG)
     118#define DS1375_HR_1224  (1<<6)
     119#define DS1375_HR_AMPM  (1<<5)
    122120/* Are hours in AM/PM representation ?   */
    123 #define DS1375_IS_AMPM(x)       (DS1375_HR_1224 & ((x)[DS1375_HR_OFF]))
     121#define DS1375_IS_AMPM(x)  (DS1375_HR_1224 & ((x)[DS1375_HR_OFF]))
    124122/* Are we PM ?                           */
    125 #define DS1375_IS_PM(x)         (DS1375_HR_AMPM & ((x)[DS1375_HR_OFF]))
     123#define DS1375_IS_PM(x)    (DS1375_HR_AMPM & ((x)[DS1375_HR_OFF]))
    126124/* Extract hours (12h mode) and convert to binary */
    127 #define DS1375_HR_12(x) ds1375_bcd2bin( ((x)[DS1375_HR_OFF]) & 0x1f )
     125#define DS1375_HR_12(x)  ds1375_bcd2bin( ((x)[DS1375_HR_OFF]) & 0x1f )
    128126/* Extract hours (24h mode) and convert to binary */
    129 #define DS1375_HR_24(x) ds1375_bcd2bin( ((x)[DS1375_HR_OFF]) & 0x3f )
    130 
    131 #define DS1375_DAY_REG  0x3
    132 #define DS1375_DAY_OFF  (DS1375_DAY_REG-DS1375_SEC_REG)
    133 #define DS1375_DAT_REG  0x4
    134 #define DS1375_DAT_OFF  (DS1375_DAT_REG-DS1375_SEC_REG)
     127#define DS1375_HR_24(x)  ds1375_bcd2bin( ((x)[DS1375_HR_OFF]) & 0x3f )
     128
     129#define DS1375_DAY_REG  0x3
     130#define DS1375_DAY_OFF  (DS1375_DAY_REG-DS1375_SEC_REG)
     131#define DS1375_DAT_REG  0x4
     132#define DS1375_DAT_OFF  (DS1375_DAT_REG-DS1375_SEC_REG)
    135133/* Extract date and convert to binary    */
    136 #define DS1375_DAT(x)   ds1375_bcd2bin( ((x)[DS1375_DAT_OFF]) & 0x3f )
    137 #define DS1375_MON_REG  0x5
    138 #define DS1375_MON_OFF  (DS1375_MON_REG-DS1375_SEC_REG)
    139 #define DS1375_MON_CTRY         (1<<7)
     134#define DS1375_DAT(x)  ds1375_bcd2bin( ((x)[DS1375_DAT_OFF]) & 0x3f )
     135#define DS1375_MON_REG  0x5
     136#define DS1375_MON_OFF  (DS1375_MON_REG-DS1375_SEC_REG)
     137#define DS1375_MON_CTRY    (1<<7)
    140138/* Is century bit set ?                  */
    141 #define DS1375_IS_CTRY(x)       (((x)[DS1375_MON_OFF]) & DS1375_MON_CTRY)
     139#define DS1375_IS_CTRY(x)  (((x)[DS1375_MON_OFF]) & DS1375_MON_CTRY)
    142140/* Extract month and convert to binary   */
    143 #define DS1375_MON(x)   ds1375_bcd2bin( ((x)[DS1375_MON_OFF]) & 0x1f )
    144 
    145 #define DS1375_YR_REG   0x6
    146 #define DS1375_YR_OFF   (DS1375_YR_REG-DS1375_SEC_REG)
     141#define DS1375_MON(x)  ds1375_bcd2bin( ((x)[DS1375_MON_OFF]) & 0x1f )
     142
     143#define DS1375_YR_REG  0x6
     144#define DS1375_YR_OFF  (DS1375_YR_REG-DS1375_SEC_REG)
    147145/* Extract year and convert to binary    */
    148 #define DS1375_YR(x)    ds1375_bcd2bin( ((x)[DS1375_YR_OFF]) & 0xff )
     146#define DS1375_YR(x)  ds1375_bcd2bin( ((x)[DS1375_YR_OFF]) & 0xff )
    149147
    150148/* CR Register and bit definitions       */
    151 #define DS1375_CR_REG   0xe
    152 #define DS1375_CR_ECLK          (1<<7)
    153 #define DS1375_CR_CLKSEL1       (1<<6)
    154 #define DS1375_CR_CLKSEL0       (1<<5)
    155 #define DS1375_CR_RS2           (1<<4)
    156 #define DS1375_CR_RS1           (1<<3)
    157 #define DS1375_CR_INTCN         (1<<2)
    158 #define DS1375_CR_A2IE          (1<<1)
    159 #define DS1375_CR_A1IE          (1<<0)
    160 
    161 #define DS1375_CSR_REG  0xf
     149#define DS1375_CR_REG  0xe
     150#define DS1375_CR_ECLK    (1<<7)
     151#define DS1375_CR_CLKSEL1  (1<<6)
     152#define DS1375_CR_CLKSEL0  (1<<5)
     153#define DS1375_CR_RS2    (1<<4)
     154#define DS1375_CR_RS1    (1<<3)
     155#define DS1375_CR_INTCN    (1<<2)
     156#define DS1375_CR_A2IE    (1<<1)
     157#define DS1375_CR_A1IE    (1<<0)
     158
     159#define DS1375_CSR_REG  0xf
    162160
    163161/* User SRAM (8 bytes)                   */
    164 #define DS1375_RAM              0x10    /* start of 8 bytes user ram */
     162#define DS1375_RAM    0x10  /* start of 8 bytes user ram */
    165163
    166164/* Access Primitives                     */
    167165
    168 STATIC int
    169 rd_bytes( int fd, uint32_t off, uint8_t *buf, int len )
    170 {
    171 uint8_t ptr = off;
    172 
    173         return 1 == write( fd, &ptr, 1 ) && len == read( fd, buf, len ) ? 0 : -1;
    174 }
    175 
    176 STATIC int
    177 wr_bytes( int fd, uint32_t off, uint8_t *buf, int len )
    178 {
    179 uint8_t d[ len + 1 ];
    180 
    181         /* Must not break up writing of the register pointer and
    182          * the data to-be-written into multiple write() calls
    183          * because every 'write()' operation sends START and
    184          * the chip interprets the first byte after START as
    185          * the register pointer.
    186          */
    187        
    188         d[0] = off;
    189         memcpy( d + 1, buf, len );
    190 
    191         return len + 1 == write( fd, d, len + 1 ) ? 0 : -1;
     166STATIC int rd_bytes(
     167  int      fd,
     168  uint32_t off,
     169  uint8_t *buf,
     170  int      len
     171)
     172{
     173  uint8_t ptr = off;
     174
     175  return 1 == write( fd, &ptr, 1 ) && len == read( fd, buf, len ) ? 0 : -1;
     176}
     177
     178STATIC int wr_bytes(
     179  int      fd,
     180  uint32_t off,
     181  uint8_t *buf,
     182  int      len
     183)
     184{
     185  uint8_t d[ len + 1 ];
     186
     187  /* Must not break up writing of the register pointer and
     188   * the data to-be-written into multiple write() calls
     189   * because every 'write()' operation sends START and
     190   * the chip interprets the first byte after START as
     191   * the register pointer.
     192   */
     193 
     194  d[0] = off;
     195  memcpy( d + 1, buf, len );
     196
     197  return len + 1 == write( fd, d, len + 1 ) ? 0 : -1;
    192198}
    193199
    194200/* Helpers                               */
    195201
    196 static int
    197 getfd( int minor )
    198 {
    199         return open( (const char *)RTC_Table[minor].ulCtrlPort1, O_RDWR );
     202static int getfd(
     203  int minor
     204)
     205{
     206  return open( (const char *)RTC_Table[minor].ulCtrlPort1, O_RDWR );
    200207}
    201208
    202209/* Driver Access Functions               */
    203210
    204 STATIC void
    205 ds1375_initialize( int minor )
    206 {
    207 int     fd;
    208 uint8_t cr;
    209 
    210         if ( ( fd = getfd( minor ) ) >= 0 ) {
    211                 if ( 0 == rd_bytes( fd, DS1375_CR_REG, &cr, 1 ) ) {
    212                         /* make sure clock is enabled */
    213                         if ( ! ( DS1375_CR_ECLK & cr ) ) {
    214                                 cr |= DS1375_CR_ECLK;
    215                                 wr_bytes( fd, DS1375_CR_REG, &cr, 1 );
    216                         }
    217                 }
    218                 close( fd );
    219         }
    220 
    221 }
    222 
    223 STATIC int
    224 ds1375_get_time( int minor, rtems_time_of_day *time )
    225 {
    226 int     rval = -1;
    227 int     fd;
    228 uint8_t buf[DS1375_YR_REG + 1 - DS1375_SEC_REG];
    229 
    230         if ( time && ( ( fd = getfd( minor ) ) >= 0 ) ) {
    231                 if ( 0 == rd_bytes( fd, DS1375_SEC_REG, buf, sizeof(buf) ) ) {
    232                         time->year       =  DS1375_IS_CTRY( buf ) ? 2000 : 1900;
    233                         time->year  +=  DS1375_YR ( buf );
    234                         time->month  =  DS1375_MON( buf );
    235                         time->day    =  DS1375_DAT( buf );      /* DAY is weekday */
    236 
    237                         if ( DS1375_IS_AMPM( buf ) ) {
    238                                 time->hour   = DS1375_HR_12 ( buf );
    239                                 if ( DS1375_IS_PM( buf ) )
    240                                         time->hour += 12;
    241                         } else {
    242                                 time->hour   = DS1375_HR_24 ( buf );
    243                         }
    244 
    245                         time->minute =  DS1375_MIN( buf );
    246                         time->second =  DS1375_SEC( buf );
    247                         time->ticks  = 0;
    248                         rval = 0;
    249                 }
    250                 close( fd );
    251         }
    252         return rval;
    253 }
    254 
    255 STATIC int
    256 ds1375_set_time( int minor, rtems_time_of_day *time )
    257 {
    258 int       rval = -1;
    259 int       fd   = -1;
    260 time_t    secs;
    261 struct tm tm;
    262 uint8_t   buf[DS1375_YR_REG + 1 - DS1375_SEC_REG];
    263 uint8_t   cr = 0xff;
    264         /*
    265          * The clock hardware maintains the day-of-week as a separate counter
    266          * so we must compute it ourselves (rtems_time_of_day doesn't come
    267          * with a day of week).
    268          */
    269         secs = _TOD_To_seconds( time );
    270         /* we're only interested in tm_wday... */
    271         gmtime_r( &secs, &tm );
    272 
    273         buf[DS1375_SEC_OFF] = ds1375_bin2bcd( time->second );
    274         buf[DS1375_MIN_OFF] = ds1375_bin2bcd( time->minute );
    275         /* bin2bcd(hour) implicitly selects 24h mode since ms-bit is clear */
    276         buf[DS1375_HR_OFF]  = ds1375_bin2bcd( time->hour   );
    277         buf[DS1375_DAY_OFF] = tm.tm_wday + 1;
    278         buf[DS1375_DAT_OFF] = ds1375_bin2bcd( time->day    );
    279         buf[DS1375_MON_OFF] = ds1375_bin2bcd( time->month  );
    280        
    281         if ( time->year >= 2000 ) {
    282                 buf[DS1375_YR_OFF]   = ds1375_bin2bcd( time->year - 2000 );
    283                 buf[DS1375_MON_OFF] |= DS1375_MON_CTRY;
    284         } else {
    285                 buf[DS1375_YR_OFF]   = ds1375_bin2bcd( time->year - 1900 );
    286         }
    287 
    288         /*
    289          * Stop clock; update registers and restart. This is slightly
    290          * slower than just writing everyting but if we did that we
    291          * could get inconsistent registers if this routine would not
    292          * complete in less than 1s (says the datasheet) and we don't
    293          * know if we are going to be pre-empted for some time...
    294          */
    295         if ( ( fd = getfd( minor ) ) < 0 ) {
    296                 goto cleanup;
    297         }
    298 
    299         if ( rd_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
    300                 goto cleanup;
    301 
    302         cr &= ~DS1375_CR_ECLK;
    303 
    304         /* This stops the clock */
    305         if ( wr_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
    306                 goto cleanup;
    307 
    308         /* write new contents */
    309         if ( wr_bytes( fd, DS1375_SEC_REG, buf, sizeof(buf) ) )
    310                 goto cleanup;
    311 
    312         rval = 0;
    313        
     211STATIC void ds1375_initialize(
     212  int minor
     213)
     214{
     215  int     fd;
     216  uint8_t cr;
     217
     218  if ( ( fd = getfd( minor ) ) >= 0 ) {
     219    if ( 0 == rd_bytes( fd, DS1375_CR_REG, &cr, 1 ) ) {
     220      /* make sure clock is enabled */
     221      if ( ! ( DS1375_CR_ECLK & cr ) ) {
     222        cr |= DS1375_CR_ECLK;
     223        wr_bytes( fd, DS1375_CR_REG, &cr, 1 );
     224      }
     225    }
     226    close( fd );
     227  }
     228
     229}
     230
     231STATIC int ds1375_get_time(
     232  int                minor,
     233  rtems_time_of_day *time
     234)
     235{
     236  int   rval = -1;
     237  int   fd;
     238  uint8_t  buf[DS1375_YR_REG + 1 - DS1375_SEC_REG];
     239
     240  if ( time && ( ( fd = getfd( minor ) ) >= 0 ) ) {
     241    if ( 0 == rd_bytes( fd, DS1375_SEC_REG, buf, sizeof(buf) ) ) {
     242      time->year    =  DS1375_IS_CTRY( buf ) ? 2000 : 1900;
     243      time->year  +=  DS1375_YR ( buf );
     244      time->month  =  DS1375_MON( buf );
     245      time->day    =  DS1375_DAT( buf );  /* DAY is weekday */
     246
     247      if ( DS1375_IS_AMPM( buf ) ) {
     248        time->hour   = DS1375_HR_12 ( buf );
     249        if ( DS1375_IS_PM( buf ) )
     250          time->hour += 12;
     251      } else {
     252        time->hour   = DS1375_HR_24 ( buf );
     253      }
     254
     255      time->minute =  DS1375_MIN( buf );
     256      time->second =  DS1375_SEC( buf );
     257      time->ticks  = 0;
     258      rval = 0;
     259    }
     260    close( fd );
     261  }
     262  return rval;
     263}
     264
     265STATIC int ds1375_set_time(
     266  int                      minor,
     267  const rtems_time_of_day *time
     268)
     269{
     270  int       rval = -1;
     271  int       fd   = -1;
     272  time_t    secs;
     273  struct tm tm;
     274  uint8_t   buf[DS1375_YR_REG + 1 - DS1375_SEC_REG];
     275  uint8_t   cr = 0xff;
     276
     277  /*
     278   * The clock hardware maintains the day-of-week as a separate counter
     279   * so we must compute it ourselves (rtems_time_of_day doesn't come
     280   * with a day of week).
     281   */
     282  secs = _TOD_To_seconds( time );
     283  /* we're only interested in tm_wday... */
     284  gmtime_r( &secs, &tm );
     285
     286  buf[DS1375_SEC_OFF] = ds1375_bin2bcd( time->second );
     287  buf[DS1375_MIN_OFF] = ds1375_bin2bcd( time->minute );
     288  /* bin2bcd(hour) implicitly selects 24h mode since ms-bit is clear */
     289  buf[DS1375_HR_OFF]  = ds1375_bin2bcd( time->hour   );
     290  buf[DS1375_DAY_OFF] = tm.tm_wday + 1;
     291  buf[DS1375_DAT_OFF] = ds1375_bin2bcd( time->day    );
     292  buf[DS1375_MON_OFF] = ds1375_bin2bcd( time->month  );
     293 
     294  if ( time->year >= 2000 ) {
     295    buf[DS1375_YR_OFF]   = ds1375_bin2bcd( time->year - 2000 );
     296    buf[DS1375_MON_OFF] |= DS1375_MON_CTRY;
     297  } else {
     298    buf[DS1375_YR_OFF]   = ds1375_bin2bcd( time->year - 1900 );
     299  }
     300
     301  /*
     302   * Stop clock; update registers and restart. This is slightly
     303   * slower than just writing everyting but if we did that we
     304   * could get inconsistent registers if this routine would not
     305   * complete in less than 1s (says the datasheet) and we don't
     306   * know if we are going to be pre-empted for some time...
     307   */
     308  if ( ( fd = getfd( minor ) ) < 0 ) {
     309    goto cleanup;
     310  }
     311
     312  if ( rd_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
     313    goto cleanup;
     314
     315  cr &= ~DS1375_CR_ECLK;
     316
     317  /* This stops the clock */
     318  if ( wr_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
     319    goto cleanup;
     320
     321  /* write new contents */
     322  if ( wr_bytes( fd, DS1375_SEC_REG, buf, sizeof(buf) ) )
     323    goto cleanup;
     324
     325  rval = 0;
     326 
    314327cleanup:
    315         if ( fd >= 0 ) {
    316                 if ( ! ( DS1375_CR_ECLK & cr ) ) {
    317                         /* start clock; this handles some cases of failure
    318                         * after stopping the clock by restarting it again
    319                         */
    320                         cr |= DS1375_CR_ECLK;
    321                         if ( wr_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
    322                                 rval = -1;
    323                 }
    324                 close( fd );
    325         }
    326         return rval;
     328  if ( fd >= 0 ) {
     329    if ( ! ( DS1375_CR_ECLK & cr ) ) {
     330      /* start clock; this handles some cases of failure
     331      * after stopping the clock by restarting it again
     332      */
     333      cr |= DS1375_CR_ECLK;
     334      if ( wr_bytes( fd, DS1375_CR_REG, &cr, 1 ) )
     335        rval = -1;
     336    }
     337    close( fd );
     338  }
     339  return rval;
    327340}
    328341
     
    340353rtems_time_of_day rtod;
    341354time_t            secs;
    342        
    343         ds1375_get_time( 0, &rtod );           
    344         secs = _TOD_To_seconds( &rtod );
    345         printf( "%s\n", ctime( &secs ) );
    346         return secs;
     355 
     356  ds1375_get_time( 0, &rtod );   
     357  secs = _TOD_To_seconds( &rtod );
     358  printf( "%s\n", ctime( &secs ) );
     359  return secs;
    347360}
    348361
     
    354367rtems_time_of_day rt;
    355368
    356         if ( !datstr )
    357                 return -1;
    358 
    359         if ( ! strptime( datstr, "%Y-%m-%d/%T", &tm ) )
    360                 return -2;
    361 
    362         if ( ! prt )
    363                 prt = &rt;
    364        
    365         secs = mktime( &tm );
    366 
    367         /* convert to UTC */
    368         gmtime_r( &secs, &tm );
    369 
    370         printf("Y: %"PRIu32" ",  (prt->year    = tm.tm_year + 1900) );
    371         printf("M: %"PRIu32" ",  (prt->month   = tm.tm_mon  +    1) );
    372         printf("D: %"PRIu32" ",  (prt->day     = tm.tm_mday       ) );
    373         printf("h: %"PRIu32" ",  (prt->hour    = tm.tm_hour       ) );
    374         printf("m: %"PRIu32" ",  (prt->minute  = tm.tm_min        ) );
    375         printf("s: %"PRIu32"\n", (prt->second  = tm.tm_sec        ) );
    376         prt->ticks = 0;
    377 
    378         return ( prt == &rt ) ? ds1375_set_time( 0, &rt ) : 0;
     369  if ( !datstr )
     370    return -1;
     371
     372  if ( ! strptime( datstr, "%Y-%m-%d/%T", &tm ) )
     373    return -2;
     374
     375  if ( ! prt )
     376    prt = &rt;
     377 
     378  secs = mktime( &tm );
     379
     380  /* convert to UTC */
     381  gmtime_r( &secs, &tm );
     382
     383  printf("Y: %"PRIu32" ",  (prt->year    = tm.tm_year + 1900) );
     384  printf("M: %"PRIu32" ",  (prt->month   = tm.tm_mon  +    1) );
     385  printf("D: %"PRIu32" ",  (prt->day     = tm.tm_mday       ) );
     386  printf("h: %"PRIu32" ",  (prt->hour    = tm.tm_hour       ) );
     387  printf("m: %"PRIu32" ",  (prt->minute  = tm.tm_min        ) );
     388  printf("s: %"PRIu32"\n", (prt->second  = tm.tm_sec        ) );
     389  prt->ticks = 0;
     390
     391  return ( prt == &rt ) ? ds1375_set_time( 0, &rt ) : 0;
    379392}
    380393
     
    389402uint32_t rval = -1;
    390403
    391         if ( ( fd = open( (const char*)port, O_RDWR ) ) >= 0 ) {
    392 
    393                 if ( 0 == rd_bytes( fd, reg, &v, 1 ) ) {
    394                         rval = v;
    395                 }
    396                 close( fd );
    397         }
    398 
    399         return rval;
     404  if ( ( fd = open( (const char*)port, O_RDWR ) ) >= 0 ) {
     405
     406    if ( 0 == rd_bytes( fd, reg, &v, 1 ) ) {
     407      rval = v;
     408    }
     409    close( fd );
     410  }
     411
     412  return rval;
    400413}
    401414
     
    405418int     fd;
    406419uint8_t v = value;
    407        
    408         if ( ( fd = open( (const char*)port, O_RDWR ) ) >= 0 ) {
    409                 wr_bytes( fd, reg, &v, 1 );
    410                 close( fd );
    411         }
    412 
    413 }
    414 
    415 bool
    416 rtc_ds1375_device_probe( int minor )
    417 {
    418 int fd;
    419 
    420         if ( ( fd = getfd( minor ) ) < 0 ) {
    421                 STDIOSAFE( "ds1375_probe (open): %s\n", strerror( errno ) );
    422                 return false;
    423         }
    424 
    425         /* Try to set file pointer */
    426         if ( 0 != wr_bytes( fd, DS1375_SEC_REG, 0, 0 ) ) {
    427                 STDIOSAFE( "ds1375_probe (wr_bytes): %s\n", strerror( errno ) );
    428                 close( fd );
    429                 return false;
    430         }
    431 
    432         if ( close( fd ) ) {
    433                 STDIOSAFE( "ds1375_probe (close): %s\n", strerror( errno ) );
    434                 return false;
    435         }
    436 
    437         return true;
     420 
     421  if ( ( fd = open( (const char*)port, O_RDWR ) ) >= 0 ) {
     422    wr_bytes( fd, reg, &v, 1 );
     423    close( fd );
     424  }
     425
     426}
     427
     428bool rtc_ds1375_device_probe(
     429 int minor
     430)
     431{
     432  int fd;
     433
     434  if ( ( fd = getfd( minor ) ) < 0 ) {
     435    STDIOSAFE( "ds1375_probe (open): %s\n", strerror( errno ) );
     436    return false;
     437  }
     438
     439  /* Try to set file pointer */
     440  if ( 0 != wr_bytes( fd, DS1375_SEC_REG, 0, 0 ) ) {
     441    STDIOSAFE( "ds1375_probe (wr_bytes): %s\n", strerror( errno ) );
     442    close( fd );
     443    return false;
     444  }
     445
     446  if ( close( fd ) ) {
     447    STDIOSAFE( "ds1375_probe (close): %s\n", strerror( errno ) );
     448    return false;
     449  }
     450
     451  return true;
    438452}
    439453
    440454rtc_fns rtc_ds1375_fns = {
    441         deviceInitialize:       ds1375_initialize,
    442         deviceGetTime:          ds1375_get_time,
    443         deviceSetTime:          ds1375_set_time,
     455  deviceInitialize:  ds1375_initialize,
     456  deviceGetTime:    ds1375_get_time,
     457  deviceSetTime:    ds1375_set_time,
    444458};
  • c/src/libchip/rtc/mc146818a.c

    r81fb3d3 r9c2eaca  
    135135 */
    136136int mc146818a_set_time(
    137   int                minor,
    138   rtems_time_of_day *time
     137  int                      minor,
     138  const rtems_time_of_day *time
    139139)
    140140{
Note: See TracChangeset for help on using the changeset viewer.