Пример #1
0
//-----------------------------------------------------------------------------
int 
kuroBoxSerialStop(void)
{
	sdStop(&Serial2);
	sdStop(&Serial1);
	kbg_setSerial1Pwr(0);
	kbg_setSerial2Pwr(0);

	return KB_OK;
}
Пример #2
0
bool stopTsPort(ts_channel_s *tsChannel) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
	if (isCommandLineConsoleOverTTL()) {
#if 0
		usb_serial_stop();
#endif
		// don't stop USB!
		return false;
	} else
#endif
	{
		if (CONFIGB(useSerialPort)) {
			// todo: disable Rx/Tx pads?
#if TS_UART_DMA_MODE
			uartStop(TS_DMA_UART_DEVICE);
#else
			sdStop(TS_SERIAL_UART_DEVICE);
#endif /* TS_UART_DMA_MODE */
		}
	}

	tsChannel->channel = (BaseChannel *) NULL;
	return true;
#else  /* EFI_PROD_CODE */
	// don't stop simulator!
	return false;
#endif /* EFI_PROD_CODE */
}
Пример #3
0
void setSerialEn( uint8_t en, int newBaud )
{
	if ( en )
	{
        palSetPadMode( GPIOB, 10, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
        palSetPadMode( GPIOB, 11, PAL_MODE_INPUT );

        static SerialConfig config =
        {
        	SERIAL_BAUD,
            0,
            0,
            0
        };
        if ( newBaud > 0 )
        	config.sc_speed = (uint32_t)newBaud;

        sdStart( &SERIAL_UART, &config );
	}
	else
	{
		sdStop( &SERIAL_UART );
	}

    /*
    uint32_t i;
    for ( i=0; i<128; i++ )
    {
        //chprintf( (BaseChannel *)&SERIAL_UART, "Hello!\r\n" );
        sdWrite( &SERIAL_UART, (const uint8_t *)"Hello!\r\n", 8 );
        chThdSleepSeconds( 1 );
    }
    */
}
Пример #4
0
void gps_reset() {
	palSetPadMode(GPIO_GPS_PWR_PORT, GPIO_GPS_PWR_PIN, PAL_MODE_OUTPUT_PUSHPULL);

	//! Set GPS power Off
	palClearPad(GPIO_GPS_PWR_PORT, GPIO_GPS_PWR_PIN);

	chThdSleepMilliseconds(500);

	//! Set GPS power On
	palClearPad(GPIO_GPS_PWR_PORT, GPIO_GPS_PWR_PIN);

	sdStop(&GPS_SERIAL);
	SD3_Config.sc_speed = 9600;
	sdStart(&GPS_SERIAL, &SD3_Config);

	// Wait until initialized
	while (sdReadTimeout(&GPS_SERIAL, gps_data, GPS_CMD_BUF, 100) <= 0) {}

	// Set serial config
	GPS_CMD_SEND("PSRF100,1,38400,8,1,0");
	chThdSleepMilliseconds(100);

	sdStop(&GPS_SERIAL);
	SD3_Config.sc_speed = 38400;
	sdStart(&GPS_SERIAL, &SD3_Config);

	// Disable unneeded
	GPS_CMD_SEND("PSRF103,01,00,00,01");
	chThdSleepMilliseconds(100);
	GPS_CMD_SEND("PSRF103,02,00,00,01");
	chThdSleepMilliseconds(100);
	GPS_CMD_SEND("PSRF103,03,00,00,01");
	chThdSleepMilliseconds(100);
	GPS_CMD_SEND("PSRF103,05,00,00,01");

	// Enable needed
	// GGA
	GPS_CMD_SEND("PSRF103,00,00,01,01");
	chThdSleepMilliseconds(100);
	// RMC
	GPS_CMD_SEND("PSRF103,04,00,01,01");
	chThdSleepMilliseconds(100);

	sdAsynchronousRead(&GPS_SERIAL, gps_data, GPS_CMD_BUF);
}
Пример #5
0
/**
 * Set baudrate
 */
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud )
{
  struct SerialInit *init_struct = (struct SerialInit*)(p->init_struct);
  SerialConfig *conf = init_struct->conf;
  // set new baudrate
  conf->speed = baud;
  // restart periph
  sdStop((SerialDriver*)(p->reg_addr));
  sdStart((SerialDriver*)(p->reg_addr), conf);
}
void oledSetBaud (oledConfig *oledConfig, uint32_t baud)
{
  uint8_t baudCode ;
  uint32_t actualbaudRate; 

  struct SerialDriver *sd = (struct SerialDriver *) oledConfig->serial;

  RET_UNLESS_INIT(oledConfig);

  switch (baud) {
  case 110    : baudCode = 0x0;  actualbaudRate = 110; break;
  case 300    : baudCode = 0x1;  actualbaudRate = 300; break;
  case 600    : baudCode = 0x2;  actualbaudRate = 600; break;
  case 1200   : baudCode = 0x3;  actualbaudRate = 1200; break;
  case 2400   : baudCode = 0x4;  actualbaudRate = 2402; break;
  case 4800   : baudCode = 0x5;  actualbaudRate = 4808; break;
  case 9600   : baudCode = 0x6;  actualbaudRate = 9632; break;
  case 14400  : baudCode = 0x7;  actualbaudRate = 14423; break;
  case 19200  : baudCode = 0x8;  actualbaudRate = 19264; break;
  case 31250  : baudCode = 0x9;  actualbaudRate = 31250; break;
  case 38400  : baudCode = 0xa;  actualbaudRate = 38527; break;
  case 56000  : baudCode = 0xb;  actualbaudRate = 56250; break;
  case 57600  : baudCode = 0xc;  actualbaudRate = 58594; break;
  case 115200 : baudCode = 0xd;  actualbaudRate = 117188; break;
  case 128000 : baudCode = 0xe;  actualbaudRate = 133929; break;
  case 256000 : baudCode = 0xf;  actualbaudRate = 281250; break;
  case 300000 : baudCode = 0x10; actualbaudRate = 312500; break;
  case 375000 : baudCode = 0x11; actualbaudRate = 401786; break;
  case 500000 : baudCode = 0x12; actualbaudRate = 562500; break;
  case 600000 : baudCode = 0x13; actualbaudRate = 703125; break;

  default : return;
  }

  //  oledConfig->serialConfig.speed = baud < actualbaudRate ? baud : actualbaudRate; // Test avec actualbaudRate
  oledConfig->serialConfig.speed = actualbaudRate; 

  // send command, do not wait response
  if (oledConfig->deviceType == PICASO) {
    OLED_KOF (KOF_NONE, "%c%c%c%c", 0x0, 0x26, 0x0, baudCode);
    chThdSleepMilliseconds(10);
  }
  sdStop (sd);
  sdStart (sd, &(oledConfig->serialConfig));

  // wait 150ms, and wait for response at new speed
  chThdSleepMilliseconds(150);
  if (oledConfig->deviceType == PICASO) {
    oledReceiveAnswer (oledConfig, 1, __FUNCTION__, __LINE__);
  }
}
Пример #7
0
void deinitialiseHw(void)
{
    /* Led for status */
    palSetPadMode(LED_PORT, LED_STATUS, PAL_MODE_UNCONNECTED);
    
    /* Led for error */
    palSetPadMode(LED_PORT, LED_ERROR, PAL_MODE_UNCONNECTED);
 
    /* Serial for debugging */
    sdStop(&SERIAL_DRIVER);
    palSetPadMode(SERIAL_PORT, SERIAL_TX, PAL_MODE_UNCONNECTED);
    palSetPadMode(SERIAL_PORT, SERIAL_RX, PAL_MODE_UNCONNECTED);

}
Пример #8
0
void setLineCoding(cdc_linecoding_t* lcp, SerialDriver *sdp, SerialConfig* scp)
{
  const uint32_t baudrate = (uint32_t)lcp->dwDTERate;

  scp->speed = baudrate;
  scp->cr1 = 0;
  scp->cr2 = 0;
  scp->cr3 = 0;

  switch (lcp->bCharFormat)
  {
    case 0:
      scp->cr2 = USART_CR2_STOP1_BITS;
      break;
    case 1:
      scp->cr2 = USART_CR2_STOP1P5_BITS;
      break;
    case 2:
      scp->cr2 = USART_CR2_STOP2_BITS;
      break;
    default:
      break;
  }

  // TODO
  switch (lcp->bParityType)
  {
    default:
      break;
  }

  // TODO
  switch (lcp->bDataBits)
  {
    default:
      break;
  }

  if (sdp->state != SD_UNINIT)
    return;

  while(sdp->state != SD_READY) chThdSleepMilliseconds(1);
  sdStop(sdp);

  while(sdp->state != SD_STOP) chThdSleepMilliseconds(1);
  sdStart(sdp, scp);
}
Пример #9
0
/**
 * Stop the system and jump to the bootloader.
 */
