/**
 * \brief Initialize the UART with correct baud rate settings
 *
 * This function will initialize the UART baud rate registers with the correct
 * values using the AVR libc setbaud utility. In addition set the UART to
 * 8-bit, 1 stop and no parity.
 */
static void uart_init(void)
{
#if defined UBRR0H
	// get the values from the setbaud tool
	UBRR0H = UBRRH_VALUE;
	UBRR0L = UBRRL_VALUE;
#else
#error "Device is not supported by the driver"
#endif

#if USE_2X
	UCSR0A |= (1 << U2X0);
#endif

	// enable RX and TX and set interrupts on rx complete
	UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);

	// 8-bit, 1 stop bit, no parity, asynchronous UART
	UCSR0C = (1 << UCSZ01) | (1 << UCSZ00) | (0 << USBS0) |
			(0 << UPM01) | (0 << UPM00) | (0 << UMSEL01) |
			(0 << UMSEL00);

	// initialize the in and out buffer for the UART
	ring_buffer_out = ring_buffer_init(out_buffer, BUFFER_SIZE);
	ring_buffer_in = ring_buffer_init(in_buffer, BUFFER_SIZE);
}
int main(int argc, char *argv[])
{
    struct xdma6_ring_info ring1, ring2;
    char * dev_file = argv[1];
    int status = 0;
    int i,j;
    int offset;

    int data[] = { 0,5,5,5,2,3,6,8 };
    int data_len = 8;

    ring1.buffer_size = 100 * BUFSIZE;
    ring1.ring_size = 10;
    ring1.flags = 0
            | xdma_MEM_TO_DEV
            | xdma_SELFCHECK
            ;

    ring2 = ring1;
    ring2.buffer_size = 100 * BUFSIZE;
    ring2.ring_size = 10;
    ring2.flags = 0
            | xdma_DEV_TO_MEM
            | xdma_SELFCHECK
            ;

    // open file //
    int fd = open(dev_file, O_RDWR);
    if(!fd) {
        printf("error opening device file\n");
        return 1;
    }

    ring_buffer_init(&ring1,fd);
    ring_buffer_init(&ring2,fd);

    printf("start stream:\n");
    ring_start_stream(fd);

    for(i=0;i<50;++i){
        try_send_something(fd,data,data_len);
        try_receive_something(fd,data,data_len);
    }


    sleep(1);
    printf("stop stream:\n");
    ring_stop_stream(fd);

    printf("release buffers:\n");
    ring_buffer_release(&ring2,fd);
    ring_buffer_release(&ring1,fd);

    return 0;
}
OSStatus user_uartInit(void)
{
    OSStatus err = kUnknownErr;
    mico_uart_config_t uart_config;

    //USART init
    uart_config.baud_rate    = 115200;
    uart_config.data_width   = DATA_WIDTH_8BIT;
    uart_config.parity       = NO_PARITY;
    uart_config.stop_bits    = STOP_BITS_1;
    uart_config.flow_control = FLOW_CONTROL_DISABLED;
    uart_config.flags = UART_WAKEUP_DISABLE;
    ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, USER_UART_BUFFER_LENGTH );

    MicoUartInitialize( USER_UART, &uart_config, (ring_buffer_t *)&rx_buffer );

    //USART receive thread		启动uart接收线程
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv",
                                  uartRecv_thread, STACK_SIZE_USART_RECV_THREAD,
                                  NULL );
    require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the USART recv thread.") );


    //ZCB Msg Handle Thread		启动 ZCB Msg 处理线程
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "ZCB Msg Handle",
                                  ZCB_MessageHandle_thread, STACK_SIZE_ZCBMSG_HANDLE_THREAD,
                                  NULL );
    require_noerr_action( err, exit, user_uart_log("ERROR: Unable to start the zcbMsg hdl thread.") );


    return kNoErr;

exit:
    return err;
}
示例#4
0
文件: main.c 项目: rongfengyu/WiFiMCU
int application_start( void )
{
//start
//  lua_printf( "\r\n\r\nMiCO starting...(Free memory %d bytes)\r\n",MicoGetMemoryInfo()->free_memory);
  MicoInit();

//watch dog 
  MicoWdgInitialize( DEFAULT_WATCHDOG_TIMEOUT);
  mico_init_timer(&_watchdog_reload_timer,DEFAULT_WATCHDOG_TIMEOUT/2, _watchdog_reload_timer_handler, NULL);
  mico_start_timer(&_watchdog_reload_timer);
  
//usrinterface
  //MicoCliInit();
#if 1
//  lua_printf("Free memory %d bytes\r\n", MicoGetMemoryInfo()->free_memory); 
  lua_rx_data = (uint8_t*)malloc(INBUF_SIZE);
  ring_buffer_init  ( (ring_buffer_t*)&lua_rx_buffer, (uint8_t*)lua_rx_data, INBUF_SIZE );
  MicoUartInitialize( LUA_UART, &lua_uart_config, (ring_buffer_t*)&lua_rx_buffer );
  mico_rtos_create_thread(NULL, MICO_DEFAULT_WORKER_PRIORITY, "lua_main_thread", lua_main_thread, 20*1024, 0);
#endif
//  while(1) {;}
  mico_rtos_delete_thread(NULL);
  lua_printf("application_start exit\r\n");
  return 0;
 }
