Fork me on GitHub

root/kernel/cmos.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cmos_update_in_progress
  2. cmos_read_date
  3. cmos_write_date
  4. cmos_read
  5. cmos_write

   1 /*
   2  * fiwix/kernel/cmos.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/asm.h>
   9 #include <fiwix/cmos.h>
  10 
  11 int cmos_update_in_progress(void)
  12 {
  13         return(cmos_read(CMOS_STATA) & CMOS_STATA_UIP);
  14 }
  15 
  16 unsigned char cmos_read_date(unsigned char addr)
  17 {
  18         /* make sure an update isn't in progress */
  19         while(cmos_update_in_progress());
  20 
  21         if(!(cmos_read(CMOS_STATB) & CMOS_STATB_DM)) {
  22                 return BCD2BIN(cmos_read(addr));
  23         }
  24         return cmos_read(addr);
  25 }
  26 
  27 void cmos_write_date(unsigned char addr, unsigned char value)
  28 {
  29         /* make sure an update isn't in progress */
  30         while(cmos_update_in_progress());
  31 
  32         if(!(cmos_read(CMOS_STATB) & CMOS_STATB_DM)) {
  33                 cmos_write(addr, BIN2BCD(value));
  34         }
  35         cmos_write(addr, value);
  36 }
  37 
  38 unsigned char cmos_read(unsigned char addr)
  39 {
  40         unsigned long int flags;
  41 
  42         SAVE_FLAGS(flags); CLI();
  43         outport_b(CMOS_INDEX, addr);
  44         RESTORE_FLAGS(flags);
  45 
  46         return inport_b(CMOS_DATA);
  47 }
  48 
  49 void cmos_write(unsigned char addr, unsigned char value)
  50 {
  51         unsigned long int flags;
  52 
  53         SAVE_FLAGS(flags); CLI();
  54         outport_b(CMOS_INDEX, addr);
  55         outport_b(CMOS_DATA, value);
  56         RESTORE_FLAGS(flags);
  57 }

/* [previous][next][first][last][top][bottom][index][help] */