Browse Source

C-Dateien

jakob 5 years ago
parent
commit
157061caed
4 changed files with 100 additions and 0 deletions
  1. 2 0
      C_Source/dest.hex
  2. 83 0
      C_Source/prog.c
  3. BIN
      C_Source/prog.o
  4. 15 0
      C_Source/source.hex

+ 2 - 0
C_Source/dest.hex

@@ -0,0 +1,2 @@
+100000000C9434000C9400000C9400000C9400003C
+100010000C9400000C940

+ 83 - 0
C_Source/prog.c

@@ -0,0 +1,83 @@
+//Define Constants---------------------------------------------------
+#define USB_PORT /dev/ttyACM3
+#define PAGESIZE 64
+
+//Include Header Files-----------------------------------------------
+#include<stdlib.h>
+#include<stdio.h>
+#include<time.h>
+#include<errno.h>
+#include<unistd.h>
+#include<termios.h>
+#include<sys/types.h>
+#include<sys/stat.h>
+#include<fcntl.h>
+#include<sys/resource.h>
+
+//Prototypes---------------------------------------------------------
+void delay(int delay_time);
+void print_attrTermios(struct termios * ptr_attr);
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//Main-Program
+int main(int argc, const char * argv[]){
+
+//initializing USART at USB_PORT-------------------------------------
+	int USB = open("/dev/ttyACM3", O_RDWR|O_NOCTTY);
+	if(isatty(USB)==0){
+		printf("ERROR: No File Descriptor! \n");
+		return 0;
+	}
+	struct termios * ptr_attr = (struct termios *)
+									malloc(sizeof(struct termios));
+	if(ptr_attr==NULL){
+		printf("ERROR: Termios not available \n");
+		return 0;
+	}
+	tcgetattr(USB, ptr_attr);
+	(*ptr_attr).c_iflag = IGNPAR;
+	(*ptr_attr).c_oflag = 0;
+	(*ptr_attr).c_cflag = CS8|CREAD;
+	(*ptr_attr).c_lflag = 0;
+	cfsetspeed(ptr_attr, B19200);
+	tcsetattr(USB, TCSANOW ,ptr_attr);
+	delay(1000);
+
+//Establishing  Connection-------------------------------------------
+	char req[] = "REQ";
+	char ack[] = "ACK";
+	char * ptr_ack = &ack[0];
+	char * ptr_input = (char *)malloc(3*sizeof(char));
+		char * ptr_req = &req[0];
+		while(1){
+			write(USB, ptr_req, 3*sizeof(char));
+//			tcflush(USB, TCIFLUSH);
+			read(USB, ptr_input, 3*sizeof(char));
+//			tcflush(USB, TCOFLUSH);
+			printf("%s \n", &ptr_input[0]);
+		}
+		//delay(100);
+	close(USB);
+	return EXIT_SUCCESS;
+}	
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+//Delay-Function-----------------------------------------------------
+void delay(int delay_time){
+	clock_t time1 = clock();
+	while(((clock()-time1)/CLOCKS_PER_SEC)*1000
+			 							!= (clock_t)delay_time);
+}
+
+//Print Termios-Attributes-------------------------------------------
+void print_attrTermios(struct termios * ptr_attr){
+	printf("Input Mode Flag: %d \n", (*ptr_attr).c_iflag);
+	printf("Output Mode Flag: %d \n", (*ptr_attr).c_oflag);
+	printf("Control Mode Flag: %d \n", (*ptr_attr).c_cflag);
+	printf("Local Mode Flag: %d \n", (*ptr_attr).c_lflag);
+	printf("Baudrate Input: %d \n", (*ptr_attr).c_ispeed);
+	printf("Baudrate Output: %d \n", (*ptr_attr).c_ospeed);
+}

BIN
C_Source/prog.o


+ 15 - 0
C_Source/source.hex

@@ -0,0 +1,15 @@
+100000000C9434000C9400000C9400000C9400003C
+100010000C9400000C9400000C9400000C94000060
+100020000C9400000C9400000C9400000C94000050
+100030000C9400000C945C000C9400000C940000E4
+100040000C9400000C9400000C9400000C94000030
+100050000C9400000C9400000C9400000C94000020
+100060000C9400000C9400000FEF0DBF08E00EBFD1
+1000700010E02FEF27B90E943F007894FFCF0F9335
+100080001093800002E0009381001093820001E051
+1000900000936F001093000101E0009301010F91A4
+1000A00008950F930091010108B9000F06FD01E0CA
+1000B000009301010F9108950F93009100010395A2
+1000C000033019F40E9451000027009300010F91A2
+0200D000189581
+00000001FF