示例#5
0
bool mfg_test_for_app (void)
{
  mico_uart_config_t uart_config;
  volatile ring_buffer_t  rx_buffer;
  volatile uint8_t *      rx_data;

  rx_data = malloc (50);
  require (rx_data, exit);

  /* Initialize UART interface */
  uart_config.baud_rate    = 115200;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  uart_config.flags = UART_WAKEUP_DISABLE;

  ring_buffer_init ((ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, 50);
  MicoUartInitialize (MFG_TEST, &uart_config, (ring_buffer_t *)&rx_buffer);

  if (MicoUartRecv (MFG_TEST, cmd_str, 3, 100) == kNoErr) {
    if (cmd_str[0]=='#' && cmd_str[1]=='#' && cmd_str[2]=='#') {
      test_for_app = 1;
      return true;
    } else
      return false;
  }

exit:
  return false;
}
示例#6
0
文件: midi.c 项目: recri/keyer
static void *_init(void *arg) {
  _t *data = (_t *)arg;
  void *e = ring_buffer_init(&data->rb, sizeof(data->buff), data->buff); if (e != &data->rb) return e;
  data->started = 0;
  midi_buffer_init(&data->midi);
  return arg;
}
int application_start(void)
{
    app_log_trace();
    OSStatus err = kNoErr;
    mico_uart_config_t uart_config;
    app_context_t* app_context;
    mico_Context_t* mico_context;

    /* Create application context */
    app_context = ( app_context_t *)calloc(1, sizeof(app_context_t) );
    require_action( app_context, exit, err = kNoMemoryErr );

    /* Create mico system context and read application's config data from flash */
    mico_context = mico_system_context_init( sizeof( application_config_t) );
    app_context->appConfig = mico_system_context_get_user_data( mico_context );

    /* mico system initialize */
    err = mico_system_init( mico_context );
    require_noerr( err, exit );

    /* Bonjour for service searching */
    MICOStartBonjourService( Station, app_context );

    /* Protocol initialize */
    sppProtocolInit( app_context );

    /*UART receive thread*/
    uart_config.baud_rate    = app_context->appConfig->USART_BaudRate;
    uart_config.data_width   = DATA_WIDTH_8BIT;
    uart_config.parity       = NO_PARITY;
    uart_config.stop_bits    = STOP_BITS_1;
    uart_config.flow_control = FLOW_CONTROL_DISABLED;
    if(mico_context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
        uart_config.flags = UART_WAKEUP_ENABLE;
    else
        uart_config.flags = UART_WAKEUP_DISABLE;
    
    ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
    MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer );
    err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_UART_RECV_THREAD, (void*)app_context );
    require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") );

    /* Local TCP server thread */
    if(app_context->appConfig->localServerEnable == true)
    {
        err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)app_context );
        require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") );
    }

    /* Remote TCP client thread */
    if(app_context->appConfig->remoteServerEnable == true)
    {
        err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, STACK_SIZE_REMOTE_TCP_CLIENT_THREAD, (void*)app_context );
        require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") );
    }

exit:
    mico_rtos_delete_thread(NULL);
    return err;
}
示例#8
0
CFfmpeg::CFfmpeg()
{
	m_pFp = NULL;
	transcode = 0;
	infmt_ctx = NULL;
	video = -1;
	audio1 = -1;
	audio2 = -1;
	ring_buffer_init(&outputringbuffer, 1024*1024);
	buffer_init(&cbuffer, 1024*1024, 0); //+
	oc = NULL;
	vst = NULL; 
	ast1 = NULL;
	ast2 = NULL;
	bsfc = NULL;
	filesize = 0;
	curpos = 0;
	eof = 0;
	pthread_mutex_init(&iolock, NULL);
	pthread_mutex_init(&iolock2, NULL);
	vdts_base = 0;
	a1dts_base = 0;
	a2dts_base = 0;
	acodec1 = NULL;
	acodec2 = NULL;
	av_register_all();
	
	inputbuffer = (unsigned char*)malloc(MAIN_BUFFER_SIZE); //+
}
示例#9
0
//uart.setup(1,9600,'n','8','1')
//baud:all supported
//parity:
//      n,NO_PARITY;
//      o,ODD_PARITY;
//      e,EVEN_PARITY
//databits:
//      5:DATA_WIDTH_5BIT,
//      6:DATA_WIDTH_6BIT,
//      7:DATA_WIDTH_7BIT,
//      8:DATA_WIDTH_8BIT,
//      9:DATA_WIDTH_9BIT
//stopbits:
//      1,STOP_BITS_1
//      2,STOP_BITS_2
static int uart_setup( lua_State* L )
{
  uint16_t id, databits=DATA_WIDTH_8BIT, parity=NO_PARITY, stopbits=STOP_BITS_1;
  uint32_t baud=9600;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  baud = luaL_checkinteger( L, 2 );
  size_t sl=0;
  char const *str = luaL_checklstring( L, 3, &sl );
  if(sl == 1 && strcmp(str, "n") == 0)
    parity = NO_PARITY;
  else if(sl == 1 && strcmp(str, "o") == 0)
    parity = ODD_PARITY;
  else if(sl == 1 && strcmp(str, "e") == 0)
    parity = EVEN_PARITY;
  else
    return luaL_error( L, "arg parity should be 'n' or 'o' or 'e' " );
  
  str = luaL_checklstring( L, 4, &sl );
  if(sl == 1 && strcmp(str, "5") == 0)
    databits = DATA_WIDTH_5BIT;
  else if(sl == 1 && strcmp(str, "6") == 0)
    databits = DATA_WIDTH_6BIT;
  else if(sl == 1 && strcmp(str, "7") == 0)
    databits = DATA_WIDTH_7BIT;
  else if(sl == 1 && strcmp(str, "8") == 0)
    databits = DATA_WIDTH_8BIT;
  else if(sl == 1 && strcmp(str, "9") == 0)
    databits = DATA_WIDTH_9BIT;
  else
    return luaL_error( L, "arg databits should be '5'~'9' " );
  
  str = luaL_checklstring( L, 5, &sl );
  if(sl == 1 && strcmp(str, "1") == 0)
    stopbits = STOP_BITS_1;
  else if(sl == 1 && strcmp(str, "2") == 0)
    stopbits = STOP_BITS_2;
  else
    return luaL_error( L, "arg stopbits should be '1' or '2' " );

  lua_usr_uart_config.baud_rate = baud;
  lua_usr_uart_config.parity=(platform_uart_parity_t)parity;
  lua_usr_uart_config.data_width =(platform_uart_data_width_t)databits;
  lua_usr_uart_config.stop_bits =(platform_uart_stop_bits_t)stopbits;
  
  if(lua_usr_rx_data !=NULL) free(lua_usr_rx_data);
  lua_usr_rx_data = (uint8_t*)malloc(USR_INBUF_SIZE);
  if(pinbuf !=NULL) free(pinbuf);
  pinbuf = (uint8_t*)malloc(USR_UART_LENGTH);
  ring_buffer_init( (ring_buffer_t*)&lua_usr_rx_buffer, (uint8_t*)lua_usr_rx_data, USR_INBUF_SIZE );
  
  //MicoUartFinalize(LUA_USR_UART);
  MicoUartInitialize( LUA_USR_UART, &lua_usr_uart_config, (ring_buffer_t*)&lua_usr_rx_buffer );
  gL = L;
  usr_uart_cb_ref = LUA_NOREF;
  if(plua_usr_usart_thread !=NULL) mico_rtos_delete_thread(plua_usr_usart_thread);  
  mico_rtos_create_thread(plua_usr_usart_thread, MICO_DEFAULT_WORKER_PRIORITY, "lua_usr_usart_thread", lua_usr_usart_thread, 0x300, 0);
  return 0;
}
示例#10
0
void ConfigSoftApWillStart(mico_Context_t * const inContext )
{
  OSStatus err;
  mico_uart_config_t uart_config;

  mico_stop_timer(&_Led_EL_timer);
  mico_deinit_timer( &_Led_EL_timer );
  mico_init_timer(&_Led_EL_timer, SYS_LED_TRIGGER_INTERVAL_AFTER_EASYLINK, _led_EL_Timeout_handler, NULL);
  mico_start_timer(&_Led_EL_timer);
  
  sppProtocolInit(inContext);
  
   /*UART receive thread*/
  uart_config.baud_rate    = inContext->flashContentInRam.appConfig.USART_BaudRate;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
  MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer );
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, STACK_SIZE_UART_RECV_THREAD, (void*)inContext );
  require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the uart recv thread.") );

 if(inContext->flashContentInRam.appConfig.localServerEnable == true){
   err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, STACK_SIZE_LOCAL_TCP_SERVER_THREAD, (void*)inContext );
   require_noerr_action( err, exit, config_delegate_log("ERROR: Unable to start the local server thread.") );
 }