void flash_helper_jump_to_bootloader(void) {
	typedef void (*pFunction)(void);

	mc_interface_unlock();
	mc_interface_release_motor();
	usbDisconnectBus(&USBD1);
	usbStop(&USBD1);

	sdStop(&HW_UART_DEV);
	palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_INPUT);
	palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_INPUT);

	// Disable watchdog
	timeout_configure_IWDT_slowest();

	chSysDisable();

	pFunction jump_to_bootloader;

	// Variable that will be loaded with the start address of the application
	volatile uint32_t* jump_address;
	const volatile uint32_t* bootloader_address = (volatile uint32_t*)0x080E0000;

	// Get jump address from application vector table
	jump_address = (volatile uint32_t*) bootloader_address[1];

	// Load this address into function pointer
	jump_to_bootloader = (pFunction) jump_address;

	// Clear pending interrupts
	SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk;

	// Disable all interrupts
	for(int i = 0;i < 8;i++) {
		NVIC->ICER[i] = NVIC->IABR[i];
	}

	// Set stack pointer
	__set_MSP((uint32_t) (bootloader_address[0]));

	// Jump to the bootloader
	jump_to_bootloader();
}
Пример #10
0
//-----------------------------------------------------------------------------
int 
kbse_setBaud(int which, int32_t baud)
{
	SerialConfig * cfg = NULL;
	SerialDriver * drv = NULL;
	switch ( which )
	{
	case 1:
		{
			cfg = serial1_cfg;
			drv = &Serial1;
		} break;
	case 2:
		{
			cfg = serial2_cfg;
			drv = &Serial2;
		} break;
	default: return KB_ERR_VALUE;
	}

	switch( baud )
	{
	case 300:
	case 1200:
	case 9600:
	case 19200:
	case 38400:
	case 57600:
	case 115200:
	case 230400:
	case 460800:
	case 921600:
		cfg->speed = baud;
		break;
	default:
		cfg->speed = 9600;
	}

	sdStop(drv);
	sdStart(drv, cfg);

	return KB_OK;
}
Пример #11
0
/**
 * Set parity and stop bits
 */
