Browse Source

C-Source, USART

jakob 5 years ago
parent
commit
438b7fa210
5 changed files with 119 additions and 0 deletions
  1. 2 0
      Source/C_Source/dest.hex
  2. 49 0
      Source/C_Source/prog.c
  3. 53 0
      Source/C_Source/prog.h
  4. BIN
      Source/C_Source/prog.o
  5. 15 0
      Source/C_Source/source.hex

+ 2 - 0
Source/C_Source/dest.hex

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

+ 49 - 0
Source/C_Source/prog.c

@@ -0,0 +1,49 @@
+//Include Header-----------------------------------------------------
+#include"prog.h"
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//Main-Program
+
+int main(int argc, const char * argv[]){
+
+	delay(1000);		//delete me!!
+
+//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 * termios_ptr = (struct termios *)
+									malloc(sizeof(struct termios));
+	if(termios_ptr==NULL){
+		printf("ERROR: Termios not available! \n");
+		return 0;
+	}
+	(*termios_ptr).c_iflag = IGNPAR;			//ignore Parity-Err
+	(*termios_ptr).c_oflag = 0;
+	(*termios_ptr).c_cflag = CS8|CREAD;			//set Size, enable RX 
+	(*termios_ptr).c_lflag = 0;
+//	(*termios_ptr).c_cc[VMIN] = 2;				//set min Characters
+//	(*termios_ptr).c_cc[VTIME] = 0.1;			//Timeout after 10ms
+	cfsetspeed(termios_ptr, B19200);			//set Baudrate 19.2k
+	tcsetattr(USB, TCSANOW ,termios_ptr);
+
+//Get Command--------------------------------------------------------
+	cmd_t * cmd_ptr = cmd_build(page_read, 0xFF);
+	char * frame_ptr = &((*cmd_ptr).mode);
+	for(int i=0; i<3; i++, frame_ptr++){
+		write(USB, frame_ptr, sizeof(char));
+		tcflush(USB, TCIFLUSH);
+	}
+//	frame_ptr = &frame[0];
+//	read(USB, frame_ptr, sizeof(frame));
+//	tcflush(USB, TCOFLUSH);
+	close(USB);
+	return EXIT_SUCCESS;
+}	
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+

+ 53 - 0
Source/C_Source/prog.h

@@ -0,0 +1,53 @@
+//Inculde Header Files-----------------------------------------------
+#include<stdlib.h>
+#include<stdio.h>
+#include<time.h>
+#include<unistd.h>
+#include<termios.h>
+#include<sys/types.h>
+#include<sys/stat.h>
+#include<fcntl.h>
+#include<sys/resource.h>
+
+//Enumerations-------------------------------------------------------
+typedef enum {false, true} bool; 
+typedef enum {fuse_read,
+		      fuse_write,
+		      page_read,
+		  	  page_write,
+		  	  prog_check} mode;
+
+//Constants----------------------------------------------------------
+#define nibble_lo 0x0F
+#define nibble_hi 0xF0
+#define frame_mask 0x90
+
+//Structs------------------------------------------------------------
+typedef struct {
+	char mode;
+	char opt_lo;
+	char opt_hi;
+} cmd_t;
+
+//Protoypes----------------------------------------------------------
+cmd_t * cmd_build(mode cmd_mode, char cmd_option);
+void delay(int delay_time);
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//Build Command
+cmd_t * cmd_build(mode cmd_mode, char cmd_option){
+	cmd_t * cmd_ptr = (cmd_t *)malloc(sizeof(cmd_t));
+	(*cmd_ptr).mode = frame_mask|cmd_mode;
+	(*cmd_ptr).opt_lo = frame_mask|(cmd_option&nibble_lo);
+	(*cmd_ptr).opt_hi = frame_mask|((4>>cmd_option)&nibble_lo);
+	return cmd_ptr;
+}
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+//Delay in ms
+
+void delay(int delay_time){
+	clock_t time1 = clock();
+	while(((clock()-time1)/CLOCKS_PER_SEC)*1000
+			 							!= (clock_t)delay_time);
+}

BIN
Source/C_Source/prog.o


+ 15 - 0
Source/C_Source/source.hex

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