Exemplo n.º 1
0
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
{
	uart1_puts("\n\rStack overflow! ");
	uart1_puts((char*)pcTaskName);
	uart1_puts("\n\r");
	while(1) ; 
}
Exemplo n.º 2
0
/*
 *   Used for displaying an artificial horizon on PC (VB app)
 */
void PrintForVbApp(float roll, float acc_roll)
{
    PrintSignedInteger((int)roll, &uart1_puts); // Send result to uart
    uart1_puts(";");
    PrintSignedInteger((int)(acc_roll/3.14*180.0), &uart1_puts);  // Send accelerometer angle to uart
    uart1_puts("\n\r");
}
Exemplo n.º 3
0
void printCurrentCoordinatesUART(char* str, float x, float y, float z)
{
	char buffer[15];
	uart1_puts(str);
	dtostrf(x,5,2,buffer);
    uart1_puts(buffer);
	uart1_puts("\n");
}
Exemplo n.º 4
0
void printResolverAngleUART(char* str, int16_t angle)
{
	char buffer[7];
	uart1_puts(str);
	itoa(angle, buffer, 10); // the parameter 10 signifies base 10        
    uart1_puts(buffer);
	uart1_puts("\n");
}
Exemplo n.º 5
0
/*
 *   Used for connecting to my stabilization module using UART
 */
