forked from M-Labs/nix-servo
- Si5340 should be initialized first before calling any PL register since if Si5340 is not preprogrammed, there is not PL system clock driving any PL register. - Adc Initialization causes the PL MMCM to relock and trigger a global PL reset. Thus, CSR registers should only be altered after Adc is initialized successfully.
87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
# This file is part of Fast Servo Software Package.
|
|
#
|
|
# Copyright (C) 2023 Jakub Matyas
|
|
# Warsaw University of Technology <jakubk.m@gmail.com>
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import mmap
|
|
import os
|
|
import time
|
|
import argparse
|
|
|
|
from pyfastservo.common import (
|
|
LED0_BASE_ADDR,
|
|
LED1_BASE_ADDR,
|
|
LED2_BASE_ADDR,
|
|
LED3_BASE_ADDR,
|
|
MAP_MASK,
|
|
PAGESIZE,
|
|
)
|
|
|
|
ON = 1
|
|
OFF = 0
|
|
|
|
|
|
def turn_on_led(led, on):
|
|
f = os.open("/dev/mem", os.O_SYNC | os.O_RDWR)
|
|
addrs = [LED0_BASE_ADDR, LED1_BASE_ADDR, LED2_BASE_ADDR, LED3_BASE_ADDR]
|
|
addr = addrs[led]
|
|
|
|
with mmap.mmap(
|
|
f,
|
|
PAGESIZE,
|
|
mmap.MAP_SHARED,
|
|
mmap.PROT_READ | mmap.PROT_WRITE,
|
|
offset=addr & ~MAP_MASK,
|
|
) as mem:
|
|
start_addr = addr & MAP_MASK
|
|
stop_addr = start_addr + 4
|
|
if on:
|
|
mem[start_addr:stop_addr] = ON.to_bytes(4, "little")
|
|
else:
|
|
mem[start_addr:stop_addr] = OFF.to_bytes(4, "little")
|
|
contents = mem[start_addr:stop_addr]
|
|
os.close(f)
|
|
|
|
|
|
def turn_off_all_leds():
|
|
addrs = [LED0_BASE_ADDR, LED1_BASE_ADDR, LED2_BASE_ADDR, LED3_BASE_ADDR]
|
|
|
|
f = os.open("/dev/mem", os.O_SYNC | os.O_RDWR)
|
|
for addr in addrs:
|
|
with mmap.mmap(
|
|
f,
|
|
PAGESIZE,
|
|
mmap.MAP_SHARED,
|
|
mmap.PROT_READ | mmap.PROT_WRITE,
|
|
offset=addr & ~MAP_MASK,
|
|
) as mem:
|
|
start_addr = addr & MAP_MASK
|
|
stop_addr = start_addr + 4
|
|
mem[start_addr:stop_addr] = OFF.to_bytes(4, "little")
|
|
os.close(f)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("led", type=int)
|
|
parser.add_argument("state", type=int)
|
|
args = parser.parse_args()
|
|
turn_on_led(args.led, bool(args.state))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|