void execute_sensor_measurement()
{
#ifdef PLATFORM_EFM32GG_STK3700
  float internal_temp = hw_get_internal_temperature();
  lcd_write_temperature(internal_temp*10, 1);

  uint32_t vdd = hw_get_battery();


  fs_write_file(SENSOR_FILE_ID, 0, (uint8_t*)&internal_temp, sizeof(internal_temp)); // File 0x40 is configured to use D7AActP trigger an ALP action which broadcasts this file data on Access Class 0
#endif

#if (defined PLATFORM_EFM32HG_STK3400  || defined PLATFORM_EZR32LG_WSTK6200A)
  char str[30];

  float internal_temp = hw_get_internal_temperature();
  sprintf(str, "Int T: %2d.%d C", (int)internal_temp, (int)(internal_temp*10)%10);
  lcd_write_line(2,str);
  log_print_string(str);

  uint32_t rhData;
  uint32_t tData;
  getHumidityAndTemperature(&rhData, &tData);

  sprintf(str, "Ext T: %d.%d C", (tData/1000), (tData%1000)/100);
  lcd_write_line(3,str);
  log_print_string(str);

  sprintf(str, "Ext H: %d.%d", (rhData/1000), (rhData%1000)/100);
  lcd_write_line(4,str);
  log_print_string(str);

  uint32_t vdd = hw_get_battery();

  sprintf(str, "Batt %d mV", vdd);
  lcd_write_line(5,str);
  log_print_string(str);

  //TODO: put sensor values in array

  uint8_t sensor_values[8];
  uint16_t *pointer =  (uint16_t*) sensor_values;
  *pointer++ = (uint16_t) (internal_temp * 10);
  *pointer++ = (uint16_t) (tData /100);
  *pointer++ = (uint16_t) (rhData /100);
  *pointer++ = (uint16_t) (vdd /10);

  fs_write_file(SENSOR_FILE_ID, 0, (uint8_t*)&sensor_values,8);
#endif

  timer_post_task_delay(&execute_sensor_measurement, SENSOR_UPDATE);
}
static void increase_channel() {
	if (current_channel_id.channel_header.ch_freq_band == PHY_BAND_433)
	{
		if (current_channel_id.channel_header.ch_class == PHY_CLASS_LO_RATE)
		{
			current_channel_id.center_freq_index = (current_channel_id.center_freq_index == 68) ? 0 : current_channel_id.center_freq_index + 1;
		}
		else
		{
			current_channel_id.center_freq_index = (current_channel_id.center_freq_index == 56) ? 0 : current_channel_id.center_freq_index + 8;
		}
	}else if (current_channel_id.channel_header.ch_freq_band == PHY_BAND_868)
	{
		if (current_channel_id.channel_header.ch_class == PHY_CLASS_LO_RATE)
		{
			current_channel_id.center_freq_index = (current_channel_id.center_freq_index == 279) ? 0 : current_channel_id.center_freq_index + 1;
		}
		else
		{
			current_channel_id.center_freq_index = (current_channel_id.center_freq_index == 272) ? 0 : current_channel_id.center_freq_index + 8;
		}
	}



	#ifdef PLATFORM_EZR32LG_WSTK6200A
		char str[20];
		channel_id_to_string(&current_channel_id, str, sizeof(str));
		console_print(str);
		lcd_write_line(6, str);
	#endif
}
static void packet_received(hw_radio_packet_t* packet) {
    uint16_t crc = __builtin_bswap16(crc_calculate(packet->data, packet->length - 2));
    if(memcmp(&crc, packet->data + packet->length + 1 - 2, 2) != 0)
    {
        DPRINT("CRC error");
        missed_packets_counter++;
    }
    else
    {
		#if HW_NUM_LEDS > 0
			led_toggle(0);
		#endif
		uint16_t msg_counter = 0;
        uint64_t msg_id;
        memcpy(&msg_id, packet->data + 1, sizeof(msg_id));
        memcpy(&msg_counter, packet->data + 1 + sizeof(msg_id), sizeof(msg_counter));
        char chan[8];
        channel_id_to_string(&(packet->rx_meta.rx_cfg.channel_id), chan, sizeof(chan));
        console_printf("%7s,%i,%i,%lu,%lu,%i\n", chan, msg_counter, packet->rx_meta.rssi, (unsigned long)msg_id, (unsigned long)id, packet->rx_meta.timestamp);
    

		if(counter == 0)
		{
			// just start, assume received all previous counters to reset PER to 0%
			received_packets_counter = msg_counter - 1;
			counter = msg_counter - 1;
		}

		uint16_t expected_counter = counter + 1;
		if(msg_counter == expected_counter)
		{
			received_packets_counter++;
			counter++;
		}
		else if(msg_counter > expected_counter)
		{
			missed_packets_counter += msg_counter - expected_counter;
			counter = msg_counter;
		}
		else
		{
            sched_post_task(&start);
		}

	    double per = 0;
	    if(msg_counter > 0)
	        per = 100.0 - ((double)received_packets_counter / (double)msg_counter) * 100.0;

	    sprintf(lcd_msg, "%i %i", (int)per, packet->rx_meta.rssi);

#ifdef PLATFORM_EFM32GG_STK3700
	    lcd_write_string(lcd_msg);
#else
	    lcd_write_line(4, lcd_msg);
#endif

    }
}
static void start() {
    counter = 0;
    missed_packets_counter = 0;
    received_packets_counter = 0;
    uint8_t lcd_line = 0;

    switch(current_state)
    {
        case STATE_CONFIG_DIRECTION:
            is_mode_rx? sprintf(lcd_msg, "PER RX") : sprintf(lcd_msg, "PER TX");
            break;
        case STATE_CONFIG_DATARATE:
        	lcd_line = 1;
            switch(current_channel_id.channel_header.ch_class)
            {
                case PHY_CLASS_LO_RATE:
                    sprintf(lcd_msg, "LO-RATE");
                    break;
                case PHY_CLASS_NORMAL_RATE:
                    sprintf(lcd_msg, "NOR-RATE");
                    break;
                case PHY_CLASS_HI_RATE:
                    sprintf(lcd_msg, "HI-RATE");
                    break;
            }
            break;
        case STATE_RUNNING:
        	lcd_line = 2;
            if(is_mode_rx)
            {
                sprintf(lcd_msg, "RUN RX");
                //lcd_write_string(lcd_msg);
                console_printf("%s,%s,%s,%s,%s,%s\n", "channel_id", "counter", "rssi", "tx_id", "rx_id", "timestamp");
                rx_cfg.channel_id = current_channel_id;
                timer_post_task(&start_rx, TIMER_TICKS_PER_SEC * 5);
            }
            else
            {
                hw_radio_set_idle();
                sprintf(lcd_msg, "RUN TX");
                //lcd_write_string(lcd_msg);
                timer_post_task(&transmit_packet, TIMER_TICKS_PER_SEC * 5);
            }
            break;
    }

#ifdef PLATFORM_EFM32GG_STK3700
    lcd_write_string(lcd_msg);
#else
    lcd_write_line(lcd_line, lcd_msg);
#endif

}
void bootstrap() {
    DPRINT("Device booted at time: %d\n", timer_get_counter_value());

#ifndef FRAMEWORK_LOG_BINARY
    console_print("\r\nPER TEST - commands:\r\n");
    console_print("  CHANfffriii  channel settings:\r\n");
    console_print("               fff frequency : 433, 868, 915\r\n");
    console_print("               r   rate      : L(ow) N(ormal) H(igh)\r\n");
    console_print("               iii center_freq_index\r\n");
    console_print("  TRANsss      transmit a packet every sss seconds.\r\n");
    console_print("  RECV         receive packets\r\n");
    console_print("  RSET         reset module\r\n");
#endif

    id = hw_get_unique_id();
    hw_radio_init(&alloc_new_packet, &release_packet);

    rx_cfg.channel_id = current_channel_id;
    tx_cfg.channel_id = current_channel_id;

    ubutton_register_callback(0, &userbutton_callback);
    ubutton_register_callback(1, &userbutton_callback);

    fifo_init(&uart_rx_fifo, uart_rx_buffer, sizeof(uart_rx_buffer));

    console_set_rx_interrupt_callback(&uart_rx_cb);
    console_rx_interrupt_enable();

    sched_register_task(&start_rx);
    sched_register_task(&transmit_packet);
    sched_register_task(&start);
    sched_register_task(&process_uart_rx_fifo);

    current_state = STATE_CONFIG_DIRECTION;

    sched_post_task(&start);
    sched_post_task(&process_uart_rx_fifo);


#ifdef PLATFORM_EFM32GG_STK3700
#else
    	char str[20];
    	channel_id_to_string(&current_channel_id, str, sizeof(str));
    	lcd_write_line(6, str);
#endif

    timer_post_task(&transmit_packet, TIMER_TICKS_PER_SEC * 1);

}
static void packet_transmitted(hw_radio_packet_t* packet) {
#if HW_NUM_LEDS > 0
    led_toggle(0);
#endif
    DPRINT("packet transmitted");
    sprintf(lcd_msg, "TX %i", counter);
#ifdef PLATFORM_EFM32GG_STK3700
	    lcd_write_string(lcd_msg);
#else
	    lcd_write_line(4, lcd_msg);
#endif

    timer_tick_t delay;
    if(tx_packet_delay_s == 0)
        delay = TIMER_TICKS_PER_SEC / 5;
    else
        delay = TIMER_TICKS_PER_SEC * tx_packet_delay_s;

    //increase_channel();
    timer_post_task(&transmit_packet, delay);
}
示例#7
0
void lcd_task (void *)
{
	std::stringstream output;
	std::string outputstring;
	const char * chararray;
	int i = 0;
	for(;;)
	{
		stuff = 0;
		output.str(std::string());
		output << "Counter: " << i%1000;
		outputstring = "";
		outputstring = output.str();
		chararray = "";
		chararray = outputstring.c_str();
		lcd_write_line (1, (char *) chararray);
		for( volatile long int counter = 0;counter<1000000;counter++)
		  		;
		i++;
		taskYIELD();
	}
}
示例#8
0
/** @brief main function, entry point of the application */
int
main (void)
{
  init_system ();
  HAL_Init ();

  lcd_init ();
  lcd_write_line (0, (char *) "Hello FreeRTOS");

  //xTaskCreate( (pdTASK_CODE)test_task, 	"test", configMINIMAL_STACK_SIZE, 0, TEST_TASK_PRIORITY, NULL);

  //xTaskCreate( (pdTASK_CODE)led1_task, 	"led1", 256, 0, LED_TASK_PRIORITY, NULL);
  //xTaskCreate( (pdTASK_CODE)led2_task, 	"led2", 256, 0, LED_TASK_PRIORITY, NULL);
  //xTaskCreate( (pdTASK_CODE)lcd_task, 	"lcd", 256, 0, LCD_TASK_PRIORITY, NULL);

  //xTaskCreate( (pdTASK_CODE)led1_task_timeslicing, 	"led1", 256, 0, LED_TASK_PRIORITY, NULL);
  //xTaskCreate( (pdTASK_CODE)led2_task_timeslicing, 	"led1", 256, 0, LED_TASK_PRIORITY, NULL);
  //xTaskCreate( (pdTASK_CODE)led3_task_timeslicing, 	"led1", 256, 0, LED_TASK_PRIORITY, NULL);

  //job_descriptor blink1_job_descriptor = job_descriptor(1000/3, LED1);
  //xTaskCreate( (pdTASK_CODE)blink1_task, 	"led1", 256, &blink1_job_descriptor, LED_TASK_PRIORITY, NULL);

  //job_descriptor blink2_job_descriptor = job_descriptor(2000/3, LED2);
  //xTaskCreate( (pdTASK_CODE)blink2_task, 	"led2", 256, &blink2_job_descriptor, LED_TASK_PRIORITY, NULL);

  //job_descriptor blink3_job_descriptor = job_descriptor(3000/3, LED3);
  //xTaskCreate( (pdTASK_CODE)blink3_task, 	"led3", 256, &blink3_job_descriptor, LED_TASK_PRIORITY, NULL);

  //job_descriptor blink4_job_descriptor = job_descriptor(4000/3, LED4);
  //xTaskCreate( (pdTASK_CODE)blink4_task, 	"led4", 256, &blink4_job_descriptor, LED_TASK_PRIORITY, NULL);

  xTaskCreate( (pdTASK_CODE)blink_task_low_priority, 	"led4", 256, 0, LED_TASK_PRIORITY_LOW, NULL);
  xTaskCreate( (pdTASK_CODE)blink_task_high_priority, 	"led4", 256, 0, LED_TASK_PRIORITY_HIGH, NULL);

  vTaskStartScheduler ();
  return 0;
}
示例#9
0
void
bargraph_task (void *)
{

	lcd_write_line (0, (char *) "Hello FreeRTOS");

	while (true)
	{
		if( xSemaphore != NULL )
		{
			if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
			{
				for (uint16_t width = 0; width < 240; ++width)
				{
					BSP_LCD_SetTextColor(LCD_COLOR_RED);
					BSP_LCD_FillRect (0, 50, width, 10);
					BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
					BSP_LCD_FillRect (width, 50, 240 - width - 1, 10);
					vTaskDelay (1);
				}
				for (uint16_t width = 239; width > 0; --width)
				{
					BSP_LCD_SetTextColor(LCD_COLOR_RED);
					BSP_LCD_FillRect (0, 50, width, 10);
					BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
					BSP_LCD_FillRect (width, 50, 240 - width - 1, 10);
					vTaskDelay (1);
				}
				vTaskDelay(333);
			}
		}

		// bargraph_task suspendieren
		// vTaskSuspend(0);
	}
}
// TODO code duplication with noise_test, refactor later
// Eg. 433L001
static void process_command_chan()
{
    while(fifo_get_size(&uart_rx_fifo) < COMMAND_CHAN_PARAM_SIZE);

    char param[COMMAND_CHAN_PARAM_SIZE];
    fifo_pop(&uart_rx_fifo, param, COMMAND_CHAN_PARAM_SIZE);

    channel_id_t new_channel;

    if(strncmp(param, "433", 3) == 0)
        new_channel.channel_header.ch_freq_band = PHY_BAND_433;
    else if(strncmp(param, "868", 3) == 0)
        new_channel.channel_header.ch_freq_band = PHY_BAND_868;
    else if(strncmp(param, "915", 3) == 0)
        new_channel.channel_header.ch_freq_band = PHY_BAND_915;
    else
        goto error;

    char channel_class = param[3];
    if(channel_class == 'L')
        new_channel.channel_header.ch_class = PHY_CLASS_LO_RATE;
    else if(channel_class == 'N')
        new_channel.channel_header.ch_class = PHY_CLASS_NORMAL_RATE;
    else if(channel_class == 'H')
        new_channel.channel_header.ch_class = PHY_CLASS_HI_RATE;
    else
        goto error;

    uint16_t center_freq_index = atoi((const char*)(param + 5));
    new_channel.center_freq_index = center_freq_index;

    // validate
    if(new_channel.channel_header.ch_freq_band == PHY_BAND_433)
    {
        if(new_channel.channel_header.ch_class == PHY_CLASS_NORMAL_RATE
                && (new_channel.center_freq_index % 8 != 0 || new_channel.center_freq_index > 56))
            goto error;
        else if(new_channel.channel_header.ch_class == PHY_CLASS_LO_RATE && new_channel.center_freq_index > 68)
            goto error;
        else if(new_channel.channel_header.ch_class == PHY_CLASS_HI_RATE)
            goto error;
    } // TODO validate PHY_BAND_868

    // valid band, apply ...
    current_channel_id = new_channel;

    char str[20];
    channel_id_to_string(&current_channel_id, str, sizeof(str));
    console_print(str);

#ifdef PLATFORM_EFM32GG_STK3700
#else
	    lcd_write_line(6, str);
#endif

    // change channel and restart
    // TODOsched_post_task(&start_rx);
    return;

    error:
        console_print("Error parsing CHAN command. Expected format example: '433L001'\n");
        fifo_clear(&uart_rx_fifo);
}