2016-08-08 09:19:08 +00:00
|
|
|
/*
|
|
|
|
* main.c
|
|
|
|
*
|
|
|
|
* Created on: Aug 2, 2016
|
|
|
|
* Author: tkl
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "shell.h"
|
|
|
|
|
2016-08-10 09:31:49 +00:00
|
|
|
struct engine_ctrl {
|
|
|
|
const struct driver *pwm;
|
|
|
|
const struct driver *enable;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct drive_ctrl {
|
|
|
|
struct engine_ctrl *left_forward;
|
|
|
|
struct engine_ctrl *left_backward;
|
|
|
|
struct engine_ctrl *right_forward;
|
|
|
|
struct engine_ctrl *right_backward;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct engine_ctrl right_forward = {
|
|
|
|
.pwm = &pwm_1,
|
|
|
|
.enable = &gpio_c1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct engine_ctrl right_backward = {
|
|
|
|
.pwm = &pwm_2,
|
|
|
|
.enable = &gpio_c0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct engine_ctrl left_forward = {
|
|
|
|
.pwm = &pwm_3,
|
|
|
|
.enable = &gpio_c3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct engine_ctrl left_backward = {
|
|
|
|
.pwm = &pwm_4,
|
|
|
|
.enable = &gpio_c2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drive_ctrl drive_ctrl = {
|
|
|
|
.left_forward = &left_forward,
|
|
|
|
.left_backward = &left_backward,
|
|
|
|
.right_forward = &right_forward,
|
|
|
|
.right_backward = &right_backward,
|
|
|
|
};
|
2016-08-09 08:43:47 +00:00
|
|
|
|
2016-08-08 09:19:08 +00:00
|
|
|
#define TH_STACK_SIZE 256
|
|
|
|
stack_t th_stack[TH_STACK_SIZE];
|
|
|
|
struct thread_context th_ctx;
|
|
|
|
static void th_func(void *arg)
|
|
|
|
{
|
2016-08-09 09:57:54 +00:00
|
|
|
unsigned int duty = 0;
|
2016-08-10 09:31:49 +00:00
|
|
|
open(drive_ctrl.left_forward->enable);
|
|
|
|
write(drive_ctrl.left_forward->enable, "0", 1);
|
|
|
|
open(drive_ctrl.left_forward->pwm);
|
|
|
|
open(drive_ctrl.left_backward->enable);
|
|
|
|
write(drive_ctrl.left_backward->enable, "0", 1);
|
|
|
|
open(drive_ctrl.left_backward->pwm);
|
|
|
|
|
|
|
|
write(drive_ctrl.left_forward->enable, "1", 1);
|
|
|
|
write(drive_ctrl.left_backward->enable, "1", 1);
|
2016-08-08 09:19:08 +00:00
|
|
|
while(1) {
|
2016-08-10 09:31:49 +00:00
|
|
|
duty = 0;
|
|
|
|
ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
|
|
|
for(duty = 0; duty < 100; duty++) {
|
|
|
|
ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
|
|
|
sleep_ms(100);
|
2016-08-09 10:32:19 +00:00
|
|
|
}
|
2016-08-10 09:31:49 +00:00
|
|
|
duty = 0;
|
|
|
|
ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
|
|
|
sleep_ms(100);
|
|
|
|
for(duty = 0; duty < 100; duty++) {
|
|
|
|
ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
|
|
|
sleep_ms(100);
|
2016-08-09 10:32:19 +00:00
|
|
|
}
|
2016-08-10 09:31:49 +00:00
|
|
|
sleep_ms(100);
|
2016-08-08 09:19:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
thread_create(&th_ctx, th_stack, TH_STACK_SIZE, th_func, NULL, THREAD_PRIO_LOW);
|
|
|
|
schedule_start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|