コード例 #1
0
ファイル: client.c プロジェクト: 4nykey/rockbox
// do the baudrate configuration for the Recoder/FM
int ConfigFirstlevelRecorder (tUartHandle serial_handle)
{
	UINT32 result_nbr;

	if(!UartConfig(serial_handle, 4800, eNOPARITY, eTWOSTOPBITS, 8))
	{
		UINT32 dwErr = GET_LAST_ERR();
		printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
		exit(1);
	}

	// this will read as 0x08 when viewed with 2120 baud like the recorder does
	result_nbr = UartWrite(serial_handle, (UINT8*)"\x00\x00", 2);
	if(result_nbr != 2)
	{
		printf("Error transmitting baudrate byte\n");
		exit(1);
	}

	SLEEP(100); // wait for the chars to be sent, is there a better way?

	// the read 0x08 means 38400 baud with 11.0592 MHz
	if(!UartConfig(serial_handle, 38400, eNOPARITY, eONESTOPBIT, 8))
	{
		UINT32 dwErr = GET_LAST_ERR();
		printf("Error %lu setting up COM params for 1st level loader\n", dwErr);
		exit(1);
	}

	return 0;
}
コード例 #2
0
ファイル: client.c プロジェクト: 4nykey/rockbox
// do the baudrate configuration for the Player
int ConfigFirstlevelPlayer (tUartHandle serial_handle)
{
	UINT32 result_nbr;

	if(!UartConfig(serial_handle, 4800, eMARKPARITY, eTWOSTOPBITS, 8))
	{
		UINT32 dwErr = GET_LAST_ERR();
		printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
		exit(1);
	}

	// this will read as 0x19 when viewed with 2300 baud like the player does
	result_nbr = UartWrite(serial_handle, (UINT8*)"\x86\xC0", 2);
	if (result_nbr != 2)
	{
		UINT32 dwErr = GET_LAST_ERR();
		printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
	}

	SLEEP(100); // wait for the chars to be sent, is there a better way?

	// the read 0x19 means 14423 baud with 12 MHz
	if(!UartConfig(serial_handle, 14400, eNOPARITY, eONESTOPBIT, 8))
	{
		printf("Error setting up COM params for 1st level loader\n");
		exit(1);
	}

	return 0;
}
コード例 #3
0
ファイル: board.c プロジェクト: AlexanderWiniger/LoRaMac-node
void BoardInitMcu( void )
{
    if ( McuInitialized == false ) {
        /* Initialize low level components */
        low_level_init();

        /*! SPI channel to be used by Semtech SX1276 */
#if defined(SX1276_BOARD_EMBED)
        SpiInit(&SX1276.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC);
        SX1276IoInit();
#endif

#if defined (USE_USB_CDC)
        UartInit( &UartUsb, UART_USB_CDC, NC, NC );
        UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
        TimerSetLowPowerEnable(false);
#elif defined(DEBUG)
#if defined(USE_SHELL)
        Shell_Init();
#else
#if !defined(USE_CUSTOM_UART_HAL)
        FifoInit(&Uart1.FifoRx, DbgRxBuffer, DBG_FIFO_RX_SIZE);
        FifoInit(&Uart1.FifoTx, DbgTxBuffer, DBG_FIFO_TX_SIZE);
#endif

        UartInit(&Uart1, UART_1, UART1_TX, UART1_RX);
        UartConfig(&Uart1, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY,
                NO_FLOW_CTRL);
#endif
        DbgConsole_Init(&Uart1);
        TimerSetLowPowerEnable(false);
#elif( LOW_POWER_MODE_ENABLE )
        TimerSetLowPowerEnable(true);
#else
        TimerSetLowPowerEnable(false);
#endif
        BoardUnusedIoInit();

#if !defined(USE_FREE_RTOS)
        if ( TimerGetLowPowerEnable() == true ) {
            RtcInit();
        } else {
            TimerHwInit();
        }
#endif /* USE_FREE_RTOS */

        McuInitialized = true;
    }
}
コード例 #4
0
ファイル: uart.cpp プロジェクト: stxy0509/GoldRoulette
void C_UART::Configure(int rate,void (*p)())
{
	if(!IsvalidBitRate(rate) || p == NULL || HaveConfigured) 
	{
		return;
	}
	BitRate = rate;
	UartConfig(Channel,BitRate);
	if(Channel == 0)
	{
		FullDuplex = true;
	}
	else 
	{
		FullDuplex = false;
		//485 CONTROL LINE,半双工需要一个
		//开关来控制数据的接收和发送
		gpio_set_port_output(45);
	}
	SetInterruptPriority(UartIntNumber[Channel],1);
	vgSetInterrupt(UartIntNumber[Channel],p);
	EnableReceData();
	//enable data receive interrupt
    *(UIE[Channel]) = 0x01; 
	vgEnableInterrupt(UartIntNumber[Channel],true); 
	HaveConfigured = true;
}
コード例 #5
0
ファイル: client.c プロジェクト: 4nykey/rockbox
// change baudrate using target monitor
int SetTargetBaudrate(tUartHandle serial_handle, long lClock, long lBaudrate)
{
	UINT8 send;
	UINT8 received;
	UINT8 brr;
	long lBRR;

	lBRR = lClock / lBaudrate;
	lBRR = ((lBRR + 16) / 32) - 1; // with rounding
	brr = (UINT8)lBRR;

	// send the command
	send = BAUDRATE;
	UartWrite(serial_handle, &send, 1);
	UartWrite(serial_handle, &brr, 1); // send the BRR value
	UartRead(serial_handle, &received, 1); // response ack

	if (received != BAUDRATE)
	{	// bad situation, now we're unclear about the baudrate of the target
		printf("Protocol error!\n");
		return 1;
	}

	SLEEP(100); // give it some time to settle

	// change our baudrate, too
	UartConfig(serial_handle, lBaudrate, eNOPARITY, eONESTOPBIT, 8); 

	return 0;
}
コード例 #6
0
ファイル: board.c プロジェクト: czj-tyro/LoRaMac-node
void BoardInitMcu( void )
{
    Gpio_t ioPin;

    if( McuInitialized == false )
    {
        HAL_Init( );

        // LEDs
        GpioInit( &Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
        GpioInit( &Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 );
        GpioInit( &Led3, LED_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, Led3Status );

        SystemClockConfig( );

        GpioInit( &ioPin, UART_RX, PIN_INPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        if( GpioRead( &ioPin ) == 1 )   // Debug Mode
        {
            UsbIsConnected = true;
            FifoInit( &Uart1.FifoTx, UartTxBuffer, UART_FIFO_TX_SIZE );
            FifoInit( &Uart1.FifoRx, UartRxBuffer, UART_FIFO_RX_SIZE );
            // Configure your terminal for 8 Bits data (7 data bit + 1 parity bit), no parity and no flow ctrl
            UartInit( &Uart1, UART_1, UART_TX, UART_RX );
            UartConfig( &Uart1, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
        }
        else
        {
            UsbIsConnected = false;
            UartDeInit( &Uart1 );
        }

        RtcInit( );

        BoardUnusedIoInit( );
    }
    else
    {
        SystemClockReConfig( );
    }

    I2cInit( &I2c, I2C_SCL, I2C_SDA );
    AdcInit( &Adc, BAT_LEVEL_PIN );

    SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
    SX1272IoInit( );

    if( McuInitialized == false )
    {
        McuInitialized = true;
        if( GetBoardPowerSource( ) == BATTERY_POWER )
        {
            CalibrateSystemWakeupTime( );
        }
    }
}
コード例 #7
0
ファイル: gps-board.c プロジェクト: abouillot/LoRaMac-node
void GpsMcuOnPpsSignal( void )
{
    bool parseData = false;

    GpsPpsHandler( &parseData );

    if( parseData == true )
    {
        UartInit( &Uart1, UART_1, UART_TX, UART_RX );
        UartConfig( &Uart1, RX_ONLY, 9600, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
    }
}
コード例 #8
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      ConfigureUart
 *
 *  DESCRIPTION
 *      This function configures the UART Baud rate. A TRUE value in the 
 *      parameter means that high baud rate is to be configured and a FALSE 
 *      means that low baud rate is to be configured.
 *
 *  RETURNS
 *      Nothing
 *
 *----------------------------------------------------------------------------*/
extern void ConfigureUart(bool b_high)
{
    if(b_high)
    {
        /* Configure the UART for high baud rate */
        UartConfig(HIGH_BAUD_RATE,0);
        
        /* Enable the UART back */
        UartEnable(TRUE);
        
        /* Read from UART */
        UartRead(1,0);
        
        /* Disable deep sleep, so characters dont go missing  */
        SleepModeChange(sleep_mode_never); 
                
        /* Setup the variable to indicate the current baud rate is high */
        g_is_current_baud_rate_high = TRUE;
    }
    else
    {
        /* Configure the UART for high baud rate */
        UartConfig(LOW_BAUD_RATE,0);
        
        /* Enable the UART back */
        UartEnable(TRUE);
        
        /* Read from UART */
        UartRead(1,0);
        
        /* Enable deep sleep */
        SleepModeChange(sleep_mode_deep);  
        
        /* Setup the variable to indicate the current baud rate is low */
        g_is_current_baud_rate_high = FALSE;
    }
}
コード例 #9
0
ファイル: board.c プロジェクト: AlessandroLipari/LoRaMac-node
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
#if defined( USE_BOOTLOADER )
        // Set the Vector Table base location at 0x3000
        NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x3000 );
#endif
        // We use IRQ priority group 4 for the entire project
        // When setting the IRQ, only the preemption priority is used
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

        // Disable Systick
        SysTick->CTRL  &= ~SysTick_CTRL_TICKINT_Msk;    // Systick IRQ off 
        SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;            // Clear SysTick Exception pending flag

        I2cInit( &I2c, I2C_SCL, I2C_SDA );
        AdcInit( &Adc, BAT_LEVEL );

        SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
        SX1272IoInit( );

#if defined( USE_DEBUG_PINS )
        GpioInit( &DbgPin1, CON_EXT_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin2, CON_EXT_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin3, CON_EXT_7, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
        GpioInit( &DbgPin4, CON_EXT_9, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
#endif

        BoardUnusedIoInit( );

#if defined( USE_USB_CDC )
        UsbMcuInit( );
        UartInit( &UartUsb, UART_USB_CDC, NC, NC );
        UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );
#endif

#ifdef LOW_POWER_MODE_ENABLE
        RtcInit( );
#else
        TimerHwInit( );
#endif
        McuInitialized = true;
    }
}
コード例 #10
0
ファイル: main.c プロジェクト: NeoBelerophon/openHC
int main(int argc, char* argv[])
{
    int retval = 0;

    if (argc < 2)
    {
        printf("Usage: phc_log <COM port> {<JRM list>}\n");
#ifdef WIN32
        printf("       <COM port> is e.g. COM1, COM2, etc.\n");
#else
        printf("       <COM port> is e.g. /dev/ttyS0, /dev/ttyS1, etc.\n");
#endif
        printf("       <JRM list> is a comma/dash separated list of JRM modules\n");
        printf("Example: phc_log COM5 24-27,30\n");
        return -1;
    }

    if (argc >= 3)
    {
        // which AM module(s) to treat as JRM
        retval = get_range(argv[2]);
        if (retval)
        {
            printf("Error: bad address specified %s\n", argv[2]);
            return retval;
        }
        
    }
    
    ghUart = UartOpen(argv[1]);
    if (!ghUart)
    {
        printf("Error opening %s\n", argv[1]);
        return -2;
    }

    //UartConfig(ghUart, 19200, eNOPARITY, eTWOSTOPBITS, 8, 0);
    UartConfig(ghUart, 19200, eNOPARITY, eONESTOPBIT, 8, 0);

    log_loop(ghUart); // do the action

    UartClose(ghUart);

    return retval;
}
コード例 #11
0
ファイル: board.c プロジェクト: Lora-net/LoRaMac-node
void BoardInitMcu( void )
{
    if( McuInitialized == false )
    {
#if defined( USE_BOOTLOADER )
        // Set the Vector Table base location at 0x3000
        SCB->VTOR = FLASH_BASE | 0x3000;
#endif
        HAL_Init( );

        SystemClockConfig( );

#if defined( USE_USB_CDC )
        UartInit( &UartUsb, UART_USB_CDC, NC, NC );
        UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL );

        DelayMs( 1000 ); // 1000 ms for Usb initialization
#endif

        RtcInit( );

        BoardUnusedIoInit( );

        I2cInit( &I2c, I2C_1, I2C_SCL, I2C_SDA );
    }
    else
    {
        SystemClockReConfig( );
    }

    AdcInit( &Adc, BAT_LEVEL_PIN );

    SpiInit( &SX1272.Spi, SPI_1, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
    SX1272IoInit( );

    if( McuInitialized == false )
    {
        McuInitialized = true;
        if( GetBoardPowerSource( ) == BATTERY_POWER )
        {
            CalibrateSystemWakeupTime( );
        }
    }
}
コード例 #12
0
ファイル: client.c プロジェクト: 4nykey/rockbox
// rarely used variant: download our monitor using the built-in Archos monitor
int DownloadArchosMonitor(tUartHandle serial_handle, char* szFilename)
{
	FILE* pFile;
	size_t filesize;
	UINT8 byte;
	UINT16 checksum = 0;
	unsigned i;

	// the onboard monitor uses 115200 baud
	if(!UartConfig(serial_handle, 115200, eNOPARITY, eONESTOPBIT, 8))
	{
		UINT32 dwErr = GET_LAST_ERR();
		printf("Error %lu setting up COM params for baudrate %d\n", dwErr, 115200);
		exit(1);
	}

	// wait for receiving "#SERIAL#"
	WaitForString(serial_handle, "#SERIAL#");
	
	// send magic "SRL" command to get interactive mode
	SendWithEcho(serial_handle, "SRL\r");
	
	// wait for menu completion: "ROOT>" at the end
	WaitForString(serial_handle, "ROOT>");
	
	// send upload command "UP"
	SendWithEcho(serial_handle, "UP\r");
	
	pFile = fopen(szFilename, "rb");
	if (pFile == NULL)
	{
		printf("\nMonitor file %s not found, exiting\n", szFilename);
		exit(1);
	}

	// determine file size
	fseek(pFile, 0, SEEK_END);
	filesize = ftell(pFile);
	fseek(pFile, 0, SEEK_SET);
	
	// calculate checksum
	for (i=0; i<filesize; i++)
	{
		fread(&byte, 1, 1, pFile);
		checksum += byte;
	}
	fseek(pFile, 0, SEEK_SET);
	
	// send header

	// size as 32 bit little endian
	byte = (UINT8)( filesize	  & 0xFF);
	UartWrite(serial_handle, &byte, 1);
	byte = (UINT8)((filesize>>8)  & 0xFF);
	UartWrite(serial_handle, &byte, 1);
	byte = (UINT8)((filesize>>16) & 0xFF);
	UartWrite(serial_handle, &byte, 1);
	byte = (UINT8)((filesize>>24) & 0xFF);
	UartWrite(serial_handle, &byte, 1);

	// checksum as 16 bit little endian
	byte = (UINT8)( checksum	  & 0xFF);
	UartWrite(serial_handle, &byte, 1);
	byte = (UINT8)((checksum>>8)  & 0xFF);
	UartWrite(serial_handle, &byte, 1);
	
	UartWrite(serial_handle, (unsigned char*)"\x00", 1); // kind (3 means flash)
	UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte

	// wait for monitor to accept data
	WaitForString(serial_handle, "#OKCTRL#");
	
	// transmit the image
	for (i=0; i<filesize; i++)
	{
		fread(&byte, 1, 1, pFile);
		UartWrite(serial_handle, &byte, 1); // payload
	}
	fclose (pFile);
	
	UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte

	// wait for menu completion: "ROOT>" at the end
	WaitForString(serial_handle, "ROOT>");

	// send start program command "SPRO"
	SendWithEcho(serial_handle, "SPRO\r");

	SLEEP(100); // wait a little while for startup

	return 0;
}