├── img ├── BIT4.jpg └── instruction.png ├── AtmelStudioProject-BIT4 ├── ExtendedDebug │ ├── AtmelStudioProject-BIT4.eep │ ├── makedep.mk │ ├── Makefile │ └── AtmelStudioProject-BIT4.srec ├── Release │ ├── makedep.mk │ └── Makefile ├── AtmelStudioProject-BIT4.atsln ├── AtmelStudioProject-BIT4.componentinfo.xml └── AtmelStudioProject-BIT4.cproj ├── instruction set.pdf ├── hardware ├── v1.0 │ ├── BOM.xlsx │ ├── pinout.png │ ├── pcb_bot.PNG │ ├── pcb_top.PNG │ ├── place_bot.png │ ├── place_top.png │ ├── schematic1.png │ ├── schematic2.png │ ├── schematic3.png │ ├── TPS_v1_2019-03-24.zip │ └── TPS_v1.dru └── v1.1b │ ├── layout_bot.png │ ├── layout_top.png │ ├── place_bot.png │ ├── place_top.png │ ├── schematic_1.png │ ├── schematic_2.png │ ├── schematic_3.png │ ├── BOM-BIT4-V11b.xlsx │ └── BIT4_v11b_2019-06-03.zip ├── firmware ├── ucunit │ ├── avr │ │ ├── Makefile │ │ └── System.c │ ├── Testsuite.h │ ├── System.h │ ├── Testsuite.c │ └── uCUnit-v1.0.h ├── common │ ├── randomSeed.h │ └── randomSeed.c ├── peripheral │ ├── adc.h │ ├── timer.h │ ├── timer.c │ ├── adc.c │ ├── gpio.h │ └── gpio.c ├── memory │ ├── eeprom.h │ └── eeprom.c └── core │ ├── tps.h │ ├── tps.c │ └── main.c ├── .gitignore ├── LICENSE └── README.md /img/BIT4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/img/BIT4.jpg -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/ExtendedDebug/AtmelStudioProject-BIT4.eep: -------------------------------------------------------------------------------- 1 | :00000001FF 2 | -------------------------------------------------------------------------------- /img/instruction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/img/instruction.png -------------------------------------------------------------------------------- /instruction set.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/instruction set.pdf -------------------------------------------------------------------------------- /hardware/v1.0/BOM.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/BOM.xlsx -------------------------------------------------------------------------------- /hardware/v1.0/pinout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/pinout.png -------------------------------------------------------------------------------- /hardware/v1.0/pcb_bot.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/pcb_bot.PNG -------------------------------------------------------------------------------- /hardware/v1.0/pcb_top.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/pcb_top.PNG -------------------------------------------------------------------------------- /hardware/v1.0/place_bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/place_bot.png -------------------------------------------------------------------------------- /hardware/v1.0/place_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/place_top.png -------------------------------------------------------------------------------- /firmware/ucunit/avr/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/firmware/ucunit/avr/Makefile -------------------------------------------------------------------------------- /hardware/v1.0/schematic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/schematic1.png -------------------------------------------------------------------------------- /hardware/v1.0/schematic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/schematic2.png -------------------------------------------------------------------------------- /hardware/v1.0/schematic3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/schematic3.png -------------------------------------------------------------------------------- /hardware/v1.1b/layout_bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/layout_bot.png -------------------------------------------------------------------------------- /hardware/v1.1b/layout_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/layout_top.png -------------------------------------------------------------------------------- /hardware/v1.1b/place_bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/place_bot.png -------------------------------------------------------------------------------- /hardware/v1.1b/place_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/place_top.png -------------------------------------------------------------------------------- /hardware/v1.1b/schematic_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/schematic_1.png -------------------------------------------------------------------------------- /hardware/v1.1b/schematic_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/schematic_2.png -------------------------------------------------------------------------------- /hardware/v1.1b/schematic_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/schematic_3.png -------------------------------------------------------------------------------- /hardware/v1.1b/BOM-BIT4-V11b.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/BOM-BIT4-V11b.xlsx -------------------------------------------------------------------------------- /hardware/v1.0/TPS_v1_2019-03-24.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.0/TPS_v1_2019-03-24.zip -------------------------------------------------------------------------------- /hardware/v1.1b/BIT4_v11b_2019-06-03.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GClown25/BIT4/HEAD/hardware/v1.1b/BIT4_v11b_2019-06-03.zip -------------------------------------------------------------------------------- /firmware/common/randomSeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * randomSeed.h 3 | * 4 | * Created: 24.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | 9 | #ifndef RANDOMSEED_H 10 | #define RANDOMSEED_H 11 | 12 | #include 13 | 14 | uint16_t getSeed(); 15 | 16 | #endif //RANDOMSEED_H -------------------------------------------------------------------------------- /firmware/peripheral/adc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * adc.h 3 | * 4 | * Created: 24.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #ifndef ADC_H 9 | #define ADC_H 10 | 11 | #include 12 | 13 | void adcInit(void); 14 | void adcDeInit(void); 15 | uint16_t adcRead(void); 16 | 17 | 18 | #endif //ADC_H -------------------------------------------------------------------------------- /firmware/memory/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * eeprom.h 3 | * 4 | * Created: 08.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #ifndef EEPROM_H 9 | #define EEPROM_H 10 | 11 | void EEPROM_write(unsigned int uiAddress, unsigned char ucData); 12 | unsigned char EEPROM_read(unsigned int uiAddress); 13 | 14 | 15 | #endif //EEPROM_H -------------------------------------------------------------------------------- /firmware/memory/eeprom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * eeprom.c 3 | * 4 | * Created: 08.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "eeprom.h" 9 | 10 | #include 11 | #include 12 | 13 | void EEPROM_write(unsigned int uiAddress, unsigned char ucData) 14 | { 15 | eeprom_write_byte(uiAddress, ucData); 16 | } 17 | 18 | unsigned char EEPROM_read(unsigned int uiAddress) 19 | { 20 | return eeprom_read_byte(uiAddress); 21 | } -------------------------------------------------------------------------------- /firmware/common/randomSeed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * randomSeed.c 3 | * 4 | * Created: 24.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "randomSeed.h" 9 | #include "../peripheral/adc.h" 10 | #include 11 | 12 | uint16_t getSeed(){ 13 | uint16_t seed = 0; 14 | uint16_t adcResult; 15 | 16 | for(int x = 0; x < 5; x++){ 17 | for(int i = 0; i <= 15; i++){ 18 | adcResult = adcRead(); 19 | seed |= ((adcResult&0x01) << i); 20 | } 21 | if(seed != 0)break; 22 | } 23 | 24 | return seed; 25 | } -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/Release/makedep.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit or delete the file 3 | ################################################################################ 4 | 5 | ..\firmware\common\randomSeed.c 6 | 7 | ..\firmware\core\main.c 8 | 9 | ..\firmware\core\tps.c 10 | 11 | ..\firmware\memory\eeprom.c 12 | 13 | ..\firmware\peripheral\adc.c 14 | 15 | ..\firmware\peripheral\gpio.c 16 | 17 | ..\firmware\peripheral\timer.c 18 | 19 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/ExtendedDebug/makedep.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit or delete the file 3 | ################################################################################ 4 | 5 | ..\firmware\common\randomSeed.c 6 | 7 | ..\firmware\core\main.c 8 | 9 | ..\firmware\core\tps.c 10 | 11 | ..\firmware\memory\eeprom.c 12 | 13 | ..\firmware\peripheral\adc.c 14 | 15 | ..\firmware\peripheral\gpio.c 16 | 17 | ..\firmware\peripheral\timer.c 18 | 19 | -------------------------------------------------------------------------------- /firmware/peripheral/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.h 3 | * 4 | * Created: 10.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #ifndef TIMER_H 9 | #define TIMER_H 10 | 11 | #include 12 | 13 | 14 | 15 | /* 16 | @brief: Init Timer TypeB for basic pwm led brightness control. 17 | Note that timer starts with first call of 'timerb_setDC'. 18 | 19 | */ 20 | void timerb_initPWM(TCB_t *tcbn); 21 | 22 | /* 23 | @brief: The duty cycle for the timerB is set, according to an 24 | exponential function to let the led brightness control appear smoother 25 | 26 | @param: aDC should have a value 27 | between 0 and 15. (4bit value) 28 | */ 29 | void timerb_setDC(TCB_t *tcbn, uint8_t aDC); 30 | 31 | 32 | #endif // TIMER_H -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #AtmelStudioProject Files 2 | Debug/ 3 | .vs/ 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Linker output 15 | *.ilk 16 | *.map 17 | *.exp 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Libraries 24 | *.lib 25 | *.a 26 | *.la 27 | *.lo 28 | 29 | # Shared objects (inc. Windows DLLs) 30 | *.dll 31 | *.so 32 | *.so.* 33 | *.dylib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | *.i*86 40 | *.x86_64 41 | *.hex 42 | 43 | # Debug files 44 | *.dSYM/ 45 | *.su 46 | *.idb 47 | *.pdb 48 | 49 | # Kernel Module Compile Results 50 | *.mod* 51 | *.cmd 52 | .tmp_versions/ 53 | modules.order 54 | Module.symvers 55 | Mkfile.old 56 | dkms.conf 57 | -------------------------------------------------------------------------------- /firmware/core/tps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tps.h 3 | * 4 | * Created: 09.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | 9 | #ifndef TPS_H 10 | #define TPS_H 11 | 12 | #include 13 | 14 | void tps_splitInstruction(uint8_t aInstruction, uint8_t *aCommand, uint8_t *aData); 15 | void tps_unifyInstruction(uint8_t *aInstruction, uint8_t aCommand, uint8_t aData); 16 | 17 | 18 | uint8_t tps_add(uint8_t term1, uint8_t term2); 19 | uint8_t tps_subtract(uint8_t minuend, uint8_t subtrahend); 20 | uint8_t tps_multiply(uint8_t multiplier1, uint8_t multiplier2); 21 | uint8_t tps_divide(uint8_t dividend, uint8_t divisor); 22 | 23 | uint8_t tps_mod(uint8_t a, uint8_t b); 24 | 25 | uint8_t tps_shiftLeft(uint8_t x, uint8_t n); 26 | uint8_t tps_shiftRight(uint8_t x, uint8_t n); 27 | 28 | 29 | 30 | #endif //TPS_H -------------------------------------------------------------------------------- /firmware/peripheral/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.c 3 | * 4 | * Created: 10.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "timer.h" 9 | 10 | #include 11 | 12 | //exponential function 13 | const uint8_t brightnessLookup[] = {0, 1, 2, 3, 4, 6, 9, 13, 19, 27, 40, 58, 84, 121, 176, 255}; 14 | 15 | void timerb_initPWM(TCB_t *tcbn){ 16 | 17 | tcbn->CTRLA = TCB_CLKSEL_CLKDIV2_gc; 18 | tcbn->CTRLB = TCB_CCMPEN_bm | TCB_CNTMODE_PWM8_gc; 19 | 20 | tcbn->CCMPL = 0xff; //Set period of the output pulse 21 | } 22 | 23 | void timerb_setDC(TCB_t *tcbn, uint8_t aDC){ 24 | 25 | tcbn->CTRLA &= ~TCB_ENABLE_bm; //disable timer 26 | 27 | tcbn->CCMPL = 0xff; //Set period of the output pulse 28 | tcbn->CCMPH = brightnessLookup[aDC & 0xf]; //Set DC 29 | tcbn->CNT = 0x0000; 30 | 31 | tcbn->CTRLA |= TCB_ENABLE_bm; //enable timer 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 GClown25 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /firmware/peripheral/adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * adc.c 3 | * 4 | * Created: 24.4.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "adc.h" 9 | #include 10 | #include 11 | 12 | /* 13 | * @brief: Init ADC to measure the internal temperature sensor 14 | */ 15 | void adcInit(void) 16 | { 17 | // The adc gets initialized with a faster sample time than for the internal 18 | // temp sensor recommended, to get more noise. 19 | 20 | VREF.CTRLA |= VREF_ADC0REFSEL_1V1_gc; 21 | VREF.CTRLB |= VREF_ADC0REFEN_bm; 22 | 23 | ADC0.CTRLC = ADC_REFSEL_INTREF_gc | ADC_PRESC_DIV2_gc | ADC_SAMPCAP_bm; 24 | ADC0.MUXPOS = ADC_MUXPOS_TEMPSENSE_gc; 25 | 26 | ADC0.CTRLD = ADC_INITDLY_DLY16_gc; 27 | ADC0.SAMPCTRL = 0x0; 28 | 29 | ADC0.CTRLA = ADC_ENABLE_bm | ADC_RESSEL_10BIT_gc; 30 | 31 | } 32 | 33 | void adcDeInit(void){ 34 | VREF.CTRLB &= ~VREF_ADC0REFEN_bm; 35 | ADC0.CTRLA &= ~ADC_ENABLE_bm; 36 | 37 | } 38 | 39 | uint16_t adcRead(void) 40 | { 41 | /* Start ADC conversion */ 42 | ADC0.COMMAND = ADC_STCONV_bm; 43 | /* Wait until ADC conversion done */ 44 | while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) ) 45 | { 46 | ; 47 | } 48 | /* Clear the interrupt flag by writing 1: */ 49 | ADC0.INTFLAGS = ADC_RESRDY_bm; 50 | return ADC0.RES; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/AtmelStudioProject-BIT4.atsln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Atmel Studio Solution File, Format Version 11.00 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "AtmelStudioProject-BIT4", "AtmelStudioProject-BIT4.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|AVR = Debug|AVR 11 | ExtendedDebug|AVR = ExtendedDebug|AVR 12 | Release|AVR = Release|AVR 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR 16 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR 17 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.ExtendedDebug|AVR.ActiveCfg = ExtendedDebug|AVR 18 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.ExtendedDebug|AVR.Build.0 = ExtendedDebug|AVR 19 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR 20 | {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /firmware/peripheral/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio.h 3 | * 4 | * Created: 09.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #ifndef GPIO_H 9 | #define GPIO_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #define MASK_SET_4BIT(offset) (0x0f << (offset)) 16 | #define MASK_CLEAR_4BIT(offset) (~(0x0f << (offset))) 17 | 18 | #define MASK_SET_1BIT(offset) (0x01 << (offset)) 19 | #define MASK_CLEAR_1BIT(offset) (~(0x01 << (offset))) 20 | 21 | 22 | 23 | typedef enum{ 24 | NORMAL, 25 | REVERSED 26 | }GPIO_SEQUENCE; 27 | 28 | //4bit output port 29 | typedef struct 30 | { 31 | volatile uint8_t *out; 32 | volatile uint8_t *dir; 33 | GPIO_SEQUENCE sequence; 34 | uint8_t pin0; 35 | }GPIO_DOUT; 36 | 37 | //4bit input port 38 | typedef struct 39 | { 40 | volatile uint8_t *pinctrl; 41 | volatile uint8_t *dir; 42 | volatile uint8_t *in; 43 | GPIO_SEQUENCE sequence; 44 | uint8_t pin0; 45 | 46 | #ifdef BOARD_V11B 47 | volatile uint8_t *intflags; 48 | GPIO_DOUT shadowReg; 49 | #endif 50 | 51 | }GPIO_DIN; 52 | 53 | //Button 54 | typedef struct 55 | { 56 | volatile uint8_t *pinctrl; 57 | volatile uint8_t *dir; 58 | volatile uint8_t *in; 59 | uint8_t pin; 60 | }GPIO_BTN; 61 | 62 | 63 | 64 | void gpio_dout_init(GPIO_DOUT *aDout); 65 | void gpio_dout_write(GPIO_DOUT *aDout, uint8_t aData); 66 | void gpio_dout_writeBit(GPIO_DOUT *aDout, uint8_t aBit, uint8_t aBitNr); 67 | void gpio_dout_toggleBit(GPIO_DOUT *aDout, uint8_t aBitNr); 68 | uint8_t gpio_dout_read(GPIO_DOUT *aDout); 69 | 70 | void gpio_din_init(GPIO_DIN *aDin); 71 | uint8_t gpio_din_read(GPIO_DIN *aDin); 72 | uint8_t gpio_din_readBit(GPIO_DIN *aDin, uint8_t aBitNr); 73 | 74 | void gpio_btn_init(GPIO_BTN *aBtn); 75 | bool gpio_btn_read(GPIO_BTN *aBtn); 76 | 77 | #endif //GPIO_H -------------------------------------------------------------------------------- /firmware/ucunit/Testsuite.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * uCUnit - A unit testing framework for microcontrollers * 4 | * * 5 | * (C) 2007 - 2008 Sven Stefan Krauss * 6 | * https://www.ucunit.org * 7 | * * 8 | * File : Testsuite.h * 9 | * Description : Public testsuite functions * 10 | * Author : Sven Stefan Krauss * 11 | * Contact : www.ucunit.org * 12 | * * 13 | *****************************************************************************/ 14 | 15 | /* 16 | * This file is part of ucUnit. 17 | * 18 | * You can redistribute and/or modify it under the terms of the 19 | * Common Public License as published by IBM Corporation; either 20 | * version 1.0 of the License, or (at your option) any later version. 21 | * 22 | * uCUnit is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * Common Public License for more details. 26 | * 27 | * You should have received a copy of the Common Public License 28 | * along with uCUnit. 29 | * 30 | * It may also be available at the following URL: 31 | * http://www.opensource.org/licenses/cpl1.0.txt 32 | * 33 | * If you cannot obtain a copy of the License, please contact the 34 | * author. 35 | */ 36 | #ifndef TESTSUITE_H_ 37 | #define TESTSUITE_H_ 38 | 39 | void Testsuite_RunTests(void); 40 | 41 | #endif /* TESTSUITE_H_ */ 42 | -------------------------------------------------------------------------------- /firmware/ucunit/System.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * uCUnit - A unit testing framework for microcontrollers * 4 | * * 5 | * (C) 2007 - 2008 Sven Stefan Krauss * 6 | * https://www.ucunit.org * 7 | * * 8 | * File : System.h * 9 | * Description : System dependent functions used by uCUnit. * 10 | * Author : Sven Stefan Krauss * 11 | * Contact : www.ucunit.org * 12 | * * 13 | *****************************************************************************/ 14 | 15 | /* 16 | * This file is part of ucUnit. 17 | * 18 | * You can redistribute and/or modify it under the terms of the 19 | * Common Public License as published by IBM Corporation; either 20 | * version 1.0 of the License, or (at your option) any later version. 21 | * 22 | * uCUnit is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * Common Public License for more details. 26 | * 27 | * You should have received a copy of the Common Public License 28 | * along with uCUnit. 29 | * 30 | * It may also be available at the following URL: 31 | * http://www.opensource.org/licenses/cpl1.0.txt 32 | * 33 | * If you cannot obtain a copy of the License, please contact the 34 | * author. 35 | */ 36 | #ifndef SYSTEM_H_ 37 | #define SYSTEM_H_ 38 | 39 | /* function prototypes */ 40 | void System_Init(void); 41 | void System_Shutdown(void); 42 | void System_Safestate(void); 43 | void System_Recover(void); 44 | void System_WriteString(char * msg); 45 | void System_WriteInt(int n); 46 | 47 | #endif /* SYSTEM_H_ */ 48 | -------------------------------------------------------------------------------- /firmware/core/tps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tps.c 3 | * 4 | * Created: 09.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "tps.h" 9 | 10 | #include 11 | 12 | void tps_splitInstruction(uint8_t aInstruction, uint8_t *aCommand, uint8_t *aData){ 13 | *aCommand = (aInstruction & 0xf0) >> 4; 14 | *aData = aInstruction & 0x0f; 15 | } 16 | 17 | void tps_unifyInstruction(uint8_t *aInstruction, uint8_t aCommand, uint8_t aData){ 18 | *aInstruction = ((aCommand & 0x0f) << 4) | (aData & 0x0f); 19 | } 20 | 21 | 22 | uint8_t tps_add(uint8_t term1, uint8_t term2){ 23 | uint8_t sum; 24 | 25 | term1 = term1 & 0xf; 26 | term2 = term2 & 0xf; 27 | 28 | sum = term1 + term2; 29 | 30 | if(sum > 15){ 31 | sum -= 16; 32 | } 33 | 34 | return sum; 35 | } 36 | 37 | uint8_t tps_subtract(uint8_t minuend, uint8_t subtrahend){ 38 | int8_t difference; 39 | 40 | minuend = minuend & 0xf; 41 | subtrahend = subtrahend & 0xf; 42 | 43 | difference = minuend - subtrahend; 44 | 45 | if (difference < 0){ 46 | difference += 16; 47 | } 48 | 49 | return difference; 50 | } 51 | 52 | uint8_t tps_multiply(uint8_t multiplier1, uint8_t multiplier2){ 53 | uint8_t product; 54 | 55 | multiplier1 = multiplier1 & 0xf; 56 | multiplier2 = multiplier2 & 0xf; 57 | 58 | product = multiplier1 * multiplier2; 59 | 60 | while(product > 15){ 61 | product -= 16; 62 | } 63 | 64 | return product; 65 | } 66 | 67 | uint8_t tps_divide(uint8_t dividend, uint8_t divisor){ 68 | uint8_t quotient; 69 | 70 | dividend = dividend & 0xf; 71 | divisor = divisor & 0xf; 72 | 73 | quotient = dividend/divisor; 74 | 75 | quotient = quotient & 0xf; 76 | 77 | return quotient; 78 | } 79 | 80 | uint8_t tps_mod(uint8_t a, uint8_t b){ 81 | a = a & 0xf; 82 | b = b & 0xf; 83 | 84 | a = a % b; 85 | 86 | b = b & 0xf; 87 | 88 | return a; 89 | } 90 | 91 | uint8_t tps_shiftLeft(uint8_t x, uint8_t n){ 92 | x = x & 0xf; 93 | n = n & 0xf; 94 | 95 | x = x << n; 96 | 97 | x = x & 0xf; 98 | 99 | return x; 100 | } 101 | 102 | uint8_t tps_shiftRight(uint8_t x, uint8_t n){ 103 | x = x & 0xf; 104 | n = n & 0xf; 105 | 106 | x = x >> n; 107 | 108 | x = x & 0xf; 109 | 110 | return x; 111 | } -------------------------------------------------------------------------------- /hardware/v1.0/TPS_v1.dru: -------------------------------------------------------------------------------- 1 | description[de] = EAGLE Design Rules\n

