Skip to content

Commit

Permalink
Merge remote-tracking branch 'carkot/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlevchenko committed Sep 8, 2016
2 parents ec21d48 + c08b1c4 commit a00e93e
Show file tree
Hide file tree
Showing 748 changed files with 167,053 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.DS_Store
.idea/shelf
dependencies
dist
translator/src/test/kotlin/tests/*/linked
out
tmp
workspace.xml
*.versionsBackup

.gradle
build
translator/.gradle/2.9/taskArtifacts

kotstd/kotstd.iml


# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# local project files
lib/
.idea/
proto/compiler/protoc-artifacts
proto/compiler/tests

proto/compiler/google/src/google/protobuf/compiler/kotlin/bin
proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc

# translator auto generated artifacts
kotstd/ll
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Nikolay Igotti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# kotlin-native
# kotlin-native
75 changes: 75 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
clr='\033[1;33m'
red='\033[0;31m'
nc='\033[0m'

# ============= Building ================
# Build Proto Compiler
echo -e "${clr}Building protoc compiler${nc}"
cd proto/compiler
echo -e "${clr}Checking prerequisites for building protoc${nc}"
./pre-build.sh
if [ $? -ne 0 ]; then
echo -e "${red}Error launching carkot/proto/compiler/pre-build.sh${nc}"
exit 1
fi

echo -e "${clr}Building protoc${nc}"
make
if [ $? -ne 0 ]; then
echo -e "${red}Error building protoc with carkot/proto/compiler/Makefile ${nc}"
exit 1
fi
cd ../../

# Compile proto-files
echo -e "${clr}Compiling proto-files sources${nc}"
cd proto/protofiles_sources
./compile_proto.sh
if [ $? -ne 0 ]; then
echo -e "${red}Error compiling proto-files with carkot/proto/protofiles_sources/compile_proto.sh${nc}"
exit 1
fi
cd ../../

# Build central server
echo -e "${clr}Building central server${nc}"
cd server
./gradlew build
if [ $? -ne 0 ]; then
echo -e "${red}Error building central server with carkot/server/gradlew build${nc}"
exit 1
fi
cd ../

# Build Raspberry server
echo -e "${clr}Building Raspberry Pi server${nc}"
cd car_srv/kotlinSrv
./build.sh
if [ $? -ne 0 ]; then
echo -e "${red}Error building Raspberry Pi server with carkot/car_srv/kotlinSrv/build.sh${nc}"
exit 1
fi
cd ../../

# Build Kotlin->Native translator
echo -e "${clr}Building translator${nc}"
cd translator
./gradlew jar
if [ $? -ne 0 ]; then
echo -e "${red}Error building translator with translator/gradlew jar${nc}"
exit 1
fi
cd ../

# Build Kotstd libary for translator
echo -e "${clr}Building Kotstd${nc}"
cd kotstd
make
if [ $? -ne 0 ]; then
echo -e "${red}Error building Kotlin STDlib with kotstd/Makefile${nc}"
exit 1
fi



2 changes: 2 additions & 0 deletions car_cfmw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags
bin
71 changes: 71 additions & 0 deletions car_cfmw/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
SRC_DIR=src
BIN_DIR=bin

CAR_FMW_OBJ=$(BIN_DIR)/car_fmw.o
CAR_FMW_ELF=$(BIN_DIR)/car_fmw.elf
CAR_FMW_BIN=$(BIN_DIR)/car_fmw.bin

LIB_CARHW_DIR=../car_hw
LIB_CARHW_OBJ=$(LIB_CARHW_DIR)/bin/car_hw.o
LIB_CARHW_LIB_DIR=$(LIB_CARHW_DIR)/src/lib/

CC=arm-none-eabi-gcc
AS=arm-none-eabi-as
LD=arm-none-eabi-ld
OBJ_COPY=arm-none-eabi-objcopy

INCLUDES=-I$(LIB_CARHW_LIB_DIR)/cmsis \
-I$(LIB_CARHW_LIB_DIR)/stdperiph \
-I$(LIB_CARHW_LIB_DIR)/stm32f4d \
-I$(LIB_CARHW_LIB_DIR)/usb_device \
-I$(LIB_CARHW_LIB_DIR)/usb_otg \
-I$(LIB_CARHW_LIB_DIR)/usb_vcp \
-I$(LIB_CARHW_LIB_DIR)/usart \
-I$(LIB_CARHW_DIR)/src/include \
-I$(SRC_DIR)

DEFINES=-DUSE_STM32_DISCOVERY=1 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F4XX=1 -DHSE_VALUE=8000000
CFLAGS=-g -nostdlib -ffreestanding -O0 \
-mcpu=cortex-m3 -mfloat-abi=soft -mthumb \
$(DEFINES)
ASMFLAGS=-g -mthumb

LD_ALL_DEPS=$(LD) -r $(filter %.o,$^) -o $@
CC_ALL_DEPS=$(CC) $(CFLAGS) -c $(INCLUDES) $(filter %.c,$^) -o $@
AS_ALL_DEPS=$(AS) $(ASMFLAGS) $(filter %.s,$^) -o $@

dirhs=$(wildcard $(1)/*.h)
dircs=$(wildcard $(1)/*.c)
dircs_to_prefxd_objs=\
$(patsubst $(1)/%.c,$(BIN_DIR)/$(2)%.o,$(call dircs,$1))

CARFMW_OBJ_PREFIX=carfmw_

$(CAR_FMW_BIN): $(CAR_FMW_ELF) $(BIN_DIR)
$(OBJ_COPY) -O binary $< $@

$(CAR_FMW_ELF): $(LIB_CARHW_OBJ) $(CAR_FMW_OBJ)
$(CC) $(CFLAGS) $^ -T $(SRC_DIR)/stm32_flash.ld -o $@

$(CAR_FMW_OBJ): \
$(call dircs_to_prefxd_objs,$(SRC_DIR),$(CARFMW_OBJ_PREFIX))
$(LD_ALL_DEPS)

$(BIN_DIR)/$(CARFMW_OBJ_PREFIX)%.o: $(SRC_DIR)/%.c \
$(call dirhs,$(SRC_DIR))
$(CC_ALL_DEPS)

$(LIB_CARHW_OBJ):
make -C $(LIB_CARHW_DIR)

$(BIN_DIR):
mkdir -p $(BIN_DIR)

clean:
rm -rf bin/*
make -C $(LIB_CARHW_DIR) clean

tags:
ctags -R * $(LIB_CARHW_DIR)

.PHONY: clean tags
2 changes: 2 additions & 0 deletions car_cfmw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Car firmware project for low level experimentation
using C.
105 changes: 105 additions & 0 deletions car_cfmw/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <car_leds.h>
#include <car_engine.h>
#include <car_time.h>
#include <car_user_btn.h>
#include <car_conn.h>
#include <car_sonar.h>
#include <usart_test.h>

size_t strlen(const char *str)
{
size_t len = 0;

while (str[len])
++len;
return len;
}

char digit_to_char(uint8_t digit)
{
if (digit <= 9)
return '0' + digit;
else return 'A' + (digit - 10);
}

// Should allow to store up to "65535\0"
char uint16_str[6] = "65535";

char *uint16_to_str(uint16_t val)
{
int dix = 4;
for (; dix >= 0; --dix) {
uint8_t digit = (uint8_t)(val % 10);
uint16_str[dix] = digit_to_char(digit);
val = val / 10;
if (val == 0)
break;
}
if (dix == -1)
dix = 0;
return &uint16_str[dix];
}

void sonar_prog_dist_to_conn(void)
{
while (1) {
uint16_t dist = 0;

car_leds_clear_all();
dist = car_sonar_get_dist(90);

if (dist == CAR_SONAR_DIST_ERR)
car_led_set(CAR_LED_RED, true);
else {
car_led_set(CAR_LED_GREEN, true);
const char *str = uint16_to_str(dist);
car_conn_snd_buf(strlen(str), (int)str);
car_conn_snd_byte('\n');
}
car_time_wait(1000);
}
}

void sonar_prog_rotate(void)
{
uint8_t degree = 0;
while (1) {
uint16_t dist = 0;

car_leds_clear_all();
dist = car_sonar_get_dist(degree);
if (degree == 0 ||
degree == 45 ||
degree == 90 ||
degree == (90 + 45) ||
degree == 180)
car_time_wait(500);

degree += 5;
if (degree > 180)
degree = 0;
if (dist == CAR_SONAR_DIST_ERR)
car_led_set(CAR_LED_RED, true);
else
car_led_set(CAR_LED_GREEN, true);
car_time_wait(300);
}
}

int main(void)
{
car_time_init();
car_leds_init();
car_engine_init();
car_user_btn_init(NULL);
car_conn_init();
car_sonar_init();

car_sonar_get_dist(0);
car_time_wait(3000);
car_sonar_get_dist(180);
car_time_wait(3000);
/* sonar_prog_rotate(); */
sonar_prog_dist_to_conn();
// Also we can run usart test from here
}
Loading

0 comments on commit a00e93e

Please sign in to comment.