exit:
  return;
}
示例#11
0
struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
{
	struct ring_buffer *rb;
	unsigned long size;
	void *all_buf;

	size = sizeof(struct ring_buffer);
	size += sizeof(void *);

	rb = kzalloc(size, GFP_KERNEL);
	if (!rb)
		goto fail;

	INIT_WORK(&rb->work, rb_free_work);

	all_buf = vmalloc_user((nr_pages + 1) * PAGE_SIZE);
	if (!all_buf)
		goto fail_all_buf;

	rb->user_page = all_buf;
	rb->data_pages[0] = all_buf + PAGE_SIZE;
	rb->page_order = ilog2(nr_pages);
	rb->nr_pages = 1;

	ring_buffer_init(rb, watermark, flags);

	return rb;

fail_all_buf:
	kfree(rb);

fail:
	return NULL;
}
示例#12
0
OSStatus MVDDevInterfaceInit(mico_Context_t* const inContext)
{
  OSStatus err = kUnknownErr;
  mico_uart_config_t uart_config;
  
  //USART init
  uart_config.baud_rate    = inContext->flashContentInRam.appConfig.virtualDevConfig.USART_BaudRate;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
    uart_config.flags = UART_WAKEUP_ENABLE;
  else
    uart_config.flags = UART_WAKEUP_DISABLE;
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
  
  MicoUartInitialize( UART_FOR_MCU, &uart_config, (ring_buffer_t *)&rx_buffer );
  
  //USART receive thread
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", 
                                uartRecv_thread, STACK_SIZE_USART_RECV_THREAD, 
                                (void*)inContext );
  require_noerr_action( err, exit, dev_if_log("ERROR: Unable to start the USART recv thread.") );
  return kNoErr;
  
exit:
  return err;
}
示例#13
0
/* _____GLOBAL FUNCTIONS_____________________________________________________ */
void usart0_init(void)
{
    // Clear flag
    usart0_tx_finished_flag = FALSE;

    // Initialise ring buffers
    ring_buffer_init(&usart0_rx_ring_buffer, usart0_rx_buffer, USART0_RX_BUFFER_SIZE);
    ring_buffer_init(&usart0_tx_ring_buffer, usart0_tx_buffer, USART0_TX_BUFFER_SIZE);

    // Configure PIO pins for USART0 peripheral
    PIO_Configure(USART0_Pins, PIO_LISTSIZE(USART0_Pins));    

    // Disable the interrupt on the interrupt controller
    AIC_DisableIT(AT91C_ID_US0);

    // Enable USART0 clock
    PMC_EnablePeripheral(AT91C_ID_US0);

    // Disable all USART0 interrupts
    AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;

    // Configure USART
    USART_Configure(AT91C_BASE_US0,
                    AT91C_US_USMODE_NORMAL |
                    AT91C_US_CLKS_CLOCK    |
                    AT91C_US_CHRL_8_BITS   | 
                    AT91C_US_PAR_NONE      | 
                    AT91C_US_NBSTOP_1_BIT,
                    115200,
                    BOARD_MCK);

    USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
    USART_SetReceiverEnabled(AT91C_BASE_US0, 1);

    // Configure the AIC for USART0 interrupts
    AIC_ConfigureIT(AT91C_ID_US0, AT91C_AIC_PRIOR_LOWEST | AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, usart0_interrupt);

    // Enable the interrupt on the interrupt controller
    AIC_EnableIT(AT91C_ID_US0);

    // Enable selected USART0 interrupts
    AT91C_BASE_US0->US_IER = AT91C_US_RXRDY     |
                             AT91C_US_RXBRK     |
                             AT91C_US_OVRE      |
                             AT91C_US_FRAME     |
                             AT91C_US_PARE;
}
示例#14
0
wiced_result_t bluetooth_wiced_init_config_uart( const platform_uart_config_t* bt_uart_config )
{
    wiced_result_t result;

    ring_buffer_init( (wiced_ring_buffer_t*) &rx_ring_buffer, (uint8_t*) rx_data, sizeof( rx_data ) );
    result = platform_uart_init( wiced_bt_uart_driver, wiced_bt_uart_peripheral, bt_uart_config, (wiced_ring_buffer_t*) &rx_ring_buffer );
    return result;
}
示例#15
0
static void *_init(void *arg) {
  _t *dp = (_t *)arg;
  dp->opts.detime.sample_rate = sdrkit_sample_rate(&dp->fw);
  dp->opts.detime.word = dp->opts.word;
  dp->opts.detime.wpm = dp->opts.wpm;
  void *p = detime_preconfigure(&dp->detime, &dp->opts.detime); if (p != &dp->detime) return p;
  detime_configure(&dp->detime, &dp->opts.detime);
  ring_buffer_init(&dp->ring, RING_SIZE, dp->buff);
  return arg;
}
示例#16
0
static int display_deltacast_reconfigure_audio(void *state, int quant_samples, int channels,
                                int sample_rate)
{
        struct state_deltacast *s = (struct state_deltacast *)state;
        int i;

        assert(channels <= 16);

        pthread_mutex_lock(&s->lock);
        s->audio_configured = FALSE;
        for(i = 0; i < 16; ++i) {
                ring_buffer_destroy(s->audio_channels[i]);
                s->audio_channels[i] = NULL;
        }
        free(s->audio_tmp);

        s->audio_desc.bps = quant_samples / 8;
        s->audio_desc.ch_count = channels;
        s->audio_desc.sample_rate = sample_rate;

        for(i = 0; i < channels; ++i) {
                s->audio_channels[i] = ring_buffer_init(s->audio_desc.bps * s->audio_desc.sample_rate);
        }
        s->audio_tmp = (char *) malloc(s->audio_desc.bps * s->audio_desc.sample_rate);

        /* Configure audio info */
        memset(&s->AudioInfo, 0, sizeof(VHD_AUDIOINFO));
        for(i = 0; i < channels; ++i) {
                VHD_AUDIOCHANNEL *pAudioChn=NULL;
                pAudioChn = &s->AudioInfo.pAudioGroups[i / 4].pAudioChannels[i % 4];
                pAudioChn->Mode = VHD_AM_MONO;
                switch(quant_samples) {
                        case 16:
                                pAudioChn->BufferFormat = VHD_AF_16; 
                                break;
                        case 20:
                                pAudioChn->BufferFormat = VHD_AF_20; 
                                break;
                        case 24:
                                pAudioChn->BufferFormat = VHD_AF_24; 
                                break;
                        default:
                                fprintf(stderr, "[DELTACAST] Unsupported PCM audio: %d bits.\n", quant_samples);
                                pthread_mutex_unlock(&s->lock);
                                return FALSE;
                }
                pAudioChn->pData = new BYTE[s->audio_desc.bps * s->audio_desc.sample_rate];
        }

        s->audio_configured = TRUE;
        pthread_mutex_unlock(&s->lock);

        return TRUE;
}
示例#17
0
文件: Console_Task.c 项目: saiyn/web
void console_task(void *parameter)
{
	SYS_TRACE("console task running\r\n");
	ring_buffer_init();
	
	//	Enable UART0 interupt
	IntEnable(INT_UART0);
	while(1){
		serial_poll_handler();
		vTaskDelay(50/portTICK_RATE_MS);
	}
}
/* mxchip library manufacture test. */
void mxchip_mfg_test(void)
{
  char str[64];
  char mac[6];
  char *ssid;
  mico_uart_config_t uart_config;
  volatile ring_buffer_t  rx_buffer;
  volatile uint8_t *      rx_data;
  
  rx_data = malloc(50);
  require(rx_data, exit);
  
  /* Initialize UART interface */
  uart_config.baud_rate    = 115200;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  uart_config.flags = UART_WAKEUP_DISABLE;
  
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, 50 );
  MicoUartInitialize( MFG_TEST, &uart_config, (ring_buffer_t *)&rx_buffer );  

  mf_printf("==== MXCHIP Manufacture Test ====\r\n");
  mf_printf("Bootloader Version: ");
  mf_printf(mico_get_bootloader_ver());
  mf_printf("\r\n");
  sprintf(str, "Library Version: %s\r\n", system_lib_version());
  mf_printf(str);
  mf_printf("APP Version: ");
  memset(str, 0, sizeof(str));
  system_version(str, sizeof(str));
  mf_printf(str);
  mf_printf("\r\n");
  memset(str, 0, sizeof(str));
  MicoGetRfVer(str, sizeof(str));
  mf_printf("Driver: ");
  mf_printf(str);
  mf_printf("\r\n");
  wlan_get_mac_address(mac);
  sprintf(str, "MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n",
          mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  mf_printf(str);
  
  mfg_scan();
  
  ssid = ssid_get();
  mfg_connect(ssid);
  
exit:
  mico_thread_sleep(MICO_NEVER_TIMEOUT);
}
示例#19
0
文件: pe_workers.c 项目: sasw/opflex
/* ============================================================
 *
 * \brief pe_workers_init()
 *        Initializes the worker thread pool.
 *
 * @param[]
 *          none
 *
 * \return { void }
 *
 **/
void pe_workers_init() {
    static char mod[] = "pe_workers_init";

    DBUG_PUSH("d:F:i:L:n:t");
    DBUG_PROCESS("pe_workers");
    DBUG_ENTER(mod);

    ring_buffer_init();

    /* create the crew and put them to sleep on the ring buffer*/
    pe_crew_create();

    DBUG_LEAVE;
}
示例#20
0
void usb_config(void) {
    GPIO_InitTypeDef gpioInitStructure;
    EXTI_InitTypeDef extiInitStructure;
    NVIC_InitTypeDef nvicInitStructure;

    print_info("usb_config\n");

    ring_buffer_init(&usb_tx_ring_buffer, usb_tx_buffer, USB_TX_BUFFER_SIZE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    /* Enable the USB disconnect GPIO clock */
    RCC_APB2PeriphClockCmd(USB_DISCONNECT_RCC, ENABLE);

    /* USB_DISCONNECT used as USB pull-up */
    gpioInitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
    gpioInitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(USB_DISCONNECT, &gpioInitStructure);

    /* Configure the EXTI line 18 connected internally to the USB IP */
    EXTI_ClearITPendingBit(EXTI_Line18);
    extiInitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    extiInitStructure.EXTI_Line = EXTI_Line18;
    extiInitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    extiInitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&extiInitStructure);

    USB_Cable_Config(DISABLE);

    /* Enable USB clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);

    nvicInitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
    nvicInitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    nvicInitStructure.NVIC_IRQChannelSubPriority = 0;
    nvicInitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicInitStructure);

    /* Enable the USB Wake-up interrupt */
    nvicInitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
    nvicInitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_Init(&nvicInitStructure);

    print_info("USB_Init\n");
    USB_Init();
    delay_ms(100); // TODO remove?
}
示例#21
0
wiced_result_t command_console_init( wiced_uart_t uart, uint32_t line_len, char* buffer, uint32_t history_len, char* history_buffer_ptr, const char* delimiter_string )
{
    wiced_result_t result;
    UNUSED_PARAMETER(result);

    cons.uart = uart;

    cons.command_table_count = 0;
    cons.console_line_len   = line_len;
    cons.console_buffer = buffer;

    cons.console_buffer[0] = 0;
    cons.console_cursor_position = 0;
    cons.console_current_line = 0;
    cons.console_in_esc_seq = WICED_FALSE;
    cons.console_esc_seq_last_char = ' ';

    cons.history_buffer = history_buffer_ptr;
    cons.history_length = history_len;
    cons.history_num_lines = 0;
    cons.history_newest_line = 0;
    cons.quit = WICED_FALSE;
    cons.console_delimit_string = delimiter_string;
    cons.console_prompt_string = "> ";

    cons.console_thread_is_running = WICED_FALSE;

    console_add_cmd_table( commands );


    if( uart != STDIO_UART )
    {
        /* Init uart the same as stdio uart configuration */
        ring_buffer_init( (wiced_ring_buffer_t*) &cons.console_rx_ring_buffer, (uint8_t*) console_rx_ring_data, sizeof(console_rx_ring_data) );
        result = wiced_uart_init(uart, &uart_console_config, &cons.console_rx_ring_buffer);
    }

    wiced_rtos_init_semaphore(&cons.console_quit_semaphore);

    send_str(cons.console_prompt_string);

    /* create a console thread */
    result = wiced_rtos_create_thread( &cons.console_thread, WICED_DEFAULT_LIBRARY_PRIORITY, "console", console_thread_func, CONSOLE_THREAD_STACK_SIZE, NULL);

    return result;

}
OSStatus user_uartInit(void)
{
 // OSStatus err = kUnknownErr;
  mico_uart_config_t uart_config;
  
  //USART init
  uart_config.baud_rate    = 115200;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  uart_config.flags = UART_WAKEUP_DISABLE;
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, USER_UART_BUFFER_LENGTH );
  
  MicoUartInitialize( USER_UART, &uart_config, (ring_buffer_t *)&rx_buffer );
  
  return kNoErr;
}
示例#23
0
OSStatus MICOStartUart( mico_Context_t * const inContext )
{
    OSStatus err = kNoErr;
    mico_uart_config_t uart_config;
        /*UART receive thread*/
    uart_config.baud_rate    = 115200;
    uart_config.data_width   = DATA_WIDTH_8BIT;
    uart_config.parity       = NO_PARITY;
    uart_config.stop_bits    = STOP_BITS_1;
    uart_config.flow_control = FLOW_CONTROL_DISABLED;

    if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
        uart_config.flags = UART_WAKEUP_ENABLE;
    else
        uart_config.flags = UART_WAKEUP_DISABLE;
    ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
    MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer );
    return err;
}
示例#24
0
OSStatus MICOStartApplication( mico_Context_t * const inContext )
{
  app_log_trace();

  OSStatus err = kNoErr;
  mico_uart_config_t uart_config;
  require_action(inContext, exit, err = kParamErr);

  haProtocolInit(inContext);

  /*Bonjour for service searching*/
  if(inContext->flashContentInRam.micoSystemConfig.bonjourEnable == true)
    MICOStartBonjourService( Station, inContext );
  
  /*UART receive thread*/
  uart_config.baud_rate    = inContext->flashContentInRam.appConfig.USART_BaudRate;
  uart_config.data_width   = DATA_WIDTH_8BIT;
  uart_config.parity       = NO_PARITY;
  uart_config.stop_bits    = STOP_BITS_1;
  uart_config.flow_control = FLOW_CONTROL_DISABLED;
  if(inContext->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true)
    uart_config.flags = UART_WAKEUP_ENABLE;
  else
    uart_config.flags = UART_WAKEUP_DISABLE;
  ring_buffer_init  ( (ring_buffer_t *)&rx_buffer, (uint8_t *)rx_data, UART_BUFFER_LENGTH );
  MicoUartInitialize( UART_FOR_APP, &uart_config, (ring_buffer_t *)&rx_buffer );
  err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART Recv", uartRecv_thread, 0x200, (void*)inContext );
  require_noerr_action( err, exit, app_log("ERROR: Unable to start the uart recv thread.") );

 if(inContext->flashContentInRam.appConfig.localServerEnable == true){
   err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Local Server", localTcpServer_thread, 0x350, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the local server thread.") );
 }

 if(inContext->flashContentInRam.appConfig.remoteServerEnable == true){
   err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "Remote Client", remoteTcpClient_thread, 0x300, (void*)inContext );
   require_noerr_action( err, exit, app_log("ERROR: Unable to start the remote client thread.") );
 }

exit:
  return err;
}
示例#25
0
int main (int argc, const char* argv[])
{
	ring_buffer_t ring;
	ring_buffer_init(&ring, buf, sizeof(buf));

	while (1) {
		printf("av: %d/%d\nhead=%ld, tail=%ld\n\n> ",
			ring_buffer_av_data(&ring), ring_buffer_av_space(&ring),
			ring.head - ring.buffer, ring.tail - ring.buffer
		);

		size_t sz = 128;
		char* str = malloc(sz);
		int bytes = getline(&str, &sz, stdin);

		bytes--; // remove '\n'

		if (bytes > 0) {

			uint32_t pushed = ring_buffer_push(&ring, str, bytes);
			printf("push(%d) %d\n", bytes, pushed);

		} else if (bytes == 0) {

			uint32_t to_pop = 10;
			uint32_t popped = ring_buffer_pop(&ring, str, to_pop);
			printf("pop(%d) %d\n", to_pop, popped);
			if (popped > 0) {
				for (int i = 0; i < popped; i++) {
					printf("%c", str[i]);
				}
				printf("\n");
			}

		} else if (bytes < 0) {
			return -1;
		}
	}

	return 0;
}
示例#26
0
struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
{
	struct ring_buffer *rb;
	unsigned long size;
	int i;

	size = sizeof(struct ring_buffer);
	size += nr_pages * sizeof(void *);

	rb = kzalloc(size, GFP_KERNEL);
	if (!rb)
		goto fail;

	rb->user_page = perf_mmap_alloc_page(cpu);
	if (!rb->user_page)
		goto fail_user_page;

	for (i = 0; i < nr_pages; i++) {
		rb->data_pages[i] = perf_mmap_alloc_page(cpu);
		if (!rb->data_pages[i])
			goto fail_data_pages;
	}

	rb->nr_pages = nr_pages;

	ring_buffer_init(rb, watermark, flags);

	return rb;

fail_data_pages:
	for (i--; i >= 0; i--)
		free_page((unsigned long)rb->data_pages[i]);

	free_page((unsigned long)rb->user_page);

fail_user_page:
	kfree(rb);

fail:
	return NULL;
}
示例#27
0
文件: main.c 项目: Zhang-Jia/WiFiMCU
int application_start( void )
{
//start
//  lua_printf( "\r\n\r\nMiCO starting...(Free memory %d bytes)\r\n",MicoGetMemoryInfo()->free_memory);
  MicoInit();

//watch dog 
  MicoWdgInitialize( DEFAULT_WATCHDOG_TIMEOUT);
  mico_init_timer(&_watchdog_reload_timer,DEFAULT_WATCHDOG_TIMEOUT/2, _watchdog_reload_timer_handler, NULL);
  mico_start_timer(&_watchdog_reload_timer);
  
#if 0
  #include "tm_stm32f4_usb_vcp.h"
  lua_printf("\r\n\r\n TM_USB_VCP_Init:%d",TM_USB_VCP_Init());
  uint8_t c;
  //NVIC_SetVectorTable(NVIC_VectTab_FLASH, new_addr);
  while(1)
  {
   if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)
   {
     if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) 
     {
       TM_USB_VCP_Putc(c);/* Return data back */
     }
   }
  }