\nDie Standard-Design-Rules sind so gewählt, dass sie für \ndie meisten Anwendungen passen. Sollte ihre Platine \nbesondere Anforderungen haben, treffen Sie die erforderlichen\nEinstellungen hier und speichern die Design Rules unter \neinem neuen Namen ab. 2 | description[en] = EAGLE Design Rules\n

\nThe default Design Rules have been set to cover\na wide range of applications. Your particular design\nmay have different requirements, so please make the\nnecessary adjustments and save your customized\ndesign rules under a new name. 3 | layerSetup = (1*16) 4 | mtCopper = 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 5 | mtIsolate = 1.5mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 6 | mdWireWire = 5mil 7 | mdWirePad = 5mil 8 | mdWireVia = 5mil 9 | mdPadPad = 5mil 10 | mdPadVia = 5mil 11 | mdViaVia = 5mil 12 | mdSmdPad = 5mil 13 | mdSmdVia = 5mil 14 | mdSmdSmd = 5mil 15 | mdViaViaSameLayer = 6mil 16 | mnLayersViaInSmd = 2 17 | mdCopperDimension = 5mil 18 | mdDrill = 6mil 19 | mdSmdStop = 0mil 20 | msWidth = 5mil 21 | msDrill = 0.2mm 22 | msMicroVia = 9.99mm 23 | msBlindViaRatio = 0.500000 24 | rvPadTop = 0.100000 25 | rvPadInner = 0.250000 26 | rvPadBottom = 0.250000 27 | rvViaOuter = 0.250000 28 | rvViaInner = 0.250000 29 | rvMicroViaOuter = 0.250000 30 | rvMicroViaInner = 0.250000 31 | rlMinPadTop = 18mil 32 | rlMaxPadTop = 20mil 33 | rlMinPadInner = 18mil 34 | rlMaxPadInner = 20mil 35 | rlMinPadBottom = 18mil 36 | rlMaxPadBottom = 20mil 37 | rlMinViaOuter = 8mil 38 | rlMaxViaOuter = 20mil 39 | rlMinViaInner = 8mil 40 | rlMaxViaInner = 20mil 41 | rlMinMicroViaOuter = 4mil 42 | rlMaxMicroViaOuter = 20mil 43 | rlMinMicroViaInner = 4mil 44 | rlMaxMicroViaInner = 20mil 45 | psTop = -1 46 | psBottom = -1 47 | psFirst = -1 48 | psElongationLong = 100 49 | psElongationOffset = 100 50 | mvStopFrame = 1.000000 51 | mvCreamFrame = 0.000000 52 | mlMinStopFrame = 4mil 53 | mlMaxStopFrame = 4mil 54 | mlMinCreamFrame = 0mil 55 | mlMaxCreamFrame = 0mil 56 | mlViaStopLimit = 0mil 57 | srRoundness = 0.000000 58 | srMinRoundness = 0mil 59 | srMaxRoundness = 0mil 60 | slThermalIsolate = 10mil 61 | slThermalsForVias = 0 62 | dpMaxLengthDifference = 10mm 63 | dpGapFactor = 2.500000 64 | checkAngle = 0 65 | checkFont = 1 66 | checkRestrict = 1 67 | checkStop = 0 68 | checkValues = 0 69 | checkNames = 1 70 | checkWireStubs = 1 71 | checkPolygonWidth = 0 72 | useDiameter = 13 73 | maxErrors = 50 74 | -------------------------------------------------------------------------------- /firmware/peripheral/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio.c 3 | * 4 | * Created: 09.02.2019 5 | * Author : GClown25 6 | */ 7 | 8 | #include "gpio.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | const uint8_t lookupReverse4bit[] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf}; 15 | 16 | 17 | 18 | void gpio_dout_init(GPIO_DOUT *aDout){ 19 | //Configure the 4 DOUT bits a output 20 | *aDout->dir |= MASK_SET_4BIT(aDout->pin0); 21 | } 22 | 23 | void gpio_din_init(GPIO_DIN *aDin){ 24 | //Configure the 4 DIN bits a input 25 | *aDin->dir &= MASK_CLEAR_4BIT(aDin->pin0); 26 | 27 | for(int i = 0; i <= 3; i++){ 28 | #ifdef BOARD_V10 29 | *(aDin->pinctrl + i) = 0x08; /* Set the internal pullup for the input pins */ 30 | #elif BOARD_V11B 31 | *(aDin->pinctrl + i) = 0x08 | 0x03; /* Set the internal pullup and enable the interrupt on the falling edge */ 32 | gpio_dout_init(&aDin->shadowReg); 33 | #else 34 | #error Please define a Board Version 35 | #endif 36 | } 37 | } 38 | 39 | void gpio_btn_init(GPIO_BTN *aBtn){ 40 | //Configure button pin as input 41 | *aBtn->dir &= ~(1 << aBtn->pin); 42 | 43 | //Set the internal pullup for the button 44 | *aBtn->pinctrl = 0x08; 45 | } 46 | 47 | 48 | 49 | void gpio_dout_write(GPIO_DOUT *aDout, uint8_t aData){ 50 | uint8_t tempReg, tempData; 51 | 52 | if(aDout->sequence == REVERSED){ 53 | tempData = lookupReverse4bit[aData]; 54 | }else{ 55 | tempData = aData; 56 | } 57 | 58 | tempReg = *aDout->out; 59 | 60 | tempReg |= (MASK_SET_4BIT(aDout->pin0) & (tempData << aDout->pin0)); 61 | tempReg &= (MASK_CLEAR_4BIT(aDout->pin0) | (tempData << aDout->pin0)); 62 | 63 | *aDout->out = tempReg; 64 | } 65 | 66 | void gpio_dout_writeBit(GPIO_DOUT *aDout, uint8_t aBit, uint8_t aBitNr){ 67 | uint8_t tempReg, tempBitNr; 68 | 69 | if(aDout->sequence == REVERSED){ 70 | tempBitNr = 3 - aBitNr; 71 | }else{ 72 | tempBitNr = aBitNr; 73 | } 74 | 75 | tempReg = *aDout->out; 76 | 77 | tempReg |= (MASK_SET_1BIT(aDout->pin0 + tempBitNr) & (aBit << (aDout->pin0 + tempBitNr))); 78 | tempReg &= (MASK_CLEAR_1BIT(aDout->pin0 + tempBitNr) | (aBit << (aDout->pin0 + tempBitNr))); 79 | 80 | *aDout->out = tempReg; 81 | } 82 | 83 | void gpio_dout_toggleBit(GPIO_DOUT *aDout, uint8_t aBitNr){ 84 | uint8_t tempReg, tempBitNr; 85 | 86 | if(aDout->sequence == REVERSED){ 87 | tempBitNr = 3 - aBitNr; 88 | }else{ 89 | tempBitNr = aBitNr; 90 | } 91 | 92 | tempReg = *aDout->out; 93 | 94 | tempReg ^= MASK_SET_1BIT(aDout->pin0 + tempBitNr); 95 | 96 | *aDout->out = tempReg; 97 | } 98 | 99 | uint8_t gpio_dout_read(GPIO_DOUT *aDout){ 100 | uint8_t tempReg; 101 | 102 | tempReg = (*aDout->out >> aDout->pin0) & 0xf; 103 | 104 | if(aDout->sequence == REVERSED){ 105 | return lookupReverse4bit[tempReg]; 106 | }else{ 107 | return tempReg; 108 | } 109 | 110 | } 111 | 112 | 113 | 114 | uint8_t gpio_din_read(GPIO_DIN *aDin){ 115 | uint8_t tempReg; 116 | 117 | #ifdef BOARD_V10 118 | tempReg = (*aDin->in >> aDin->pin0) & 0xf; 119 | 120 | if(aDin->sequence == REVERSED){ 121 | return lookupReverse4bit[tempReg]; 122 | }else{ 123 | return tempReg; 124 | } 125 | #elif BOARD_V11B 126 | tempReg = gpio_dout_read(&aDin->shadowReg); 127 | #endif 128 | 129 | return tempReg; 130 | } 131 | 132 | 133 | uint8_t gpio_din_readBit(GPIO_DIN *aDin, uint8_t aBitNr){ 134 | uint8_t tempReg; 135 | 136 | tempReg = gpio_din_read(aDin); 137 | 138 | return (tempReg >> aBitNr) & 0x01; 139 | } 140 | 141 | 142 | bool gpio_btn_read(GPIO_BTN *aBtn){ 143 | return (*aBtn->in & (1 << aBtn->pin)) ? true : false; 144 | } 145 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BIT4 2 | BIT4 is a 4Bit microcontroller - fully programmable with only three buttons. 3 | 4 | ![pinout](hardware/v1.0/pinout.png) 5 | 6 | # Programming guide: 7 | 8 | The BIT4 microcontroller has 256 Bytes of programm memory, split in 16 pages with each 16 instructions. 9 | A instruction is 8bit wide and consists of an command and data: 10 | \ 11 | ![instruction](img/instruction.png) 12 | \ 13 | To enter the programming mode, hold BTN2 down, press the RESET button once and then release BTN2. 14 | In programming mode, step through the instructions with BTN2. When going to a new instruction, 15 | the leds will show the current address for a fraktion of a second. 16 | With BTN1 the value of the command and data of the current instruction can be changed. 17 | When stepping to a new address with BTN2, the instuction of the address above gets saved in the EEPROM. 18 | At the end, press RESET to leave the programming mode and to start the programm execution. 19 | 20 | ## Instruction set explained: 21 | 22 | - command 0x0: load a constant value to doutB 23 | - command 0x1: load a constant value to doutA 24 | - command 0x2: delay 25 | - command 0x3: do a relative jump back 26 | - command 0x4: load constant value to variable A 27 | - command 0x5: load something with the value of variable A 28 | - command 0x6: load the value of something into the variable A 29 | - command 0x7: do arithmetic and logic operations with variable A (and B) 30 | - command 0x8: set the high nibble of the address to jump to in absolute jump instructions 31 | - command 0x9: do an absolute jump to the specified address 32 | - command 0xA, 0xB: acts like a for loop. Every time this command is executed, 33 | if the variable C (or D) is greater than zero, an absolute jump to the specified address is done. 34 | Then the variable C (or D) gets decremented. 35 | - command 0xC: skip the next instruction if the argument is true 36 | - command 0xD: call a function at the specified address 37 | - command 0xE: return from the function call 38 | - command 0xF: sets the address of the virtual 4bit RAM. 39 | The value stored in this address can be read with 0x6e and written with 0x50. 40 | 41 | ## Examples: 42 | 43 | 44 | **Blinki:** 45 | 46 | | address | instruction | comment | 47 | | :------ | :---------- | -------------------------: | 48 | | 0 | 1f | turn all leds on doutA on | 49 | | 1 | 28 | wait for 500ms | 50 | | 2 | 10 | turn all leds on doutB off | 51 | | 3 | 28 | wait for 500ms | 52 | | 4 | 34 | relative jump -4 | 53 | 54 | \ 55 | **Binary counter:** 56 | \ 57 | https://www.youtube.com/watch?v=6CpZszKlP7Y 58 | 59 | | address | instruction | comment | 60 | | :------ | :---------- | ---------------: | 61 | | 0 | 5B | DoutB = A | 62 | | 1 | 59 | PWM1 = A | 63 | | 2 | 71 | A++ | 64 | | 3 | 28 | wait for 500ms | 65 | | 4 | 34 | relative jump -4 | 66 | 67 | \ 68 | **Blinki with adjustable speed:** 69 | \ 70 | https://www.youtube.com/watch?v=YPoedGGZs4g 71 | 72 | | address | instruction | comment | 73 | | :-------- | :---------- | --------------------: | 74 | | **main:** | 75 | | 0 | 10 | DoutA = 0x0 | 76 | | 1 | d5 | call myWait | 77 | | 2 | 1f | DoutA = 0xf | 78 | | 3 | d5 | call myWait | 79 | | 4 | 34 | relative jump -4 | 80 | | **myWait:** | 81 | | 5 | 64 | A = Din | 82 | | 6 | 52 | C = A | 83 | | 7 | 25 | wait for 50ms | 84 | | 8 | a7 | for(C > 0; C--) jmp 7 | 85 | | 9 | e0 | return | 86 | 87 | \ 88 | **Credits:**\ 89 | The idea for this project came from the german microcontroller learning plattform "TPS" (http://elektronik-labor.de/Lernpakete/TPS/TPS0.html). 90 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/AtmelStudioProject-BIT4.componentinfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.3.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include\avr\iom4809.h 30 | 31 | header 32 | C 33 | FdR+b+YeApGpfuP34POBng== 34 | 35 | include/avr/iom4809.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\templates\main.c 41 | template 42 | source 43 | C Exe 44 | LZ/P/HEbtU22yKGklnMZjw== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega4809 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/Atmel/ATmega_DFP/1.3.300/Atmel.ATmega_DFP.pdsc 75 | 1.3.300 76 | true 77 | ATmega4809 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /firmware/ucunit/avr/System.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * uCUnit - A unit testing framework for microcontrollers * 4 | * * 5 | * (C) 2007 - 2008 Sven Stefan Krauss * 6 | * https://www.ucunit.org * 7 | * * 8 | * File : System.c * 9 | * Description : System dependent functions used by uCUnit. * 10 | * This file has to be customized for your hardware. * 11 | * Author : Sven Stefan Krauss * 12 | * Contact : www.ucunit.org * 13 | * * 14 | *****************************************************************************/ 15 | 16 | /* 17 | * This file is part of ucUnit. 18 | * 19 | * You can redistribute and/or modify it under the terms of the 20 | * Common Public License as published by IBM Corporation; either 21 | * version 1.0 of the License, or (at your option) any later version. 22 | * 23 | * uCUnit is distributed in the hope that it will be useful, 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | * Common Public License for more details. 27 | * 28 | * You should have received a copy of the Common Public License 29 | * along with uCUnit. 30 | * 31 | * It may also be available at the following URL: 32 | * http://www.opensource.org/licenses/cpl1.0.txt 33 | * 34 | * If you cannot obtain a copy of the License, please contact the 35 | * author. 36 | */ 37 | 38 | #define F_CPU 20000000UL 39 | 40 | #include 41 | 42 | #include 43 | #include 44 | #include "../System.h" 45 | 46 | 47 | 48 | #define USART_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float)BAUD_RATE)) + 0.5) 49 | 50 | /* Stub: Initialize your hardware here */ 51 | void System_Init(void) 52 | { 53 | //Disable Clk Prescaler (F_CPU = 20MHz) 54 | CCP = 0xd8; 55 | CLKCTRL.MCLKCTRLB = 0x00; 56 | 57 | //Initialize UART 58 | /*//for discovery kit 59 | PORTB.DIR |= PIN0_bm; 60 | USART3.BAUD = (uint16_t)USART_BAUD_RATE(9600); 61 | USART3.CTRLB |= USART_TXEN_bm; 62 | */ 63 | 64 | //for custom pcb 65 | PORTA.DIR |= PIN0_bm; 66 | USART0.BAUD = (uint16_t)USART_BAUD_RATE(115200); 67 | USART0.CTRLB |= USART_TXEN_bm; 68 | 69 | 70 | printf("Init of hardware finished.\n"); 71 | } 72 | 73 | /* Stub: Shutdown your hardware here */ 74 | void System_Shutdown(void) 75 | { 76 | 77 | /* asm("\tSTOP"); */ 78 | printf("System shutdown.\n"); 79 | exit(0); 80 | } 81 | 82 | /* Stub: Resets the system */ 83 | void System_Reset(void) 84 | { 85 | /* Stub: Reset the hardware */ 86 | /* asm("\tRESET"); */ 87 | printf("System reset.\n"); 88 | exit(0); 89 | } 90 | 91 | /* Stub: Put system in a safe state */ 92 | void System_Safestate(void) 93 | { 94 | /* Disable all port pins */ 95 | /* PORTA = 0x0000; */ 96 | /* PORTB = 0x0000; */ 97 | /* PORTC = 0x0000; */ 98 | 99 | /* Disable interrupts */ 100 | /* DIE(); */ 101 | 102 | /* Put processor into idle state */ 103 | /* asm("\tIDLE"); */ 104 | printf("System safe state.\n"); 105 | exit(0); 106 | } 107 | 108 | void uart_putc(char c) 109 | { 110 | // for discovery kit 111 | // while (!(USART3.STATUS & USART_DREIF_bm)) 112 | // { 113 | // ; 114 | // } 115 | // USART3.TXDATAL = c; 116 | 117 | // for custom pcb 118 | while (!(USART0.STATUS & USART_DREIF_bm)) 119 | { 120 | ; 121 | } 122 | USART0.TXDATAL = c; 123 | } 124 | 125 | 126 | /* Stub: Transmit a string to the host/debugger/simulator */ 127 | void System_WriteString(char * s) 128 | { 129 | while(*s) 130 | { 131 | uart_putc(*s); 132 | s++; 133 | } 134 | } 135 | 136 | void System_WriteInt(int n) 137 | { 138 | uint8_t buffer[10]; 139 | itoa(n, buffer, 10); 140 | System_WriteString(buffer); 141 | } 142 | 143 | -------------------------------------------------------------------------------- /firmware/ucunit/Testsuite.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * uCUnit - A unit testing framework for microcontrollers * 4 | * * 5 | * (C) 2007 - 2008 Sven Stefan Krauss * 6 | * https://www.ucunit.org * 7 | * * 8 | * File : Testsuite.h * 9 | * Description : Sample testsuite * 10 | * Author : Sven Stefan Krauss * 11 | * Contact : www.ucunit.org * 12 | * * 13 | *****************************************************************************/ 14 | 15 | /* 16 | * This file is part of ucUnit. 17 | * 18 | * You can redistribute and/or modify it under the terms of the 19 | * Common Public License as published by IBM Corporation; either 20 | * version 1.0 of the License, or (at your option) any later version. 21 | * 22 | * uCUnit is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * Common Public License for more details. 26 | * 27 | * You should have received a copy of the Common Public License 28 | * along with uCUnit. 29 | * 30 | * It may also be available at the following URL: 31 | * http://www.opensource.org/licenses/cpl1.0.txt 32 | * 33 | * If you cannot obtain a copy of the License, please contact the 34 | * author. 35 | */ 36 | 37 | #include "System.h" 38 | #include "uCUnit-v1.0.h" 39 | #include "Testsuite.h" 40 | 41 | #include 42 | #include "memory/eeprom.h" 43 | 44 | static void Test_eeprom_01(void){ 45 | uint8_t data1, data2; 46 | 47 | UCUNIT_TestcaseBegin("EEPROM: check write and read"); 48 | 49 | cli(); 50 | EEPROM_write(0x0000, 0xAB ); 51 | EEPROM_write(0x07ff, 0xCD ); 52 | 53 | data1 = EEPROM_read(0x0000); 54 | data2 = EEPROM_read(0x07ff); //dec2047 55 | sei(); 56 | 57 | UCUNIT_CheckIsEqual(0xAB, data1); 58 | UCUNIT_CheckIsEqual(0xCD, data2); 59 | 60 | UCUNIT_TestcaseEnd(); 61 | } 62 | 63 | 64 | 65 | static void Test_tps_01(void){ 66 | uint8_t instruction1, command1, data1; 67 | instruction1 = 0x3b; 68 | 69 | UCUNIT_TestcaseBegin("TPS: tps_splitInstruction"); 70 | 71 | tps_splitInstruction(instruction1, &command1, &data1); 72 | 73 | UCUNIT_CheckIsEqual(0x03, command1); 74 | UCUNIT_CheckIsEqual(0x0b, data1); 75 | 76 | UCUNIT_TestcaseEnd(); 77 | 78 | } 79 | 80 | static void Test_tps_02(void){ 81 | uint8_t instruction1, command1, data1; 82 | command1 = 0x0a; 83 | data1 = 0x0e; 84 | 85 | UCUNIT_TestcaseBegin("TPS: tps_unifyInstruction"); 86 | 87 | tps_unifyInstruction(&instruction1, command1, data1); 88 | 89 | UCUNIT_CheckIsEqual(0xae, instruction1); 90 | 91 | 92 | UCUNIT_TestcaseEnd(); 93 | } 94 | 95 | 96 | 97 | static void Test_tps_03(void){ 98 | uint8_t term1_1 = 9, term2_1 = 0, sum_1; 99 | uint8_t term1_2 = 11, term2_2 = 4, sum_2; 100 | uint8_t term1_3 = 15, term2_3 = 15, sum_3; 101 | uint8_t term1_4 = 15, term2_4 = 1, sum_4; 102 | 103 | UCUNIT_TestcaseBegin("TPS: tps_add"); 104 | 105 | sum_1 = tps_add(term1_1, term2_1); 106 | sum_2 = tps_add(term1_2, term2_2); 107 | sum_3 = tps_add(term1_3, term2_3); 108 | sum_4 = tps_add(term1_4, term2_4); 109 | 110 | 111 | UCUNIT_CheckIsEqual(9, sum_1); 112 | UCUNIT_CheckIsEqual(15, sum_2); 113 | UCUNIT_CheckIsEqual(14, sum_3); 114 | UCUNIT_CheckIsEqual(0, sum_4); 115 | 116 | 117 | UCUNIT_TestcaseEnd(); 118 | } 119 | 120 | 121 | static void Test_tps_04(void){ 122 | uint8_t a_1 = 15, b_1 = 11, c_1; 123 | uint8_t a_2 = 15, b_2 = 15, c_2; 124 | uint8_t a_3 = 0, b_3 = 1, c_3; 125 | uint8_t a_4 = 0, b_4 = 15, c_4; 126 | 127 | UCUNIT_TestcaseBegin("TPS: tps_subtract"); 128 | 129 | c_1 = tps_subtract(a_1, b_1); 130 | c_2 = tps_subtract(a_2, b_2); 131 | c_3 = tps_subtract(a_3, b_3); 132 | c_4 = tps_subtract(a_4, b_4); 133 | 134 | 135 | UCUNIT_CheckIsEqual(4, c_1); 136 | UCUNIT_CheckIsEqual(0, c_2); 137 | UCUNIT_CheckIsEqual(15, c_3); 138 | UCUNIT_CheckIsEqual(1, c_4); 139 | 140 | 141 | UCUNIT_TestcaseEnd(); 142 | } 143 | 144 | static void Test_tps_05(void){ 145 | uint8_t a_1 = 3, b_1 = 4, c_1; 146 | uint8_t a_2 = 8, b_2 = 2, c_2; 147 | uint8_t a_3 = 8, b_3 = 3, c_3; 148 | uint8_t a_4 = 15, b_4 = 15, c_4; 149 | 150 | UCUNIT_TestcaseBegin("TPS: tps_multiply"); 151 | 152 | c_1 = tps_multiply(a_1, b_1); 153 | c_2 = tps_multiply(a_2, b_2); 154 | c_3 = tps_multiply(a_3, b_3); 155 | c_4 = tps_multiply(a_4, b_4); 156 | 157 | 158 | UCUNIT_CheckIsEqual(12, c_1); 159 | UCUNIT_CheckIsEqual(0, c_2); 160 | UCUNIT_CheckIsEqual(8, c_3); 161 | UCUNIT_CheckIsEqual(1, c_4); 162 | 163 | 164 | UCUNIT_TestcaseEnd(); 165 | } 166 | 167 | 168 | static void Test_tps_06(void){ 169 | uint8_t a_1 = 1, b_1 = 0, c_1; 170 | uint8_t a_2 = 15, b_2 = 3, c_2; 171 | uint8_t a_3 = 15, b_3 = 1, c_3; 172 | 173 | UCUNIT_TestcaseBegin("TPS: tps_divide"); 174 | 175 | c_1 = tps_divide(a_1, b_1); 176 | c_2 = tps_divide(a_2, b_2); 177 | c_3 = tps_divide(a_3, b_3); 178 | 179 | 180 | UCUNIT_CheckIsEqual(15, c_1); 181 | UCUNIT_CheckIsEqual(5, c_2); 182 | UCUNIT_CheckIsEqual(15, c_3); 183 | 184 | 185 | UCUNIT_TestcaseEnd(); 186 | } 187 | 188 | 189 | static void Test_tps_07(void){ 190 | uint8_t a_1 = 10, b_1 = 1, c_1; 191 | uint8_t a_2 = 15, b_2 = 0, c_2; 192 | uint8_t a_3 = 15, b_3 = 4, c_3; 193 | 194 | UCUNIT_TestcaseBegin("TPS: tps_shiftLeft"); 195 | 196 | c_1 = tps_shiftLeft(a_1, b_1); 197 | c_2 = tps_shiftLeft(a_2, b_2); 198 | c_3 = tps_shiftLeft(a_3, b_3); 199 | 200 | UCUNIT_CheckIsEqual(4, c_1); 201 | UCUNIT_CheckIsEqual(15, c_2); 202 | UCUNIT_CheckIsEqual(0, c_3); 203 | 204 | 205 | UCUNIT_TestcaseEnd(); 206 | } 207 | 208 | static void Test_tps_08(void){ 209 | uint8_t a_1 = 10, b_1 = 1, c_1; 210 | uint8_t a_2 = 15, b_2 = 0, c_2; 211 | uint8_t a_3 = 15, b_3 = 4, c_3; 212 | 213 | UCUNIT_TestcaseBegin("TPS: tps_shiftRight"); 214 | 215 | c_1 = tps_shiftRight(a_1, b_1); 216 | c_2 = tps_shiftRight(a_2, b_2); 217 | c_3 = tps_shiftRight(a_3, b_3); 218 | 219 | UCUNIT_CheckIsEqual(5, c_1); 220 | UCUNIT_CheckIsEqual(15, c_2); 221 | UCUNIT_CheckIsEqual(0, c_3); 222 | 223 | 224 | UCUNIT_TestcaseEnd(); 225 | } 226 | 227 | static void Test_tps_09(void){ 228 | uint8_t a_1 = 3, b_1 = 3, c_1; 229 | uint8_t a_2 = 0, b_2 = 0, c_2; 230 | uint8_t a_3 = 4, b_3 = 0, c_3; 231 | uint8_t a_4 = 0, b_4 = 15, c_4; 232 | 233 | UCUNIT_TestcaseBegin("TPS: tps_mod"); 234 | 235 | c_1 = tps_shiftRight(a_1, b_1); 236 | c_2 = tps_shiftRight(a_2, b_2); 237 | c_3 = tps_shiftRight(a_3, b_3); 238 | c_4 = tps_shiftRight(a_4, b_4); 239 | 240 | UCUNIT_CheckIsEqual(0, c_1); 241 | UCUNIT_CheckIsEqual(0, c_2); 242 | UCUNIT_CheckIsEqual(4, c_3); 243 | UCUNIT_CheckIsEqual(0, c_4); 244 | 245 | 246 | UCUNIT_TestcaseEnd(); 247 | } 248 | 249 | 250 | void Testsuite_RunTests(void) 251 | { 252 | //Test_eeprom_01(); 253 | Test_tps_01(); 254 | Test_tps_02(); 255 | Test_tps_03(); 256 | Test_tps_04(); 257 | Test_tps_05(); 258 | Test_tps_06(); 259 | Test_tps_07(); 260 | Test_tps_08(); 261 | Test_tps_09(); 262 | 263 | UCUNIT_WriteSummary(); 264 | } 265 | 266 | int main(void) 267 | { 268 | UCUNIT_Init(); 269 | 270 | UCUNIT_WriteString("\n**************************************"); 271 | UCUNIT_WriteString("\nName: "); 272 | UCUNIT_WriteString("TPS Project UNIT Test"); 273 | UCUNIT_WriteString("\nCompiled: "); 274 | UCUNIT_WriteString(__DATE__); 275 | UCUNIT_WriteString("\nTime: "); 276 | UCUNIT_WriteString(__TIME__); 277 | UCUNIT_WriteString("\nVersion: "); 278 | UCUNIT_WriteString(UCUNIT_VERSION); 279 | UCUNIT_WriteString("\n**************************************"); 280 | Testsuite_RunTests(); 281 | UCUNIT_Shutdown(); 282 | 283 | return 0; 284 | } 285 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/Release/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | SHELL := cmd.exe 6 | RM := rm -rf 7 | 8 | USER_OBJS := 9 | 10 | LIBS := 11 | PROJ := 12 | 13 | O_SRCS := 14 | C_SRCS := 15 | S_SRCS := 16 | S_UPPER_SRCS := 17 | OBJ_SRCS := 18 | ASM_SRCS := 19 | PREPROCESSING_SRCS := 20 | OBJS := 21 | OBJS_AS_ARGS := 22 | C_DEPS := 23 | C_DEPS_AS_ARGS := 24 | EXECUTABLES := 25 | OUTPUT_FILE_PATH := 26 | OUTPUT_FILE_PATH_AS_ARGS := 27 | AVR_APP_PATH :=$$$AVR_APP_PATH$$$ 28 | QUOTE := " 29 | ADDITIONAL_DEPENDENCIES:= 30 | OUTPUT_FILE_DEP:= 31 | LIB_DEP:= 32 | LINKER_SCRIPT_DEP:= 33 | 34 | # Every subdirectory with source files must be described here 35 | SUBDIRS := 36 | 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | C_SRCS += \ 40 | ../../firmware/common/randomSeed.c \ 41 | ../../firmware/core/main.c \ 42 | ../../firmware/core/tps.c \ 43 | ../../firmware/memory/eeprom.c \ 44 | ../../firmware/peripheral/adc.c \ 45 | ../../firmware/peripheral/gpio.c \ 46 | ../../firmware/peripheral/timer.c 47 | 48 | 49 | PREPROCESSING_SRCS += 50 | 51 | 52 | ASM_SRCS += 53 | 54 | 55 | OBJS += \ 56 | randomSeed.o \ 57 | main.o \ 58 | tps.o \ 59 | eeprom.o \ 60 | adc.o \ 61 | gpio.o \ 62 | timer.o 63 | 64 | OBJS_AS_ARGS += \ 65 | randomSeed.o \ 66 | main.o \ 67 | tps.o \ 68 | eeprom.o \ 69 | adc.o \ 70 | gpio.o \ 71 | timer.o 72 | 73 | C_DEPS += \ 74 | randomSeed.d \ 75 | main.d \ 76 | tps.d \ 77 | eeprom.d \ 78 | adc.d \ 79 | gpio.d \ 80 | timer.d 81 | 82 | C_DEPS_AS_ARGS += \ 83 | randomSeed.d \ 84 | main.d \ 85 | tps.d \ 86 | eeprom.d \ 87 | adc.d \ 88 | gpio.d \ 89 | timer.d 90 | 91 | OUTPUT_FILE_PATH +=AtmelStudioProject-BIT4.elf 92 | 93 | OUTPUT_FILE_PATH_AS_ARGS +=AtmelStudioProject-BIT4.elf 94 | 95 | ADDITIONAL_DEPENDENCIES:= 96 | 97 | OUTPUT_FILE_DEP:= ./makedep.mk 98 | 99 | LIB_DEP+= 100 | 101 | LINKER_SCRIPT_DEP+= 102 | 103 | 104 | # AVR32/GNU C Compiler 105 | ./randomSeed.o: ../../firmware/common/randomSeed.c 106 | @echo Building file: $< 107 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 108 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 109 | @echo Finished building: $< 110 | 111 | 112 | ./main.o: ../../firmware/core/main.c 113 | @echo Building file: $< 114 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 115 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 116 | @echo Finished building: $< 117 | 118 | 119 | ./tps.o: ../../firmware/core/tps.c 120 | @echo Building file: $< 121 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 122 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 123 | @echo Finished building: $< 124 | 125 | 126 | ./eeprom.o: ../../firmware/memory/eeprom.c 127 | @echo Building file: $< 128 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 129 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 130 | @echo Finished building: $< 131 | 132 | 133 | ./adc.o: ../../firmware/peripheral/adc.c 134 | @echo Building file: $< 135 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 136 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 137 | @echo Finished building: $< 138 | 139 | 140 | ./gpio.o: ../../firmware/peripheral/gpio.c 141 | @echo Building file: $< 142 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 143 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 144 | @echo Finished building: $< 145 | 146 | 147 | ./timer.o: ../../firmware/peripheral/timer.c 148 | @echo Building file: $< 149 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 150 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DNDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 151 | @echo Finished building: $< 152 | 153 | 154 | 155 | 156 | 157 | # AVR32/GNU Preprocessing Assembler 158 | 159 | 160 | 161 | # AVR32/GNU Assembler 162 | 163 | 164 | 165 | 166 | ifneq ($(MAKECMDGOALS),clean) 167 | ifneq ($(strip $(C_DEPS)),) 168 | -include $(C_DEPS) 169 | endif 170 | endif 171 | 172 | # Add inputs and outputs from these tool invocations to the build variables 173 | 174 | # All Target 175 | all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES) 176 | 177 | $(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP) 178 | @echo Building target: $@ 179 | @echo Invoking: AVR/GNU Linker : 5.4.0 180 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="AtmelStudioProject-BIT4.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" 181 | @echo Finished building target: $@ 182 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.hex" 183 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.eep" || exit 0 184 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "AtmelStudioProject-BIT4.elf" > "AtmelStudioProject-BIT4.lss" 185 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.srec" 186 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "AtmelStudioProject-BIT4.elf" 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | # Other Targets 195 | clean: 196 | -$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES) 197 | -$(RM) $(C_DEPS_AS_ARGS) 198 | rm -rf "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.a" "AtmelStudioProject-BIT4.hex" "AtmelStudioProject-BIT4.lss" "AtmelStudioProject-BIT4.eep" "AtmelStudioProject-BIT4.map" "AtmelStudioProject-BIT4.srec" "AtmelStudioProject-BIT4.usersignatures" 199 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/ExtendedDebug/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit! 3 | ################################################################################ 4 | 5 | SHELL := cmd.exe 6 | RM := rm -rf 7 | 8 | USER_OBJS := 9 | 10 | LIBS := 11 | PROJ := 12 | 13 | O_SRCS := 14 | C_SRCS := 15 | S_SRCS := 16 | S_UPPER_SRCS := 17 | OBJ_SRCS := 18 | ASM_SRCS := 19 | PREPROCESSING_SRCS := 20 | OBJS := 21 | OBJS_AS_ARGS := 22 | C_DEPS := 23 | C_DEPS_AS_ARGS := 24 | EXECUTABLES := 25 | OUTPUT_FILE_PATH := 26 | OUTPUT_FILE_PATH_AS_ARGS := 27 | AVR_APP_PATH :=$$$AVR_APP_PATH$$$ 28 | QUOTE := " 29 | ADDITIONAL_DEPENDENCIES:= 30 | OUTPUT_FILE_DEP:= 31 | LIB_DEP:= 32 | LINKER_SCRIPT_DEP:= 33 | 34 | # Every subdirectory with source files must be described here 35 | SUBDIRS := 36 | 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | C_SRCS += \ 40 | ../../firmware/common/randomSeed.c \ 41 | ../../firmware/core/main.c \ 42 | ../../firmware/core/tps.c \ 43 | ../../firmware/memory/eeprom.c \ 44 | ../../firmware/peripheral/adc.c \ 45 | ../../firmware/peripheral/gpio.c \ 46 | ../../firmware/peripheral/timer.c 47 | 48 | 49 | PREPROCESSING_SRCS += 50 | 51 | 52 | ASM_SRCS += 53 | 54 | 55 | OBJS += \ 56 | randomSeed.o \ 57 | main.o \ 58 | tps.o \ 59 | eeprom.o \ 60 | adc.o \ 61 | gpio.o \ 62 | timer.o 63 | 64 | OBJS_AS_ARGS += \ 65 | randomSeed.o \ 66 | main.o \ 67 | tps.o \ 68 | eeprom.o \ 69 | adc.o \ 70 | gpio.o \ 71 | timer.o 72 | 73 | C_DEPS += \ 74 | randomSeed.d \ 75 | main.d \ 76 | tps.d \ 77 | eeprom.d \ 78 | adc.d \ 79 | gpio.d \ 80 | timer.d 81 | 82 | C_DEPS_AS_ARGS += \ 83 | randomSeed.d \ 84 | main.d \ 85 | tps.d \ 86 | eeprom.d \ 87 | adc.d \ 88 | gpio.d \ 89 | timer.d 90 | 91 | OUTPUT_FILE_PATH +=AtmelStudioProject-BIT4.elf 92 | 93 | OUTPUT_FILE_PATH_AS_ARGS +=AtmelStudioProject-BIT4.elf 94 | 95 | ADDITIONAL_DEPENDENCIES:= 96 | 97 | OUTPUT_FILE_DEP:= ./makedep.mk 98 | 99 | LIB_DEP+= 100 | 101 | LINKER_SCRIPT_DEP+= 102 | 103 | 104 | # AVR32/GNU C Compiler 105 | ./randomSeed.o: ../../firmware/common/randomSeed.c 106 | @echo Building file: $< 107 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 108 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 109 | @echo Finished building: $< 110 | 111 | 112 | ./main.o: ../../firmware/core/main.c 113 | @echo Building file: $< 114 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 115 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 116 | @echo Finished building: $< 117 | 118 | 119 | ./tps.o: ../../firmware/core/tps.c 120 | @echo Building file: $< 121 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 122 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 123 | @echo Finished building: $< 124 | 125 | 126 | ./eeprom.o: ../../firmware/memory/eeprom.c 127 | @echo Building file: $< 128 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 129 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 130 | @echo Finished building: $< 131 | 132 | 133 | ./adc.o: ../../firmware/peripheral/adc.c 134 | @echo Building file: $< 135 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 136 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 137 | @echo Finished building: $< 138 | 139 | 140 | ./gpio.o: ../../firmware/peripheral/gpio.c 141 | @echo Building file: $< 142 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 143 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 144 | @echo Finished building: $< 145 | 146 | 147 | ./timer.o: ../../firmware/peripheral/timer.c 148 | @echo Building file: $< 149 | @echo Invoking: AVR/GNU C Compiler : 5.4.0 150 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -DEXTENDED_DEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"../../firmware" -Og -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<" 151 | @echo Finished building: $< 152 | 153 | 154 | 155 | 156 | 157 | # AVR32/GNU Preprocessing Assembler 158 | 159 | 160 | 161 | # AVR32/GNU Assembler 162 | 163 | 164 | 165 | 166 | ifneq ($(MAKECMDGOALS),clean) 167 | ifneq ($(strip $(C_DEPS)),) 168 | -include $(C_DEPS) 169 | endif 170 | endif 171 | 172 | # Add inputs and outputs from these tool invocations to the build variables 173 | 174 | # All Target 175 | all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES) 176 | 177 | $(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP) 178 | @echo Building target: $@ 179 | @echo Invoking: AVR/GNU Linker : 5.4.0 180 | $(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="AtmelStudioProject-BIT4.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" 181 | @echo Finished building target: $@ 182 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.hex" 183 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.eep" || exit 0 184 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "AtmelStudioProject-BIT4.elf" > "AtmelStudioProject-BIT4.lss" 185 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.srec" 186 | "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "AtmelStudioProject-BIT4.elf" 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | # Other Targets 195 | clean: 196 | -$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES) 197 | -$(RM) $(C_DEPS_AS_ARGS) 198 | rm -rf "AtmelStudioProject-BIT4.elf" "AtmelStudioProject-BIT4.a" "AtmelStudioProject-BIT4.hex" "AtmelStudioProject-BIT4.lss" "AtmelStudioProject-BIT4.eep" "AtmelStudioProject-BIT4.map" "AtmelStudioProject-BIT4.srec" "AtmelStudioProject-BIT4.usersignatures" 199 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/AtmelStudioProject-BIT4.cproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.0 5 | 7.0 6 | com.Atmel.AVRGCC8.C 7 | dce6c7e3-ee26-4d79-826b-08594b9ad897 8 | ATmega4809 9 | none 10 | Executable 11 | C 12 | $(MSBuildProjectName) 13 | .elf 14 | $(MSBuildProjectDirectory)\$(Configuration) 15 | AtmelStudioProject-BIT4 16 | AtmelStudioProject-BIT4 17 | AtmelStudioProject-BIT4 18 | Native 19 | true 20 | false 21 | true 22 | true 23 | 0x20000000 24 | 25 | true 26 | exception_table 27 | 2 28 | 0 29 | 0 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | com.atmel.avrdbg.tool.nedbg 44 | ATML3094051800000926 45 | 0x1E9651 46 | UPDI 47 | 48 | 49 | 50 | 750000 51 | 52 | UPDI 53 | 54 | com.atmel.avrdbg.tool.nedbg 55 | ATML3094051800000926 56 | nEDBG 57 | 58 | 750000 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | com.atmel.avrdbg.tool.simulator 67 | 68 | 69 | Simulator 70 | 71 | 72 | 73 | 74 | 75 | -mmcu=atmega4809 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" 76 | True 77 | True 78 | True 79 | True 80 | False 81 | True 82 | True 83 | 84 | 85 | NDEBUG 86 | 87 | 88 | 89 | 90 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 91 | 92 | 93 | Optimize for size (-Os) 94 | True 95 | True 96 | True 97 | 98 | 99 | libm 100 | 101 | 102 | 103 | 104 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -mmcu=atmega4809 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" 114 | True 115 | True 116 | True 117 | True 118 | False 119 | True 120 | True 121 | 122 | 123 | DEBUG 124 | BOARD_V11B 125 | 126 | 127 | 128 | 129 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 130 | ../../firmware 131 | 132 | 133 | Optimize debugging experience (-Og) 134 | True 135 | True 136 | Default (-g2) 137 | True 138 | 139 | 140 | libm 141 | 142 | 143 | 144 | 145 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 146 | 147 | 148 | Default (-Wa,-g) 149 | 150 | 151 | 152 | 153 | 154 | 155 | -mmcu=atmega4809 -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" 156 | True 157 | True 158 | True 159 | True 160 | False 161 | True 162 | True 163 | 164 | 165 | DEBUG 166 | EXTENDED_DEBUG 167 | 168 | 169 | 170 | 171 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 172 | ../../firmware 173 | 174 | 175 | Optimize debugging experience (-Og) 176 | True 177 | True 178 | Default (-g2) 179 | True 180 | 181 | 182 | libm 183 | 184 | 185 | 186 | 187 | %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include 188 | 189 | 190 | Default (-Wa,-g) 191 | 192 | 193 | bin\ExtendedDebug\ 194 | 195 | 196 | 197 | compile 198 | randomSeed.c 199 | 200 | 201 | compile 202 | randomSeed.h 203 | 204 | 205 | compile 206 | main.c 207 | 208 | 209 | compile 210 | tps.c 211 | 212 | 213 | compile 214 | tps.h 215 | 216 | 217 | compile 218 | eeprom.c 219 | 220 | 221 | compile 222 | eeprom.h 223 | 224 | 225 | compile 226 | adc.c 227 | 228 | 229 | compile 230 | adc.h 231 | 232 | 233 | compile 234 | gpio.c 235 | 236 | 237 | compile 238 | gpio.h 239 | 240 | 241 | compile 242 | timer.c 243 | 244 | 245 | compile 246 | timer.h 247 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /AtmelStudioProject-BIT4/ExtendedDebug/AtmelStudioProject-BIT4.srec: -------------------------------------------------------------------------------- 1 | S01F000041746D656C53747564696F50726F6A6563742D424954342E7372656383 2 | S11300000C948D000C94AA000C94AA000C94AA00E1 3 | S11300100C94AA000C94AA000C94AA000C94AA00B4 4 | S11300200C94AA000C94AA000C94AA000C94AA00A4 5 | S11300300C94AA000C94AA000C94AA000C94AA0094 6 | S11300400C94AA000C94AA000C94AA000C94AA0084 7 | S11300500C94AA000C94AA000C94AA000C94AA0074 8 | S11300600C9454060C94AA000C94AA000C94AA00B4 9 | S11300700C94AA000C94AA000C94AA000C94AA0054 10 | S11300800C94AA000C94AA000C94AA000C94AA0044 11 | S11300900C94AA000C94AA000C94AA000C94AA0034 12 | S11300A09101A201B301C301D401E2017402F1017F 13 | S11300B002021302240235024502550265028C0233 14 | S11300C09702A302AC02B502BE02C702CF02D70256 15 | S11300D0E002E702F002F8020003090329032E03F9 16 | S11300E0330338033F0347034F0357038F038F033F 17 | S11300F05F036C0373037A038403C603CF03D4033F 18 | S1130100D903DE03E503ED03F503FD0305040C0445 19 | S113011013041A0422042A04320411241FBECFEF4C 20 | S1130120CDBFDFE3DEBF18E2A0E0B8E2EAE2F2E12D 21 | S113013002C005900D92AE34B107D9F729E2AEE4BE 22 | S1130140B8E201C01D92AA36B207E1F70E94760513 23 | S11301500C94F3080C940000EF92FF920F931F93FA 24 | S1130160CF93DF93E12CF12C00E010E019C00E9442 25 | S1130170F606817099270C2E02C0880F991F0A94E5 26 | S1130180E2F7082B192B219602C0C0E0D0E0C03161 27 | S1130190D1056CF30115110539F48FEFE81AF80A4B 28 | S11301A025E0E216F1048CF3C801DF91CF911F9191 29 | S11301B00F91FF90EF9008958091692990E020912C 30 | S11301C06528309166282817390738F0281B390B21 31 | S11301D0209365283093662808951092652810921C 32 | S11301E06628089580916929809362288091652802 33 | S11301F090916628019680936528909366280895C7 34 | S1130200809169298093642880916528909166285B 35 | S113021001968093652890936628089580916428B8 36 | S113022020E1829FC001112420916929822B8093AF 37 | S113023065289093662808958091602818168CF498 38 | S11302408150809360288091642820E1829FC001BE 39 | S1130250112420916929822B809365289093662824 40 | S11302600895809165289091662801968093652869 41 | S113027090936628089580915F2818168CF4815015 42 | S113028080935F288091642820E1829FC00111241B 43 | S113029020916929822B809365289093662808957C 44 | S11302A080916528909166280196809365289093A3 45 | S11302B06628089580916528809363288091642836 46 | S11302C020E1829FC001112420916929822B80930F 47 | S11302D065289093662808958091632890E001969C 48 | S11302E08093652890936628089580916929809366 49 | S11302F04E28809165289091662801968093652800 50 | S1130300909366280895E09169298E2F90E0FC016E 51 | S11303103197EF30F10508F0E7C0E05BFF4F0C9434 52 | S11303201208909162288091612889170CF0DCC032 53 | S11303308091652890916628019680936528909312 54 | S11303406628D2C0909162288091612898170CF099 55 | S1130350CBC080916528909166280196809365288A 56 | S113036090936628C1C09091622880916128981367 57 | S1130370BBC080916528909166280196809365287A 58 | S113038090936628B1C09091622880916128981753 59 | S113039009F4AAC0809165289091662801968093FB 60 | S11303A0652890936628A0C08091622881119CC022 61 | S11303B08091652890916628019680936528909392 62 | S11303C0662892C080916228882309F48DC08091A8 63 | S11303D065289091662801968093652890936628F5 64 | S11303E083C060E084E298E20E94CC0781117CC063 65 | S11303F08091652890916628019680936528909352 66 | S1130400662872C061E084E298E20E94CC07811100 67 | S11304106BC0809165289091662801968093652829 68 | S11304209093662861C062E084E298E20E94CC075F 69 | S113043081115AC080916528909166280196809315 70 | S113044065289093662850C063E084E298E20E9495 71 | S1130450CC07811149C08091652890916628019646 72 | S113046080936528909366283FC08FE398E20E94AA 73 | S1130470D907811139C08091652890916628019629 74 | S113048080936528909366282FC088E398E20E94A1 75 | S1130490D907811129C08091652890916628019619 76 | S11304A080936528909366281FC08FE398E20E948A 77 | S11304B0D9078823C9F08091652890916628019610 78 | S11304C080936528909366280FC088E398E20E9481 79 | S11304D0D907882349F08091652890916628019670 80 | S11304E0809365289093662880916528909166286A 81 | S11304F0019680936528909366280895E091692970 82 | S11305008E2F90E0FC013197EF30F10508F089C09F 83 | S1130510E15AFF4F0C941208809162288F3024F422 84 | S11305208F5F809362287DC0109262287AC0809188 85 | S11305306228181624F481508093622872C08FE0D8 86 | S1130540809362286EC060916128809162280E9425 87 | S113055098068093622865C0609161288091622822 88 | S11305600E949F06809362285CC0609161288091FC 89 | S113057062280E94A8068093622853C06091612873 90 | S1130580809162280E94B206809362284AC09091AA 91 | S113059062288091612889238093622842C09091C7 92 | S11305A0622880916128892B809362283AC09091B7 93 | S11305B062288091612889278F708093622831C0D6 94 | S11305C08091622880958F70809362282AC0609100 95 | S11305D06128809162280E94B7068093622821C016 96 | S11305E061E0809162280E94BD068093622819C050 97 | S11305F061E0809162280E94C7068093622811C03E 98 | S113060060916128809162280E94BD0680936228CF 99 | S113061008C060916128809162280E94C706809377 100 | S113062062288091652890916628019680936528B8 101 | S1130630909366280895E09169298E2F90E0FC013B 102 | S11306403197EF30F10508F06AC0E259FF4F0C947E 103 | S11306501208809161288093622861C0809160288B 104 | S1130660809362285CC080915F288093622857C081 105 | S113067084E298E20E94B5078093622850C060E04B 106 | S113068084E298E20E94CC078093622848C061E02B 107 | S113069084E298E20E94CC078093622840C062E022 108 | S11306A084E298E20E94CC078093622838C063E019 109 | S11306B084E298E20E94CC078093622830C00E94B2 110 | S11306C064088F709078992324F40197806F9F6F4A 111 | S11306D001968093622823C082E398E20E949E07D9 112 | S11306E0809362281CC08CE298E20E949E0780934B 113 | S11306F0622815C0E0914E28F0E0E15BF74D80815F 114 | S11307008F70809362280BC0E09161280E2E000C3C 115 | S1130710FF0BE15BF74D80818F708093622880919D 116 | S113072065289091662801968093652890936628A1 117 | S113073008956091692982E398E20E944F078091AD 118 | S11307406528909166280196809365289093662881 119 | S11307500895609169298CE298E20E944F07809184 120 | S11307606528909166280196809365289093662861 121 | S11307700895E09169298E2F90E08031910508F069 122 | S113078078C0FC01E358FF4F0C941208E0914E2806 123 | S1130790F0E0E15BF74D8091622880836AC080912C 124 | S11307A062288093612865C08091622880936028C4 125 | S11307B060C08091622880935F285BC0609162284A 126 | S11307C082E398E20E944F0754C040E0609162289F 127 | S11307D082E398E20E9476074CC041E0609162286F 128 | S11307E082E398E20E94760744C042E06091622866 129 | S11307F082E398E20E9476073CC043E0609162285D 130 | S113080082E398E20E94760734C06091622880E80F 131 | S11308109AE00E94F3072DC06091622880E99AE073 132 | S11308200E94F30726C0609162288CE298E20E943D 133 | S11308304F071FC040E0609162288CE298E20E945A 134 | S1130840760717C041E0609162288CE298E20E942A 135 | S113085076070FC042E0609162288CE298E20E9421 136 | S1130860760707C043E0609162288CE298E20E9418 137 | S11308707607809165289091662801968093652873 138 | S113088090936628089581E090E007C0E1EEF4E0DB 139 | S11308903197F1F700C000000196E0916929F0E07A 140 | S11308A0EE0FFF1FE651FE4A2081318128173907D8 141 | S11308B068F7809165289091662801968093652851 142 | S11308C0909366280895CF93DF9380916528909143 143 | S11308D066280E94D4068093682849E659E267E6B0 144 | S11308E078E20E94860660E082E398E20E944F0765 145 | S11308F060E08CE298E20E944F072FE986E891E0DD 146 | S1130900215080409040E1F700C0000060916528CC 147 | S113091082E398E20E944F076091652870916628EF 148 | S1130920729562956F7067277F7067278CE298E2F3 149 | S11309300E944F072FED83E994E0215080409040BE 150 | S1130940E1F700C0000060E082E398E20E944F07F4 151 | S113095060E08CE298E20E944F072FE986E891E07C 152 | S1130960215080409040E1F700C00000609167286A 153 | S11309708CE298E20E944F0788E398E20E94D9072C 154 | S11309808823D1F383E294EF0197F1F700C00000CC 155 | S1130990C0E029C08FE398E20E94D907811123C0E7 156 | S11309A0C11104C010926728C1E005C08091672876 157 | S11309B08F5F80936728609167288CE298E20E9499 158 | S11309C04F0783E294EF0197F1F700C000008FE333 159 | S11309D098E20E94D9078823D1F383E294EF019728 160 | S11309E0F1F700C0000088E398E20E94D907811162 161 | S11309F0D1CF60E08CE298E20E944F0760916929B0 162 | S1130A0082E398E20E944F0783E294EF0197F1F7A3 163 | S1130A1000C0000088E398E20E94D9078823D1F33C 164 | S1130A2083E294EF0197F1F700C00000D0E029C001 165 | S1130A308FE398E20E94D907811123C0D11104C029 166 | S1130A4010926929D1E005C0809169298F5F809354 167 | S1130A5069296091692982E398E20E944F0783E241 168 | S1130A6094EF0197F1F700C000008FE398E20E9431 169 | S1130A70D9078823D1F383E294EF0197F1F700C0FB 170 | S1130A80000088E398E20E94D9078111D1CF60E089 171 | S1130A9082E398E20E944F07C11102C0DD2319F1DD 172 | S1130AA0409169296091672888E698E20E948F0640 173 | S1130AB06091682880916528909166280E94D106EB 174 | S1130AC060E082E398E20E944F0760E08CE298E2E3 175 | S1130AD00E944F079FE52EEA8AE091502040804013 176 | S1130AE0E1F700C00000DF91CF910895FF920F93CA 177 | S1130AF01F93CF93DF9300D000D0CDB7DEB788ED3E 178 | S1130B0084BFE0E6F0E0108284BF83E0818300E4E8 179 | S1130B1014E082E0F80181838583E0E0F4E081E081 180 | S1130B208183868384E0F801818386E498E20E94CD 181 | S1130B303A07E0E1F1E080818160808388E182838B 182 | S1130B40F80180898160808B86E498E20E94D9074D 183 | S1130B50882321F084E08093460403C084E08093DA 184 | S1130B604504789482E398E20E9404078CE298E2B8 185 | S1130B700E9404078FE398E20E943A0788E398E210 186 | S1130B800E943A0784E298E20E94170780E89AE0FC 187 | S1130B900E94EB0780E99AE00E94EB070E94D706C7 188 | S1130BA00E94AC000E9469080E94EB0688E398E268 189 | S1130BB00E94D907811146C000E010E021C08FE0F7 190 | S1130BC089831A828B831C82E1E0F0E0EC0FFD1F25 191 | S1130BD0E00FF11FF0806F2D82E398E20E944F072F 192 | S1130BE06F2D8CE298E20E944F07FFEE29E482E029 193 | S1130BF0F15020408040E1F700C000000F5F1F4F1C 194 | S1130C0004301105E4F20BC00E946304809165284E 195 | S1130C109091662801968093652890936628809128 196 | S1130C206528909166288F3F910571F368F331C070 197 | S1130C30C8010E94D406F801E759F74D80830F5F7D 198 | S1130C401F4F02C000E010E00F3F110589F384F349 199 | S1130C5018C021E020930704FC01E759F74D49E649 200 | S1130C6059E267E678E280810E948606E09167286F 201 | S1130C70F0E0EE0FFF1FEC5FF74D0190F081E02DE7 202 | S1130C80099580916528909166288F3F910509F315 203 | S1130C9000F380E090E02496CDBFDEBFDF91CF91DA 204 | S1130CA01F910F91FF9008951F920F920FB60F920C 205 | S1130CB011242F933F934F935F936F937F938F935D 206 | S1130CC09F93AF93BF93EF93FF9386E498E20E94C0 207 | S1130CD0D907882321F084E08093460403C084E08C 208 | S1130CE08093450481E080934904FF91EF91BF9183 209 | S1130CF0AF919F918F917F916F915F914F913F91B0 210 | S1130D002F910F900FBE0F901F901895982F9295CA 211 | S1130D109F70FB0190838F70FA018083089520E116 212 | S1130D20629FB00111244F70642BFC01608308950D 213 | S1130D308F706F70860F803108F0805108958F7026 214 | S1130D406F70982F961B892F12F480E1890F0895F4 215 | S1130D508F706F70869F802D112401C08051803167 216 | S1130D60E8F708958F706F700E94060808958F70D9 217 | S1130D706F700E940608892F08958F706F7090E03D 218 | S1130D8002C0880F991F6A95E2F78F7008958F70DB 219 | S1130D906F7090E002C0959587956A95E2F78F7021 220 | S1130DA008950E947C0808950E9474080895E0EA5A 221 | S1130DB0F0E0808180618083818182608183E0E0D2 222 | S1130DC0F6E080E482838EE1868380E28383158269 223 | S1130DD081E080830895E0EAF0E081818D7F818362 224 | S1130DE0E0E0F6E080818E7F8083089581E0809347 225 | S1130DF0080680910B0680FFFCCFE0E0F6E081E07E 226 | S1130E008387808991890895DC011296ED91FC9184 227 | S1130E10139740812FE030E0C90115960C9002C071 228 | S1130E20880F991F0A94E2F7842B80830895DC01CC 229 | S1130E301296ED91FC91139720818FE090E0179624 230 | S1130E400C90179702C0880F991F0A94E2F78095B7 231 | S1130E508223808320E030E009C0ED91FC9111975A 232 | S1130E60E20FF31F98E090832F5F3F4F243031054A 233 | S1130E70A4F30895FC01A281B3818C9121E030E0B8 234 | S1130E80068002C0220F331F0A94E2F7209528231C 235 | S1130E902C930190F081E02D88E080830895DC019B 236 | S1130EA014968C911497813029F4E62FF0E0E65FD4 237 | S1130EB0FD4A6081ED91FC911197208115963C913A 238 | S1130EC08FE090E0032E02C0880F991F0A94E2F786 239 | S1130ED070E002C0660F771F3A95E2F7962F9823C9 240 | S1130EE0922B8095682B692360830895DC01149606 241 | S1130EF08C911497813019F483E0841B482FED9171 242 | S1130F00FC911197208115968C9150E0480F511D4A 243 | S1130F1081E090E0042E02C0880F991F0A94E2F742 244 | S1130F2070E002C0660F771F4A95E2F7962F982368 245 | S1130F30922B8095682B692360830895FC01A0811E 246 | S1130F40B1812C9130E0058002C0359527950A9433 247 | S1130F50E2F72F708481813031F4E22FF0E0E65F14 248 | S1130F60FD4A80810895822F0895FC01A481B581F2 249 | S1130F702C9130E0078002C0359527950A94E2F75A 250 | S1130F802F708681813031F4E22FF0E0E65FFD4A74 251 | S1130F9080810895822F0895CF93C62F0E94B507AC 252 | S1130FA090E002C095958795CA95E2F78170CF913C 253 | S1130FB00895DC011496ED91FC911597208130E0A1 254 | S1130FC016960C9002C0359527950A94E2F781E0B5 255 | S1130FD020FF80E00895FC0182E0808387E1818323 256 | S1130FE08FEF84870895FC0180818E7F80838FEF4B 257 | S1130FF084876F70A62FB0E0A65EBD4A8C9185876A 258 | S1131000128613868081816080830895991B79E01C 259 | S113101004C0991F961708F0961B881F7A95C9F784 260 | S113102080950895EE0FFF1F0590F491E02D09942B 261 | S11310308F929F92AF92BF92CF92DF92EF92FF92E4 262 | S1131040CF93DF93EC01688179818A819B8161155B 263 | S113105071058105910521F464E279ED8BE597E052 264 | S11310602DE133EF41E050E00E94900849015A011C 265 | S11310709B01AC01A7EAB1E40E94AF086B017C01BB 266 | S1131080ACEEB4EFA50194010E94BD08DC01CB01D4 267 | S11310908C0D9D1DAE1DBF1DB7FF03C00197A10997 268 | S11310A0B04888839983AA83BB839F77DF91CF91CC 269 | S11310B0FF90EF90DF90CF90BF90AF909F908F9074 270 | S11310C008950E941808089580E098E20E94180884 271 | S11310D00895A0E0B0E08093002890930128A093A5 272 | S11310E00228B0930328089503D080819927089596 273 | S11310F0FC01E050FC4E0895262FAF93BF93E0E02F 274 | S1131100F0E1328131FDFDCFDC01A050BC4E2C93C7 275 | S11311102DE924BF23E020830196BF91AF91089568 276 | S1131120052E97FB1EF400940E94A70857FD07D0D4 277 | S11311300E94C20807FC03D04EF40C94A7085095F3 278 | S11311404095309521953F4F4F4F5F4F08959095AF 279 | S11311508095709561957F4F8F4F9F4F08950E94A2 280 | S1131160E408A59F900DB49F900DA49F800D911D40 281 | S113117011240895B7FF0C94AF080E94AF08821B96 282 | S1131180930B0895A1E21A2EAA1BBB1BFD010DC0EF 283 | S1131190AA1FBB1FEE1FFF1FA217B307E407F50723 284 | S11311A020F0A21BB30BE40BF50B661F771F881FFF 285 | S11311B0991F1A9469F760957095809590959B0195 286 | S11311C0AC01BD01CF010895A29FB001B39FC0013E 287 | S11311D0A39F700D811D1124911DB29F700D811D5F 288 | S10D11E01124911D0895F894FFCF27 289 | S11311EA0100020005000A00140032006400C8006D 290 | S11311FAF401E803D00788131027204E307560EAFB 291 | S113120A0008040C020A060E0109050D030B070F58 292 | S113121A000102030406090D131B283A5479B0FF8E 293 | S113122A01000000A90399034304DC00F200B90396 294 | S113123A1B037E0200010E011C013B0183015A01BA 295 | S113124A6C0175017104600468040101240420041A 296 | S113125A00000404000400047504600468040570B2 297 | S111126A0460046804005004400448040000BA 298 | S9030000FC 299 | -------------------------------------------------------------------------------- /firmware/core/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * 4 | * Created: 09.02.2019 5 | * Author : GClown25 6 | * 7 | * 8 | * @info Make sure the correct board version is defined in the 9 | * project properties (Allowed values are: BOARD_V10 or BOARD_V11B) 10 | * 11 | */ 12 | 13 | #define F_CPU 5000000UL 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "core/tps.h" 21 | #include "memory/eeprom.h" 22 | #include "peripheral/gpio.h" 23 | #include "peripheral/timer.h" 24 | #include "peripheral/adc.h" 25 | #include "common/randomSeed.h" 26 | 27 | /* Size of the EEPROM in bytes */ 28 | #define MEMORY_SIZE 256 29 | 30 | /* IOs */ 31 | GPIO_BTN mcpStat = { &PORTC.PIN0CTRL, &PORTC.DIR, &PORTC.IN, PIN0_bp }; 32 | GPIO_BTN btn1 = { &PORTD.PIN0CTRL, &PORTD.DIR, &PORTD.IN, PIN0_bp }; 33 | GPIO_BTN btn2 = { &PORTD.PIN5CTRL, &PORTD.DIR, &PORTD.IN, PIN5_bp }; 34 | GPIO_DOUT doutA = { &PORTA.OUT, &PORTA.DIR, NORMAL, PIN4_bp }; 35 | GPIO_DOUT doutB = { &PORTB.OUT, &PORTB.DIR, NORMAL, PIN0_bp }; 36 | #ifdef BOARD_V10 37 | GPIO_DIN dinA = { &PORTD.PIN1CTRL, &PORTD.DIR, &PORTD.IN, REVERSED, PIN1_bp }; 38 | #elif BOARD_V11B 39 | 40 | GPIO_DIN dinA = { &PORTD.PIN1CTRL, &PORTD.DIR, &PORTD.IN, REVERSED, PIN1_bp, &PORTD.INTFLAGS, 41 | { &PORTE.OUT, &PORTE.DIR, NORMAL, PIN0_bp } 42 | }; 43 | #endif 44 | 45 | #define PWM1 TCB0 46 | #define PWM2 TCB1 47 | 48 | /* Global variables for BIT4 interpreter */ 49 | uint16_t progCounter = 0; 50 | uint8_t page = 0; 51 | uint8_t retVector = 0; 52 | uint8_t instruction, command, data; 53 | uint8_t buffer[MEMORY_SIZE]; 54 | 55 | int8_t varA = 0, varB = 0, varC = 0, varD = 0; 56 | 57 | uint8_t ram[16] = {0}; 58 | uint8_t ramAddr = 0; 59 | 60 | /* Lookup table for wait command */ 61 | const uint16_t waitCounterNr[] = {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 30000, 60000}; 62 | 63 | /* Function prototypes */ 64 | static void programmInstruction(); 65 | static void command0(); 66 | static void command1(); 67 | static void command2(); 68 | static void command3(); 69 | static void command4(); 70 | static void command5(); 71 | static void command6(); 72 | static void command7(); 73 | static void command8(); 74 | static void command9(); 75 | static void commandA(); 76 | static void commandB(); 77 | static void commandC(); 78 | static void commandD(); 79 | static void commandE(); 80 | static void commandF(); 81 | 82 | void ( *commandFunc[])() = { 83 | command0, 84 | command1, 85 | command2, 86 | command3, 87 | command4, 88 | command5, 89 | command6, 90 | command7, 91 | command8, 92 | command9, 93 | commandA, 94 | commandB, 95 | commandC, 96 | commandD, 97 | commandE, 98 | commandF 99 | }; 100 | 101 | 102 | int main(void){ 103 | 104 | /* Clock init */ 105 | CCP = CCP_IOREG_gc; 106 | CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_OSC20M_gc; 107 | CCP = CCP_IOREG_gc; 108 | CLKCTRL.MCLKCTRLB = CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm; 109 | 110 | /* turn on POWER incicator led */ 111 | PORTC.DIRSET = PIN1_bm; 112 | PORTC.OUTSET = PIN1_bm; 113 | 114 | #ifdef EXTENDED_DEBUG 115 | /* Init debug pin */ 116 | PORTA.DIRSET = PIN0_bm; 117 | PORTA.OUTCLR = PIN0_bm; 118 | #endif //EXTENDED_DEBUG 119 | 120 | /* Init MCP73831 charging indicator led */ 121 | PORTC.DIRSET = PIN2_bm; 122 | 123 | /* Init MCP73831 Charge status sensing */ 124 | gpio_btn_init(&mcpStat); 125 | 126 | CPUINT.CTRLA |= CPUINT_LVL0RR_bm; // Set the Round-robin Scheduling Enable bit 127 | CPUINT.LVL0PRI = PORTC_PORT_vect_num; //Set Interrupt priority 128 | PORTC.PIN0CTRL |= 0x01; //Enable interrupt on both edges (mcpStat pin) 129 | 130 | if(gpio_btn_read(&mcpStat)) 131 | PORTC.OUTCLR = PIN2_bm; 132 | else 133 | PORTC.OUTSET = PIN2_bm; 134 | 135 | sei(); //Enable interrupts 136 | 137 | /* Init peripherals */ 138 | gpio_dout_init(&doutA); 139 | gpio_dout_init(&doutB); 140 | gpio_btn_init(&btn1); 141 | gpio_btn_init(&btn2); 142 | gpio_din_init(&dinA); 143 | 144 | timerb_initPWM(&PWM1); 145 | timerb_initPWM(&PWM2); 146 | 147 | adcInit(); 148 | srand(getSeed()); //Get seed for random function (getSeed uses the ADC) 149 | adcDeInit(); 150 | 151 | 152 | //Enter program mode 153 | if(gpio_btn_read(&btn2) == 0){ 154 | 155 | //blink twice to visualize entering of prog mode 156 | for(int i = 0; i < 4; i++){ 157 | uint8_t doutVal[] = {0xf, 0x0, 0xf, 0x0}; 158 | 159 | gpio_dout_write(&doutA, doutVal[i]); 160 | gpio_dout_write(&doutB, doutVal[i]); 161 | _delay_ms(150); 162 | } 163 | 164 | while(progCounter < MEMORY_SIZE){ 165 | programmInstruction(); 166 | progCounter++; 167 | } 168 | 169 | //Enter intepretor mode 170 | }else{ 171 | 172 | //Load instructions in buffer 173 | for(int i = 0; i < MEMORY_SIZE; i++){ 174 | buffer[i] = EEPROM_read(i); 175 | } 176 | 177 | while(progCounter < MEMORY_SIZE){ 178 | 179 | #ifdef EXTENDED_DEBUG 180 | PORTA.OUTTGL = PIN0_bm; 181 | #endif //EXTENDED_DEBUG 182 | 183 | tps_splitInstruction(buffer[progCounter], &command, &data); 184 | 185 | ( *(commandFunc[command]))(); 186 | 187 | } 188 | 189 | } 190 | 191 | } 192 | 193 | 194 | //load const val to doutB port 195 | void command0(){ 196 | gpio_dout_write(&doutB, data); 197 | progCounter++; 198 | } 199 | 200 | //load const val to doutA port 201 | void command1(){ 202 | gpio_dout_write(&doutA, data); 203 | progCounter++; 204 | } 205 | 206 | //delay 207 | void command2(){ 208 | for(uint16_t i = 1; i <= waitCounterNr[data]; i++) 209 | _delay_ms(1); 210 | progCounter++; 211 | } 212 | 213 | //relative jump back 214 | void command3(){ 215 | if(progCounter >= data ) 216 | progCounter -= data; 217 | else 218 | progCounter = 0; 219 | } 220 | 221 | //load const val to A 222 | void command4(){ 223 | varA = data; 224 | progCounter++; 225 | } 226 | 227 | //load smth with the val of A 228 | void command5(){ 229 | switch(data){ 230 | case 0x0: 231 | ram[ramAddr] = varA; 232 | break; 233 | case 0x1: 234 | varB = varA; 235 | break; 236 | case 0x2: 237 | varC = varA; 238 | break; 239 | case 0x3: 240 | varD = varA; 241 | break; 242 | case 0x4: 243 | gpio_dout_write(&doutA, varA); 244 | break; 245 | case 0x5: 246 | gpio_dout_writeBit(&doutA, varA, 0); 247 | break; 248 | case 0x6: 249 | gpio_dout_writeBit(&doutA, varA, 1); 250 | break; 251 | case 0x7: 252 | gpio_dout_writeBit(&doutA, varA, 2); 253 | break; 254 | case 0x8: 255 | gpio_dout_writeBit(&doutA, varA, 3); 256 | break; 257 | case 0x9: 258 | timerb_setDC(&PWM1, varA); 259 | break; 260 | case 0xA: 261 | timerb_setDC(&PWM2, varA); 262 | break; 263 | case 0xB: 264 | gpio_dout_write(&doutB, varA); 265 | break; 266 | case 0xC: 267 | gpio_dout_writeBit(&doutB, varA, 0); 268 | break; 269 | case 0xD: 270 | gpio_dout_writeBit(&doutB, varA, 1); 271 | break; 272 | case 0xE: 273 | gpio_dout_writeBit(&doutB, varA, 2); 274 | break; 275 | case 0xF: 276 | gpio_dout_writeBit(&doutB, varA, 3); 277 | break; 278 | } 279 | progCounter++; 280 | } 281 | 282 | //load smth into A 283 | void command6(){ 284 | switch(data){ 285 | case 0x1: 286 | varA = varB; 287 | break; 288 | case 0x2: 289 | varA = varC; 290 | break; 291 | case 0x3: 292 | varA = varD; 293 | break; 294 | case 0x4: 295 | varA = gpio_din_read(&dinA); 296 | break; 297 | case 0x5: 298 | varA = gpio_din_readBit(&dinA, 0); 299 | break; 300 | case 0x6: 301 | varA = gpio_din_readBit(&dinA, 1); 302 | break; 303 | case 0x7: 304 | varA = gpio_din_readBit(&dinA, 2); 305 | break; 306 | case 0x8: 307 | varA = gpio_din_readBit(&dinA, 3); 308 | break; 309 | case 0xB: 310 | varA = rand() % 16; 311 | break; 312 | case 0xC: 313 | varA = gpio_dout_read(&doutA); 314 | break; 315 | case 0xD: 316 | varA = gpio_dout_read(&doutB); 317 | break; 318 | case 0xE: 319 | varA = ram[ramAddr] & 0xf; 320 | break; 321 | case 0xF: 322 | varA = ram[varB] & 0xf; 323 | break; 324 | } 325 | progCounter++; 326 | } 327 | 328 | //Do calculations with A (and B) 329 | void command7(){ 330 | switch(data){ 331 | case 0x1: 332 | if(varA < 15) 333 | varA++; 334 | else 335 | varA = 0; 336 | break; 337 | case 0x2: 338 | if(varA > 0) 339 | varA--; 340 | else 341 | varA = 15; 342 | break; 343 | case 0x3: 344 | varA = tps_add(varA, varB); 345 | break; 346 | case 0x4: 347 | varA = tps_subtract(varA, varB); 348 | break; 349 | case 0x5: 350 | varA = tps_multiply(varA, varB); 351 | break; 352 | case 0x6: 353 | varA = tps_divide(varA, varB); 354 | break; 355 | case 0x7: 356 | varA = (varA & varB); 357 | break; 358 | case 0x8: 359 | varA = (varA | varB); 360 | break; 361 | case 0x9: 362 | varA = (varA ^ varB) & 0xf; 363 | break; 364 | case 0xA: 365 | varA = (~varA) & 0xf; 366 | break; 367 | case 0xB: 368 | varA = tps_mod(varA, varB); 369 | break; 370 | case 0xC: 371 | varA = tps_shiftLeft(varA, 1); 372 | break; 373 | case 0xD: 374 | varA = tps_shiftRight(varA, 1); 375 | break; 376 | case 0xE: 377 | varA = tps_shiftLeft(varA, varB); 378 | break; 379 | case 0xF: 380 | varA = tps_shiftRight(varA, varB); 381 | break; 382 | } 383 | progCounter++; 384 | } 385 | 386 | //Set page for absolute jumps 387 | void command8(){ 388 | page = data; 389 | progCounter++; 390 | } 391 | 392 | //Do an absolute jump 393 | void command9(){ 394 | progCounter = (page << 4) | data; 395 | } 396 | 397 | //Do an absolute jump C times 398 | void commandA(){ 399 | if(varC > 0){ 400 | varC--; 401 | progCounter = (page << 4) | data; 402 | }else{ 403 | progCounter++; 404 | } 405 | } 406 | 407 | //Do an absolute jump D times 408 | void commandB(){ 409 | if(varD > 0){ 410 | varD--; 411 | progCounter = (page << 4) | data; 412 | }else{ 413 | progCounter++; 414 | } 415 | } 416 | 417 | //Skip if 418 | void commandC(){ 419 | switch(data){ 420 | case 0x1: 421 | if(varA > varB) 422 | progCounter++; 423 | break; 424 | case 0x2: 425 | if(varA < varB) 426 | progCounter++; 427 | break; 428 | case 0x3: 429 | if(varA == varB) 430 | progCounter++; 431 | break; 432 | case 0x4: 433 | if(varA != varB) 434 | progCounter++; 435 | break; 436 | case 0x5: 437 | if(varA == 0) 438 | progCounter++; 439 | break; 440 | case 0x6: 441 | if(varA != 0) 442 | progCounter++; 443 | break; 444 | case 0x7: 445 | break; 446 | case 0x8: 447 | if(gpio_din_readBit(&dinA, 0) == 0) 448 | progCounter++; 449 | break; 450 | case 0x9: 451 | if(gpio_din_readBit(&dinA, 1) == 0) 452 | progCounter++; 453 | break; 454 | case 0xA: 455 | if(gpio_din_readBit(&dinA, 2) == 0) 456 | progCounter++; 457 | break; 458 | case 0xB: 459 | if(gpio_din_readBit(&dinA, 3) == 0) 460 | progCounter++; 461 | break; 462 | case 0xC: 463 | if(gpio_btn_read(&btn1) == 0) 464 | progCounter++; 465 | break; 466 | case 0xD: 467 | if(gpio_btn_read(&btn2) == 0) 468 | progCounter++; 469 | break; 470 | case 0xE: 471 | if(gpio_btn_read(&btn1) == 1) 472 | progCounter++; 473 | break; 474 | case 0xF: 475 | if(gpio_btn_read(&btn2) == 1) 476 | progCounter++; 477 | break; 478 | } 479 | progCounter++; 480 | } 481 | 482 | //Call 483 | void commandD(){ 484 | retVector = progCounter; 485 | progCounter = (page << 4) | data; 486 | } 487 | 488 | //Return 489 | void commandE(){ 490 | progCounter = retVector + 1; 491 | } 492 | 493 | //Set the RAM r/w Address 494 | void commandF(){ 495 | ramAddr = data; 496 | progCounter++; 497 | } 498 | 499 | 500 | void programmInstruction(){ 501 | bool lockCommand = false, lockData = false; 502 | 503 | instruction = EEPROM_read(progCounter); 504 | tps_splitInstruction(instruction, &command, &data); 505 | 506 | //************************************************************************************************* Show adress 507 | gpio_dout_write(&doutA, 0x00); 508 | gpio_dout_write(&doutB, 0x00); 509 | _delay_ms(100); 510 | gpio_dout_write(&doutA, progCounter); //display low nibble of current address for some ms 511 | gpio_dout_write(&doutB, progCounter>>4); //display high nibble of current address for some ms 512 | _delay_ms(300); 513 | gpio_dout_write(&doutA, 0x00); 514 | gpio_dout_write(&doutB, 0x00); 515 | _delay_ms(100); 516 | 517 | //************************************************************************************************* Show and modify command 518 | gpio_dout_write(&doutB, command); //display COMMAND of current address 519 | 520 | while(gpio_btn_read(&btn2) == 0); //wait till button2 released 521 | _delay_ms(50); //Debounce 522 | 523 | while(gpio_btn_read(&btn2) == 1){ //while button2 is released 524 | 525 | if(gpio_btn_read(&btn1) == 0){ //if button1 is pressed: if it's the first time set command to 0, otherwise increment it 526 | if(lockCommand == false){ 527 | command = 0; 528 | lockCommand = true; 529 | }else{ 530 | command++; 531 | } 532 | gpio_dout_write(&doutB, command); 533 | _delay_ms(50); //Debounce 534 | while(gpio_btn_read(&btn1) == 0); //wait till button1 is released 535 | _delay_ms(50); //Debounce 536 | } 537 | 538 | } 539 | gpio_dout_write(&doutB, 0x00); 540 | 541 | //************************************************************************************************* Show and modify data 542 | gpio_dout_write(&doutA, data); //display DATA of current address 543 | 544 | _delay_ms(50); //Debounce 545 | while(gpio_btn_read(&btn2) == 0); //wait till button2 released 546 | _delay_ms(50); //Debounce 547 | 548 | while(gpio_btn_read(&btn2) == 1){ //while button2 is released 549 | 550 | if(gpio_btn_read(&btn1) == 0){ //if button1 is pressed: if it's the first time set data to 0, otherwise increment it 551 | if(lockData == false){ 552 | data = 0; 553 | lockData = true; 554 | }else{ 555 | data++; 556 | } 557 | gpio_dout_write(&doutA, data); 558 | _delay_ms(50); //Debounce 559 | while(gpio_btn_read(&btn1) == 0); //wait till button1 is released 560 | _delay_ms(50); //Debounce 561 | } 562 | 563 | } 564 | gpio_dout_write(&doutA, 0x00); 565 | 566 | //************************************************************************************************* Optional: write to EEPROM 567 | if(lockCommand || lockData){ 568 | tps_unifyInstruction(&instruction, command, data); 569 | EEPROM_write(progCounter, instruction); 570 | 571 | gpio_dout_write(&doutA, 0x00); 572 | gpio_dout_write(&doutB, 0x00); 573 | _delay_ms(700); 574 | } 575 | 576 | 577 | } 578 | 579 | 580 | //Update MCP73831 Charge status led 581 | ISR(PORTC_PORT_vect){ 582 | if(gpio_btn_read(&mcpStat)) 583 | PORTC.OUTCLR = PIN2_bm; 584 | else 585 | PORTC.OUTSET = PIN2_bm; 586 | 587 | PORTC.INTFLAGS = PIN0_bm; 588 | } 589 | 590 | #ifdef BOARD_V11B 591 | ISR(PORTD_PORT_vect){ 592 | 593 | /* Toggle the bit in the shadow register if the corresponding Din Button got pressed */ 594 | for(int i = 0; i <= 3; i++){ 595 | if(*dinA.intflags & (1 << (dinA.pin0 + i)) ){ 596 | if(dinA.sequence == NORMAL) 597 | gpio_dout_toggleBit(&dinA.shadowReg, i); 598 | else 599 | gpio_dout_toggleBit(&dinA.shadowReg, 3U-i); 600 | 601 | *dinA.intflags = 1 << (dinA.pin0 + i); 602 | } 603 | } 604 | 605 | } 606 | #endif -------------------------------------------------------------------------------- /firmware/ucunit/uCUnit-v1.0.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * uCUnit - A unit testing framework for microcontrollers * 4 | * * 5 | * (C) 2007 - 2008 Sven Stefan Krauss * 6 | * https://www.ucunit.org * 7 | * * 8 | * File : uCUnit-v1.0.h * 9 | * Description : Macros for Unit-Testing * 10 | * Author : Sven Stefan Krauss * 11 | * Contact : www.ucunit.org * 12 | * * 13 | *****************************************************************************/ 14 | 15 | /* 16 | * This file is part of ucUnit. 17 | * 18 | * You can redistribute and/or modify it under the terms of the 19 | * Common Public License as published by IBM Corporation; either 20 | * version 1.0 of the License, or (at your option) any later version. 21 | * 22 | * uCUnit is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * Common Public License for more details. 26 | * 27 | * You should have received a copy of the Common Public License 28 | * along with uCUnit. 29 | * 30 | * It may also be available at the following URL: 31 | * http://www.opensource.org/licenses/cpl1.0.txt 32 | * 33 | * If you cannot obtain a copy of the License, please contact the 34 | * author. 35 | */ 36 | 37 | #ifndef UCUNIT_0101_H_ 38 | #define UCUNIT_0101_H_ 39 | 40 | /*****************************************************************************/ 41 | /****** Customizing area ******/ 42 | /*****************************************************************************/ 43 | 44 | /** 45 | * @Macro: UCUNIT_WriteString(msg) 46 | * 47 | * @Description: Encapsulates a function which is called for 48 | * writing a message string to the host computer. 49 | * 50 | * @param msg: Message which shall be written. 51 | * 52 | * @Remarks: Implement a function to write an integer to a host 53 | * computer. 54 | * 55 | * For most microcontrollers a special implementation of 56 | * printf is available for writing to a serial 57 | * device or network. In some cases you will have 58 | * also to implement a putch(char c) function. 59 | */ 60 | #define UCUNIT_WriteString(msg) System_WriteString(msg) 61 | 62 | /** 63 | * @Macro: UCUNIT_WriteInt(n) 64 | * 65 | * @Description: Encapsulates a function which is called for 66 | * writing an integer to the host computer. 67 | * 68 | * @param n: Integer number which shall be written 69 | * 70 | * @Remarks: Implement a function to write an integer to a host 71 | * computer. 72 | * 73 | * For most microcontrollers a special implementation of 74 | * printf is available for writing to a serial 75 | * device or network. In some cases you will have 76 | * also to implement a putch(char c) function. 77 | */ 78 | #define UCUNIT_WriteInt(n) System_WriteInt(n) 79 | 80 | /** 81 | * @Macro: UCUNIT_Safestate() 82 | * 83 | * @Description: Encapsulates a function which is called for 84 | * putting the hardware to a safe state. 85 | * 86 | * @Remarks: Implement a function to put your hardware into 87 | * a safe state. 88 | * 89 | * For example, imagine a motor controller 90 | * application: 91 | * 1. Stop the motor 92 | * 2. Power brake 93 | * 3. Hold the brake 94 | * 4. Switch warning lamp on 95 | * 5. Wait for acknowledge 96 | * ... 97 | * 98 | */ 99 | #define UCUNIT_Safestate() System_Safestate() 100 | 101 | /** 102 | * @Macro: UCUNIT_Recover() 103 | * 104 | * @Description: Encapsulates a function which is called for 105 | * recovering the hardware from a safe state. 106 | * 107 | * @Remarks: Implement a function to recover your hardware from 108 | * a safe state. 109 | * 110 | * For example, imagine our motor controller 111 | * application: 112 | * 1. Acknowledge the error with a key switch 113 | * 2. Switch warning lamp off 114 | * 3. Reboot 115 | * ... 116 | * 117 | */ 118 | #define UCUNIT_Recover() System_Reset() 119 | 120 | /** 121 | * @Macro: UCUNIT_Init() 122 | * 123 | * @Description: Encapsulates a function which is called for 124 | * initializing the hardware. 125 | * 126 | * @Remarks: Implement a function to initialize your microcontroller 127 | * hardware. You need at least to initialize the 128 | * communication device for transmitting your results to 129 | * a host computer. 130 | * 131 | */ 132 | #define UCUNIT_Init() System_Init() 133 | 134 | /** 135 | * @Macro: UCUNIT_Shutdown() 136 | * 137 | * @Description: Encapsulates a function which is called to 138 | * stop the tests if a checklist fails. 139 | * 140 | * @Remarks: Implement a function to stop the execution of the 141 | * tests. 142 | * 143 | */ 144 | #define UCUNIT_Shutdown() System_Shutdown() 145 | 146 | /** 147 | * Verbose Mode. 148 | * UCUNIT_MODE_SILENT: Checks are performed silently. 149 | * UCUNIT_MODE_NORMAL: Only checks that fail are displayes 150 | * UCUNIT_MODE_VERBOSE: Passed and failed checks are displayed 151 | */ 152 | //#define UCUNIT_MODE_NORMAL 153 | #define UCUNIT_MODE_VERBOSE 154 | 155 | /** 156 | * Max. number of checkpoints. This may depend on your application 157 | * or limited by your RAM. 158 | */ 159 | #define UCUNIT_MAX_TRACEPOINTS 16 160 | 161 | /*****************************************************************************/ 162 | /* **** End of customizing area ***** */ 163 | /*****************************************************************************/ 164 | 165 | /*****************************************************************************/ 166 | /* Some useful constants */ 167 | /*****************************************************************************/ 168 | 169 | #define UCUNIT_VERSION "v1.0" /* Version info */ 170 | 171 | #ifndef NULL 172 | #define NULL (void *)0 173 | #endif 174 | 175 | #ifndef TRUE 176 | #define TRUE 1 177 | #endif 178 | 179 | #ifndef FALSE 180 | #define FALSE 0 181 | #endif 182 | 183 | /* Action to take if check fails */ 184 | #define UCUNIT_ACTION_WARNING 0 /* Goes through the checks 185 | with message depending on level */ 186 | #define UCUNIT_ACTION_SHUTDOWN 1 /* Stops on the end of the checklist 187 | if any check has failed */ 188 | #define UCUNIT_ACTION_SAFESTATE 2 /* Goes in safe state if check fails */ 189 | 190 | /*****************************************************************************/ 191 | /* Variables */ 192 | /*****************************************************************************/ 193 | 194 | /* Variables for simple statistics */ 195 | static int ucunit_checks_failed = 0; /* Numer of failed checks */ 196 | static int ucunit_checks_passed = 0; /* Number of passed checks */ 197 | 198 | static int ucunit_testcases_failed = 0; /* Number of failed test cases */ 199 | static int ucunit_testcases_passed = 0; /* Number of passed test cases */ 200 | static int ucunit_testcases_failed_checks = 0; /* Number of failed checks in a testcase */ 201 | static int ucunit_checklist_failed_checks = 0; /* Number of failed checks in a checklist */ 202 | static int ucunit_action = UCUNIT_ACTION_WARNING; /* Action to take if a check fails */ 203 | static int ucunit_checkpoints[UCUNIT_MAX_TRACEPOINTS]; /* Max. number of tracepoints */ 204 | static int ucunit_index = 0; /* Tracepoint index */ 205 | 206 | /*****************************************************************************/ 207 | /* Internal (private) Macros */ 208 | /*****************************************************************************/ 209 | 210 | /** 211 | * @Macro: UCUNIT_DefineToStringHelper(x) 212 | * 213 | * @Description: Helper macro for converting a define constant into 214 | * a string. 215 | * 216 | * @Param x: Define value to convert. 217 | * 218 | * @Remarks: This macro is used by UCUNIT_DefineToString(). 219 | * 220 | */ 221 | #define UCUNIT_DefineToStringHelper(x) #x 222 | 223 | /** 224 | * @Macro: UCUNIT_DefineToString(x) 225 | * 226 | * @Description: Converts a define constant into a string. 227 | * 228 | * @Param x: Define value to convert. 229 | * 230 | * @Remarks: This macro uses UCUNIT_DefineToStringHelper(). 231 | * 232 | */ 233 | #define UCUNIT_DefineToString(x) UCUNIT_DefineToStringHelper(x) 234 | 235 | #ifdef UCUNIT_MODE_VERBOSE 236 | /** 237 | * @Macro: UCUNIT_WritePassedMsg(msg, args) 238 | * 239 | * @Description: Writes a message that check has passed. 240 | * 241 | * @Param msg: Message to write. This is the name of the called 242 | * Check, without the substring UCUNIT_Check. 243 | * @Param args: Argument list as string. 244 | * 245 | * @Remarks: This macro is used by UCUNIT_Check(). A message will 246 | * only be written if verbose mode is set 247 | * to UCUNIT_MODE_VERBOSE. 248 | * 249 | */ 250 | #define UCUNIT_WritePassedMsg(msg, args) \ 251 | do \ 252 | { \ 253 | UCUNIT_WriteString(__FILE__); \ 254 | UCUNIT_WriteString(":"); \ 255 | UCUNIT_WriteString(UCUNIT_DefineToString(__LINE__)); \ 256 | UCUNIT_WriteString(": passed:"); \ 257 | UCUNIT_WriteString(msg); \ 258 | UCUNIT_WriteString("("); \ 259 | UCUNIT_WriteString(args); \ 260 | UCUNIT_WriteString(")\n"); \ 261 | } while(0) 262 | #else 263 | #define UCUNIT_WritePassedMsg(msg, args) 264 | #endif 265 | 266 | #ifdef UCUNIT_MODE_SILENT 267 | #define UCUNIT_WriteFailedMsg(msg, args) 268 | #else 269 | /** 270 | * @Macro: UCUNIT_WriteFailedMsg(msg, args) 271 | * 272 | * @Description: Writes a message that check has failed. 273 | * 274 | * @Param msg: Message to write. This is the name of the called 275 | * Check, without the substring UCUNIT_Check. 276 | * @Param args: Argument list as string. 277 | * 278 | * @Remarks: This macro is used by UCUNIT_Check(). A message will 279 | * only be written if verbose mode is set 280 | * to UCUNIT_MODE_NORMAL and UCUNIT_MODE_VERBOSE. 281 | * 282 | */ 283 | #define UCUNIT_WriteFailedMsg(msg, args) \ 284 | do \ 285 | { \ 286 | UCUNIT_WriteString(__FILE__); \ 287 | UCUNIT_WriteString(":"); \ 288 | UCUNIT_WriteString(UCUNIT_DefineToString(__LINE__)); \ 289 | UCUNIT_WriteString(": failed:"); \ 290 | UCUNIT_WriteString(msg); \ 291 | UCUNIT_WriteString("("); \ 292 | UCUNIT_WriteString(args); \ 293 | UCUNIT_WriteString(")\n"); \ 294 | } while(0) 295 | #endif 296 | 297 | /** 298 | * @Macro: UCUNIT_FailCheck(msg, args) 299 | * 300 | * @Description: Fails a check. 301 | * 302 | * @Param msg: Message to write. This is the name of the called 303 | * Check, without the substring UCUNIT_Check. 304 | * @Param args: Argument list as string. 305 | * 306 | * @Remarks: This macro is used by UCUNIT_Check(). A message will 307 | * only be written if verbose mode is set 308 | * to UCUNIT_MODE_NORMAL and UCUNIT_MODE_VERBOSE. 309 | * 310 | */ 311 | #define UCUNIT_FailCheck(msg, args) \ 312 | do \ 313 | { \ 314 | if (UCUNIT_ACTION_SAFESTATE==ucunit_action) \ 315 | { \ 316 | UCUNIT_Safestate(); \ 317 | } \ 318 | UCUNIT_WriteFailedMsg(msg, args); \ 319 | ucunit_checks_failed++; \ 320 | ucunit_checklist_failed_checks++; \ 321 | } while(0) 322 | 323 | /** 324 | * @Macro: UCUNIT_PassCheck(msg, args) 325 | * 326 | * @Description: Passes a check. 327 | * 328 | * @Param msg: Message to write. This is the name of the called 329 | * Check, without the substring UCUNIT_Check. 330 | * @Param args: Argument list as string. 331 | * 332 | * @Remarks: This macro is used by UCUNIT_Check(). A message will 333 | * only be written if verbose mode is set 334 | * to UCUNIT_MODE_VERBOSE. 335 | * 336 | */ 337 | #define UCUNIT_PassCheck(message, args) \ 338 | do \ 339 | { \ 340 | UCUNIT_WritePassedMsg(message, args); \ 341 | ucunit_checks_passed++; \ 342 | } while(0) 343 | 344 | /*****************************************************************************/ 345 | /* Checklist Macros */ 346 | /*****************************************************************************/ 347 | 348 | /** 349 | * @Macro: UCUNIT_ChecklistBegin(action) 350 | * 351 | * @Description: Begin of a checklist. You have to tell what action 352 | * shall be taken if a check fails. 353 | * 354 | * @Param action: Action to take. This can be: 355 | * * UCUNIT_ACTION_WARNING: A warning message will be printed 356 | * that a check has failed 357 | * * UCUNIT_ACTION_SHUTDOWN: The system will shutdown at 358 | * the end of the checklist. 359 | * * UCUNIT_ACTION_SAFESTATE: The system goes into the safe state 360 | * on the first failed check. 361 | 362 | * @Remarks: A checklist must be finished with UCUNIT_ChecklistEnd() 363 | * 364 | */ 365 | #define UCUNIT_ChecklistBegin(action) \ 366 | do \ 367 | { \ 368 | ucunit_action = action; \ 369 | ucunit_checklist_failed_checks = 0; \ 370 | } while (0) 371 | 372 | /** 373 | * @Macro: UCUNIT_ChecklistEnd() 374 | * 375 | * @Description: End of a checklist. If the action was UCUNIT_ACTION_SHUTDOWN 376 | * the system will shutdown. 377 | * 378 | * @Remarks: A checklist must begin with UCUNIT_ChecklistBegin(action) 379 | * 380 | */ 381 | #define UCUNIT_ChecklistEnd() \ 382 | if (ucunit_checklist_failed_checks!=0) \ 383 | { \ 384 | UCUNIT_WriteFailedMsg("Checklist",""); \ 385 | if (UCUNIT_ACTION_SHUTDOWN==ucunit_action) \ 386 | { \ 387 | UCUNIT_Shutdown(); \ 388 | } \ 389 | } \ 390 | else \ 391 | { \ 392 | UCUNIT_WritePassedMsg("Checklist",""); \ 393 | } 394 | 395 | /*****************************************************************************/ 396 | /* Check Macros */ 397 | /*****************************************************************************/ 398 | 399 | /** 400 | * @Macro: UCUNIT_Check(condition, msg, args) 401 | * 402 | * @Description: Checks a condition and prints a message. 403 | * 404 | * @Param msg: Message to write. 405 | * @Param args: Argument list as string 406 | * 407 | * @Remarks: Basic check. This macro is used by all higher level checks. 408 | * 409 | */ 410 | #define UCUNIT_Check(condition, msg, args) \ 411 | if ( (condition) ) { UCUNIT_PassCheck(msg, args); } else { UCUNIT_FailCheck(msg, args); } 412 | 413 | /** 414 | * @Macro: UCUNIT_CheckIsEqual(expected,actual) 415 | * 416 | * @Description: Checks that actual value equals the expected value. 417 | * 418 | * @Param expected: Expected value. 419 | * @Param actual: Actual value. 420 | * 421 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 422 | * 423 | */ 424 | #define UCUNIT_CheckIsEqual(expected,actual) \ 425 | UCUNIT_Check( (expected) == (actual), "IsEqual", #expected "," #actual ) 426 | 427 | /** 428 | * @Macro: UCUNIT_CheckIsNull(pointer) 429 | * 430 | * @Description: Checks that a pointer is NULL. 431 | * 432 | * @Param pointer: Pointer to check. 433 | * 434 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 435 | * 436 | */ 437 | #define UCUNIT_CheckIsNull(pointer) \ 438 | UCUNIT_Check( (pointer) == NULL, "IsNull", #pointer) 439 | 440 | /** 441 | * @Macro: UCUNIT_CheckIsNotNull(pointer) 442 | * 443 | * @Description: Checks that a pointer is not NULL. 444 | * 445 | * @Param pointer: Pointer to check. 446 | * 447 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 448 | * 449 | */ 450 | #define UCUNIT_CheckIsNotNull(pointer) \ 451 | UCUNIT_Check( (pointer) != NULL, "IsNotNull", #pointer) 452 | 453 | /** 454 | * @Macro: UCUNIT_CheckIsInRange(value, lower, upper) 455 | * 456 | * @Description: Checks if a value is between lower and upper bounds (inclusive) 457 | * Mathematical: lower <= value <= upper 458 | * 459 | * @Param value: Value to check. 460 | * @Param lower: Lower bound. 461 | * @Param upper: Upper bound. 462 | * 463 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 464 | * 465 | */ 466 | #define UCUNIT_CheckIsInRange(value, lower, upper) \ 467 | UCUNIT_Check( ( (value>=lower) && (value<=upper) ), "IsInRange", #value "," #lower "," #upper) 468 | 469 | /** 470 | * @Macro: UCUNIT_CheckIs8Bit(value) 471 | * 472 | * @Description: Checks if a value fits into 8-bit. 473 | * 474 | * @Param value: Value to check. 475 | * 476 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 477 | * 478 | */ 479 | #define UCUNIT_CheckIs8Bit(value) \ 480 | UCUNIT_Check( value==(value & 0xFF), "Is8Bit", #value ) 481 | 482 | /** 483 | * @Macro: UCUNIT_CheckIs16Bit(value) 484 | * 485 | * @Description: Checks if a value fits into 16-bit. 486 | * 487 | * @Param value: Value to check. 488 | * 489 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 490 | * 491 | */ 492 | #define UCUNIT_CheckIs16Bit(value) \ 493 | UCUNIT_Check( value==(value & 0xFFFF), "Is16Bit", #value ) 494 | 495 | /** 496 | * @Macro: UCUNIT_CheckIs32Bit(value) 497 | * 498 | * @Description: Checks if a value fits into 32-bit. 499 | * 500 | * @Param value: Value to check. 501 | * 502 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 503 | * 504 | */ 505 | #define UCUNIT_CheckIs32Bit(value) \ 506 | UCUNIT_Check( value==(value & 0xFFFFFFFF), "Is32Bit", #value ) 507 | 508 | /** 509 | * Checks if bit is set 510 | */ 511 | /** 512 | * @Macro: UCUNIT_CheckIsBitSet(value, bitno) 513 | * 514 | * @Description: Checks if a bit is set in value. 515 | * 516 | * @Param value: Value to check. 517 | * @Param bitno: Bit number. The least significant bit is 0. 518 | * 519 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 520 | * 521 | */ 522 | #define UCUNIT_CheckIsBitSet(value, bitno) \ 523 | UCUNIT_Check( (1==(((value)>>(bitno)) & 0x01) ), "IsBitSet", #value "," #bitno) 524 | 525 | /** 526 | * @Macro: UCUNIT_CheckIsBitClear(value, bitno) 527 | * 528 | * @Description: Checks if a bit is not set in value. 529 | * 530 | * @Param value: Value to check. 531 | * @Param bitno: Bit number. The least significant bit is 0. 532 | * 533 | * @Remarks: This macro uses UCUNIT_Check(condition, msg, args). 534 | * 535 | */ 536 | #define UCUNIT_CheckIsBitClear(value, bitno) \ 537 | UCUNIT_Check( (0==(((value)>>(bitno)) & 0x01) ), "IsBitClear", #value "," #bitno) 538 | 539 | /*****************************************************************************/ 540 | /* Testcases */ 541 | /*****************************************************************************/ 542 | 543 | /** 544 | * @Macro: UCUNIT_TestcaseBegin(name) 545 | * 546 | * @Description: Marks the beginning of a test case and resets 547 | * the test case statistic. 548 | * 549 | * @Param name: Name of the test case. 550 | * 551 | * @Remarks: This macro uses UCUNIT_WriteString(msg) to print the name. 552 | * 553 | */ 554 | #define UCUNIT_TestcaseBegin(name) \ 555 | do \ 556 | { \ 557 | UCUNIT_WriteString("\n======================================\n"); \ 558 | UCUNIT_WriteString(name); \ 559 | UCUNIT_WriteString("\n======================================\n"); \ 560 | ucunit_testcases_failed_checks = ucunit_checks_failed; \ 561 | } \ 562 | while(0) 563 | 564 | /** 565 | * @Macro: UCUNIT_TestcaseEnd() 566 | * 567 | * @Description: Marks the end of a test case and calculates 568 | * the test case statistics. 569 | * 570 | * @Remarks: This macro uses UCUNIT_WriteString(msg) to print the result. 571 | * 572 | */ 573 | #define UCUNIT_TestcaseEnd() \ 574 | do \ 575 | { \ 576 | UCUNIT_WriteString("======================================\n"); \ 577 | if( 0==(ucunit_testcases_failed_checks - ucunit_checks_failed) ) \ 578 | { \ 579 | UCUNIT_WriteString("Testcase passed.\n"); \ 580 | ucunit_testcases_passed++; \ 581 | } \ 582 | else \ 583 | { \ 584 | UCUNIT_WriteFailedMsg("EndTestcase",""); \ 585 | ucunit_testcases_failed++; \ 586 | } \ 587 | UCUNIT_WriteString("======================================\n"); \ 588 | } \ 589 | while(0) 590 | 591 | /*****************************************************************************/ 592 | /* Support for code coverage */ 593 | /*****************************************************************************/ 594 | 595 | /** 596 | * @Macro: UCUNIT_Tracepoint(index) 597 | * 598 | * @Description: Marks a trace point. 599 | * If a trace point is executed, its coverage state switches 600 | * from 0 to the line number. 601 | * If a trace point was never executed, the state 602 | * remains 0. 603 | * 604 | * @Param index: Index of the tracepoint. 605 | * 606 | * @Remarks: This macro fails if index>UCUNIT_MAX_TRACEPOINTS. 607 | * 608 | */ 609 | #define UCUNIT_Tracepoint(index) \ 610 | if(indexUCUNIT_MAX_TRACEPOINTS. 627 | * 628 | */ 629 | #define UCUNIT_ResetTracepointCoverage() \ 630 | for (ucunit_index=0; ucunit_indexUCUNIT_MAX_TRACEPOINTS. 643 | * 644 | */ 645 | #define UCUNIT_CheckTracepointCoverage(index) \ 646 | UCUNIT_Check( (ucunit_checkpoints[index]!=0), "TracepointCoverage", #index); 647 | 648 | /*****************************************************************************/ 649 | /* Testsuite Summary */ 650 | /*****************************************************************************/ 651 | 652 | /** 653 | * @Macro: UCUNIT_WriteSummary() 654 | * 655 | * @Description: Writes the test suite summary. 656 | * 657 | * @Remarks: This macro uses UCUNIT_WriteString(msg) and 658 | * UCUNIT_WriteInt(n) to write the summary. 659 | * 660 | */ 661 | #define UCUNIT_WriteSummary() \ 662 | { \ 663 | UCUNIT_WriteString("\n**************************************"); \ 664 | UCUNIT_WriteString("\nTestcases: failed: "); \ 665 | UCUNIT_WriteInt(ucunit_testcases_failed); \ 666 | UCUNIT_WriteString("\n passed: "); \ 667 | UCUNIT_WriteInt(ucunit_testcases_passed); \ 668 | UCUNIT_WriteString("\nChecks: failed: "); \ 669 | UCUNIT_WriteInt(ucunit_checks_failed); \ 670 | UCUNIT_WriteString("\n passed: "); \ 671 | UCUNIT_WriteInt(ucunit_checks_passed); \ 672 | UCUNIT_WriteString("\n**************************************\n"); \ 673 | } 674 | 675 | #endif /*UCUNIT_H_*/ 676 | --------------------------------------------------------------------------------