1 /* FreeEMS - the open source engine management system
3 * Copyright 2012 Fred Cooke
5 * This file is part of the FreeEMS project.
7 * FreeEMS software is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * FreeEMS software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
20 * We ask that if you make any changes to this file you email them upstream to
21 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 * Thank you for choosing FreeEMS to run your engine!
29 * @brief Simple GPIO functionality
31 * Code for handling low frequency bit-bang switching of general pins based on
32 * the value of internal variables lives in this file.
37 #include "inc/freeEMS.h"
38 #include "inc/interrupts.h"
39 #include "inc/simpleGPIO.h"
43 * Perform GP outputs based on values of assigned variables. Compare upper and
44 * lower thresholds with the value of the selected variable and switch on or off
45 * as appropriate. Atomic blocks ensure no concurrency issues with current ECT.
47 void performSimpleGPIO(){
49 for(i
= 0;i
< fixedConfigs1
.simpleGPIOSettings
.numberConfigured
&& i
< NUMBER_OF_OUTPUT_CONFIGS
;i
++){
50 unsigned short value
= *(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].variable
);
51 if(value
>= fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].upperValue
){
52 if(!(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].flags
)){
53 ATOMIC_START(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
54 *(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].port
) |= fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].mask
;
55 ATOMIC_END(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
57 ATOMIC_START(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
58 *(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].port
) &= (unsigned char)~(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].mask
);
59 ATOMIC_END(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
61 }else if(value
<= fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].lowerValue
){
62 if(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].flags
){
63 ATOMIC_START(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
64 *(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].port
) |= fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].mask
;
65 ATOMIC_END(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
67 ATOMIC_START(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
68 *(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].port
) &= (unsigned char)~(fixedConfigs1
.simpleGPIOSettings
.outputConfigs
[i
].mask
);
69 ATOMIC_END(); /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
71 } // Do nothing if in hysteresis region