Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
bdd27a6bea | |||
a882534979 | |||
a7a915faf4 | |||
f1f06f056a | |||
5b78b7da02 | |||
713cc80417 | |||
7d422c5494 | |||
8436ba76b0 | |||
9cd6f6cf82 |
4
build.sh
4
build.sh
@ -1,4 +0,0 @@
|
|||||||
avr-gcc -Os -DF_CPU=16000000UL -Wall -Wextra -Wpedantic -Wformat -pedantic-errors -Werror -Wfatal-errors -mmcu=atmega2560 -c -o src/main.o src/main.c
|
|
||||||
avr-gcc -mmcu=atmega2560 src/main.o -o bin/atmega2560-user-code.elf
|
|
||||||
avr-objcopy -O ihex -R .eeprom bin/atmega2560-user-code.elf bin/atmega2560-user-code.ihx
|
|
||||||
avrdude -v -F -V -c stk500v2 -p m2560 -P /dev/ttyACM0 -b 115200 -U flash:w:bin/atmega2560-user-code.ihx
|
|
12
src/hmi_msg.h
Normal file
12
src/hmi_msg.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef _HMI_MSG_H_
|
||||||
|
#define _HMI_MSG_H_
|
||||||
|
|
||||||
|
#define STUD_NAME "Arti Zirk"
|
||||||
|
const char *ENG_MONTH[6] = {"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",};
|
||||||
|
|
||||||
|
#endif /* _HMI_MSG_H_ */
|
47
src/main.c
47
src/main.c
@ -1,9 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#define __ASSERT_USE_STDERR
|
#include "hmi_msg.h"
|
||||||
#include <assert.h>
|
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "print_helper.h"
|
||||||
|
|
||||||
#define BLINK_DELAY_MS 100
|
#define BLINK_DELAY_MS 100
|
||||||
|
|
||||||
@ -11,35 +12,39 @@ int main (void)
|
|||||||
{
|
{
|
||||||
/* set pin 3 of PORTA for output*/
|
/* set pin 3 of PORTA for output*/
|
||||||
DDRA |= _BV(DDA3);
|
DDRA |= _BV(DDA3);
|
||||||
/* Init error console as stderr in UART3 and print user code info */
|
/* Init stdio on UART0 and UART3 and print user code info */
|
||||||
|
uart0_init();
|
||||||
uart3_init();
|
uart3_init();
|
||||||
|
stdout = stdin = &uart0_io;
|
||||||
stderr = &uart3_out;
|
stderr = &uart3_out;
|
||||||
fprintf(stderr, "Version: %s built on: %s %s\n",
|
fprintf(stderr, "Version: %s built on: %s %s\n",
|
||||||
GIT_DESCR, __DATE__, __TIME__);
|
GIT_DESCR, __DATE__, __TIME__);
|
||||||
fprintf(stderr, "avr-libc version: %s\n", __AVR_LIBC_VERSION_STRING__);
|
fprintf(stderr, "avr-libc version: %s\n", __AVR_LIBC_VERSION_STRING__);
|
||||||
/*End UART3 init and info print */
|
/* End stdio init and info print */
|
||||||
/* Test assert - REMOVE IN FUTURE LABS */
|
|
||||||
char *array;
|
fprintf(stdout, STUD_NAME "\n");
|
||||||
uint32_t i = 1;
|
/* ASCII table print */
|
||||||
extern int __heap_start, *__brkval;
|
print_ascii_tbl(stdout);
|
||||||
int v;
|
unsigned char ascii[128] = {0};
|
||||||
array = malloc( i * sizeof(char));
|
for (unsigned char i = 0; i < sizeof(ascii); i++) {
|
||||||
assert(array);
|
ascii[i] = i;
|
||||||
/* End test assert */
|
}
|
||||||
|
print_for_human(stdout, ascii, sizeof(ascii));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
char month_first_leter;
|
||||||
|
fprintf(stdout, "Enter Month name first letter >");
|
||||||
|
fscanf(stdin, "%c", &month_first_leter);
|
||||||
|
fprintf(stdout, "%c\n", month_first_leter);
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
if (!strncmp(strupr(&month_first_leter), ENG_MONTH[i], 1)) {
|
||||||
|
fprintf(stdout, "%s\n", ENG_MONTH[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* set pin 3 high to turn led on */
|
/* set pin 3 high to turn led on */
|
||||||
PORTA |= _BV(PORTA3);
|
PORTA |= _BV(PORTA3);
|
||||||
_delay_ms(BLINK_DELAY_MS);
|
_delay_ms(BLINK_DELAY_MS);
|
||||||
/* Test assert - REMOVE IN FUTURE LABS */
|
|
||||||
/* Increase memory allocated for array by 100 chars
|
|
||||||
* until we have eaten it all and print space between Stack and Heap.
|
|
||||||
* Thats how assert works in run-time */
|
|
||||||
array = realloc( array, (i++ * 100) * sizeof(char));
|
|
||||||
fprintf(stderr, "%d ",
|
|
||||||
(int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval));
|
|
||||||
assert(array);
|
|
||||||
/* End test assert */
|
|
||||||
/* set pin 3 low to turn led off */
|
/* set pin 3 low to turn led off */
|
||||||
PORTA &= ~_BV(PORTA3);
|
PORTA &= ~_BV(PORTA3);
|
||||||
_delay_ms(BLINK_DELAY_MS);
|
_delay_ms(BLINK_DELAY_MS);
|
||||||
|
27
src/print_helper.c
Normal file
27
src/print_helper.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "print_helper.h"
|
||||||
|
|
||||||
|
int print_ascii_tbl (FILE *stream) {
|
||||||
|
for (char c = ' '; c <= '~'; c++) {
|
||||||
|
if(!fprintf(stream, "%c ", c)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fprintf(stream, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int print_for_human (FILE *stream, const unsigned char *array, const int len) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (array[i] >= ' ' && array[i] <= '~') {
|
||||||
|
if(!fprintf(stream, "%c", array[i])) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!fprintf(stream, "\"0x%02x\"", array[i])) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fprintf(stream, "\n");;
|
||||||
|
}
|
7
src/print_helper.h
Normal file
7
src/print_helper.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef _PRINT_HELPER_H_
|
||||||
|
#define _PRINT_HELPER_H_
|
||||||
|
|
||||||
|
int print_ascii_tbl (FILE *stream);
|
||||||
|
int print_for_human (FILE *stream, const unsigned char *array, const int len);
|
||||||
|
|
||||||
|
#endif /* _PRINT_HELPER_H_ */
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef _UART_H_
|
||||||
|
#define _UART_H_
|
||||||
|
|
||||||
int uart0_putchar(char c, FILE *stream);
|
int uart0_putchar(char c, FILE *stream);
|
||||||
int uart0_getchar(FILE *stream);
|
int uart0_getchar(FILE *stream);
|
||||||
|
|
||||||
@ -10,3 +13,5 @@ void uart3_init(void);
|
|||||||
|
|
||||||
FILE uart0_io = FDEV_SETUP_STREAM(uart0_putchar, uart0_getchar, _FDEV_SETUP_RW);
|
FILE uart0_io = FDEV_SETUP_STREAM(uart0_putchar, uart0_getchar, _FDEV_SETUP_RW);
|
||||||
FILE uart3_out = FDEV_SETUP_STREAM(uart3_putchar, NULL, _FDEV_SETUP_WRITE);
|
FILE uart3_out = FDEV_SETUP_STREAM(uart3_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
|
#endif /* _UART_H_ */
|
||||||
|
51
tooling/package-and-deliver.sh
Executable file
51
tooling/package-and-deliver.sh
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Test project build"
|
||||||
|
|
||||||
|
make clean && make
|
||||||
|
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "Build failed!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Build OK!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "Format code"
|
||||||
|
make format
|
||||||
|
|
||||||
|
# Test if there are changed files that are not commited
|
||||||
|
|
||||||
|
if [ -n "$(git status --porcelain)" ] ; then
|
||||||
|
echo "Uncommited files detected"
|
||||||
|
git status
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "Currently set tags on this project"
|
||||||
|
git tag
|
||||||
|
echo -n "Are the required tags added? (Y/n)"
|
||||||
|
read ANSWER
|
||||||
|
if [ "$ANSWER" == "n" ]; then
|
||||||
|
echo "Please add required tags"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "Packaging the project"
|
||||||
|
|
||||||
|
make clean && make
|
||||||
|
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
cp bin/atmega2560-user-code.ihx $TEMP_DIR
|
||||||
|
make clean
|
||||||
|
git archive --format=tar.gz -o $TEMP_DIR/$(git describe --abbrev=6 --dirty --always --tags --long).tar.gz HEAD
|
||||||
|
mv $TEMP_DIR/* bin/
|
||||||
|
rm -rf $TEMP_DIR
|
||||||
|
|
||||||
|
echo "Project packaging succeeded"
|
||||||
|
exit 0
|
Reference in New Issue
Block a user