Beispiel #1
0
int rs232_SendByte (U1 *pthreads_ptr, U1 *varlist_ptr, U1 *vm_mem_ptr, S4 threadnum, S8 stacksize)
{
	S8 portnumber;
	S8 retvar_index;
	S8 ret;
	S8 byte;
	U1 byte_b;

	struct pthreads *pthreads;
	struct varlist *varlist;
	struct vm_mem *vm_mem;
	
	pthreads = (struct pthreads *) pthreads_ptr;
	varlist = (struct varlist *) varlist_ptr;
	vm_mem = (struct vm_mem *) vm_mem_ptr;

	if (stpull_l (threadnum, pthreads, stacksize, &retvar_index) != ERR_STACK_OK) printf ("rs232_SendByte: stack error!\n");
	if (stpull_l (threadnum, pthreads, stacksize, &byte) != ERR_STACK_OK) printf ("rs232_SendByte: stack error!\n");
	if (stpull_l (threadnum, pthreads, stacksize, &portnumber) != ERR_STACK_OK) printf ("rs232_SendByte stack error!\n");
	
	byte_b = byte;
	ret = RS232_SendByte (portnumber, byte_b);

	var_lock (varlist, retvar_index);
	if (! let_2array_qint (varlist, vm_mem, ret, retvar_index, 0)) printf ("rs232_SendByte: return value array overflow!\n");
	var_unlock (varlist, retvar_index);
	
	return (0);
}
void programByte(uint8_t dat)
{
	uint8_t datr;
again:
	RS232_SendByte(24,dat);
	RS232_PollComport(24,&datr,1);
	if (datr!='N')
		printf("Error programming byte letter code '%c'\n",datr);
}
void changeInput(int cport_nr, char commands[32][13], int inputToSelect, int tvToSelect){
	int i=0;
	while(i < 13){
		RS232_SendByte(cport_nr, commands[(tvToSelect * 4) + inputToSelect][i]);
		usleep(30000);		// 30 microseconds (ms)
		i++;
	}
    printf("Select input %d for TV %d.\n", inputToSelect+1, tvToSelect+1);
}
void FPGAFitnessCalculator::enviar_individuo(int comport_num,
        const Cromossomo& individuo) {
    RS232_SendByte(comport_num, (unsigned char) SET_CIRCUIT);

    auto descricao_les = individuo.descricao_les();
    auto descricao_outs = individuo.descricao_outs();

    RS232_SendBuf(comport_num, &descricao_les[0], descricao_les.size());
    RS232_SendBuf(comport_num, &descricao_outs[0], descricao_outs.size());
}
Beispiel #5
0
/*====================================================================================================*/
void UART0_IRQHandler( void )
{
  u8 RecvData = 0;

  RS232_RecvByte(&RecvData);
  if(RecvData == 0x0D)
    RS232_SendStr((u8*)"\r\n");
  else
    RS232_SendByte(RecvData);
}
Beispiel #6
0
void test_uartLoopback_should_echo_bytes_sent(void){
	char buffer[256], *dataPtr = buffer;
	
	RS232_OpenComport(COMPORT, baudrate);
	RS232_SendByte(COMPORT,'H');
	*(dataPtr++) = RS232_ReadByte(COMPORT);
	RS232_SendByte(COMPORT,'e');
	*(dataPtr++) = RS232_ReadByte(COMPORT);
	RS232_SendByte(COMPORT,'l');
	*(dataPtr++) = RS232_ReadByte(COMPORT);
	RS232_SendByte(COMPORT,'l');
	*(dataPtr++) = RS232_ReadByte(COMPORT);
	RS232_SendByte(COMPORT,'o');
	*(dataPtr++) = RS232_ReadByte(COMPORT);
	*(dataPtr++) = '\0';
	RS232_CloseComport(COMPORT);
	
	TEST_ASSERT_EQUAL_STRING("Hello",buffer);
	
}
/*====================================================================================================*/
void USART1_IRQHandler( void )
{
  uint8_t RecvData = 0;

  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
    RecvData = RS232_RecvByte();
    if(RecvData == 0x0D)
      RS232_SendStr((int8_t*)"\r\n");
    else
      RS232_SendByte(RecvData);
  }
  USART_ClearFlag(USART1, USART_IT_RXNE);
}
std::vector<std::vector<std::bitset<8>>> FPGAFitnessCalculator::receive_data(
    int comport_num) {
    unsigned char buffer[4096];
    std::vector<std::vector<std::bitset<8>>> results;

    for (int i = 0; i < (int) pow(2, genetic_params.num_in); i++) {
        unsigned int total = 0;
        RS232_SendByte(comport_num, (unsigned char) SET_VALUE);
        RS232_SendByte(comport_num, (unsigned char) i);
        results.emplace_back(std::vector<std::bitset<8>>());

        Timer timeout_timer;
        timeout_timer.start(1000);
        while (total < num_samples) {
            timeout_timer.update();
            if (timeout_timer.isDone()) {
                std::cout << "TIMEOUT Detectado com " << total << " amostras coletadas." << std::endl;
                std::cout << "Replicando a ultima amostra." << std::endl;
                for (unsigned int j = total; j < num_samples; j++) {
                    results[i].emplace_back(results[i][total - 1]);
                }
                break;
            }
            int n = RS232_PollComport(comport_num, buffer, 4096);
            if (n != 0) { // Se dados foram recebidos
                timeout_timer.start(1000);
            }
            for (int j = 0; j < n; j++, total++) {
                results[i].emplace_back(std::bitset<8>(buffer[j]));
            }
        }

        Sleep(100);
    }

    return results;
}
Beispiel #9
0
//------------------------------------------------------------------------------
void ShowOutMessage()
{
 u08 i;

 AVC_HoldLine();
 
 RS232_S((u16)PSTR("out > "));
 for (i=0; i<data_len; i++) {
	RS232_PrintHex8(data[i]);
	RS232_SendByte(' ');
 }
 RS232_Print("\n");

 AVC_ReleaseLine();
}
Beispiel #10
0
int main(void){
	int i;
	char charReceived, char2Send = 0;
	printf("Test UART, ready to receive character!!!\n");
	RS232_OpenComport(COMPORT, baudrate);
	char2Send = getch();
	while(char2Send != ESC_KEY){
		RS232_SendByte(COMPORT, char2Send);
		charReceived = RS232_ReadByte(COMPORT);
		printf("%c", charReceived);
		char2Send = getch();
	}
	if(char2Send == ESC_KEY)
		printf("BYE\n");
	RS232_CloseComport(COMPORT);
}
Beispiel #11
0
// -------------------------------------------------------------------------------------
//	MAIN PROGRAM
//
int main()
{

 u08 readSeq 	= 0;
 u08 s_len	= 0;
 u08 s_dig	= 0;
 u08 s_c[2];
 u08 i;
 u08 data_tmp[32];

 Setup();
 
 RS232_S((u16)PSTR("AVCLan reader 1.00\nReady\n\n"));
 LED_OFF();
 RS232_S((u16)PSTR("T - device id\n"));
 RS232_S((u16)PSTR("H - HU id\n"));
 RS232_S((u16)PSTR("S - read sequence\n"));
 RS232_S((u16)PSTR("W - send command\n"));
 RS232_S((u16)PSTR("Q - send broadcast\n"));
 RS232_S((u16)PSTR("L/l - log on/off\n"));
 RS232_S((u16)PSTR("K/k - seq. echo on/off\n"));
 RS232_S((u16)PSTR("R/r - register device\n"));
 
 while (1) {

	if (INPUT_IS_SET) {	 // if message from some device on AVCLan begin
		//LED_ON();
  		AVCLan_Read_Message();
		// show message
	} else {
		//LED_OFF();
		// check command from HU
		if (answerReq != 0) AVCLan_SendAnswer();
	}

	// HandleEvent
	switch (Event) {
	  case EV_STATUS:	Event &= ~EV_STATUS;
						AVCLan_Send_Status();
						break;
	}


	// Key handler
	if (RS232_RxCharEnd) {
		cbi(UCSR0B, RXCIE0);				// disable RX complete interrupt
		readkey = RS232_RxCharBuffer[RS232_RxCharBegin];// read begin of received Buffer
		RS232_RxCharBegin++;
		if (RS232_RxCharBegin == RS232_RxCharEnd)	// if Buffer is empty
			RS232_RxCharBegin = RS232_RxCharEnd = 0;// do reset Buffer
		sbi(UCSR0B, RXCIE0);				// enable RX complete interrupt
		switch (readkey) {
			case 'T':	if (readSeq) {
						  CD_ID_1 = data_tmp[0];
						  CD_ID_2 = data_tmp[1];
						  RS232_Print("DEV ID SET: 0x");
						  RS232_PrintHex8(CD_ID_1);
						  RS232_PrintHex8(CD_ID_2);
						  RS232_Print("\n");
						  showLog = 1;	
						  readSeq=0;
						} else {
						  showLog = 0;
						  RS232_Print("DEV ID SET: 0x");
						  RS232_PrintHex8(CD_ID_1);
						  RS232_PrintHex8(CD_ID_2);
						  RS232_Print("\n");
						  RS232_Print("DEV ID > \n");
						  readSeq = 1;
						  s_len=0;
						  s_dig=0;
						  s_c[0]=s_c[1]=0;
						}
						break;

			case 'H':	if (readSeq) {
						  HU_ID_1 = data_tmp[0];
						  HU_ID_2 = data_tmp[1];
						  RS232_Print("HU ID SET: 0x");
						  RS232_PrintHex8(HU_ID_1);
						  RS232_PrintHex8(HU_ID_2);
						  RS232_Print("\n");
						  showLog = 1;	
						  readSeq=0;
						} else {
						  showLog = 0;
						  RS232_Print("HU ID SET: 0x");
						  RS232_PrintHex8(HU_ID_1);
						  RS232_PrintHex8(HU_ID_2);
						  RS232_Print("\n");
						  RS232_Print("HU ID > \n");
						  readSeq = 1;
						  s_len=0;
						  s_dig=0;
						  s_c[0]=s_c[1]=0;
						}
						break;

			case 'S':	showLog = 0;
						RS232_Print("READ SEQUENCE > \n");
						readSeq = 1;
						s_len=0;
						s_dig=0;
						s_c[0]=s_c[1]=0;
						break;
			case 'W' :  showLog = 1;
						readSeq=0;
						AVCLan_SendMyData(data_tmp, s_len);
						break;
			case 'Q' :  showLog = 1;
						readSeq=0;
						AVCLan_SendMyDataBroadcast(data_tmp, s_len);
						break;


			case 'R':	RS232_Print("REGIST:\n");
						AVCLan_Command( cmRegister );
 						_delay_us(15);
 						CHECK_AVC_LINE;
						break;
			case 'r':	AVCLan_Register();
						break;


			case 'l':	RS232_Print("Log OFF\n");
						showLog = 0;
						break;
			case 'L':	RS232_Print("Log ON\n");
						showLog = 1;
						break;

			case 'k':	RS232_Print("str OFF\n");
						showLog2 = 0;
						break;
			case 'K':	RS232_Print("str ON\n");
						showLog2 = 1;
						break;

			default :
				if (readSeq==1) {
					s_c[s_dig]=readkey;
				
					s_dig++;
					if (s_dig==2) {
						if (s_c[0]<':') s_c[0] -= 48;
								   else s_c[0] -= 55;
						data_tmp[s_len] = 16 * s_c[0];
						if (s_c[1]<':') s_c[1] -= 48;
								   else s_c[1] -= 55;
						data_tmp[s_len] += s_c[1];
						s_len++;
						s_dig=0;
						s_c[0]=s_c[1]=0;
					}
					if (showLog2) {
						RS232_Print("CURREENT SEQUENCE > ");
						for (i=0; i<s_len; i++) {
								RS232_PrintHex8(data_tmp[i]);
								RS232_SendByte(' ');
						}
						RS232_Print("\n");
					}
				}
		} // switch (readkey)

	}// if (RS232_RxCharEnd)

 }
 return 0;
}
Beispiel #12
0
void RS232_cputs(int comport_number, const char *text)  /* sends a string to serial port */
{
  while(*text != 0)   RS232_SendByte(comport_number, *(text++));
}
Beispiel #13
0
// Write a byte
bool CCPCBooster::WriteByte(const unsigned char val)
{
  return RS232_SendByte(_COMPortHandle, val) == 0;
}
int main(int argc,char ** argv)
{
	uint8_t dump=0;
	if (argc!=2&&argc!=3){
		help();
		return 1;
	}
	else if(argc==3){
		if(strcmp("-d",argv[2])==0)
			dump=1;
		else{
			printf("To specify dumping you need to use -d but you did %s instead\nThis program will show help and exit\n",argv[2]);
			help();
			return 1;
		}
	}
	if(RS232_OpenComport(24,500000)){
		puts("Com-port 24 could not be opened");
		return 1;
	}
	waitRDY();
	RS232_SendByte(24,'R');
	if(dump)
		RS232_SendByte(24,'R');
	else
		RS232_SendByte(24,'W');
	waitRDY();
	uint8_t id,manid;
	RS232_PollComport(24,&manid,1);
	printf("Manufacture ID: 0x%X\nDetcted as: ",manid);
	if(manid==0xBF)
			puts("SST/microchip");
	else
		puts("Unkown manufacturer");
	RS232_PollComport(24,&id,1);
	printf("Device ID: 0x%X\n",id);
	uint32_t capcity=524288;
	switch(id){
		case 0xB5:
			puts("SST39SF010A");
			capcity=131072;
		case 0xB6:
			puts("SST39SF020A");
			capcity=262144;
		break;
		case 0xB7:
			puts("SST39SF040");
			capcity=524288;
		break;
		default:
			puts("ERROR: cannot deterim chip capacity defaulting to 524288");
		break;
	}
	FILE* fp;
	uint8_t* dat;
	if(!dump){
		fp=fopen(argv[1],"rb");
		fseek(fp, 0L, SEEK_END);
		size_t size = ftell(fp);
		if (size > capcity){
			puts("Your file is too large");
			fclose(fp);
			return 1;
		}
		rewind(fp);
		dat=calloc(1,capcity);
		if (dat==0){
			puts("Error allocating memory");
			fclose(fp);
			return 1;
		}
		fread(dat,1,size,fp);
		fclose(fp);
		RS232_PollComport(24,&id,1);
		//putchar(id);//should be upercase 'D'
		if(id!='D'){
			puts("An error has occuring exiting...");
			free(dat);
			return 1;
		}
		putchar('\n');
		RS232_PollComport(24,&id,1);
		if (id == 'S')
			puts("Chip is erased");
		else{
			printf("Error erasing chip code %c\n",id);
			free(dat);
			return 1;
		}
	}else
		fp=fopen(argv[1],"wb");	
	//now program the chip
	putchar('\n');
	uint32_t x;
	for (x=0;x<capcity;++x){
		uint8_t data;
		if(dump){
			RS232_PollComport(24,&data,1);
			fputc(data,fp);
		}else{
			programByte(dat[x]);
			RS232_PollComport(24,&data,1);
			if (data!=dat[x])
				printf("Byte %d at address %d should be %d\n\n",data,x,dat[x]);
		}
		printf("Progress : %% %f\r",(float)x/(float)capcity*100.0);
	}
	if(dump)
		fclose(fp);
	free(dat);
	return 0;
}
Beispiel #15
0
void test_RS232_OpenComport(void){
	RS232_OpenComport(COMPORT,baudrate);
	RS232_SendByte(COMPORT,0x85);
	RS232_CloseComport(COMPORT);
}
Beispiel #16
0
void test_RS232_OpenComport(void) {
  RS232_OpenComport(2, 9600);
  RS232_SendByte(2, 0x6a);
  RS232_CloseComport(COMPORT);
}