commit 157866a4a53c37e42237c42c3a0ebbbf9e382c09 Author: Wolfgang Hottgenroth Date: Mon Aug 29 19:24:24 2016 +0200 initial, ported from constantly failed C++ variant diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..f453d3a --- /dev/null +++ b/.cproject @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..18535bf --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + TeaThermoTimer + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + dk.xpg.msp430eclipse.msp430nature + + diff --git a/.settings/dk.xpg.msp430eclipse.prefs b/.settings/dk.xpg.msp430eclipse.prefs new file mode 100644 index 0000000..2bd9001 --- /dev/null +++ b/.settings/dk.xpg.msp430eclipse.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +msp430/DeviceSerialNumber= +msp430/MSP430TARGETMCU=msp430g2553 +msp430/MSPDebugConnection= +msp430/MSPDebugProtocol=SBW +msp430/MSPDebugTTYDevice= diff --git a/docs/tea.txt b/docs/tea.txt new file mode 100644 index 0000000..11e7f8e --- /dev/null +++ b/docs/tea.txt @@ -0,0 +1,12 @@ +P1.7 A +P1.6 B +P2.5 F +P2.4 E +P2.3 D +P2.2 G +P2.1 C +P2.0 1 +P1.5 2 +P1.0 T + + diff --git a/src/PontCoopScheduler.c b/src/PontCoopScheduler.c new file mode 100644 index 0000000..8b97b25 --- /dev/null +++ b/src/PontCoopScheduler.c @@ -0,0 +1,60 @@ +/* + * PontCoopScheduler.c + * + * Created on: 29.08.2016 + * Author: wn + */ + + +#include + +#include "PontCoopScheduler.h" + +tTask tasks[MAX_NUM_OF_TASKS]; + + +void schInit() { + for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { + tasks[i].delay = 0; + tasks[i].period = 0; + tasks[i].run = 0; + tasks[i].exec = NULL; + } +} + +void schAdd(void (*exec)(void), uint32_t delay, uint32_t period) { + for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { + if (tasks[i].exec == NULL) { + tasks[i].delay = delay; + tasks[i].period = period; + tasks[i].run = 0; + tasks[i].exec = exec; + break; + } + } +} + +void schExec() { + for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { + if (tasks[i].exec != NULL && tasks[i].run > 0) { + tasks[i].run--; + tasks[i].exec(); + if (tasks[i].period == 0) { + tasks[i].exec = NULL; + } + } + } +} + +void schUpdate() { + for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { + if (tasks[i].exec != NULL) { + if (tasks[i].delay == 0) { + tasks[i].delay = tasks[i].period; + tasks[i].run++; + } else { + tasks[i].delay--; + } + } + } +} diff --git a/src/PontCoopScheduler.h b/src/PontCoopScheduler.h new file mode 100644 index 0000000..91c6a1d --- /dev/null +++ b/src/PontCoopScheduler.h @@ -0,0 +1,33 @@ +/* + * PontCoopScheduler.h + * + * Created on: 29.08.2016 + * Author: wn + */ + +#ifndef PONTCOOPSCHEDULER_H_ +#define PONTCOOPSCHEDULER_H_ + + +#include + + + +#define MAX_NUM_OF_TASKS 3 + + +typedef struct { + uint32_t delay; + uint32_t period; + uint8_t run; + void (*exec)(void); +} tTask; + + +void schInit(); +void schAdd(void (*exec)(void), uint32_t delay, uint32_t period); +void schExec(); +void schUpdate(); + + +#endif /* PONTCOOPSCHEDULER_H_ */ diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..d7f775d --- /dev/null +++ b/src/display.c @@ -0,0 +1,107 @@ +/* + * display.c + * + * Created on: 29.08.2016 + * Author: wn + */ + + +#include +#include +#include + +#include "display.h" +#include "gpio.h" +#include "time.h" + + + +const uint16_t INIT_CYCLE_DELAY = 200; + +typedef enum { + ALL_ID = 10, + H_ID, + I_ID, + EMPTY_ID, +} tPatternId; + +const tPin ALL_PATTERN[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, PINS_END }; +const tPin H_PATTERN[] = { SEG_B, SEG_C, SEG_E, SEG_F, SEG_G, PINS_END }; +const tPin I_PATTERN[] = { SEG_B, SEG_C, PINS_END }; +const tPin EMPTY_PATTERN[] = { PINS_END }; +const tPin NUMBER0[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, PINS_END }; +const tPin NUMBER1[] = { SEG_B, SEG_C, PINS_END }; +const tPin NUMBER2[] = { SEG_A, SEG_B, SEG_G, SEG_E, SEG_D, PINS_END }; +const tPin NUMBER3[] = { SEG_A, SEG_B, SEG_G, SEG_C, SEG_D, PINS_END }; +const tPin NUMBER4[] = { SEG_F, SEG_G, SEG_B, SEG_C, PINS_END }; +const tPin NUMBER5[] = { SEG_A, SEG_F, SEG_G, SEG_C, SEG_D, PINS_END }; +const tPin NUMBER6[] = { SEG_A, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, PINS_END }; +const tPin NUMBER7[] = { SEG_A, SEG_B, SEG_C, PINS_END }; +const tPin NUMBER8[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, PINS_END }; +const tPin NUMBER9[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_F, SEG_G, PINS_END }; + +const tPin *NUMBERS[] = { NUMBER0, NUMBER1, NUMBER2, NUMBER3, NUMBER4, + NUMBER5, NUMBER6, NUMBER7, NUMBER8, NUMBER9, ALL_PATTERN, H_PATTERN, + I_PATTERN, EMPTY_PATTERN }; + +const tPin DIGITS[] = { DIGIT_0, DIGIT_1, PINS_END }; + + +uint8_t digitValues[2] = { EMPTY_ID, EMPTY_ID }; + + + +void displayInit() { + for (tPin d = DIGIT_0; d <= DIGIT_1; d++) { + gpioSetPin(d, LOW); + for (tPin s = SEG_A; s <= SEG_G; s++) { + gpioSetPin(s, HIGH); + ms_active_delay(INIT_CYCLE_DELAY); + gpioSetPin(s, LOW); + } + gpioSetPin(d, HIGH); + } +} + +static void showNumber(uint8_t n) { + const tPin *pattern = NUMBERS[10]; + do { + gpioSetPin(*pattern, LOW); + pattern++; + } while (*pattern != PINS_END); + pattern = NUMBERS[n]; + do { + gpioSetPin(*pattern, HIGH); + pattern++; + } while (*pattern != PINS_END); +} + +void displaySetValue(uint8_t v) { + if (v >= 100) { + digitValues[1] = H_ID; + digitValues[0] = I_ID; + } else { + digitValues[1] = v / 10; + digitValues[0] = v - digitValues[1]; + } +} + +void displayExec() { + static uint8_t activeDigit = 0; + + activeDigit++; + if (activeDigit == 2) { + activeDigit = 0; + } + + const tPin *digit = DIGITS; + do { + gpioSetPin(*digit, HIGH); + digit++; + } while (*digit != PINS_END); + + digit = DIGITS + activeDigit; + gpioSetPin(*digit, LOW); + + showNumber(digitValues[activeDigit]); +} diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..16abc26 --- /dev/null +++ b/src/display.h @@ -0,0 +1,17 @@ +/* + * display.h + * + * Created on: 29.08.2016 + * Author: wn + */ + +#ifndef DISPLAY_H_ +#define DISPLAY_H_ + + +void displayInit(); +void displayExec(); +void displaySetValue(uint8_t v); + + +#endif /* DISPLAY_H_ */ diff --git a/src/gpio.c b/src/gpio.c new file mode 100644 index 0000000..fa2857c --- /dev/null +++ b/src/gpio.c @@ -0,0 +1,49 @@ +/* + * gpio.c + * + * Created on: 29.08.2016 + * Author: wn + */ + + +#include +#include + +#define GPIO_C +#include "gpio.h" +#undef GPIO_C + + + +extern tPinCfg pinCfg[]; + + +void gpioInitPins() { + for (tPin p = PINS_FIRST; p < PINS_END; p += 1) { + tPinCfg pin = pinCfg[p]; + if (pin.portId == PORT1) { + P1DIR |= pin.bit; + } else if (pin.portId == PORT2) { + P2DIR |= pin.bit; + } + gpioSetPin(p, pin.defaultOut); + } +} + +void gpioSetPin(tPin p, tPinState v) { + tPinCfg pin = pinCfg[p]; + if (v == HIGH) { + if (pin.portId == PORT1) { + P1OUT |= pin.bit; + } else if (pin.portId == PORT2) { + P2OUT |= pin.bit; + } + } else { + if (pin.portId == PORT1) { + P1OUT &= ~pin.bit; + } else if (pin.portId == PORT2) { + P2OUT &= ~pin.bit; + } + } +} + diff --git a/src/gpio.h b/src/gpio.h new file mode 100644 index 0000000..7a8f4be --- /dev/null +++ b/src/gpio.h @@ -0,0 +1,56 @@ +/* + * gpio.h + * + * Created on: 29.08.2016 + * Author: wn + */ + +#ifndef GPIO_H_ +#define GPIO_H_ + + +#include +#include + + + +typedef enum { + PORT1, + PORT2 +} tPort; + +typedef enum { + LOW, + HIGH, +} tPinState; + +typedef struct { + tPort portId; + uint16_t bit; + tPinState defaultOut; +} tPinCfg; + + +typedef enum { + PINS_FIRST, + SEG_A = PINS_FIRST, + SEG_B, + SEG_C, + SEG_D, + SEG_E, + SEG_F, + SEG_G, + DIGIT_0, + DIGIT_1, + TESTPIN, + PINS_END +} tPin; + +void gpioInitPins(); +void gpioSetPin(tPin p, tPinState v); + + + + + +#endif /* GPIO_H_ */ diff --git a/src/gpioCfg.c b/src/gpioCfg.c new file mode 100644 index 0000000..5c6e381 --- /dev/null +++ b/src/gpioCfg.c @@ -0,0 +1,21 @@ +/* + * gpioCfg.c + * + * Created on: 29.08.2016 + * Author: wn + */ + +#include "gpio.h" + +tPinCfg pinCfg[PINS_END] = { + {PORT1, BIT7, LOW}, //A + {PORT1, BIT6, LOW}, //B + {PORT2, BIT1, LOW}, //C + {PORT2, BIT3, LOW}, //D + {PORT2, BIT4, LOW}, //E + {PORT2, BIT5, LOW}, //F + {PORT2, BIT2, LOW}, //G + {PORT2, BIT0, HIGH}, //0 + {PORT1, BIT5, HIGH}, //1 + {PORT1, BIT7, LOW}, // TESTPIN +}; diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..c145678 --- /dev/null +++ b/src/main.c @@ -0,0 +1,49 @@ +/* + * main.c + * + * Created on: 29.08.2016 + * Author: wn + */ + +#include +#include +#include + +#include "gpio.h" +#include "time.h" +#include "display.h" +#include "PontCoopScheduler.h" +#include "testTask.h" + + +int main() { + WDTCTL = WDTPW | WDTHOLD; + + // highest possible system clock + DCOCTL = DCO0 | DCO1 | DCO2; + BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3; + BCSCTL2 = 0; + BCSCTL3 = 0; + + + gpioInitPins(); + timeInit(); + schInit(); + + // interrupts are required for delay function in displayInit(); + __enable_interrupt(); + displayInit(); + __disable_interrupt(); + + testTaskInit(); + + // schAdd(displayExec, 0, 100); + schAdd(testTaskExec, 0, 100); + + while (1) { + schExec(); + } +} + + + diff --git a/src/testTask.c b/src/testTask.c new file mode 100644 index 0000000..737e56b --- /dev/null +++ b/src/testTask.c @@ -0,0 +1,26 @@ +/* + * testTask.c + * + * Created on: 29.08.2016 + * Author: wn + */ + +#include "gpio.h" + + +void testTaskInit() { + +} + +void testTaskExec() { + static uint8_t toggle = 0; + + if (toggle == 0) { + toggle = 1; + gpioSetPin(TESTPIN, HIGH); + } else { + toggle = 0; + gpioSetPin(TESTPIN, LOW); + } +} + diff --git a/src/testTask.h b/src/testTask.h new file mode 100644 index 0000000..c5423ae --- /dev/null +++ b/src/testTask.h @@ -0,0 +1,15 @@ +/* + * testTask.h + * + * Created on: 29.08.2016 + * Author: wn + */ + +#ifndef TESTTASK_H_ +#define TESTTASK_H_ + +void testTaskInit(); +void testTaskExec(); + + +#endif /* TESTTASK_H_ */ diff --git a/src/time.c b/src/time.c new file mode 100644 index 0000000..5b1ffcf --- /dev/null +++ b/src/time.c @@ -0,0 +1,38 @@ +/* + * time.c + * + * Created on: 20.05.2014 + * Author: wn + */ + +#include +#include +#include + +#include "time.h" +#include "PontCoopScheduler.h" + + +volatile uint32_t timestamp; + +ISR(TIMER0_A0, TA0_ISR) { + timestamp++; + schUpdate(); +} + +void timeInit() { + timestamp = 0; + + TACCR0 = 32; + TACCTL0 = CCIE; + TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR; +} + +uint32_t getMillis() { + return timestamp; +} + +void ms_active_delay(uint16_t delay) { + uint32_t start = timestamp; + while (start + delay > timestamp); +} diff --git a/src/time.h b/src/time.h new file mode 100644 index 0000000..874251e --- /dev/null +++ b/src/time.h @@ -0,0 +1,19 @@ +/* + * time.h + * + * Created on: 20.05.2014 + * Author: wn + */ + +#ifndef TIME_H_ +#define TIME_H_ + +#include + +void timeInit(); +uint32_t getMillis(); +void ms_active_delay(uint16_t delay); + + + +#endif /* TIME_H_ */