void uart_periph_set_bits_stop_parity(struct uart_periph *p,
                                      uint8_t bits, uint8_t stop, uint8_t parity)
{
  struct SerialInit *init_struct = (struct SerialInit*)(p->init_struct);
  SerialConfig *conf = init_struct->conf;

  /* Configure USART parity and data bits */
  if (parity == UPARITY_EVEN) {
    conf->cr1 |= USART_CR1_PCE; // set parity control bit
    conf->cr1 &= ~USART_CR1_PS; // clear parity selection bit
    if (bits == UBITS_7) {
      conf->cr1 &= ~USART_CR1_M; // clear word length bit
    } else { // 8 data bits by default
      conf->cr1 |= USART_CR1_M; // set word length bit
    }
  } else if (parity == UPARITY_ODD) {
    conf->cr1 |= USART_CR1_PCE; // set parity control bit
    conf->cr1 |= USART_CR1_PS; // set parity selection bit
    if (bits == UBITS_7) {
      conf->cr1 &= ~USART_CR1_M; // clear word length bit
    } else { // 8 data bits by default
      conf->cr1 |= USART_CR1_M; // set word length bit
    }
  } else { // 8 data bist, NO_PARITY by default
    conf->cr1 &= ~USART_CR1_PCE; // clear parity control bit
    conf->cr1 &= ~USART_CR1_M; // clear word length bit
  }
  /* Configure USART stop bits */
  conf->cr2 &= ~USART_CR2_STOP; // clear stop bits
  if (stop == USTOP_2) {
    conf-> cr2 |= USART_CR2_STOP2_BITS; // set bits for 2 stops
  } else { // 1 stop bit by default
    conf-> cr2 |= USART_CR2_STOP1_BITS; // set bits for 1 stop
  }

  sdStop((SerialDriver*)(p->reg_addr));
  sdStart((SerialDriver*)(p->reg_addr), conf);
}
Пример #12
0
 void close()
 {
     sdStop(mSD);
 }
