Skip to content

Instantly share code, notes, and snippets.

@EarlGray
Created March 21, 2015 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EarlGray/e80cf659fff61e26be31 to your computer and use it in GitHub Desktop.
Save EarlGray/e80cf659fff61e26be31 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# CMOS reader in Bash
#
# Copyright (C) 2015, ZOG Industries Inc, Dmytro S.
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided that
# the above copyright notice and this permission notice appear in all
# copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
# FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
CMOS_CMD_PORT=0x70
CMOS_DAT_PORT=0x71
CMOS_REG_SECS=0x00
CMOS_REG_MINS=0x02
CMOS_REG_HOURS=0x04
CMOS_REG_DAY=0x07
CMOS_REG_MONTH=0x08
CMOS_REG_YEAR=0x09
read_cmos () {
local reg=$1
echo $reg | xxd -r | tee | dd of=/dev/port bs=1 seek=$(($CMOS_CMD_PORT)) 2>/dev/null
dd if=/dev/port bs=1 count=1 skip=$(($CMOS_DAT_PORT)) 2>/dev/null | xxd -p
}
read_date () {
local year=`read_cmos $CMOS_REG_YEAR`
local month=`read_cmos $CMOS_REG_MONTH`
local day=`read_cmos $CMOS_REG_DAY`
echo "20$year/$month/$day"
}
read_time () {
local hours=`read_cmos $CMOS_REG_HOURS`
local mins=`read_cmos $CMOS_REG_MINS`
local secs=`read_cmos $CMOS_REG_SECS`
echo "${hours}:${mins}:${secs}"
}
echo "$(read_date) $(read_time)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment