void UartGetStatus(char param)
{
	int8_t tbutton[12];
	int8_t buff[COMM_BUFFER_LEN];
	float xg,yg,zg,ltemp;

	xg = LIS3DSH_Get_X_Out(LIS3DSH_Sense_2g);
	yg = LIS3DSH_Get_Y_Out(LIS3DSH_Sense_2g);
	zg = LIS3DSH_Get_Z_Out(LIS3DSH_Sense_2g);

	if(button == FALSE)
	{
		sprintf(tbutton,"NotPressed");
	}
	else
	{
		sprintf(tbutton,"Pressed");
	}
	ltemp = GetTemp();

	sprintf(buff,"s,x:%.3f,y:%.3f,z:%.3f,b:%s,t:%.3f\n",xg,yg,zg,tbutton,ltemp);

	VCP_send_str(buff);

}
Ejemplo n.º 2
0
void PutCharu(char inchar)
{
	unsigned char outstrg[2];

	outstrg[0] = inchar;
	outstrg[1] = 0;
	VCP_send_str(&outstrg);
}
Ejemplo n.º 3
0
static void failure_response(void)
{
	uint8_t data[] = {
		PROTO_INSYNC,	// "in sync"
		PROTO_FAILED	// "command failed"
	};

	VCP_send_str(data);
}
Ejemplo n.º 4
0
static void invalid_response(void)
{
	uint8_t data[] = {
		PROTO_INSYNC,	// "in sync"
		PROTO_INVALID	// "invalid command"
	};

	VCP_send_str(data);
}
Ejemplo n.º 5
0
static void sync_response(void)
{
	uint8_t data[] = {
		PROTO_INSYNC,	// "in sync"
		PROTO_OK	// "OK"
	};

	VCP_send_str(data);
}
void UartToogleLed(char param)
{
	BOOL LedError = FALSE;
	int8_t buff[30];
	int8_t LedString[10];
	DISCOVERY_OUTPUT_PINS_T tled;
	switch (param)
	{
		case 'b':
			tled = DISCOVERY_LED_BLUE;
			strcpy(LedString,"Blue");
			break;
		case 'g':
			tled = DISCOVERY_LED_GREEN;
			strcpy(LedString,"Green");
			break;
		case 'r':
			tled = DISCOVERY_LED_RED;
			strcpy(LedString,"Red");
			break;
		case 'o':
			tled = DISCOVERY_LED_ORANGE;
			strcpy(LedString,"Orange");
			break;
		default:
			LedError = TRUE;
			break;
	}

	if(LedError == FALSE)
	{
		GpioToggleLed(tled);
		sprintf(buff,"t,Toggling Led: %s\n",LedString);
		VCP_send_str(buff);
	}
	else
	{
		VCP_send_str("t,Error in Toggling Led\n");
	}

}
Ejemplo n.º 7
0
void VCP_printf2(const char *format, ...)
{
 va_list list;
 va_start(list, format);
 int len = vsnprintf(0, 0, format, list);
 char *s;
 s = (char *)malloc(len + 1);
 vsprintf(s, format, list);
 VCP_send_str(s);
 free(s);
 va_end(list);
 return;
}
Ejemplo n.º 8
0
void vTaskVCP(void *pvParameters)
{
	static u32 address = 0;
	static uint8_t usb_inited = 0;
	uint8_t c;
	int arg;
	uint8_t tmpbuf[EERROM_SIZE];
	
	for(;;)
	{
	    //Give the change to the OS scheduling. It is really a fool idea. Change me!
	    //TODO - should use semaphore
	    vTaskDelay( 1 / portTICK_RATE_MS );
//		xSemaphoreTake(onVCPSemaphore, portMAX_DELAY);

		if(usb_inited == 0)
		{
		    GPIO_InitTypeDef  gpio;
            //This is a trick to perform a USB re-enumerate
            gpio.GPIO_Pin = GPIO_Pin_12;
            gpio.GPIO_Speed = GPIO_Speed_100MHz;
            gpio.GPIO_Mode = GPIO_Mode_OUT;
            gpio.GPIO_OType = GPIO_OType_PP;
            gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
            GPIO_Init(GPIOB, &gpio);
            GPIO_SetBits(GPIOB, GPIO_Pin_12 );
            vTaskDelay(500 / portTICK_RATE_MS);
            GPIO_ResetBits(GPIOB, GPIO_Pin_12 );

            // Initialize USB VCP. Do it ASAP
            USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb,
                    &USR_cb);
            usb_inited = 1;
		}

		if (VCP_get_char(&c))
		{
			switch(c) {
				case PROTO_GET_SYNC:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					break;
				case PROTO_GET_DEVICE:
					arg = cin_wait(usb_vcp_timeout);
					if (arg < 0)
						goto cmd_bad;
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					switch (arg) {
						case PROTO_DEVICE_BL_REV:
						    VCP_send_str((uint8_t*)&bl_proto_rev);
							break;
						default:
							goto cmd_bad;
					}
			
					break;
				case PROTO_START_TRANS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					address = 0;
					memset(tmpbuf,0,EERROM_SIZE);
					break;
				case PROTO_SET_PARAMS:
					arg = cin_wait(usb_vcp_timeout);
					if (arg < 0)
						goto cmd_bad;

					// sanity-check arguments
					if (arg % 4)
						goto cmd_bad;
					if ((address + arg) > EERROM_SIZE)
						goto cmd_bad;
					for (int i = 0; i < arg; i++) 
					{
						c = cin_wait(usb_vcp_timeout);
						if (c < 0)
							goto cmd_bad;
						
						tmpbuf[address++] = c;
					}
					
					break;
				case PROTO_END_TRANS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					//ensure we receive right size
					if(address == EERROM_SIZE)
					{
						memcpy(eeprom_buffer.c,tmpbuf,EERROM_SIZE); 
//						bool ret = StoreParams();
//						if(!ret)
//						{
//							//TODO - handle flash write error here
//						}
					}
					break;
				case PROTO_SAVE_TO_FLASH:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					
					//ensure we receive right size
					if(address == EERROM_SIZE)
					{
						bool ret = StoreParams();
						if(!ret)
						{
							//TODO - handle flash write error here
						}
					}
					break;	
				case PROTO_GET_PARAMS:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;
					for (int i = 0; i < EERROM_SIZE; i++)
					{
					    VCP_put_char(eeprom_buffer.c[i]);
						//TM_USB_VCP_Putc(testbuf[i]);
						//vTaskDelay( 1 / portTICK_RATE_MS );
					}
					
					break;
				case PROTO_BL_UPLOAD:
					if (cin_wait(usb_vcp_timeout) != PROTO_EOC)
						goto cmd_bad;

					sync_response();
					vTaskDelay( 200 / portTICK_RATE_MS );
					
					GPIO_SetBits(GPIOB,GPIO_Pin_12);
					vTaskDelay( 500 / portTICK_RATE_MS );
					GPIO_ResetBits(GPIOB,GPIO_Pin_12);
					
					__DSB();  /* Ensure all outstanding memory accesses included
                                buffered write are completed before reset */
					SCB->AIRCR  = ((0x5FA << SCB_AIRCR_VECTKEY_Pos)      |
								 (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
								 SCB_AIRCR_SYSRESETREQ_Msk);                   /* Keep priority group unchanged */
					__DSB();                                                     /* Ensure completion of memory access */
					
					while(1);  
					break;
				default:
					continue;
							
			}
			
			// send the sync response for this command
			sync_response();
			continue;
		}
		
		vTaskDelay( 10 / portTICK_RATE_MS );
		continue;
cmd_bad:
		// send an 'invalid' response but don't kill the timeout - could be garbage
		invalid_response();
		continue;

cmd_fail:
		// send a 'command failed' response but don't kill the timeout - could be garbage
		failure_response();
		continue;		
	}
}