Ejemplo n.º 1
0
// write len bytes to serial
void writeData(byte *bData, int len)
{
    while (len-- > 0)
    {
        uart1_putc(*bData++);
    }
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART1---------------------------------//
//------------------------------------------------------------------------------------------------//
void uart1_puts(char *p)
{
    while(*p) // Point to character
    {
        uart1_putc(*p++);   // Send character then point to next character
    }
}
Ejemplo n.º 3
0
static int _uart1_putc(char c, FILE* stream) {
    if (c == '\n') {
        _uart1_putc('\r', NULL);
    }
    uart1_putc(c);
    return 0;
}
Ejemplo n.º 4
0
Archivo: uart.c Proyecto: thaigiang/VMS
//=======================================================
void uart1_putROMString(rom char* str)
{
    unsigned char c;
    while( c = *str++ )
	{
		while(!TXSTA1bits.TRMT);
        uart1_putc(c);
	}
}
Ejemplo n.º 5
0
Archivo: uart.c Proyecto: thaigiang/VMS
//=======================================================
void uart1_putString(unsigned char *s)
{
    unsigned char c;

    while( (c = *s++) )
	{
		while(!TXSTA1bits.TRMT);
        uart1_putc(c);
	}
}
Ejemplo n.º 6
0
void main(void) {

	uart1_init(INC,MOD,SAMP);
	
	while(1) {
		if(uart1_can_get()) {
			/* Receive buffer isn't empty */
			/* read a byte and write it to the transmit buffer */
			uart1_putc(uart1_getc());
		}
	}
	
}
Ejemplo n.º 7
0
int uart1_putc(char c) {
	if (c == '\n')
		uart1_putc('\r');
    while (CY_GET_REG8(CYDEV_ITM_BASE) == 0);
    CY_SET_REG8(CYDEV_ITM_BASE,c);
#ifndef MINIMALISTIC
	// Copy to buffer if there's at least one byte available
	// (write ptr is >= readptr or write ptr is < readptr-1)
	if((log_ring_write>=log_ring_read) || ((log_ring_write<(log_ring_read-1)) && (log_ring_read!=0))) {
		log_ring[log_ring_write]=c;
		log_ring_write++;
		if(log_ring_write==LOGRINGSIZE) log_ring_write=0;
	}
#endif
	return 0;
}
Ejemplo n.º 8
0
int main(void)
{
	char byte;
	uint32_t i;

	rtc_init_osc(1);

	default_vreg_init();
	uart_init(INC, MOD, SAMP);

	for (i = 0; i < 0x14000; i++) {
		memcpy(&byte, (void *)i, 1);
		uart1_putc(byte);
		//rtc_delay_ms(1);
	}
	while (1) ;
}
Ejemplo n.º 9
0
/*
 *    This task will send "." directly to uart1 once every 2 seconds.
 */
static void vTickTask( void *pvParameters )
{
	/* Used to wake the task at the correct frequency. */
	portTickType xLastExecutionTime; 

	uart1_puts("Tick task initializing...");
	uart1_puts("done\n\r");
	
	/* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
	works correctly. */
	xLastExecutionTime = xTaskGetTickCount();

	for( ;; )
	{
		/* Wait until it is time for the next cycle. */
		vTaskDelayUntil( &xLastExecutionTime, ( ( portTickType ) 2000 / portTICK_RATE_MS ) );

		uart1_putc('.');
	}
}
Ejemplo n.º 10
0
static void parse_buffer( void ) {
     Channel_t ch_data[4];
     uint8_t  ch  = 0;
     uint8_t  res = 0;
     uint32_t val = 0;
     rtc_clock_t datetime;

     int year, month, date, hour, min, sec;


     switch( buffer[0] ) {
	  
     case '.':
	  printf_P( PSTR("%s\r\n"), buffer );
	  break;

     case '*':
	  uart1_puts( buffer+1 );
	  uart1_putc( 13 );
	  break;

     case 'V':
     case 'v':
	  printf_P( PSTR("%d.%d\r\n"), SWVERSIONMAJOR, SWVERSIONMINOR );
	  break;

     case 'L':
     case 'l':
	  printf_P( PSTR("%02X\r\n"), PINA );
	  break;

     case 'A':
     case 'a':

	  printf_P( PSTR("%i, %i, %i, %i\r\n"), 
		    adc_get_ch(0),
		    adc_get_ch(1),
		    adc_get_ch(2),
		    adc_get_ch(3)
	       );
	  
	  break;

     case 'c':


	  res = sscanf_P( &buffer[1], PSTR ("20%2x-%2x-%2x %2x:%2x:%2x"), &year, &month, &date, &hour, &min, &sec);

	  // set clock?
	  if (res==6) {
/*
	       printf_P( PSTR(" setting to: 20%02X-%02X-%02X %02X:%02X:%02X\r\n"), 
			 year,
			 month,
			 date,
			 hour,
			 min,
			 sec
		    );
*/

	       datetime.year  = year;
	       datetime.month = month;
	       datetime.date  = date;
	       datetime.hour  = hour;
	       datetime.min   = min;
	       datetime.sec   = sec;
	  
	       rtc_write_clock( &datetime );

	  }
	  
	  rtc_read_clock( &datetime );
	  
	  printf_P( PSTR("20%02X-%02X-%02X %02X:%02X:%02X\r\n"), 
		    datetime.year,
		    datetime.month,
		    datetime.date,
		    datetime.hour,
		    datetime.min,
		    datetime.sec
	       );


	  break;

     case 'C':

	  val = ms_now();
	  
	  printf_P( PSTR("%lu msec\r\n"), val );
	  
	  break;

	  
     case 'T':
     case 't':

	  s0_getChannelData( 0, &ch_data[0], 0 );
	  s0_getChannelData( 1, &ch_data[1], 0 );
	  s0_getChannelData( 2, &ch_data[2], 0 );
	  s0_getChannelData( 3, &ch_data[3], 0 );
	  
	  printf_P( PSTR("%lu, %lu, %lu, %lu\r\n"), 
		    ch_data[0].count, 
		    ch_data[1].count, 
		    ch_data[2].count, 
		    ch_data[3].count 
	       );
	  
	  break;

     case 'P':
     case 'p':

	  s0_getChannelData( 0, &ch_data[0], 0 );
	  s0_getChannelData( 1, &ch_data[1], 0 );
	  s0_getChannelData( 2, &ch_data[2], 0 );
	  s0_getChannelData( 3, &ch_data[3], 0 );

	  printf_P( PSTR("%lu, %lu, %lu, %lu\r\n"), 
		    ch_data[0].period,
		    ch_data[1].period, 
		    ch_data[2].period,
		    ch_data[3].period
	       );
	  
	  break;

     case 'r':
     case 'R':

	  switch( buffer[1] ) {
	       
	  case '1':
	  case 'B':
	  case 'b':
	       ch = 1;
	       break;
	       
	  case '2':
	  case 'C':
	  case 'c':
	       ch = 2;
	       break;
	       
	  case '3':
	  case 'D':
	  case 'd':
	       ch = 3;
	       break;
	       
	  default:
	       ch = 0;
	       
	  }

	  s0_getChannelData( ch, &ch_data[0], (buffer[0] == 'R') );
	  
	  printf_P( PSTR("%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\r\n"), 
		     ms_now(),
		     ch_data[0].count,   // 1
		     ch_data[0].pcount,  // 2
		     ch_data[0].period,  // 3
		     ch_data[0].avg_cnt, // 4
		     ch_data[0].avg_sum, // 5
		     ch_data[0].min,     // 6
		     ch_data[0].max,     // 7
		     ch_data[0].last     // 8
	       );
	  
	  break;

     case 's':
     case 'S':

	  res = sscanf_P( &buffer[1], PSTR ("%i %lu"), &ch, &val);

	  if (ch<4) {

	       if (res == 2)
		    s0_setChannelTicks( ch, val );
	       
	  } else 
	       ch = 0;
	  

	  s0_getChannelData( ch, &ch_data[0], 0 );
	  printf_P( PSTR("%lu\r\n"), ch_data[0].count );
	  
	  break;

     case 'o':
     case 'O':

	  res = sscanf_P( &buffer[1], PSTR ("%i"), &ch);

	  if (res == 111) { // disabled ...
	       printf_P( PSTR("OK %d\r\n"), ch ? 1 : 0 );
	  } else {
	       printf_P( PSTR("?\r\n") );
	  }
	       
	  break;
	  
     case 'w':
     case 'W':

	  res = sscanf_P( &buffer[1], PSTR ("%i"), &ch);

	  if (res == 1) { // disabled ...
	       wd_set = ch;
	  }

	  printf_P( PSTR("OK %d\r\n"), wd_set );
	       
	  break;
	  

     case 'X':
     case 'x':

	  printf_P( PSTR("rebooting\r\n") );

	  while (1);
	  
	  break;
	  
	  
     default:
        printf_P( PSTR("?\r\n") );

     }
	  
}
Ejemplo n.º 11
0
int uart_putc_file(char c, FILE *stream)
{
    uart1_putc(c);    
    return 0;
}
Ejemplo n.º 12
0
uint8_t um6_rwc(uint8_t um6_register, uint8_t batch, uint8_t r_w_c, uint16_t um6_result[], uint8_t data_size)
{
	uint8_t checksum0 = 0;
	uint8_t checksum1 = 0;
	uint16_t checksum = 0;
	uint8_t pt_is_batch = 0;
	if(batch > 0)
	{
		pt_is_batch = PT_IS_BATCH;
	}

	if(r_w_c == UM6_DATA_READ)
		checksum = ('s'+'n'+'p' + (pt_is_batch | batch) + um6_register);
	else if(r_w_c == UM6_DATA_WRITE)
		checksum = ('s'+'n'+'p' + (PT_HAS_DATA | pt_is_batch | batch) + um6_register);
	else if(r_w_c == UM6_DATA_CMD)
		checksum = ('s'+'n'+'p' + um6_register);
	checksum1 = checksum >> 8;
	checksum0 = checksum & 0xff;

	uart1_putc('s');
	uart1_putc('n');
	uart1_putc('p');
	if(r_w_c == UM6_DATA_READ)
		uart1_putc(pt_is_batch | batch); //PT
	else if(r_w_c == UM6_DATA_WRITE)
		uart1_putc(PT_HAS_DATA | pt_is_batch | batch);
	else //if(r_w_c == UM6_DATA_CMD)
		uart1_putc(0);
	uart1_putc(um6_register); //ADR
	uart1_putc(checksum1); //Checksum1
	uart1_putc(checksum0); //Checksum1

	uint8_t data[8] = {0};
	uint16_t data_sum = 0;

	//if((r_w_c == UM6_DATA_CMD) || (r_w_c == UM6_DATA_WRITE))
	//	_delay_ms(25); //UM6 braucht dann etwas Zeit zum Antworten

	uint8_t new_dat = uart1_getc();
	if(new_dat & UART_NO_DATA)
	{
		//no data
		return 7;
	}
	else if(new_dat == 's')
	{
		if(uart1_getc() == 'n')
		{
			if(uart1_getc() == 'p')
			{
				uint8_t r_w_c_batch = uart1_getc();
				if( ((r_w_c_batch == (PT_HAS_DATA | pt_is_batch | batch)) && (r_w_c == UM6_DATA_READ)) ||
						((r_w_c_batch == 0) && (r_w_c == UM6_DATA_WRITE)) || //== 0 wegen COMMAND_COMPLETE
						((r_w_c_batch == 0) && (r_w_c == UM6_DATA_CMD)))
				{
					if(uart1_getc() == um6_register)
					{	
						uint8_t i_stop = 0;
						if(batch > 0)
						{
							i_stop = batch;
						}
						else
						{
							i_stop = 4; //1 Register
						}

						for(uint8_t i = 0; i<i_stop; i++)
						{
							data[i] = uart1_getc();
							data_sum += data[i];
						}
						checksum1 = uart1_getc();
						checksum0 = uart1_getc();
						checksum = ((checksum1 << 8) | checksum0);
						if( ((checksum == ('s' + 'n' + 'p' + (PT_HAS_DATA | pt_is_batch | batch) + um6_register + data_sum)) && (r_w_c == UM6_DATA_READ)) ||
								((checksum == 0) && (r_w_c == UM6_DATA_WRITE)) ||
								((checksum == 0) && (r_w_c == UM6_DATA_CMD)))
						{
							for(uint8_t i = 0; i < data_size; i++)
							{
								um6_result[i] = (data[(i*2)+1] | (data[(i*2)]<<8));
							}

							return 0;
						}
						else
						{
							flushdata();
							return 1;
						}
					}
					else
					{
						flushdata();
						return 2;
					}
				}
				else
				{
					flushdata();
					return 3;
				}
			}
			else
			{
				flushdata();
				return 4;
			}
		}
		else
		{
			flushdata();
			return 5;
		}
	}
	else
	{
		flushdata();
		return 6;
	}
}
Ejemplo n.º 13
0
/*
 *   This task will wake when a character is received on uart1.
 *   It will parse a line into the several tokens (separated by a space).
 */
static void vParseTask( void *pvParameters )
{
	char  buffer[20];
	int   buffer_position;
	int   token[5] = {0,0,0,0,0};
	int   current_token;
	
	int i, j;
	
	/* Used to wake the task at the correct frequency. */
	portTickType xLastExecutionTime; 
	
	char tmp;

	uart1_puts("Parse task initializing...");

	uart1_puts("done\n\r");
	
	for( ;; )
	{
		/* Wait until it is time for the next cycle. */
		if( xQueueReceive( xRxedChars, &tmp, portMAX_DELAY  ) )
        {
            // pcRxedMessage now points to the struct AMessage variable posted
            // by vATask.
            //uart1_putc('(');
            //uart1_putc(tmp);
            //uart1_putc(')');
            
            if (tmp == '\n' || tmp == '\r')
            {
	            buffer[buffer_position] = '\0';
	            token[current_token + 1] = buffer_position;
	            uart1_putc('{');
		        uart1_puts(buffer);
			    uart1_puts("}\n\r");
	            for (i = 0; i <= current_token && i < 5; i++)
	            {
		        	j = 0;
		        	uart1_putc('[');
		        	while (token[i]+j < token[i+1])
		        	{
		        		uart1_putc(buffer[token[i] + j++]);
		        	}	
		        	uart1_puts("]\n\r");
		        } 
            	buffer_position = 0;
            	current_token = 0;
            	token[0] = 0;
            	token[1] = 0;
            	token[2] = 0;
            	token[3] = 0;
            	token[4] = 0;
            	if (tmp == '\r')
            		uart1_puts("\n\r> ");
            }
            else if (tmp == ' ' && current_token < 5)
            {
	            //buffer[buffer_position++] = tmp;
	            token[++current_token] = buffer_position;
	            
	        } 
	        else if (buffer_position < 20)
	        	buffer[buffer_position++] = tmp;
        }
	}
}
Ejemplo n.º 14
0
// Override _write_r so we actually can do printf
int _write_r(struct _reent *ptr, int file, char *buf, int len) {
	int foo = len;
	while(foo--) uart1_putc(*buf++);
	return len;
}