diff --git a/.github/.gitignore b/.github/.gitignore deleted file mode 100644 index 8b13789..0000000 --- a/.github/.gitignore +++ /dev/null @@ -1 +0,0 @@ - diff --git a/.github/actions/avr_setup/action.yml b/.github/actions/avr_setup/action.yml new file mode 100644 index 0000000..3b92db0 --- /dev/null +++ b/.github/actions/avr_setup/action.yml @@ -0,0 +1,18 @@ +name: "Get changed files list" +description: "Setup Node with caching for dependencies" +runs: + using: "composite" + steps: + - name: Set up Arduino CLI + uses: arduino/setup-arduino-cli@v2 + + - name: Install platform + run: | + arduino-cli core update-index + arduino-cli core install ${{ env.platform }} + shell: bash + + - name: Install popular libs + run: | + arduino-cli lib install LiquidCrystal + shell: bash \ No newline at end of file diff --git a/.github/actions/get_changed_files/action.yml b/.github/actions/get_changed_files/action.yml new file mode 100644 index 0000000..ecf73ac --- /dev/null +++ b/.github/actions/get_changed_files/action.yml @@ -0,0 +1,13 @@ +name: "Get changed files list" +description: "Setup Node with caching for dependencies" +runs: + using: "composite" + steps: + - name: Get changed files list + id: get_changed_files + run: | + echo "Changed files:" + git diff --name-only ${{ github.event.pull_request.base.sha }} > changed_files.txt + cat changed_files.txt + echo "The list is saved to changed_files.txt" + shell: bash \ No newline at end of file diff --git a/.github/workflows/Lab_01_CI.yml b/.github/workflows/Lab_01_CI.yml deleted file mode 100644 index 985573b..0000000 --- a/.github/workflows/Lab_01_CI.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Cheking of compile Arduino sketch for AVR/AtMega and ESP8266 - -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] - -jobs: - test-matrix: - strategy: - matrix: - arduino-platform: - - "arduino:avr" - - "esp8266:esp8266" - include: - - arduino-platform: "arduino:avr" - fqbn: "arduino:avr:mega" - - arduino-platform: "esp8266:esp8266" - fqbn: "esp8266:esp8266:generic" - - runs-on: ubuntu-22.04 - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Arduino CLI - uses: arduino/setup-arduino-cli@v2 - - - name: Install platform - run: | - arduino-cli core update-index - arduino-cli core install ${{ matrix.arduino-platform }} - - - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} ./mc_labs/mc_lab_01/*.ino diff --git a/.github/workflows/lab-validation.yml b/.github/workflows/lab-validation.yml new file mode 100644 index 0000000..059343b --- /dev/null +++ b/.github/workflows/lab-validation.yml @@ -0,0 +1,114 @@ +name: Cheking of compile Arduino sketch for AVR/AtMega + +on: + pull_request: + branches: [main, master] + +env: + platform: "arduino:avr" + fqbn_master: "arduino:avr:mega" + COMMIT_COUNT: $(( ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 0 }} + 1 )) + +jobs: + handle_bad_branch_name: + runs-on: ubuntu-22.04 + if: (contains(github.head_ref, 'mc_lab_1') || contains(github.head_ref, 'mc_lab_2') || contains(github.head_ref, 'mc_lab_3') || contains(github.head_ref, 'mc_lab_4') || contains(github.head_ref, 'mc_lab_5') || contains(github.head_ref, 'mc_lab_6') || contains(github.head_ref, 'mc_lab_7')) == false + steps: + - name: Fail the build + run: | + echo "The branch name is not correct. It should contain 'mc_lab_' prefix" + exit 1 + build_labs_1_to_4: + runs-on: ubuntu-22.04 + if: contains(github.head_ref, 'mc_lab_1') || contains(github.head_ref, 'mc_lab_2') || contains(github.head_ref, 'mc_lab_3') || contains(github.head_ref, 'mc_lab_4') + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.COMMIT_COUNT }} + + - name: Get changed files list + uses: ./.github/actions/get_changed_files + + - name: Set up Arduino CLI + uses: ./.github/actions/avr_setup + + - name: Compile Sketch + run: arduino-cli compile --fqbn ${{ env.fqbn_master }} $(grep -E '\.ino$' changed_files.txt | xargs) + build_lab_5: + runs-on: ubuntu-22.04 + if: contains(github.head_ref, 'mc_lab_5') + env: + fqbn_slave: "arduino:avr:nano" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.COMMIT_COUNT }} + + - name: Get changed files list + uses: ./.github/actions/get_changed_files + + - name: Get master folder + run: | + cat changed_files.txt | xargs dirname | grep 'master' | grep -m 1 -vE '/(.*master.*|.*slave.*)/' > master_project.txt + echo "Master project:" + cat master_project.txt + + - name: Get slave folders + run: | + cat changed_files.txt | xargs dirname | grep 'slave' | grep -vE '/(.*master.*|.*slave.*)/' > slave_projects.txt + echo "Slave projects:" + cat slave_projects.txt + + - name: Check if there is at least one master and one slave project + run: | + if [ ! -s master_project.txt ] || [ ! -s slave_projects.txt ]; then + echo "There is no master or slave project" + exit 1 + fi + + - name: Set up Arduino CLI + uses: ./.github/actions/avr_setup + + - name: Compile master + run: while read master_folder; do arduino-cli compile --fqbn ${{ env.fqbn_master }} $master_folder/*.ino; done < master_project.txt + + - name: Compile slaves + run: while read slave_folder; do arduino-cli compile --fqbn ${{ env.fqbn_slave }} $slave_folder/*.ino; done < slave_projects.txt + build_lab_6: + runs-on: ubuntu-22.04 + if: contains(github.head_ref, 'mc_lab_6') + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.COMMIT_COUNT }} + + - name: It just passes + run: echo "It just passes. It's too complex" + build_lab_7: + runs-on: ubuntu-22.04 + if: contains(github.head_ref, 'mc_lab_7') + env: + register-bindings: "m2560def.inc" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.COMMIT_COUNT }} + + - name: Get changed files list + uses: ./.github/actions/get_changed_files + + - name: Setup AVRA Assembler + run: | + git clone https://github.com/Ro5bert/avra.git + cd avra + sudo make install + + - name: Preprocess sketch - append register bindings to the top of the file + run: printf ".include \"${{ env.register-bindings }}\"\n\n" | cat - $(grep -m 1 -E '\.(asm|S)$' changed_files.txt | xargs) > pipeline_main_assembly_source_file.asm + + - name: Compile Sketch + run: avra pipeline_main_assembly_source_file.asm diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/.vs/lab7/v14/.atsuo b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/.vs/lab7/v14/.atsuo new file mode 100644 index 0000000..723bccb Binary files /dev/null and b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/.vs/lab7/v14/.atsuo differ diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7.atsln b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7.atsln new file mode 100644 index 0000000..29a823b --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7.atsln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{18226A42-8477-4023-8AD2-40C49DA407C9}") = "lab7", "lab7\lab7.asmproj", "{59B1D629-9DCC-43ED-A0FD-8AB0E4D622AB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {59B1D629-9DCC-43ED-A0FD-8AB0E4D622AB}.Debug|AVR.ActiveCfg = Debug|AVR + {59B1D629-9DCC-43ED-A0FD-8AB0E4D622AB}.Debug|AVR.Build.0 = Debug|AVR + {59B1D629-9DCC-43ED-A0FD-8AB0E4D622AB}.Release|AVR.ActiveCfg = Release|AVR + {59B1D629-9DCC-43ED-A0FD-8AB0E4D622AB}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.asmproj b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.asmproj new file mode 100644 index 0000000..b0a381e --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.asmproj @@ -0,0 +1,108 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRAssembler + 59B1D629-9DCC-43ed-A0FD-8AB0E4D622AB + none + ATmega2560 + $(MSBuildProjectName) + .obj + $(MSBuildProjectDirectory)\$(Configuration) + ASSEMBLY + lab7 + lab7 + lab7 + Native + $(MSBuildProjectDirectory)\main.asm + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + 0 + + + + + + + + + + + + + + com.atmel.avrdbg.tool.simulator + + 0x1E9801 + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + + + + + custom + + + Custom Programming Tool + + + + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\avrasm\inc + + + m2560def.inc + + + Executable + + + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.7.374\avrasm\inc + + + m2560def.inc + + + + + + Code + + + + + Code + + + + \ No newline at end of file diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.componentinfo.xml b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.componentinfo.xml new file mode 100644 index 0000000..9416d84 --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.componentinfo.xml @@ -0,0 +1,64 @@ + + + + + + + Device + Startup + + + Atmel + 1.7.0 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.7.374\avrasm\inc + + include + AVRASM + + + avrasm/inc + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.7.374\avrasm\inc\m2560def.inc + + header + AVRASM + WfTdCEu0AkLjvEGIJEiVXg== + + avrasm/inc/m2560def.inc + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.7.374\avrasm\templates\main.asm + template + source + AVRASM + S4Kwzy8TT0G4DKwdWeyoAw== + + avrasm/templates/main.asm + Main file (.asm) + + + + ATmega_DFP + C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.7.374/Atmel.ATmega_DFP.pdsc + 1.7.374 + true + ATmega2560 + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj new file mode 100644 index 0000000..580e7fb Binary files /dev/null and b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj differ diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace new file mode 100644 index 0000000..521469f --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace @@ -0,0 +1,120 @@ + + + + 2c0000000200000003000000ffffffffffffffffffffffffffffffff92000000b3000000a00900007c050000 + + + + + + + + + + + + + + + + + + + + + + + + + + + 649 + No + 100 + 120 + 100 + + + + + 81 + No + Yes + 81 + Yes + No + No + Yes + 0 + 81 + 100 + 81 + 0 + + + + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00001940 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000200 + + + + + 2 + Yes + 2 + Yes + Yes + 00000020 + + + + + diff --git a/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/main.asm b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/main.asm new file mode 100644 index 0000000..f87a4a4 --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/avrstudio/lab7/lab7/main.asm @@ -0,0 +1,168 @@ + +.def temp = r16 +.def isr_temp1 = r17 +.def isr_temp2 = r18 + + + +.cseg +.org 0x0000 ; the next instruction has to be written to + ; address 0x0000 +rjmp setup ; the reset vector: jump to "main" + + + +.org 0x0028 +jmp TIM1_OVF ; Timer1 overflow handler + + + +.org 0x0100 +setup: + ldi temp, 0xFF + out DDRF, temp ; set ports F and K to be output ports + sts DDRK, temp + + ldi temp, 0x20 + sts DDRH, temp + + ldi temp, 0b00000101 + sts PortL, temp + + + ; stack is neccessary, because when interrupt occurs, you need to save + ; the address of the instruction you were on to return back to it later + ; this instruction is stored on the stack + ldi temp, low(RAMEND) + out SPL, temp + ldi r16, high(RAMEND) + out SPH, temp + + ldi temp, 1 ; we can only load values from registers + sts TIMSK1, temp ; enable interrupts for timer 1 + sei ; enable interrupts globally + + rcall reset_timer + + ldi temp, 0x00 + sts TCCR1A, temp ; we don't use wave generation mode, so leave this at 0 + ldi temp, 0b100 + sts TCCR1B, temp ; but we do use prescaler, which is 256 in this case + + rjmp loop + + + +loop: + lds temp, PinL + andi temp, 0x01 + cpi temp, 0 + breq loop_algo1 + + lds temp, PinL + andi temp, 0x04 + cpi temp, 0 + breq loop_algo3 + + rjmp loop + +loop_algo1: + rcall run_algo1 + rjmp loop +loop_algo3: + rcall run_algo3 + rjmp loop + + ; jump back to loop + +run_algo1: + ldi temp, 0x01 + sts PortK, temp + + rcall turn_buzzer_on + + rcall reset_timer + reti + +run_algo3: + ldi temp, 0x81 + out PortF, temp + + rcall turn_buzzer_on + + rcall reset_timer + reti + +turn_buzzer_on: + lds isr_temp1, PortH + ori isr_temp1, 0b00100000 + clz + cln + clv + sts PortH, isr_temp1 + reti + +turn_buzzer_off: + lds isr_temp1, PortH + andi isr_temp1, ~0b00100000 + clz + cln + clv + sts PortH, isr_temp1 + reti + +algo1: + lds isr_temp1, PortK + cpi isr_temp1, 0x00 + breq algo1_ret + + lsl isr_temp1 + clc + sts PortK, isr_temp1 +algo1_ret: + reti + + +algo3: + in isr_temp1, PortF + cpi isr_temp1, 0x00 + breq algo3_ret + + mov isr_temp2, isr_temp1 + lsl isr_temp1 + lsr isr_temp2 + andi isr_temp1, 0x0F + andi isr_temp2, 0xF0 + or isr_temp1, isr_temp2 + clz + cln + clv + clc + out PortF, isr_temp1 +algo3_ret: + reti + + + + +reset_timer: + ; set timer initial value to be 0xC350 + ldi isr_temp1, 0xC3 + sts TCNT1L, isr_temp1 ; load the low part of timer initial value + ldi isr_temp1, 0x50 + sts TCNT1H, isr_temp1 ; load the high part of timer initial value + reti + + +TIM1_OVF: + cli ; disable all interrupts for the time of this isr + + rcall algo1 + rcall algo3 + ;cbi PortH, 5 ; switch buzzer off + + rcall reset_timer ; reset timer + rcall turn_buzzer_off + + sei ; enable back interrupts + reti ; return from the isr diff --git a/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj b/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj new file mode 100644 index 0000000..6c021b7 Binary files /dev/null and b/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj differ diff --git a/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace b/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace new file mode 100644 index 0000000..0b59326 --- /dev/null +++ b/mc_labs/mc_lab_07/lab7-mko/lab7.pdsprj.DESKTOP-GAIO2HA.vm.workspace @@ -0,0 +1,30 @@ + + + + 2c0000000200000003000000ffffffffffffffffffffffffffffffff00000000b10000000e0900007a050000 + + + + + + + + + + + + + + + + + + + + + + + + + +