Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. /*
  2. * main.c
  3. * Created on: May 3, 2018
  4. * Author: roehrig, kindt
  5. *
  6. * ! MAKE SURE TO ACTIVATE "Reset System" IN THE LAUNCH CONFIGURATION. OTHERWISE, THIS EXERCISE WILL NOT WORK!
  7. * (the same holds true for all other exercises)
  8. */
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include "platform.h"
  14. #include <xil_printf.h>
  15.  
  16. #include "libmps.h" // For all lib_mps functions
  17. #include <mps_bridge.h> // For MPS bridge
  18.  
  19.  
  20. #define MPS_BRIDGE_PTR (XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR)
  21. u16 *bus = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
  22.  
  23. uint32_t read_var = 0;
  24. uint8_t next_val = 0;
  25.  
  26. extern u8 pattern001;
  27. extern u8 pattern010;
  28. extern u8 pattern100;
  29.  
  30. volatile u8 interrupt_occured = 0;
  31.  
  32. //extern void switch_lights(u8* pattern);
  33.  
  34. void switch_lights(u8* pattern);
  35.  
  36. extern void determine_lights();
  37.  
  38.  
  39. void isr()
  40. {
  41. interrupt_occured = 1;
  42. value_PIT();
  43. }
  44.  
  45. int main()
  46. {
  47. init_platform();
  48. init_gpioPs();
  49. init_PIT(isr, 1);
  50.  
  51.  
  52. while(1)
  53. {
  54. if(interrupt_occured)
  55. {
  56. read_var = *bus; //read from bus
  57. if(read_var == 4)
  58. {
  59. //switch_lights(&pattern001);
  60. *bus=pattern001;
  61. }
  62. else if (read_var == 1)
  63. {
  64. switch_lights(&pattern010);
  65. }
  66. else
  67. {
  68. switch_lights(&pattern100);
  69. }
  70.  
  71. //determine_lights();
  72.  
  73. interrupt_occured = 0;
  74. }
  75. }
  76. }
  77.  
  78. ________________________________________
  79.  
  80. .extern bus //make bus-ponter from C-Code known to assembly
  81.  
  82. .text //indicate the following statements as executable segment (program code, text)
  83. .global switch_lights //declare the symbol "swicht_lights" as global to make it accessible from outside
  84. switch_lights:
  85. // insert your code here :)
  86. LDR R1,=bus
  87. LDR R2,[R1]
  88. LDRB R3,[R0]
  89. STRH R3,[R2] //[[R1]]
  90. //the following line is needed to jump back
  91. bx lr
  92.  
  93. .global determine_lights
  94. determine_lights:
  95.  
  96. LDR R1,=bus
  97. LDR R2,[R1]
  98. LDRH R2,[R2]
  99.  
  100. cmp R2,#4
  101. bne else1
  102. LDR R0,=pattern001
  103. b call
  104.  
  105. else1: cmp R2,#1
  106. bne else2
  107. LDR R0,=pattern010
  108. b call
  109.  
  110. //mov R2,#2
  111.  
  112. else2:
  113. LDR R0,=pattern100
  114.  
  115.  
  116. //subs R13,R13, #4
  117. call:
  118. push {lr}
  119.  
  120.  
  121. bl switch_lights
  122.  
  123. pop {lr}
  124.  
  125. //ldr R14, [R13]
  126. //add R13,R13,#4
  127. //MOV R2,#4
  128.  
  129. bx lr
  130.  
  131.  
  132. //data section
  133. .data
  134. //make symbols global
  135. .global pattern001
  136. .global pattern010
  137. .global pattern100
  138. .align 4 //align to word boundary
  139. pattern001:
  140. .byte 0b00000001
  141. .align 4 //align to word boundary
  142. pattern010:
  143. .byte 0b00000010
  144. .align 4 //align to word boundary
  145. pattern100:
  146. .byte 0b00000100
  147.  
  148. ______________________________________________________
  149.  
  150. /*
  151. * main.c
  152. *
  153. * Created on: May 9, 2018
  154. * Author: roehrig
  155. */
  156.  
  157.  
  158. #include <stdio.h>
  159. #include "platform.h"
  160. #include <xil_printf.h>
  161.  
  162. #include "libmps.h" // For all lib_mps functions
  163. #include <mps_bridge.h> // For MPS bridge
  164.  
  165. #include <sleep.h>
  166. #include "xttcps.h"
  167. #include "xscugic.h"
  168. #include "xgpio.h"
  169.  
  170. #define MPS_BRIDGE_PTR (XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR)
  171. #define AXI_GPIO_PTR (XPAR_AXI_GPIO_0_BASEADDR)
  172. u16 *bus = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
  173. u16 *gpio = XPAR_MPS_BRIDGE_0_S_AXI_BASEADDR;
  174.  
  175. unsigned int state= 0;
  176. unsigned int a= 0;
  177.  
  178. extern int interrupt_flag_0; // External definition of interrupt_flag_0 for interrupt port 0
  179.  
  180. int main()
  181. {
  182. init_platform();
  183. init_ext_interrupt();
  184. init_PWM();
  185. init_axi_gpio();
  186. start_PWM (1000, 0);
  187.  
  188. while(1)
  189. {
  190. //read_var = *bus;
  191.  
  192. //xil_printf(" 1, before if buttons value:%d and a:%d \r \n", BUTTONS_value(),a);
  193. if((BUTTONS_value()==1)&&(state==0)){
  194. //xil_printf(" 2, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  195. state=1;
  196. //xil_printf(" 3, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  197. if(a!=1000){
  198. //xil_printf(" 4, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  199. a=a+100;
  200. //xil_printf(" 5, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  201. start_PWM (1000, a );
  202. //xil_printf(" 6, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  203. usleep(1000);
  204. //xil_printf(" 7, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  205. }}
  206.  
  207. else if((BUTTONS_value()==2)&&(state==0)){
  208. //xil_printf(" 8, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  209. state=1;
  210. //xil_printf(" 9, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  211. if(a!=0){
  212. //xil_printf(" 10, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  213. a=a-100;
  214. //xil_printf(" 11, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  215. start_PWM (1000, a);
  216. //xil_printf(" 12, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  217. usleep(1000);
  218. //xil_printf(" 13, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  219. }
  220. }
  221. else if((BUTTONS_value()==0)&&(state==1)){
  222. //xil_printf(" 14, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  223. state=0;
  224. //xil_printf(" 15, buttons value:%d and a:%d state:%d \r \n", BUTTONS_value(),a,state);
  225. }
  226.  
  227. }
  228. }
  229. ____________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement