diff --git a/.gitignore b/.gitignore index 6481c8d..9668119 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.o *.elf - +core diff --git a/Makefile b/Makefile index ec87fe6..fe5507e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ CC=msp430-gcc -CFLAGS=-O3 -g0 -Wall -mmcu=msp430g2553 -std=gnu99 -I hottislib + +# regular +CFLAGS=-Wall -mmcu=msp430g2553 -std=gnu99 -I hottislib -O3 -g0 + +# for debugging +# CFLAGS=-Wall -mmcu=msp430g2553 -std=gnu99 -I hottislib -g3 -ggdb -gdwarf-2 + LDFLAGS=-mmcu=msp430g2553 blinky1.elf: main.o led.o time.o pattern.o PontCoopScheduler.o myrand.o measure.o diff --git a/hottislib b/hottislib index d129650..8c7413c 160000 --- a/hottislib +++ b/hottislib @@ -1 +1 @@ -Subproject commit d129650a6fbc77f5b5474c2b5153fa6adbbda003 +Subproject commit 8c7413c09b39e46916fc112e49005cbe7e798487 diff --git a/main.c b/main.c index 3a352cb..fd33029 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,7 @@ #include "led.h" #include "pattern.h" +#include "measure.h" int main() { @@ -28,7 +29,8 @@ int main() { ledInit(); patternInit(); - // ledSetMatrix(0, 1, BLUE); + measureInit(); + // ledSetMatrix(0, 0, BLUE); __enable_interrupt(); diff --git a/measure.c b/measure.c index 9ace202..dfccaf4 100644 --- a/measure.c +++ b/measure.c @@ -28,20 +28,8 @@ const uint8_t AVERAGING_CYCLES = 50; -void measureInit() { - ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON; - ADC10CTL1 = INCH_3; - ADC10AE0 = BIT3; -} - -void measureCollectAndProcessConversion(); - -void measureStartConversion(void *handleArg) { - ADC10CTL0 |= ENC | ADC10SC; - schAdd(measureCollectAndProcessConversion, NULL, MEASURE_FETCH_RESULT_DELAY, 0); -} - void measureCollectAndProcessConversion() { + static uint32_t averagingSum = 0; static uint8_t averagingCnt = 0; @@ -81,4 +69,35 @@ void measureCollectAndProcessConversion() { } } +void measureTestExec() { + static uint8_t t = 0; + static int8_t dir = 1; + + if (t == 0) { + dir = 1; + } + + if (t == 50) { + dir = -1; + } + + t += dir; + + patternSetTemperature(t); +} + +void measureInit() { + ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON; + ADC10CTL1 = INCH_0; + ADC10AE0 = BIT0; + +// schAdd(measureStartConversion, NULL, 0, 100); + schAdd(measureTestExec, NULL, 0, 1000); +} + +void measureStartConversion() { + ADC10CTL0 |= ENC | ADC10SC; + schAdd(measureCollectAndProcessConversion, NULL, MEASURE_FETCH_RESULT_DELAY, 0); +} + diff --git a/pattern.c b/pattern.c index 1a8d963..4b3b1b9 100644 --- a/pattern.c +++ b/pattern.c @@ -6,8 +6,8 @@ #include "myrand.h" -uint8_t temperature = 20; -const uint8_t TEMPERATURE_THRESHOLD = 20; +uint8_t temperature = 21; +const uint8_t TEMPERATURE_THRESHOLD = 25; tColor lockedColor = OFF; @@ -35,9 +35,7 @@ void patternExec() { } */ -/* - * BLUE -void patternExec() { +void patternTestBlueExec() { static uint8_t state = 0; static uint8_t column = 0; @@ -48,12 +46,11 @@ void patternExec() { ledSetMatrix(1, 0, BLUE); ledSetMatrix(2, 0, BLUE); ledSetMatrix(3, 0, BLUE); - srand(13); state = 1; break; case 1: // select new column, row 1 - column = ((uint8_t) rand()) & 0x3; + column = 0; ledSetMatrix(column, 1, BLUE); state = 2; break; @@ -79,7 +76,7 @@ void patternExec() { break; } } -*/ + static bool _patternChangeColor() { @@ -101,7 +98,20 @@ static bool _patternChangeColor() { } uint8_t _patternStayCnt() { - return temperature; + uint8_t s = 0; + + if (temperature < TEMPERATURE_THRESHOLD) { + s = TEMPERATURE_THRESHOLD - temperature; + } else if (temperature > (TEMPERATURE_THRESHOLD * 2)) { + s = 0; + } else { + s = (TEMPERATURE_THRESHOLD * 2) - temperature; + } + + if (s == 0) { + s = 1; + } + return s; } void patternExec() { @@ -129,7 +139,7 @@ void patternExec() { ledSetMatrix(1, baseRow, lockedColor); ledSetMatrix(2, baseRow, lockedColor); ledSetMatrix(3, baseRow, lockedColor); - srand(13); + state = 1; break; case 1: @@ -177,7 +187,7 @@ void patternExec() { case 7: // same column, row 0 off ledSetMatrix(column, (lockedColor == RED) ? 0 : 3, OFF); - state = _patternChangeColor() ? 1 : 0; + state = _patternChangeColor() ? 0 : 1; stay = _patternStayCnt(); break; default: diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..7ba258f --- /dev/null +++ b/readme.md @@ -0,0 +1,12 @@ +Build: +* make all + +Flash: +* make upload + +Debugger: +* enable debugging in Makefile +* mspdebug rf2500 gdb +* ddd --debugger msp430-gdb +* for every code change upload using Makefile and restart both mspdebug and ddd (or fine a way to reset the both) +