Beckhoff / CX9020

Scripts to build a Debian based Linux system for the CX9020 Embedded PC
GNU General Public License v2.0
47 stars 23 forks source link

Ordering a CX9020 with the U900 #14

Closed stefanpoeter closed 6 years ago

stefanpoeter commented 7 years ago

If I order a CX9020 with the capacitive 1-second UPS (U900), how is it going to work? Will the CX9020 shutdown the OS automatically on powerfailure?

HWilke commented 7 years ago

Unfortunately that is not possible because the 1s UPS is only intended to be used to save persistent data (usually 1MB with TwinCAT) A normal shutdown will take too long. Therefore it is also not implemented to shut down the system automatically. If you want to read the power fail input to react and execute your own logic (e.g. flush file system cache,...) that's a function we could add.

stefanpoeter commented 7 years ago

That would be great.

stefanpoeter commented 7 years ago

Let me know if I can be of any help.

pbruenn commented 7 years ago

Hi Stefan, sorry for the delay, but today is my first day back in the office and previously I hadn't any hardware with USV on hands. It should be fairly simple to implement a GPIO reporting the USV state. I have a few urgent minor bugs one my list to respond first, but I hope I can implement a solution for you within this week. Regards, Patrick

stefanpoeter commented 7 years ago

Hi Patrick, thank you very much, I really appreciate your effort. My offer still stands, if you need any assistance then I am happy to help.

Regards, Stefan

pbruenn commented 7 years ago

Okay, I will share a few brainstorming ideas, in case you already own a CX9020-0100 with U900.

gpio3_31 should be the USV GPIO. That one uses the register 53f90000. With that information we should find a gpio in "/sys/class/gpio/gpiochip.../" with label "53f90000.gpio" Use the "base" address found in the same sysfs directory and add "31". You will get the gpio number, which you can use to export with "/sys/class/gpio/export" The exported gpio will then be available in it's own directory at "/sys/class/gpio/gpioX"

"cat /sys/class/gpio/gpioX/direction" should show "in" and "cat /sys/class/gpio/gpioX/value" shoud show "0" with power connected and "1" with power loss

I will verify that idea tomorrow with real hardware, just posting in case you have hardware available and time to test.

stefanpoeter commented 7 years ago

Not yet, but I will order one right away.

pbruenn commented 7 years ago

I got a little confused with device tree aliases. We are not looking for "53f90000" but for "53f8c000" so this is what I run on a CX9020-0100 / U900:

# check if 64 is the base we are looking for:
cat /sys/class/gpio/gpiochip64/label
53f8c000.gpio

# export gpio3_31 (base + 31)
printf $((64 + 31)) > /sys/class/gpio/export

# check state with power connected
cat /sys/class/gpio/gpio95/value
0

# disconnect power
cat /sys/class/gpio/gpio95/value
1

# power on again
cat /sys/class/gpio/gpio95/value
0

On the first look I would use something like https://github.com/larsks/gpio-watch to run custom emergency shutdown scripts. If you have a better idea let me know. I am still not sure how to add this information to the CX9020 repository to document the S-UPS functionality.

stefanpoeter commented 7 years ago

I like the solution with the gpio-watch tool. Still waiting for my device but checked your solution with a CX9020-0100 without U900. Seems good.

Can I control the TC LED on top of the PLC in a similiar way?

pbruenn commented 7 years ago

Yes, but these LEDs are not directly connected to i.MX53 but to the CCAT FPGA. So you need the ccat_gpio driver to access them. With the loaded driver look for a gpiochip with label "ccat_gpio". It should be a chip with ngpio == 9. They are the 9 RGB LED gpios for TC, FB1 and FB2 LED.

for example:

# in case 503 is the base of out ccat_gpio chip
# export the red gpio of TC LED
printf 503 > /sys/class/gpio/export

# configure as gpio output
printf out > /sys/class/gpio/gpio503/direction

# turn it on
printf 1 > /sys/class/gpio/gpio503/value

# TC LED should be red now.
stefanpoeter commented 7 years ago

Works :-) Thanks

stefanpoeter commented 6 years ago

Is this persistent or do I need to call it on every boot?

# export gpio3_31 (base + 31)
printf $((64 + 31)) > /sys/class/gpio/export

And if I assume correctly than I have to watch the GPIO 95 like so?

gpio_watch -e rising 95
stefanpoeter commented 6 years ago

Solved it myself, writing to the export interface isn't persistent. and the gpio command is the correct one.