Example #1
0
/*
 * Sets the motor speed given a percentage.
 * Disable interrupts before calling.
 */
void set_target_speed(enum motor_list motor, int8_t percent)
{
   uint32_t speed = 0;

   // Clamp the percentage of power
   if (percent >= 100)
   {
      percent = 99;
   }

   if (percent <= -100)
   {
      percent = -99;
   }

   // If the percentage is positive we want to go forward, otherwise
   // we want to go in reverse.
   if (percent >= 0)
   {
      set_target_motor_direction(motor, ROBOT_FORWARD);
   }
   else
   {
      set_target_motor_direction(motor, ROBOT_REVERSE);
   }

   percent = abs(percent);

   speed = (uint32_t)((float)percent/100 * get_timer_period(&(Motors[motor])));

   Motors[motor].target_speed = speed;
}
/**
 * @brief
 * This function initializes the Timer structure variables
 */
void init_sw_timer(void )
{
    /* TODO :Later, this function should be made to read values
     * from Device Tree */
    int iter;

    timer_cpu_info.expires_next.tval64 = TIMEVAL_MAX;
    INIT_LIST_HEAD(&timer_cpu_info.pending_routines);
    timer_cpu_info.num_events = 0;

    for(iter = 0; iter < MAX_NUM_OF_TIMERS; iter++)
    {
        timer_cpu_info.clock_info[iter].cpu_info = &timer_cpu_info;
        timer_cpu_info.clock_info[iter].clock_id = iter;
        INIT_LIST_HEAD(&timer_cpu_info.clock_info[iter].active);
        INIT_SPIN_LOCK(&timer_cpu_info.clock_info[iter].spin_lock);
        timer_cpu_info.clock_info[iter].clock_period.tval64 = 
                                                        get_clock_period();
        timer_cpu_info.clock_info[iter].timer_period.tval64 = 
                                                        get_timer_period();
    }

    /* TODO :Later this should be made to obtain from Device Tree */
    timer_cpu_info.free_run_clock_id = 0;
    timer_cpu_info.tick_timer_id = 1;

#define SW_FREE_RUNNING_CNTR    timer_cpu_info.free_run_clock_id
#define SW_TICKTIMER            timer_cpu_info.tick_timer_id


    sw_timer_info.sw_timestamp.tval64 = 0;
    sw_timer_info.abs_cycles_count = 0;
    sw_timer_info.cycles_count_new = 0;
    sw_timer_info.cycles_count_old = 0;
    sw_timer_info.timer_period.tval64 = get_timer_period();
    sw_timer_info.clock_period.tval64 = get_clock_period();

}