#endif
//usrinterface
  //MicoCliInit();
#if 1
//  lua_printf("Free memory %d bytes\r\n", MicoGetMemoryInfo()->free_memory); 
  lua_rx_data = (uint8_t*)malloc(INBUF_SIZE);
  ring_buffer_init( (ring_buffer_t*)&lua_rx_buffer, (uint8_t*)lua_rx_data, INBUF_SIZE );
  MicoUartInitialize( LUA_UART, &lua_uart_config, (ring_buffer_t*)&lua_rx_buffer );
  mico_rtos_create_thread(NULL, MICO_DEFAULT_WORKER_PRIORITY, "lua_main_thread", lua_main_thread, 20*1024, 0);
#endif
//  while(1) {;}
  mico_rtos_delete_thread(NULL);
  lua_printf("application_start exit\r\n");
  return 0;
 }
示例#28
0
static void initialize(void) {
    samples_drawable_lock = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(samples_drawable_lock, NULL);
    samples_drawable = (TYPE*) calloc(max_window_width, sizeof(TYPE));
    ring_buffer = ring_buffer_init(sizeof_ring_buffer);
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }
    main_window = glfwCreateWindow(default_window_width, default_window_height, default_window_title, NULL, NULL);
    if (!main_window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(main_window);
    glDisable(GL_DEPTH_TEST);
    set_gl_view(current_width, current_height);
    initialize_grid();
    glfwSwapInterval(1);
    producer_thread = malloc(sizeof(pthread_t));
    pthread_create(producer_thread, NULL, signal_source_start, ring_buffer);
}
void main() {
  char temp[100];
  uint16_t len;

  ring_buffer_init(&ring, buffer, BUFFER_SIZE);

  len = ring_buffer_readline(&ring, temp, 100);
  printf("%d - %s\n", len, temp);
  
  strcpy(temp, "line1\nline2\nline3");
  ring_buffer_write(&ring, temp, strlen(temp));
  while((len = ring_buffer_readline(&ring, temp, 100)) > 0) {
    printf("%d - %s\n", len, temp);
  }
  
  printf("available: %d\n", ring.available);
  ring_buffer_write_byte(&ring, '\n');
  while((len = ring_buffer_readline(&ring, temp, 100)) > 0) {
    printf("%d - %s\n", len, temp);
  }
}
/* Main application */
void application_start( )
{
	char    receiveChar;
    uint32_t expected_data_size = 1;

	wiced_init();	/* Initialize the WICED device */

    /* Configure and start the UART. */
    /* Note that WICED_DISABLE_STDIO must be defined in the make file for this to work */
	#define RX_BUFFER_SIZE (5)
	wiced_ring_buffer_t rx_buffer;
    uint8_t             rx_data[RX_BUFFER_SIZE];
	ring_buffer_init(&rx_buffer, rx_data, RX_BUFFER_SIZE ); /* Initialize ring buffer to hold receive data */
    wiced_uart_config_t uart_config =
    {
        .baud_rate    = 9600,
        .data_width   = DATA_WIDTH_8BIT,
        .parity       = NO_PARITY,
        .stop_bits    = STOP_BITS_1,
        .flow_control = FLOW_CONTROL_DISABLED,
    };
    wiced_uart_init( STDIO_UART, &uart_config, &rx_buffer); /* Setup UART */

    while ( 1 )
    {
        if ( wiced_uart_receive_bytes( STDIO_UART, &receiveChar, &expected_data_size, WICED_NEVER_TIMEOUT ) == WICED_SUCCESS )
        {
            /* If we get here then a character has been received */
        	if(receiveChar == '0') /* LED OFF for the shield (LED ON if using the baseboard by itself) */
        	{
        		wiced_gpio_output_low( WICED_LED1 );
        	}
        	if(receiveChar == '1') /* LED ON for the shield (LED OFF if using the baseboard by itself) */
        	{
        		wiced_gpio_output_high( WICED_LED1 );
        	}
        }

    }
}