Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.c
- * Created on: May 3, 2018
- * Author: roehrig, kindt
- *
- * ! MAKE SURE TO ACTIVATE "Reset System" IN THE LAUNCH CONFIGURATION. OTHERWISE, THIS EXERCISE WILL NOT WORK!
- * (the same holds true for all other exercises)
- */
- #include <stdio.h>
- #include "platform.h"
- #include <xil_printf.h>
- #include "libmps.h" // For all lib_mps functions
- #include <mps_bridge.h> // For MPS bridge
- #define MPS_BRIDGE_PTR (XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR)
- u16 *bus = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
- uint32_t read_var = 0;
- uint8_t next_val = 0;
- extern u8 pattern001;
- extern u8 pattern010;
- extern u8 pattern100;
- volatile u8 interrupt_occured = 0;
- //extern void switch_lights(u8* pattern);
- void switch_lights(u8* pattern);
- extern void determine_lights();
- void isr()
- {
- interrupt_occured = 1;
- value_PIT();
- }
- int main()
- {
- init_platform();
- init_gpioPs();
- init_PIT(isr, 1);
- while(1)
- {
- if(interrupt_occured)
- {
- read_var = *bus; //read from bus
- if(read_var == 4)
- {
- //switch_lights(&pattern001);
- *bus=pattern001;
- }
- else if (read_var == 1)
- {
- switch_lights(&pattern010);
- }
- else
- {
- switch_lights(&pattern100);
- }
- //determine_lights();
- interrupt_occured = 0;
- }
- }
- }
- ________________________________________
- .extern bus //make bus-ponter from C-Code known to assembly
- .text //indicate the following statements as executable segment (program code, text)
- .global switch_lights //declare the symbol "swicht_lights" as global to make it accessible from outside
- switch_lights:
- // insert your code here :)
- LDR R1,=bus
- LDR R2,[R1]
- LDRB R3,[R0]
- STRH R3,[R2] //[[R1]]
- //the following line is needed to jump back
- bx lr
- .global determine_lights
- determine_lights:
- LDR R1,=bus
- LDR R2,[R1]
- LDRH R2,[R2]
- cmp R2,#4
- bne else1
- LDR R0,=pattern001
- b call
- else1: cmp R2,#1
- bne else2
- LDR R0,=pattern010
- b call
- //mov R2,#2
- else2:
- LDR R0,=pattern100
- //subs R13,R13, #4
- call:
- push {lr}
- bl switch_lights
- pop {lr}
- //ldr R14, [R13]
- //add R13,R13,#4
- //MOV R2,#4
- bx lr
- //data section
- .data
- //make symbols global
- .global pattern001
- .global pattern010
- .global pattern100
- .align 4 //align to word boundary
- pattern001:
- .byte 0b00000001
- .align 4 //align to word boundary
- pattern010:
- .byte 0b00000010
- .align 4 //align to word boundary
- pattern100:
- .byte 0b00000100
- ______________________________________________________
- /*
- * main.c
- *
- * Created on: May 9, 2018
- * Author: roehrig
- */
- #include <stdio.h>
- #include "platform.h"
- #include <xil_printf.h>
- #include "libmps.h" // For all lib_mps functions
- #include <mps_bridge.h> // For MPS bridge
- #include <sleep.h>
- #include "xttcps.h"
- #include "xscugic.h"
- #include "xgpio.h"
- #define MPS_BRIDGE_PTR (XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR)
- #define AXI_GPIO_PTR (XPAR_AXI_GPIO_0_BASEADDR)
- u16 *bus = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
- u16 *gpio = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
- unsigned int state= 0;
- unsigned int a= 0;
- extern int interrupt_flag_0; // External definition of interrupt_flag_0 for interrupt port 0
- int main()
- {
- init_platform();
- init_ext_interrupt();
- init_PWM();
- init_axi_gpio();
- start_PWM (1000, 0);
- while(1)
- {
- //read_var = *bus;
- //xil_printf(" 1, before if buttons value:%d and a:%d \r \n", BUTTONS_value(),a);
- if((BUTTONS_value()==1)&&(state==0)){
- //xil_printf(" 2, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- state=1;
- //xil_printf(" 3, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- if(a!=1000){
- //xil_printf(" 4, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- a=a+100;
- //xil_printf(" 5, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- start_PWM (1000, a );
- //xil_printf(" 6, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- usleep(1000);
- //xil_printf(" 7, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- }}
- else if((BUTTONS_value()==2)&&(state==0)){
- //xil_printf(" 8, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- state=1;
- //xil_printf(" 9, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- if(a!=0){
- //xil_printf(" 10, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- a=a-100;
- //xil_printf(" 11, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- start_PWM (1000, a);
- //xil_printf(" 12, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- usleep(1000);
- //xil_printf(" 13, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- }
- }
- else if((BUTTONS_value()==0)&&(state==1)){
- //xil_printf(" 14, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- state=0;
- //xil_printf(" 15, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
- }
- }
- }
- ____________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement