diff --git a/src/PontCoopScheduler.c b/src/PontCoopScheduler.c index ec20dd3..fbcdfe4 100644 --- a/src/PontCoopScheduler.c +++ b/src/PontCoopScheduler.c @@ -14,60 +14,60 @@ 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; - tasks[i].handle = NULL; - } + 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; + tasks[i].handle = NULL; + } } void schAdd(void (*exec)(void *), void *handle, 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; - tasks[i].handle = handle; - break; - } - } + 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; + tasks[i].handle = handle; + break; + } + } } void schDel(void (*exec)(void *), void *handle) { - for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { - if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) { - tasks[i].exec = NULL; - break; - } - } + for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) { + if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) { + tasks[i].exec = NULL; + 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(tasks[i].handle); - if (tasks[i].period == 0) { - tasks[i].exec = NULL; - } - } - } + 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(tasks[i].handle); + 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--; - } - } - } + 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 index 675bed5..e3369b9 100644 --- a/src/PontCoopScheduler.h +++ b/src/PontCoopScheduler.h @@ -17,11 +17,11 @@ typedef struct { - uint32_t delay; - uint32_t period; - uint8_t run; - void (*exec)(void *handle); - void *handle; + uint32_t delay; + uint32_t period; + uint8_t run; + void (*exec)(void *handle); + void *handle; } tTask; diff --git a/src/display.c b/src/display.c index a8a669e..699dc43 100644 --- a/src/display.c +++ b/src/display.c @@ -19,10 +19,10 @@ const uint16_t INIT_CYCLE_DELAY = 200; typedef enum { - ALL_ID = 10, - H_ID, - I_ID, - EMPTY_ID, + 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 }; @@ -43,8 +43,8 @@ const tPin NUMBER8[] = { SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, PINS_E 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 }; + NUMBER5, NUMBER6, NUMBER7, NUMBER8, NUMBER9, ALL_PATTERN, H_PATTERN, + I_PATTERN, EMPTY_PATTERN }; const tPin DIGITS[] = { DIGIT_0, DIGIT_1, PINS_END }; @@ -54,56 +54,56 @@ uint8_t digitValues[2] = { EMPTY_ID, EMPTY_ID }; void displayInit(void *handleArg) { - 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); - } + 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[ALL_ID]; - do { - gpioSetPin(*pattern, LOW); - pattern++; - } while (*pattern != PINS_END); - pattern = NUMBERS[n]; - do { - gpioSetPin(*pattern, HIGH); - pattern++; - } while (*pattern != PINS_END); + const tPin *pattern = NUMBERS[ALL_ID]; + 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] * 10; - } + if (v >= 100) { + digitValues[1] = H_ID; + digitValues[0] = I_ID; + } else { + digitValues[1] = v / 10; + digitValues[0] = v - digitValues[1] * 10; + } } void displayExec(void *handleArg) { - static uint8_t activeDigit = 0; + static uint8_t activeDigit = 0; - activeDigit++; - if (activeDigit == 2) { - activeDigit = 0; - } + activeDigit++; + if (activeDigit == 2) { + activeDigit = 0; + } - const tPin *digit = DIGITS; - do { - gpioSetPin(*digit, HIGH); - digit++; - } while (*digit != PINS_END); + const tPin *digit = DIGITS; + do { + gpioSetPin(*digit, HIGH); + digit++; + } while (*digit != PINS_END); - digit = DIGITS + activeDigit; - gpioSetPin(*digit, LOW); + digit = DIGITS + activeDigit; + gpioSetPin(*digit, LOW); - showNumber(digitValues[activeDigit]); + showNumber(digitValues[activeDigit]); } diff --git a/src/displayMuxer.c b/src/displayMuxer.c index c647b82..2a80dfe 100644 --- a/src/displayMuxer.c +++ b/src/displayMuxer.c @@ -15,35 +15,35 @@ typedef struct { - uint8_t value; - bool valid; + uint8_t value; + bool valid; } tDisplayValue; tDisplayValue displayValues[MUX_ENDS]; void displayMuxerInit(void *handleArg) { - for (tMuxerSlot i = FIRST_MUX; i < MUX_ENDS; i++) { - displayValues[i].value = 0; - displayValues[i].valid = false; - } + for (tMuxerSlot i = FIRST_MUX; i < MUX_ENDS; i++) { + displayValues[i].value = 0; + displayValues[i].valid = false; + } } void displayMuxerExec(void *handleArg) { - static tMuxerSlot slot = FIRST_MUX; + static tMuxerSlot slot = FIRST_MUX; - if (displayValues[slot].valid) { - displaySetValue(displayValues[slot].value); - } + if (displayValues[slot].valid) { + displaySetValue(displayValues[slot].value); + } - slot++; - if (slot == MUX_ENDS) { - slot = FIRST_MUX; - } + slot++; + if (slot == MUX_ENDS) { + slot = FIRST_MUX; + } } void displayMuxerSetValue(uint8_t value, bool valid, tMuxerSlot slot) { - displayValues[slot].value = value; - displayValues[slot].valid = valid; + displayValues[slot].value = value; + displayValues[slot].valid = valid; } diff --git a/src/displayMuxer.h b/src/displayMuxer.h index 21d972c..13b95e4 100644 --- a/src/displayMuxer.h +++ b/src/displayMuxer.h @@ -12,10 +12,10 @@ #include typedef enum { - FIRST_MUX = 0, - TIMER_MUX = FIRST_MUX, - TEMPERATURE_MUX, - MUX_ENDS + FIRST_MUX = 0, + TIMER_MUX = FIRST_MUX, + TEMPERATURE_MUX, + MUX_ENDS } tMuxerSlot; void displayMuxerInit(void *handleArg); diff --git a/src/gpio.c b/src/gpio.c index cc91b78..f6dd2c0 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -19,35 +19,35 @@ 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; - P1SEL &= ~pin.bit; - P1SEL2 &= ~pin.bit; - } else if (pin.portId == PORT2) { - P2DIR |= pin.bit; - P2SEL &= ~pin.bit; - P2SEL2 &= ~pin.bit; - } - gpioSetPin(p, pin.defaultOut); - } + for (tPin p = PINS_FIRST; p < PINS_END; p += 1) { + tPinCfg pin = pinCfg[p]; + if (pin.portId == PORT1) { + P1DIR |= pin.bit; + P1SEL &= ~pin.bit; + P1SEL2 &= ~pin.bit; + } else if (pin.portId == PORT2) { + P2DIR |= pin.bit; + P2SEL &= ~pin.bit; + P2SEL2 &= ~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; - } - } + 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 index fd09db6..38571c5 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -15,36 +15,36 @@ typedef enum { - PORT1, - PORT2 + PORT1, + PORT2 } tPort; typedef enum { - LOW, - HIGH, + LOW, + HIGH, } tPinState; typedef struct { - tPort portId; - uint16_t bit; - tPinState defaultOut; + 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, - TESTPIN1, - TESTPIN2, - PINS_END + PINS_FIRST, + SEG_A = PINS_FIRST, + SEG_B, + SEG_C, + SEG_D, + SEG_E, + SEG_F, + SEG_G, + DIGIT_0, + DIGIT_1, + TESTPIN1, + TESTPIN2, + PINS_END } tPin; void gpioInitPins(); diff --git a/src/gpioCfg.c b/src/gpioCfg.c index ab8d7a6..6ba2086 100644 --- a/src/gpioCfg.c +++ b/src/gpioCfg.c @@ -8,15 +8,15 @@ #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, BIT1, LOW}, // TESTPIN1 - {PORT1, BIT2, LOW}, // TESTPIN2 + {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, BIT1, LOW}, // TESTPIN1 + {PORT1, BIT2, LOW}, // TESTPIN2 }; diff --git a/src/main.c b/src/main.c index f1ebd51..9d8f0c2 100644 --- a/src/main.c +++ b/src/main.c @@ -19,37 +19,37 @@ int main() { - WDTCTL = WDTPW | WDTHOLD; + WDTCTL = WDTPW | WDTHOLD; - // highest possible system clock - DCOCTL = DCO0 | DCO1 | DCO2; - BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3; - BCSCTL2 = 0; - BCSCTL3 = 0; + // highest possible system clock + DCOCTL = DCO0 | DCO1 | DCO2; + BCSCTL1 = XT2OFF | RSEL0 | RSEL1 | RSEL2 | RSEL3; + BCSCTL2 = 0; + BCSCTL3 = 0; - gpioInitPins(); - timeInit(); - schInit(); + gpioInitPins(); + timeInit(); + schInit(); - // interrupts are required for delay function in displayInit(); - __enable_interrupt(); - displayInit(NULL); - __disable_interrupt(); + // interrupts are required for delay function in displayInit(); + __enable_interrupt(); + displayInit(NULL); + __disable_interrupt(); - measureInit(NULL); -// displayMuxerInit(NULL); + measureInit(NULL); + // displayMuxerInit(NULL); - schAdd(displayExec, NULL, 0, DISPLAY_CYCLE); - schAdd(measureStartConversion, NULL, 0, MEASURE_CYCLE); -// schAdd(displayMuxerExec, NULL, 0, 500); + schAdd(displayExec, NULL, 0, DISPLAY_CYCLE); + schAdd(measureStartConversion, NULL, 0, MEASURE_CYCLE); + // schAdd(displayMuxerExec, NULL, 0, 500); - __enable_interrupt(); + __enable_interrupt(); - while (1) { - schExec(); - } + while (1) { + schExec(); + } } diff --git a/src/measure.c b/src/measure.c index 9087aaf..909b19f 100644 --- a/src/measure.c +++ b/src/measure.c @@ -26,47 +26,47 @@ const float PT1000_Coeff = 3.85e-3; void measureInit(void *handleArg) { - ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON; - ADC10CTL1 = INCH_3; - ADC10AE0 = BIT3; + ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON; + ADC10CTL1 = INCH_3; + ADC10AE0 = BIT3; } void measureCollectAndProcessConversion(void *handleArg); void measureStartConversion(void *handleArg) { - //gpioSetPin(TESTPIN1, HIGH); - ADC10CTL0 |= ENC | ADC10SC; - schAdd(measureCollectAndProcessConversion, NULL, MEASURE_FETCH_RESULT_DELAY, 0); - //gpioSetPin(TESTPIN1, LOW); + //gpioSetPin(TESTPIN1, HIGH); + ADC10CTL0 |= ENC | ADC10SC; + schAdd(measureCollectAndProcessConversion, NULL, MEASURE_FETCH_RESULT_DELAY, 0); + //gpioSetPin(TESTPIN1, LOW); } void measureCollectAndProcessConversion(void *handleArg) { - - - //gpioSetPin(TESTPIN2, HIGH); - uint16_t n = 0xffff; - if ((ADC10CTL0 & ADC10IFG) != 0) { - n = ADC10MEM; - ADC10CTL0 &= ~(ADC10IFG | ENC); - } - // process adcValue - // store result in variable temperature - float r = 0.0; - if (n == 0) { - r = 0.0; - } else if (n == N_MAX) { - r = FLT_MAX; - } else { - r = R_REF / ((((float)N_MAX) / ((float)n)) - 1.0); - } - float t = (r / PT1000_R0 - 1) / PT1000_Coeff; - uint8_t temperature = (uint8_t)t; + //gpioSetPin(TESTPIN2, HIGH); + uint16_t n = 0xffff; + if ((ADC10CTL0 & ADC10IFG) != 0) { + n = ADC10MEM; + ADC10CTL0 &= ~(ADC10IFG | ENC); + } - displaySetValue(temperature); - // displayMuxerSetValue(temperature, true, TEMPERATURE_MUX); - //gpioSetPin(TESTPIN2, LOW); + // process adcValue + // store result in variable temperature + float r = 0.0; + if (n == 0) { + r = 0.0; + } else if (n == N_MAX) { + r = FLT_MAX; + } else { + r = R_REF / ((((float)N_MAX) / ((float)n)) - 1.0); + } + float t = (r / PT1000_R0 - 1) / PT1000_Coeff; + + uint8_t temperature = (uint8_t)t; + + displaySetValue(temperature); + // displayMuxerSetValue(temperature, true, TEMPERATURE_MUX); + //gpioSetPin(TESTPIN2, LOW); } diff --git a/src/testTask.c b/src/testTask.c index 16c0db0..35f8197 100644 --- a/src/testTask.c +++ b/src/testTask.c @@ -11,34 +11,34 @@ void testTaskInit(void *handleArg, tPin pin) { - tTestTaskHandle *handle = handleArg; - handle->pin = pin; - handle->toggle = 0; + tTestTaskHandle *handle = handleArg; + handle->pin = pin; + handle->toggle = 0; } void testTaskSwitchOff(void *handleArg) { - tTestTaskHandle *handle = handleArg; + tTestTaskHandle *handle = handleArg; - if (handle->toggle == 0) { - handle->toggle = 1; - gpioSetPin(handle->pin, HIGH); - } else { - handle->toggle = 0; - gpioSetPin(handle->pin, LOW); - } + if (handle->toggle == 0) { + handle->toggle = 1; + gpioSetPin(handle->pin, HIGH); + } else { + handle->toggle = 0; + gpioSetPin(handle->pin, LOW); + } } void testTaskExec(void *handleArg) { - tTestTaskHandle *handle = handleArg; - if (handle->toggle == 0) { - handle->toggle = 1; - gpioSetPin(handle->pin, HIGH); - } else { - handle->toggle = 0; - gpioSetPin(handle->pin, LOW); - } + tTestTaskHandle *handle = handleArg; + if (handle->toggle == 0) { + handle->toggle = 1; + gpioSetPin(handle->pin, HIGH); + } else { + handle->toggle = 0; + gpioSetPin(handle->pin, LOW); + } - schAdd(testTaskSwitchOff, handle, 5, 0); + schAdd(testTaskSwitchOff, handle, 5, 0); } diff --git a/src/testTask.h b/src/testTask.h index e7b0121..919b9b2 100644 --- a/src/testTask.h +++ b/src/testTask.h @@ -13,8 +13,8 @@ typedef struct { - tPin pin; - uint8_t toggle; + tPin pin; + uint8_t toggle; } tTestTaskHandle; void testTaskInit(void *handleArg, tPin pin); diff --git a/src/time.c b/src/time.c index 0dbc902..d15ad5a 100644 --- a/src/time.c +++ b/src/time.c @@ -37,6 +37,6 @@ uint32_t getMillis() { } void ms_active_delay(uint16_t delay) { - uint32_t start = timestamp; - while (start + delay > timestamp); + uint32_t start = timestamp; + while (start + delay > timestamp); }