/** * Sets the mode of an individual timer channel. * * Note that not all timers can be configured in every mode. For * example, basic timers cannot be configured to output compare mode. * Be sure to use a timer which is appropriate for the mode you want. * * @param dev Timer whose channel mode to set * @param channel Relevant channel * @param mode New timer mode for channel */ void timer_set_mode(timer_dev *dev, uint8 channel, timer_mode mode) { ASSERT_FAULT(channel > 0 && channel <= 4); /* TODO decide about the basic timers */ ASSERT(dev->type != TIMER_BASIC); if (dev->type == TIMER_BASIC) return; switch (mode) { case TIMER_DISABLED: disable_channel(dev, channel); break; case TIMER_PWM: pwm_mode(dev, channel); break; case TIMER_OUTPUT_COMPARE: output_compare_mode(dev, channel); break; } }
bool LoRaPHYUS915::set_next_channel(channel_selection_params_t* params, uint8_t* channel, lorawan_time_t* time, lorawan_time_t* aggregate_timeOff) { uint8_t nb_enabled_channels = 0; uint8_t delay_tx = 0; uint8_t enabled_channels[US915_MAX_NB_CHANNELS] = {0}; lorawan_time_t next_tx_delay = 0; // Count 125kHz channels if (num_active_channels(current_channel_mask, 0, 4) == 0) { // If none of the 125 kHz Upstream channel found, // Reactivate default channels copy_channel_mask(current_channel_mask, channel_mask, 4); } // Check other channels if (params->current_datarate >= DR_4) { if ((current_channel_mask[4] & 0x00FF ) == 0) { current_channel_mask[4] = channel_mask[4]; } } if (params->aggregate_timeoff <= _lora_time.get_elapsed_time(params->last_aggregate_tx_time)) { // Reset Aggregated time off *aggregate_timeOff = 0; // Update bands Time OFF next_tx_delay = update_band_timeoff(params->joined, params->dc_enabled, bands, US915_MAX_NB_BANDS); // Search how many channels are enabled nb_enabled_channels = enabled_channel_count(params->joined, params->current_datarate, current_channel_mask, enabled_channels, &delay_tx); } else { delay_tx++; next_tx_delay = params->aggregate_timeoff - _lora_time.get_elapsed_time(params->last_aggregate_tx_time); } if (nb_enabled_channels > 0) { // We found a valid channel *channel = enabled_channels[get_random( 0, nb_enabled_channels - 1 )]; // Disable the channel in the mask disable_channel(current_channel_mask, *channel, US915_MAX_NB_CHANNELS - 8); *time = 0; return true; } else { if (delay_tx > 0) { // Delay transmission due to AggregatedTimeOff or to a band time off *time = next_tx_delay; return true; } // Datarate not supported by any channel *time = 0; return false; } }