Exemplo n.º 1
0
int modbus_mst_run(modbus_channel_s *modbus_channel)
	{

	USART_InitTypeDef USART_InitStructure;


	if (!modbus_channel)
		return -1;


	USART_InitStructure.USART_BaudRate = 57600;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;


	serial_port_init(modbus_channel->chno, &USART_InitStructure);
	serial_port_rx_timeout_set(modbus_channel->chno, 10000);

	vSemaphoreCreateBinary(modbus_channel->ctrl_sem);
	xSemaphoreTake(modbus_channel->ctrl_sem, 0);
	


	xTaskCreate(modbus_mst_thread, (signed char *)"mdb", configMINIMAL_STACK_SIZE, (void *)modbus_channel, USART_RX_TASK_PRIORITY, NULL);

	return 0;
	}
Exemplo n.º 2
0
int main(int argc, char*argv){
	int fd, wnbytes, rnbytes;
	char buffer[2200];
        char *bufptr;
        
	// open and configure port
	if((fd=serial_port_init(PORT, RATE))<0){
		printf("Cannot open port and set port attributes\n");
	}

	// test port send "??" and wait for the reply - eDVS CLI menu
	printf("--------------------------------\n");
	printf("WRITE: \n ??\n");
	wnbytes = write(fd, "??\n", 3);
	if (wnbytes < 0)
	  printf("write() failed!\n");

	 // read characters into our string buffer
    	bufptr = buffer;
    	while ((rnbytes = read(fd, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0){
	      bufptr += rnbytes;
       }
       
       // nul terminate the string and print it
      *bufptr = '\0';
       printf("--------------------------------\n");
       printf("READ: \n %s\n", buffer);
       
      return EXIT_SUCCESS;
}
Exemplo n.º 3
0
void serial_log_init() {
    serial_port_init(PORT_COM1);

    log_add_writer(serial_log_com1, "serial-log");
    log_set_level("serial-log", Trace);
}
Exemplo n.º 4
0
/**
 * \brief Main application
 */
int main(void)
{
	char test_file_name[] = "0:sd_image.bin";
	FRESULT res;
	FATFS fs;
	FIL file_object;
	uint32_t len=0;
	uint32_t curr_prog_addr=APP_START_ADDRESS;
	struct nvm_config config;
	UINT iRead=0;
    
	check_boot_mode();
	system_init();
	delay_init();

	irq_initialize_vectors();
	cpu_irq_enable();

	/* Initialize SD MMC stack */
	sd_mmc_init();
	
	nvm_get_config_defaults(&config);
	nvm_set_config(&config);
		/* Turn ON  LED */
	port_pin_set_output_level(BOOT_LED, false);
#ifdef __DEBUG_PRINT__	
    serial_port_init();
	printf("\x0C\n\r-- SD/MMC Card FatFs Boot Loader --\n\r");
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
	printf("Please plug an SD/MMC card in slot.\n\r");
#endif	

		/* Wait card present and ready */
	sd_mmc_ready();
	memset(&fs, 0, sizeof(FATFS));
	res = f_mount(LUN_ID_SD_MMC_0_MEM, &fs);
	if (FR_INVALID_DRIVE == res) {
		#ifdef __DEBUG_PRINT__	
		printf("[FAIL] Mounting SD card failed result= %d\r\n", res);
		#endif
			
	}
	#ifdef __DEBUG_PRINT__	
	printf("Mounting the SD card successful...\r\n");
	#endif
   
	res =f_open(&file_object,(const char *)test_file_name,FA_READ);
	if(res != FR_OK) error_fatal(FILE_OPEN_ERROR);
	do {
		if(file_object.fsize > MAX_CODE_SIZE) error_fatal(MAX_SIZE_ERROR);
		res = f_read(&file_object, (void *) buff, MAX_BUF_SIZE, &iRead);
		if(res != FR_OK) error_fatal(FILE_READ_ERROR);
	
		/* Program the read data into Flash */
		if(iRead)
		{
			program_memory(curr_prog_addr, buff,iRead);
			#ifdef __DEBUG_PRINT__
			printf("*");
			#endif
		}

		/* Increment the current programming address */
		curr_prog_addr += iRead;
		len += iRead;
	
		if(len > MAX_CODE_SIZE)
		error_fatal(MAX_SIZE_ERROR);

		/* Do this till end of file */
	} while (iRead != 0);

#ifdef __DEBUG_PRINT__		
printf("\r\n[PROGRAMMING COMPLETED]..Resetting !!!!\r\n");
#endif
		// Intentionally not closing the file object to reduce code size !!!.
		start_application();
		while(1);
		 // Should have reset by now !!!.		
}