Esempio n. 1
0
void Init(void)
{
    /********************************************
    *   Init User Button
    ********************************************/
    GPIO_InitTypeDef  GPIO_InitStructure;

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;  // OD but doesn't matter (input)
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  // doesn't matter (input)
    GPIO_Init(GPIOA, &GPIO_InitStructure);


    /********************************************
    *   Init Hardware for states
    ********************************************/
    initTrackLine();
    initBluetooth();

    /********************************************
    *   Init Motor output commands
    ********************************************/
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
}
Esempio n. 2
0
void main(void)
{
	initSysClock();

	initUartDebug();

	initLeds();

	initLaunchpadSW1();

	initSysTick();

	initBluetooth();

	initUSB();

	initRfModule(false);

	setRfTxAddress(RF_DESTINATION_ADDR);

	Network_setSelfAddress(RF_CONTOLBOARD_ADDR);

	while (true)
	{
		if ((g_bConnected == false) || (g_bSuspended == true))
		{
			GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_RED);
			continue;
		}

		GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_GREEN);

		if (g_USBRxState == USB_RX_DATA_AVAILABLE)
		{
			GPIOPinWrite(LED_PORT_BASE, LED_ALL, LED_BLUE);

			switch (usbBufferHostToDevice[0])
			{
			//-----------------Bootloader Handle-------------------

			case BOOTLOADER_BROADCAST_PACKET:
				broadcastBslData();
				break;

			case BOOTLOADER_SCAN_JAMMING:
				scanJammingSignal();
				break;

			default:
				normalPacketHandle();
				break;
			}

			g_USBRxState = USB_RX_IDLE;

			turnOffLED(LED_BLUE);
		}
	}
}
Esempio n. 3
0
int main(void)
{
	initBluetooth();
	while(1)
	{
	  if(rcvMessageFlag)
	  {
		  //Respond to the message
		  sendBluetoothString("Message Received!\r\n");
		  rcvMessageFlag=0;
	  }
	}
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	// Command line arguments
	const char *optString = "p:b:n:c:h?";
	const struct option longOpts[] = {
		{ OPT_PORT_NAME, required_argument, NULL, 'p' },
		{ OPT_BAUDRATE, required_argument, NULL, 'b' },
		{ OPT_BT_NAME, required_argument, NULL, 'n' },
		{ OPT_BT_PIN, required_argument, NULL, 'c' },
		{ OPT_HELP, no_argument, NULL, 'h' },
		{ NULL, no_argument, NULL, 0 }
	};

	// Port properties
	int nBaudrate = 0;
	const char *portName = NULL;

	// BT properties
	const char *btName = NULL;
	const char *btPin = NULL;

	int opt, longIndex;
	while ((opt = getopt_long( argc, argv, optString, longOpts, &longIndex)) != -1) {
		switch(opt) {
			case 'p':
				portName = optarg;
				break;
			case 'b':
				nBaudrate = atoi(optarg);
				break;
			case 'n':
				btName = optarg;
				break;
			case 'c':
				btPin = optarg;
				break;
			case 'h':
				usage();
				exit(0);
				break;
			// Case for long names
			case 0:
				if (strcmp(OPT_PORT_NAME, longOpts[longIndex].name) == 0) {
					portName = optarg;
				} else if (strcmp(OPT_BAUDRATE, longOpts[longIndex].name) == 0) {
					nBaudrate = atoi(optarg);
				} else if (strcmp(OPT_BT_NAME, longOpts[longIndex].name) == 0) {
					btName = optarg;
				} else if (strcmp(OPT_BT_PIN, longOpts[longIndex].name) == 0) {
					btPin = optarg;
				} else if (strcmp(OPT_HELP, longOpts[longIndex].name) == 0) {
					usage();
					exit(0);
				}
				break;
			default:
				usage();
				exit(0);
				break;
		}
	}

	if (portName == NULL) {
		portName = DEFAULT_PORT_NAME;
		LOGW("Port name not defined and will be used default \"%s\"", portName);
	}

	if (nBaudrate == 0) {
		nBaudrate = DEFAULT_BAUDRATE;
		LOGW("Baudrate not defined and will be used default \"%d\"", nBaudrate);
	}

	if (btName == NULL) {
		btName = DEFAULT_BT_NAME;
		LOGW("Bluetooth name not defined and will be used default \"%s\"", btName);
	}

	if (btPin == NULL || strlen(btPin) > DEFAULT_BT_PIN_MAX) {
		if (btPin == NULL) {
			LOGW("Bluetooth pin code not defined and will be used default \"%s\"", DEFAULT_BT_PIN);
		} else {
			LOGW("Bluetooth pin code too long (%lu), than should be (%d) and will be used default \"%s\"",
					strlen(btPin), DEFAULT_BT_PIN_MAX, btPin);
		}

		btPin = DEFAULT_BT_PIN;
	}

	LOGV("Port name = %s", portName);
	LOGV("Baudrate = %d", nBaudrate);
	LOGV("Bluetooth name = %s", btName);
	LOGV("Bluetooth pin code = %s", btPin);

	struct sserial_props *pProps = OpenPort(portName, nBaudrate);
	if (pProps == NULL) {
		LOGE("Port init failed");
		return 1;
	}

	if (!initBluetooth(pProps, btName, btPin)) {
		LOGE("[%s] Bluetooth init failed", __func__);
		goto exit;
	}

	char ch='\0';
	// print all until "a" will be be recieved
	while (ch!='a') {
		int bDisconnected = GetCts(pProps);
		// It will be true until someone connected
		if (bDisconnected != 0) {
			continue;
		}

		// skip empty and line endings
		if (ReadPort(pProps, &ch, 1) <= 0 ||
				ch == '\r' || ch == '\n')
			continue;
		LOGV(">> %c", ch);
	}

exit:
	ClosePort(pProps);
	return 0;
}
void hardwareInit() {


    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig((80000000L), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    SYSTEMConfigPerformance(80000000);
    CHECONbits.PREFEN = 0;


    int j = 0, i = 0;

    for (i = 0; i < 6; i++) {
        MyMAC.v[i] = MY_MAC_ADDRESS[i];
    }
    StartCritical();

    println_I("MAC");
    enableFlashStorage(true);
    FlashGetMac(MyMAC.v);

    for (i = 0; i < 6; i++) {
        macStr[j++] = GetHighNib(MyMAC.v[i]);
        macStr[j++] = GetLowNib(MyMAC.v[i]);
    }
    macStr[12] = 0;
    //println_I("MAC address is =");
    print_I(macStr);

    Pic32_Bowler_HAL_Init();
    usb_CDC_Serial_Init(dev, macStr, 0x04D8, 0x3742);
    InitLEDS();
    SetColor(0, 0, 1);

    mInitSwitch();

    //AVR Reset pin
    InitAVR_RST();
    HoldAVRReset();
    //AVR must be running before pin states can be synced in the pin initialization
    ReleaseAVRReset();
    //Starts co-proc uart
    initCoProcCom();
    
    InitPinFunction();
    //Must initialize IO before hardware
    LoadDefaultValues();
    //println_W("Pin States");
    SyncModes();
    //println_I("Modes synced, initializing channels");
    initAdvancedAsync();

    //println_I("Adding IO Namespace");
    addNamespaceToList( get_bcsIoNamespace());
    //println_I("Adding IO.Setmode Namespace");
    addNamespaceToList(get_bcsIoSetmodeNamespace());
    //println_I("Adding DyIO Namespace");
    addNamespaceToList(get_neuronRoboticsDyIONamespace());
    //println_I("Adding PID Namespace");
    addNamespaceToList( getBcsPidNamespace());
    //println_I("Adding DyIO PID Namespace");
    addNamespaceToList( get_bcsPidDypidNamespace());
    //println_I("Adding Safe Namespace");
    addNamespaceToList((NAMESPACE_LIST *) get_bcsSafeNamespace());


    Init_FLAG_BUSY_ASYNC();
    //InitCTS_RTS_HO();

    //ConfigUARTOpenCollector();
    ConfigUARTRXTristate();

    //Starts Timer 3
    InitCounterPins();
    InitADC();



    //SetFwRev(rev);



    GetName(Name);
    if(Name[0]==0xff){
            for(i=0;i<17;i++){
                    Name[i]=defaultName[i] ;
            }
            SetName(Name);
            GetName(Name);
    }

    if (!GetLockCode(LockCode)){
            for(i=0;i<4;i++){
                LockCode[i] = defaultlock[i];
            }
            SetLockCode(LockCode);
    }

    EndCritical();

	initBluetooth();
	if(!hasBluetooth()){
		Pic32UARTSetBaud( 115200 );
	}

    boolean defaultmac=true;
    for (i = 0; (i < 6) && defaultmac; i++) {
    	if(MyMAC.v[i] != MY_MAC_ADDRESS[i]){
    		defaultmac = false;
    	}
    }
    if(defaultmac){
    	srand((unsigned) GetRawVoltage());// random seed from the air

    	MyMAC.v[3] = MINOR_REV;
    	MyMAC.v[4] = FIRMWARE_VERSION;
    	MyMAC.v[5] = rand() % 255;
    	FlashSetMac(MyMAC.v);
		U1CON = 0x0000;
		DelayMs(100);
    	Reset();
    }

}