Пример #13
0
void BoardDriverShutdown(void)
{
    sdStop(&SD2);
    canStop(&CAND1);
}
Пример #14
0
CCM_FUNC static THD_FUNCTION(ThreadSDU, arg)
{
  (void)arg;
  uint8_t in_buffer[SERIAL_BUFFERS_SIZE];
  uint8_t out_buffer[SERIAL_BUFFERS_SIZE];
  //uint8_t buffer_check[SERIAL_BUFFERS_SIZE/2];
  size_t in, out;
  thread_t* th_shell = NULL;
  chRegSetThreadName("SDU");

  while(USBD1.state != USB_READY) chThdSleepMilliseconds(10);
  while(SDU1.state != SDU_READY) chThdSleepMilliseconds(10);
  while(SD3.state != SD_READY) chThdSleepMilliseconds(10);

  // Enable K-line transceiver
  palSetPad(PORT_KLINE_CS, PAD_KLINE_CS);

  shellInit();

  while (TRUE) {

    if (settings.serialMode == SERIAL_MODE_SHELL)  {
        if (th_shell == NULL || chThdTerminatedX(th_shell)) {
            th_shell = shellCreateStatic(&shell_cfg1, waThreadShell, sizeof(waThreadShell), NORMALPRIO +1);
        }
        chThdSleepMilliseconds(10);
        continue;
    }

    if (settings.serialMode != SERIAL_MODE_KLINE) {
        chThdSleepMilliseconds(10);
        continue;
    }

    /* In case we stop it to change baudrate */
    while (SD3.state != SD_READY) chThdSleepMilliseconds(10);

    if (doKLineInit && 0)
    {
      sdStop(&SD3);
      klineInit(false);
      //fiveBaudInit(&SD3);
      //sdReadTimeout(&SD3, buffer_check, 1, MS2ST(5)); // noise
      doKLineInit = false;
      sdStart(&SD3, &uart1Cfg);
    }

    in = chnReadTimeout(&SDU1, in_buffer, sizeof(in_buffer), TIME_IMMEDIATE);
    out = sdReadTimeout(&SD3, out_buffer, sizeof(out_buffer), TIME_IMMEDIATE);

    while (in == 0 && out == 0) {

        chThdSleepMilliseconds(1);
        in = chnReadTimeout(&SDU1, in_buffer, sizeof(in_buffer), TIME_IMMEDIATE);
        out = sdReadTimeout(&SD3, out_buffer, sizeof(out_buffer), TIME_IMMEDIATE);
    }

    if (in > 0)
    {
      sdWriteTimeout(&SD3, in_buffer, in, MS2ST(10));
    }

    if (out > 0)
    {
      chnWriteTimeout(&SDU1, out_buffer, out, MS2ST(10));
    }

  }
  return;
}