summaryrefslogtreecommitdiff
path: root/Modelica-Arduino-MDD_Arduino_Revised/MDD_build/servo/servo_pot.sh
blob: 41f9d907ccdd07cdfadb4533523c492691c245c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
clear
if [ "$#" -ne 2 ]; then
  echo "Usage: $0 port baudrate" >&2
  exit 1
fi

re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then
   echo "error: $1 -> Not a number" >&2; exit 1
fi

if ! [[ $2 =~ $re ]] ; then
   echo "error: $2-> Not a number" >&2; exit 1
fi

b_rate=$2

present=`pwd`
unamestr=`uname`

if [[ "$unamestr" == 'Linux' ]]; then
	mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include))
	om_path=($(locate /usr/include/omc/c))
	port="/dev/ttyACM$1"
	omc --simCodeTarget=ExperimentalEmbeddedC runMDD_servo_pot.mos
	if [ $? -ne 0 ]; then
		exit 1
	fi
else
	cd c:	
	om_path=($(dir -d OpenModelica*/include/omc/c/))
	path_to_om="C:$om_path"
	cd f:
	mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/))
	if [ $? -eq 0 ]; then
		path_to_mdd="F:/$mdd_path"
	else
		exit 1
	fi
	
	port="COM$1"
	cd $present
	omc --simCodeTarget=ExperimentalEmbeddedC run_servo_pot.mos
	if [ $? -ne 0 ]; then
		exit 1
	fi
fi

avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections servo_pot_main.c -o servo_pot -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]}  
if [ $? -ne 0 ]; then
	exit 1
fi
avr-objcopy -O ihex -R .eeprom servo_pot servo_pot.hex
if [ $? -ne 0 ]; then
	exit 1
fi 
avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:servo_pot.hex
if [ $? -ne 0 ]; then
	exit 1
fi