#!/bin/sh
# Copyright (c) 2012-2013 National Instruments.
# All rights reserved.
[ "${VERBOSE}" != "no" ] && echo -n "Setting up IRQ priority for deterministic devices:"

#IRQ=61 is used by NI-RIO device on arm
#IRQ is dynamic for NI-RIO device on x64

if [ $(uname -m) = "armv7l" ]; then
  echo 96 > /proc/irq/61/priority
else
  PS=`ps -eo comm,pid | grep -sm 1 "irq/[0-9]*-atomicc" | awk '{print $2}'`
  PRIO=98 # atomicchinch needs higher priority for restarting LVRT
  if [ "${PS}" == "" ]; then
    # A customer could install old RIO on new LVRT, so look for the old driver
    # IRQ thread if we don't find the new one
    PS=`ps -eo comm,pid | grep -sF -m 1 "irq/16-niriochi" | awk '{print $2}'`
    PRIO=96
  fi
  if [ "${PS}" != "" ]; then
    chrt -pf $PRIO $PS
  fi
fi

[ "${VERBOSE}" != "no" ] && echo "done"