void PrintForStabilizer(float roll)
{
    int i;
    uart1_puts("b");
    for (i = 0; i < 60; i+=2) i--;
    PrintSignedInteger((int)roll, &uart1_puts);
    for (i = 0; i < 60; i+=2) i--;
    uart1_puts("e");
}
Exemplo n.º 6
0
void printResolverReferenceAngleUART(char* str, float referenceAngle)
{
	char buffer[15];
	referenceAngle = (referenceAngle * 180.0 / M_PI);
	dtostrf(referenceAngle,5,2,buffer);
	uart1_puts(str);
    uart1_puts(buffer);
	uart1_puts("\n");
}
Exemplo n.º 7
0
void printPixelBuffer(uint8_t *image)
{
	for(uint16_t i=0; i<1536; i++)
	{
		char buff[4];
		sprintf(buff,"%d",image[i]);
		uart1_puts(buff);
		uart1_puts("\t");
	}
	uart1_puts("-------\r\n");
}
Exemplo n.º 8
0
void printMotionBurstInRobot(int8_t *burst)
{
	char moBuff[21];
	// burst[1] and burst[2] switched to get motion from the perspective of the robot
 	sprintf(moBuff,"%d;%d;%d;%u\r\n",burst[0],burst[2],burst[1],burst[3]);
 	uart1_puts(moBuff);
}
Exemplo n.º 9
0
void getMotion(int8_t *motion)
{
	uint8_t val;
	//  	while( 1 )
	{
		val = read(MOTION);
 		char moBuff[10];
 		sprintf(moBuff,"%u\t%u\r\n",val & 0x10, val & 0x80);
 		uart1_puts(moBuff);
		
		if( (val & 0x80) != 0 )
		{
			motion[0] = (int8_t)read(DELTA_X);
			_delay_us(50);
			motion[1] = (int8_t)read(DELTA_Y);
			//  			break;
		}
		else
		{
			motion[0] = 0;
			motion[1] = 0;
		}
	}
	// 	write(MOTION_CLEAR,0xFF);
}
Exemplo n.º 10
0
void gps_init(struct GpsConfig *gpsconfig)
{
	gps_open_port(gpsconfig);
		
	// Wait for GPS output. On some old EB85 devices, this can take over 2sec
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(10);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(50);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(100);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(200);		
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(400);	 // 760ms
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(800);	 // 1560ms
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(1000);	 // 2560ms

	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
	{
		uart1_puts("timeout...");
		uart2_open(115200l);
		return;	// Don't return? If module was rebooted, but GPS not, then we need to change the speed for the GPS module to become accessible
	}

	// First we configure which sentences we want. If the unit outputs all sentences at 5Hz by default, then 38400 will be too slow 
	// and the unit won't allow us to change the baudrate.
	
	gps_config_output(gpsconfig);
}
Exemplo n.º 11
0
void microcontroller_reset_type()
{
	if (RCONbits_backup.BOR)
	{
		uart1_puts("\r\nA Brown-out Reset has occurred\r\n");
	}
	if (RCONbits_backup.EXTR)
	{
		uart1_puts("\r\nA Master Clear (pin) Reset has occurred\r\n");
	}
	if (RCONbits_backup.IDLE)
	{
		uart1_puts("\r\nDevice was in Idle mode\r\n");
	}
	if (RCONbits_backup.IOPUWR)
	{
		uart1_puts("\r\nAn illegal opcode detection, an illegal address mode or uninitialized W register used as an Address Pointer caused a Reset\r\n");
	}	
	if (RCONbits_backup.POR)
	{
		uart1_puts("\r\nA Power-up Reset has occurred\r\n");
	}
	if (RCONbits_backup.SLEEP)
	{
		uart1_puts("\r\nDevice has been in Sleep mode\r\n");
	}
	if (RCONbits_backup.SWDTEN)
	{
		uart1_puts("\r\nWDT is enabled\r\n");
	}
	if (RCONbits_backup.SWR)
	{
		uart1_puts("\r\nA RESET instruction has been executed\r\n");
	}
	if (RCONbits_backup.TRAPR)
	{
		uart1_puts("\r\nA Trap Conflict Reset has occurred\r\n");
	}
	/*if (RCONbits_backup.VREGS)
	{
		uart1_puts("Voltage regulator is active during Sleep\r\n");
	}*/
	if (RCONbits_backup.WDTO)
	{
		uart1_puts("\r\nWDT time-out has occurred\r\n");
	}										
}
Exemplo n.º 12
0
void printMotionBurst(int8_t *burst)
{
	char moBuff[21];
	// sign of burst[1] and burst[2] switched to get motion from the perspective of the sensor
 	//sprintf(moBuff,"%d;%d;%d;%u\r\n",burst[0],burst[1]*(-1),burst[2]*(-1),burst[3]);
 	sprintf(moBuff,"%d;%d;%u\r\n",burst[1]*(-1),burst[2]*(-1),burst[3]);
 	uart1_puts(moBuff);
}
Exemplo n.º 13
0
void wlan_puts(const char *s )
{
	#if defined( WLAN_UART_NR )	// WLAN_UART_NR = 1
		uart1_puts(s);
	#else // WLAN_UART_NR = 0
		uart0_puts(s);
	#endif	// WLAN_UART_NR
}
Exemplo n.º 14
0
void start_meas( void ) {
    if( W1_IN & (1<< W1_PIN)) {
        w1_command( CONVERT_T, NULL );
        W1_OUT |= 1<< W1_PIN;
        W1_DDR |= 1<< W1_PIN;			// parasite power on

    } else {
        uart1_puts("Short Circuit !");
    }
}
Exemplo n.º 15
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('.');
	}
}
Exemplo n.º 16
0
int main()
{
    char buffer[20];
    int i;
    float tmp, roll_angle;
    float acc_gyro = 0, dt;
    struct Gyro1DKalman filter_roll;
    struct Gyro1DKalman filter_pitch;

    init_microcontroller();

    adc_init();
    adc_start();

    timer_init_ms();

    uart1_open();
    uart1_puts("Device initialized\n\r");

    uart1_puts("Entering main loop\n\r");

    init_Gyro1DKalman(&filter_roll, 0.0001, 0.0003, 0.69);

    while(1)
    {
        dt = timer_dt();   // time passed in s since last call

        // execute kalman filter
        tmp = PredictAccG_roll(accelero_z(), accelero_y(), accelero_x());
        ars_predict(&filter_roll, gyro_roll_rad(), dt);    // Kalman predict
        roll_angle = ars_update(&filter_roll, tmp);        // Kalman update + result (angle)

        //PrintAll(accelero_x(), accelero_y(), accelero_z(), gyro_roll_rad(), gyro_pitch_rad(), r);
        PrintForVbApp(roll_angle / 3.14*180.0, tmp);
        //PrintForStabilizer(r);
    }

    uart1_close();

    return 0;
}
Exemplo n.º 17
0
void configuration_read_and_write_test(void)
{
	reset();
	
	uart1_puts("Configuration Read/Write Test:\r\n");
	
	
	uint8_t val = getConfigurationBits();
	
	char tmpbuff[100];
	sprintf(tmpbuff,"Read default: %u\r\n",val);
	uart1_puts(tmpbuff);
	
	//_delay_us(50);
	setConfigurationBits(0x59);
	
	char tmpbuff2[100];
	uint8_t val2 = getConfigurationBits();
	sprintf(tmpbuff2,"Read after set: %u\r\n",val2);
	uart1_puts(tmpbuff2);
}
Exemplo n.º 18
0
void printFrameBinary(uint8_t *image)
{
	for(int i=0; i<RESOLUTION; i++)
	{
		for(int j=0; j<RESOLUTION; j++)
		{
			uart1_puts(*image);
			image++;
		}
	}
	//uart1_puts(EOF_FRAME);
}
Exemplo n.º 19
0
void printFrame(uint8_t *image)
{
	for(int i=0; i<RESOLUTION; i++)
	{
		for(int j=0; j<RESOLUTION; j++)
		{
			char tmpbuff[5];
			if( j == RESOLUTION -1 )
			{
				sprintf(tmpbuff,"%u\r\n",*image);
			}
			else
			{
				sprintf(tmpbuff,"%u;",*image);
			}
			uart1_puts(tmpbuff);
			image++;
		}
	}
	uart1_puts("-\r\n");
}
Exemplo n.º 20
0
void getFrame(uint8_t *image)
{
	reset();
	
	uint8_t regValue;
	bool isFirstPixel = false;
	
	write(FRAME_CAPTURE,0x83);
	// wait 3 frame periods + 10 us for frame to be captured
	_delay_us(1510);	// min frame speed is 2000 frames/second so 1 frame = 500 us.  so 500 x 3 + 10 = 1510
	// 	uint16_t count = 0;
	for(int i=0; i<RESOLUTION;)
	{
		for(int j=0; j<RESOLUTION;)
		{
			// 			count++;
			regValue = read(FRAME_CAPTURE);
			if( !isFirstPixel && (regValue & 0x40) == 0 )
			{
				//uart1_puts("failed to find first pixel!\r\n");
				i=0;
				j=0;
				break;
			}
			else
			{
				if( (regValue & 0x40) == 0x40 )
				{
					uart1_puts("first");
				}
				//uart1_puts("found first pixel!");
				isFirstPixel = true;
				//pixelValue = ( regValue << 2);
				*image = ( regValue << 2);
				//*image = regValue;
				image++;	// next array cell address
			}
			_delay_us(50);
			j++;
		}
		if( isFirstPixel )
		{
			i++;
		}
	}
	reset();
	
	// 	uart1_puts("count :");
	// 	char tmpbuff[1];
	// 	sprintf(tmpbuff,"%u\r\n",count);
	// 	uart1_puts(tmpbuff);
}
Exemplo n.º 21
0
int main()
{
	microcontroller_init();
	
	uart1_queue_init(38400l);
	
	xTaskCreate( vTickTask, ( signed portCHAR * ) "TickTask", ( configMINIMAL_STACK_SIZE * 3 ), NULL, tskIDLE_PRIORITY + 1, NULL );
	xTaskCreate( vParseTask, ( signed portCHAR * ) "ParseTask", ( configMINIMAL_STACK_SIZE * 4 ), NULL, tskIDLE_PRIORITY + 3, NULL );
	
	vTaskStartScheduler();
	uart1_puts("Not enough heap!\n\r");
	
	return 1;
}
Exemplo n.º 22
0
void printFrameFromPixelBuffer(uint8_t *image)
{
	uint16_t begin = 2000;
	for(uint16_t i=0; i<1536; i++)
	{
		if( (image[i] & 0x40) == 0x40 )
		{
			begin = i;
			break;
		}
	}
	
	//image dont fits
	if( begin > 636 )
	{
		return;
	}
	
	for(uint8_t i=0; i<RESOLUTION; i++)
	{
		for(uint8_t j=0; j<RESOLUTION; j++)
		{
			char buff[4];
			//sprintf(buff,"%d",image[begin+i*30+j]);
			sprintf(buff,"%d",image[i*30+j]);
			uart1_puts(buff);
			if( j < 29 )
			{
				uart1_puts(";");
			}
		}
		uart1_puts("\r\n");
	}
	uart1_puts("-\r\n");
	
	
}
Exemplo n.º 23
0
// Notify some debug panel, if possible.
void NotifyTrapAddress(char* code, unsigned int note)
{
    unsigned char *p = (unsigned char *)&errLoc;
    int i;

    for (i = 0; i < sizeof (void*); i++)
    {
        printf("%02x ", p[i]);
    }
    printf("\n");

    // generate debug string.
    sprintf(TrapMsgBuf, "\r\nTrap %s %p\r\n", code, errLoc);
    uart1_puts( TrapMsgBuf );

    // Now get ready to power up.
    asm("reset");
}
Exemplo n.º 24
0
void printMotion(int8_t *motion)
{
	// 	uart1_puts("motion:\r\n");
	uart1_puts("x:");
	char moBuff[4];
 	sprintf(moBuff,"%d",motion[0]);
 	uart1_puts(moBuff);
	uart1_puts("\t");
	
	uart1_puts("y:");
	sprintf(moBuff,"%d",motion[1]);
	uart1_puts(moBuff);
	uart1_puts("\r\n");
}
Exemplo n.º 25
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") );

     }
	  
}
Exemplo n.º 26
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;
        }
	}
}
Exemplo n.º 27
0
int main()
{
	microcontroller_init();

	uart1_queue_init(57600l);  // default baudrate: 57600 due to XBee bi-direction communication


	printf("Gluonpilot v%s ", version);
#ifdef LIMITED  // Limited version is pre-loaded on modules sent to Non-European countries
	printf("Limited version");
#endif
	
	printf(" [%s %s, config: %dB, logline: %dB, navigation: %dB, double: %dB]\r\n\r\n",
                __DATE__, __TIME__, sizeof(struct Configuration), sizeof(struct LogLine), sizeof(gluonscript_data.codes), sizeof(double));
	
	microcontroller_reset_type();  // printf out reason of reset; for debugging
	led_init();

	// Create semaphores needed for FreeRTOS synchronization (better to do it know, they are changed in interrupts of uart2 and ppm)
	vSemaphoreCreateBinary( xSpiSemaphore );
	vSemaphoreCreateBinary( xGpsSemaphore );

	// What hardware version are we using?
	configuration_determine_hardware_version();
	if (HARDWARE_VERSION == V01N)
		printf("Found hardware version v0.1n\r\n");
	else if (HARDWARE_VERSION == V01O)
		printf("Found hardware version v0.1o\r\n");
    else if (HARDWARE_VERSION == V01Q)
		printf("Found hardware version v0.1q (GP2)\r\n");
	else
		printf("Found hardware version v0.1j or earlier\r\n");
	
	// Open flash & load configuration
	dataflash_open();
	printf("%d MB flash found \r\n", (int)PAGE_SIZE/264);
	//printf("Loading configuration...");
	configuration_load();
	//printf("done\r\n");

	
	// Open RC receiver input: pwm_in/ppm_in task: in ppm_in/pwm_in.c
	// This is too low level to do it in the control task
	if (config.control.use_pwm)
	{
		pwm_in_open(); 
		uart1_puts("Waiting for pwm");
		pwm_in_wait_for();
		if (! (ppm.channel[0] > 900 && ppm.channel[0] < 2100))
			uart1_puts("not found!\r\n");
		else
			uart1_puts("done\r\n");
	} 
	else
	{
		uart1_puts("Opening ppm...");
		ppm_in_open(); // We need a complete frame (which takes at least 20ms) to start so never can start early enough!
		uart1_puts(" done\r\n");
	}	
	

	// Create our tasks. 
	if (config.control.servo_mix == QUADROCOPTER)
		xTaskCreate( control_copter_task,            ( signed portCHAR * ) "CControl",      ( configMINIMAL_STACK_SIZE * 3 ), NULL, tskIDLE_PRIORITY + 7, NULL );
	else
		xTaskCreate( control_wing_task,            ( signed portCHAR * ) "WControl",      ( configMINIMAL_STACK_SIZE * 3 ), NULL, tskIDLE_PRIORITY + 7, NULL );

    if (HARDWARE_VERSION == V01Q)
    	xTaskCreate( sensors_mpu6000_task,                 ( signed portCHAR * ) "Sensors",      ( configMINIMAL_STACK_SIZE * 5 ), NULL, tskIDLE_PRIORITY + 6, NULL );
    else
        xTaskCreate( sensors_analog_task,                 ( signed portCHAR * ) "Sensors",      ( configMINIMAL_STACK_SIZE * 5 ), NULL, tskIDLE_PRIORITY + 6, NULL );

    xTaskCreate( sensors_gps_task,             ( signed portCHAR * ) "GpsNavi",      ( configMINIMAL_STACK_SIZE * 4 ), NULL, tskIDLE_PRIORITY + 5, NULL );
	xTaskCreate( communication_input_task,     ( signed portCHAR * ) "ConsoleInput", ( configMINIMAL_STACK_SIZE * 5 ), NULL, tskIDLE_PRIORITY + 4, NULL );
	xTaskCreate( datalogger_task,              ( signed portCHAR * ) "Dataflash",    ( configMINIMAL_STACK_SIZE * 3 ), NULL, tskIDLE_PRIORITY + 3, NULL );
	xTaskCreate( communication_telemetry_task, ( signed portCHAR * ) "Telemetry",    ( configMINIMAL_STACK_SIZE * 2 ), NULL, tskIDLE_PRIORITY + 2, NULL );
    xTaskCreate( osd_task,                     ( signed portCHAR * ) "OSD",          ( configMINIMAL_STACK_SIZE * 1 ), NULL, tskIDLE_PRIORITY + 1, NULL );

#ifdef USE_TRACING
    printf("\r\nENABLING TRACING\r\n");
    setup_trace_pins();
#endif

	// Order the scheduler to start scheduling our two tasks.
	vTaskStartScheduler();
	
	// We should only get here when the scheduler wasn't able to allocate enough memory.
	uart1_puts("Not enough heap!\r\n");
	
	return 1;
}
Exemplo n.º 28
0
// Send a string via UART serial.
void sendStringUART (char* string)
{
	uart1_puts(string);
	// TODO: check out the type error warning...
}
Exemplo n.º 29
0
/* Monitor remote hotswap */
static void remote_tick(void)
{
    unsigned char i;
    int bat_level;
    static unsigned char pause_length=0;
    
    if(remote_state_control!=REMOTE_CONTROL_DRAW && remote_state_control!=REMOTE_CONTROL_IDLE) {
        remote_state_control=remote_state_control_next;
        remote_state_control_next=REMOTE_CONTROL_MASK;
    }
    
    switch (remote_state_control)
    {
        case REMOTE_CONTROL_IDLE:
            /* State machine never leaves idle unless remote_state_control is
             * manually set.
             */
            remote_payload_size=0;
            remote_state_control=REMOTE_CONTROL_IDLE;
            break;
            
        case REMOTE_CONTROL_NOP:
            remote_payload[0]=0x11;
            remote_payload[1]=0x30;
            
            remote_payload_size=2;
            remote_state_control=REMOTE_CONTROL_MASK;
            break;
            
        case REMOTE_CONTROL_POWER:
            remote_payload[0]=0x31;
            remote_payload[1]=remote_power;
            remote_payload[2]=remote_contrast;
            
            remote_payload_size=3;
            remote_state_control=REMOTE_CONTROL_MASK;
            break;
            
        case REMOTE_CONTROL_MASK:
            bat_level=battery_level()>>5;
            remote_payload[1]=0;
            
            if(bat_level&0x02) {
                remote_payload[1] |= 0x07 << 5;
            } else if(bat_level&0x01) {
                remote_payload[1] |= 0x03 << 5;
            } else {
                remote_payload[1] |= 0x01 << 5;
            }
            remote_payload[1]|=1<<4;
            
            remote_payload[0]=0x41;
            
            remote_payload_size=2;
            remote_state_control=REMOTE_CONTROL_MASK;
            break;
            
        case REMOTE_CONTROL_DRAW:
            remote_payload[0]=0x51;
            remote_payload[1]=0x80;
            remote_payload[2]=remote_draw_width;
            remote_payload[3]=remote_draw_x;
            
            remote_payload[5]=remote_draw_x+remote_draw_width;
            remote_payload_size=7+remote_payload[2];
            
            switch (remote_state_draw)
            {
                case DRAW_TOP:
                    remote_payload[4]=0;
                    remote_payload[6]=8;
                    
                    pause_length=6;
                    remote_state_draw_next=DRAW_BOTTOM;
                    remote_state_draw=DRAW_PAUSE;
                    break;
                    
                case DRAW_BOTTOM:
                    remote_payload[4]=8;
                    remote_payload[6]=16;
                    
                    pause_length=6;
                    remote_state_draw_next=DRAW_TOP;
                    remote_state_draw=DRAW_PAUSE;
                    break;
                    
                case DRAW_PAUSE:
                    remote_payload_size=0;
                    
                    if(--pause_length==0)
                    {
                        if(remote_state_draw_next==DRAW_TOP)
                            remote_state_control=REMOTE_CONTROL_MASK;
                            
                        remote_state_draw=remote_state_draw_next;
                    }
                    else
                        remote_state_draw=DRAW_PAUSE;

                    break;
                    
                default:
                    remote_payload_size=0;
                    break;
            }
            break;
            
        case REMOTE_CONTROL_SLEEP:
            remote_payload[0]=0x71;
            remote_payload[1]=0x30;

            remote_payload_size=2;
            remote_state_control=REMOTE_CONTROL_IDLE;
            break;
            
        default:
            remote_payload_size=0;
            break;
    }
    
    if(remote_payload_size==0)
    {
        return;
    }
    
    if(remote_payload[0]==0x51)
    {
        for(i=7; i<remote_payload_size; i++)
        {
            remote_payload[i]=
                *FBREMOTEADDR(i+remote_draw_x-7, remote_payload[4]>>3);
        }
    }
    
    /* Calculate the xor and sum to place in the payload */
    remote_payload[remote_payload_size]=remote_payload[0];
    remote_payload[remote_payload_size+1]=remote_payload[0];
    for(i=1; i<remote_payload_size; i++)
    {
        remote_payload[remote_payload_size]^=remote_payload[i];
        remote_payload[remote_payload_size+1]+=remote_payload[i];
    }

    uart1_puts(remote_payload, remote_payload_size+2);
}