Merge branch 'feature/drive' into 'develop'
Feature/drive See merge request !8
This commit is contained in:
commit
859adc5d35
12
.cproject
12
.cproject
@ -23,16 +23,22 @@
|
|||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.583579175" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.583579175" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.804428440" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.804428440" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1612628392" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1612628392" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1218410972" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1218410972" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.1838895569" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.1838895569" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1874409566" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1874409566" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.258587679" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.258587679" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.433020597" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.433020597" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.7772132" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.7772132" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.761231156" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.761231156" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
@ -64,16 +70,22 @@
|
|||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.232481989" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.232481989" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.562391475" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.562391475" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1491856129" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1491856129" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.275129533" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.275129533" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.193886409" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.193886409" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.715382618" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.715382618" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1629243941" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1629243941" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="org.eclipse.cdt.build.core.settings.holder.1854601715" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
<tool id="org.eclipse.cdt.build.core.settings.holder.1854601715" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||||
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1688578924" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1688578924" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/arm-none-eabi/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/opt/arm-2011.09/lib/gcc/arm-none-eabi/4.6.1/include"/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.683508981" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.683508981" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CHECK_FOLDER += source/application
|
CHECK_FOLDER += source/application
|
||||||
SUB_FOLDER += source/application
|
SUB_FOLDER += source/application
|
||||||
INCLUDES += source/application
|
INCLUDES += source/application/include
|
||||||
DOC_SRC += source/application
|
DOC_SRC += source/application
|
||||||
|
125
source/application/drive_ctrl.c
Normal file
125
source/application/drive_ctrl.c
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* drive_ctrl.c
|
||||||
|
*
|
||||||
|
* Created on: Aug 10, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "driver.h"
|
||||||
|
#include "board_devices.h"
|
||||||
|
#include "engines.h"
|
||||||
|
|
||||||
|
#include "drive_ctrl.h"
|
||||||
|
|
||||||
|
struct drive_ctrl {
|
||||||
|
struct engine_ctrl *left_forward;
|
||||||
|
struct engine_ctrl *left_backward;
|
||||||
|
struct engine_ctrl *right_forward;
|
||||||
|
struct engine_ctrl *right_backward;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct drive_ctrl_object {
|
||||||
|
unsigned int current_speed;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct drive_ctrl drive_ctrl = {
|
||||||
|
.left_forward = &left_forward,
|
||||||
|
.left_backward = &left_backward,
|
||||||
|
.right_forward = &right_forward,
|
||||||
|
.right_backward = &right_backward,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct drive_ctrl_object drive_ctrl_object = {
|
||||||
|
.current_speed = 50, /* % */
|
||||||
|
};
|
||||||
|
|
||||||
|
int drive_ctrl_init(void)
|
||||||
|
{
|
||||||
|
unsigned int duty = 0;
|
||||||
|
|
||||||
|
/* open enable pins */
|
||||||
|
open(drive_ctrl.left_forward->enable);
|
||||||
|
write(drive_ctrl.left_forward->enable, "0", 1);
|
||||||
|
open(drive_ctrl.left_backward->enable);
|
||||||
|
write(drive_ctrl.left_backward->enable, "0", 1);
|
||||||
|
open(drive_ctrl.right_forward->enable);
|
||||||
|
write(drive_ctrl.right_forward->enable, "0", 1);
|
||||||
|
open(drive_ctrl.right_backward->enable);
|
||||||
|
write(drive_ctrl.right_backward->enable, "0", 1);
|
||||||
|
|
||||||
|
/* open pwm's */
|
||||||
|
open(drive_ctrl.left_backward->pwm);
|
||||||
|
ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||||
|
open(drive_ctrl.left_forward->pwm);
|
||||||
|
ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||||
|
open(drive_ctrl.right_backward->pwm);
|
||||||
|
ioctl(drive_ctrl.right_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||||
|
open(drive_ctrl.right_forward->pwm);
|
||||||
|
ioctl(drive_ctrl.right_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty);
|
||||||
|
|
||||||
|
/* enable enable pins */
|
||||||
|
write(drive_ctrl.left_forward->enable, "1", 1);
|
||||||
|
write(drive_ctrl.left_backward->enable, "1", 1);
|
||||||
|
write(drive_ctrl.right_forward->enable, "1", 1);
|
||||||
|
write(drive_ctrl.right_backward->enable, "1", 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int calc_speed_front(int speed_percent)
|
||||||
|
{
|
||||||
|
unsigned int speed_front = 0;
|
||||||
|
if(speed_percent > 0) {
|
||||||
|
if(speed_percent > 100)
|
||||||
|
speed_front = 100;
|
||||||
|
else
|
||||||
|
speed_front = (unsigned int) speed_percent;
|
||||||
|
}
|
||||||
|
return speed_front;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int calc_speed_back(int speed_percent)
|
||||||
|
{
|
||||||
|
unsigned int speed_back = 0;
|
||||||
|
if(speed_percent < 0) {
|
||||||
|
if(speed_percent < -100)
|
||||||
|
speed_back = 100;
|
||||||
|
else
|
||||||
|
speed_back = (unsigned int) abs(speed_percent);
|
||||||
|
}
|
||||||
|
return speed_back;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_set_speed_left(int speed_percent)
|
||||||
|
{
|
||||||
|
unsigned int front_speed = calc_speed_front(speed_percent);
|
||||||
|
unsigned int back_speed = calc_speed_back(speed_percent);
|
||||||
|
int ret = ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&back_speed);
|
||||||
|
ret |= ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&front_speed);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_set_speed_right(int speed_percent)
|
||||||
|
{
|
||||||
|
unsigned int front_speed = calc_speed_front(speed_percent);
|
||||||
|
unsigned int back_speed = calc_speed_back(speed_percent);
|
||||||
|
int ret = ioctl(drive_ctrl.right_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&back_speed);
|
||||||
|
ret |= ioctl(drive_ctrl.right_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&front_speed);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_set_speed_value(int speed_percent)
|
||||||
|
{
|
||||||
|
drive_ctrl_object.current_speed = speed_percent;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_get_speed_value(void)
|
||||||
|
{
|
||||||
|
return drive_ctrl_object.current_speed;
|
||||||
|
}
|
19
source/application/include/drive_ctrl.h
Normal file
19
source/application/include/drive_ctrl.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* drive_ctrl.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 10, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_APPLICATION_INCLUDE_DRIVE_CTRL_H_
|
||||||
|
#define SOURCE_APPLICATION_INCLUDE_DRIVE_CTRL_H_
|
||||||
|
|
||||||
|
int drive_ctrl_init(void);
|
||||||
|
|
||||||
|
int drive_ctrl_set_speed_left(int speed_percent);
|
||||||
|
int drive_ctrl_set_speed_right(int speed_percent);
|
||||||
|
int drive_ctrl_set_speed_value(int speed_percent);
|
||||||
|
int drive_ctrl_get_speed_value(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* SOURCE_APPLICATION_INCLUDE_DRIVE_CTRL_H_ */
|
36
source/application/include/engines.h
Normal file
36
source/application/include/engines.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* engines.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 10, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_APPLICATION_INCLUDE_ENGINES_H_
|
||||||
|
#define SOURCE_APPLICATION_INCLUDE_ENGINES_H_
|
||||||
|
|
||||||
|
struct engine_ctrl {
|
||||||
|
const struct driver *pwm;
|
||||||
|
const struct driver *enable;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct engine_ctrl right_forward = {
|
||||||
|
.pwm = &pwm_2,
|
||||||
|
.enable = &gpio_c0,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct engine_ctrl right_backward = {
|
||||||
|
.pwm = &pwm_1,
|
||||||
|
.enable = &gpio_c1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct engine_ctrl left_forward = {
|
||||||
|
.pwm = &pwm_4,
|
||||||
|
.enable = &gpio_c2,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct engine_ctrl left_backward = {
|
||||||
|
.pwm = &pwm_3,
|
||||||
|
.enable = &gpio_c3,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SOURCE_APPLICATION_INCLUDE_ENGINES_H_ */
|
13
source/application/include/shell_commands.h
Normal file
13
source/application/include/shell_commands.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* shell_commands.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 10, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_APPLICATION_SHELL_COMMANDS_H_
|
||||||
|
#define SOURCE_APPLICATION_SHELL_COMMANDS_H_
|
||||||
|
|
||||||
|
int shell_commands_init(void);
|
||||||
|
|
||||||
|
#endif /* SOURCE_APPLICATION_SHELL_COMMANDS_H_ */
|
@ -1,55 +1,21 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "driver.h"
|
|
||||||
#include "board_devices.h"
|
#include "board_devices.h"
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "shell.h"
|
||||||
|
#include "shell_commands.h"
|
||||||
|
#include "drive_ctrl.h"
|
||||||
|
|
||||||
#define STACK_SIZE 256
|
|
||||||
stack_t tc_1_stack[STACK_SIZE];
|
|
||||||
struct thread_context tc_1;
|
|
||||||
|
|
||||||
void task1(void *arg)
|
|
||||||
{
|
|
||||||
char rd = '0';
|
|
||||||
open(&led_4);
|
|
||||||
write(&led_4, &rd, 1);
|
|
||||||
while(1) {
|
|
||||||
sleep_ms(1000);
|
|
||||||
read(&led_4, &rd, 1);
|
|
||||||
if(rd == '0')
|
|
||||||
rd = '1';
|
|
||||||
else
|
|
||||||
rd = '0';
|
|
||||||
write(&led_4, &rd, 1);
|
|
||||||
write(&uart_1, "Driver test\r\n", 13);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char rx_buf[80];
|
|
||||||
void task2(void *arg)
|
|
||||||
{
|
|
||||||
while(1) {
|
|
||||||
int i = read(&uart_1, rx_buf, 80);
|
|
||||||
if(i > 0) {
|
|
||||||
write(&uart_1, rx_buf, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stack_t tc_2_stack[STACK_SIZE];
|
|
||||||
struct thread_context tc_2;
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
open(&uart_1);
|
drive_ctrl_init();
|
||||||
thread_create(&tc_1, tc_1_stack, STACK_SIZE, task1, NULL, THREAD_PRIO_LOW);
|
shell_init(&uart_1);
|
||||||
thread_create(&tc_2, tc_2_stack, STACK_SIZE, task2, NULL, THREAD_PRIO_LOW);
|
shell_commands_init();
|
||||||
|
|
||||||
schedule_start();
|
schedule_start();
|
||||||
|
|
||||||
|
152
source/application/shell_commands.c
Normal file
152
source/application/shell_commands.c
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* shell_commands.c
|
||||||
|
*
|
||||||
|
* Created on: Aug 10, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
|
#include "driver.h"
|
||||||
|
#include "shell.h"
|
||||||
|
#include "drive_ctrl.h"
|
||||||
|
|
||||||
|
static void *drive_turn_right_cb(const char *param);
|
||||||
|
static void *drive_turn_left_cb(const char *param);
|
||||||
|
static void *drive_boost_cb(const char *param);
|
||||||
|
static void *drive_retard_cb(const char *param);
|
||||||
|
static void *drive_halt_cb(const char *param);
|
||||||
|
static void *drive_forward_cb(const char *param);
|
||||||
|
static void *drive_backward_cb(const char *param);
|
||||||
|
|
||||||
|
static struct command drive_forward = {
|
||||||
|
.command = "f",
|
||||||
|
.description = "Start driving forward with preset speed.",
|
||||||
|
.command_callback = drive_forward_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_backward = {
|
||||||
|
.command = "b",
|
||||||
|
.description = "Start driving backward with preset speed.",
|
||||||
|
.command_callback = drive_backward_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_halt = {
|
||||||
|
.command = "h",
|
||||||
|
.description = "Stop driving.",
|
||||||
|
.command_callback = drive_halt_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_boost = {
|
||||||
|
.command = "+",
|
||||||
|
.description = "Boost speed.",
|
||||||
|
.command_callback = drive_boost_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_retard = {
|
||||||
|
.command = "-",
|
||||||
|
.description = "Retard speed",
|
||||||
|
.command_callback = drive_retard_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_turn_left = {
|
||||||
|
.command = "l",
|
||||||
|
.description = "Turn left.",
|
||||||
|
.command_callback = drive_turn_left_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct command drive_turn_right = {
|
||||||
|
.command = "r",
|
||||||
|
.description = "Turn right",
|
||||||
|
.command_callback = drive_turn_right_cb,
|
||||||
|
};
|
||||||
|
|
||||||
|
int shell_commands_init(void)
|
||||||
|
{
|
||||||
|
shell_add_command(&drive_forward);
|
||||||
|
shell_add_command(&drive_backward);
|
||||||
|
shell_add_command(&drive_boost);
|
||||||
|
shell_add_command(&drive_retard);
|
||||||
|
shell_add_command(&drive_halt);
|
||||||
|
shell_add_command(&drive_turn_left);
|
||||||
|
shell_add_command(&drive_turn_right);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_turn_right_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
drive_ctrl_set_speed_left(abs(speed));
|
||||||
|
if(speed > 0)
|
||||||
|
speed *= -1;
|
||||||
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_turn_left_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
drive_ctrl_set_speed_right(abs(speed));
|
||||||
|
if(speed > 0)
|
||||||
|
speed *= -1;
|
||||||
|
drive_ctrl_set_speed_left(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_boost_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
speed += 10;
|
||||||
|
drive_ctrl_set_speed_value(speed);
|
||||||
|
drive_ctrl_set_speed_left(speed);
|
||||||
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_retard_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
speed -= 10;
|
||||||
|
drive_ctrl_set_speed_value(speed);
|
||||||
|
drive_ctrl_set_speed_left(speed);
|
||||||
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_halt_cb(const char *param)
|
||||||
|
{
|
||||||
|
drive_ctrl_set_speed_left(0);
|
||||||
|
drive_ctrl_set_speed_right(0);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_forward_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
if(speed < 0)
|
||||||
|
speed = abs(speed);
|
||||||
|
drive_ctrl_set_speed_value(speed);
|
||||||
|
drive_ctrl_set_speed_left(speed);
|
||||||
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *drive_backward_cb(const char *param)
|
||||||
|
{
|
||||||
|
int speed = drive_ctrl_get_speed_value();
|
||||||
|
if(speed > 0)
|
||||||
|
speed *= -1;
|
||||||
|
drive_ctrl_set_speed_value(speed);
|
||||||
|
drive_ctrl_set_speed_left(speed);
|
||||||
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
@ -3,10 +3,14 @@
|
|||||||
#ifndef BOARD_DEVICES_H
|
#ifndef BOARD_DEVICES_H
|
||||||
#define BOARD_DEVICES_H
|
#define BOARD_DEVICES_H
|
||||||
|
|
||||||
|
extern const struct driver pwm_4;
|
||||||
|
extern const struct driver pwm_3;
|
||||||
|
extern const struct driver pwm_2;
|
||||||
|
extern const struct driver pwm_1;
|
||||||
extern const struct driver uart_1;
|
extern const struct driver uart_1;
|
||||||
extern const struct driver led_3;
|
extern const struct driver gpio_c0;
|
||||||
extern const struct driver led_4;
|
extern const struct driver gpio_c1;
|
||||||
extern const struct driver led_5;
|
extern const struct driver gpio_c2;
|
||||||
extern const struct driver led_6;
|
extern const struct driver gpio_c3;
|
||||||
|
|
||||||
#endif /* BOARD_DEVICES_H */
|
#endif /* BOARD_DEVICES_H */
|
||||||
|
@ -8,10 +8,13 @@
|
|||||||
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||||
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||||
|
|
||||||
|
#define IOCTL_PWM_SET_DUTY_CYCLE 0
|
||||||
|
|
||||||
enum driver_type {
|
enum driver_type {
|
||||||
DRIVER_TYPE_ADC,
|
DRIVER_TYPE_ADC,
|
||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
DRIVER_TYPE_I2C,
|
DRIVER_TYPE_I2C,
|
||||||
|
DRIVER_TYPE_PWM,
|
||||||
DRIVER_TYPE_RTC,
|
DRIVER_TYPE_RTC,
|
||||||
DRIVER_TYPE_SPI,
|
DRIVER_TYPE_SPI,
|
||||||
DRIVER_TYPE_UART
|
DRIVER_TYPE_UART
|
||||||
@ -26,5 +29,6 @@ int open(const struct driver *driver);
|
|||||||
int close(const struct driver *driver);
|
int close(const struct driver *driver);
|
||||||
int read(const struct driver *driver, char *buffer, int len);
|
int read(const struct driver *driver, char *buffer, int len);
|
||||||
int write(const struct driver *driver, const char *buffer, int len);
|
int write(const struct driver *driver, const char *buffer, int len);
|
||||||
|
int ioctl(const struct driver *driver, unsigned int cmd, const void *data);
|
||||||
|
|
||||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
||||||
|
25
source/os/debug/include/list.h
Normal file
25
source/os/debug/include/list.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* list.h
|
||||||
|
*
|
||||||
|
* Created on: Jul 27, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_FIRMWARE_KERNEL_LIST_H_
|
||||||
|
#define SOURCE_FIRMWARE_KERNEL_LIST_H_
|
||||||
|
|
||||||
|
struct list_node {
|
||||||
|
struct list_node *next;
|
||||||
|
unsigned int data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct list {
|
||||||
|
struct list_node *front;
|
||||||
|
struct list_node *rear;
|
||||||
|
};
|
||||||
|
|
||||||
|
int list_init(struct list *head);
|
||||||
|
int list_add(struct list *head, struct list_node *node);
|
||||||
|
int list_get_len(struct list *head);
|
||||||
|
|
||||||
|
#endif /* SOURCE_FIRMWARE_KERNEL_LIST_H_ */
|
23
source/os/debug/include/shell.h
Normal file
23
source/os/debug/include/shell.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* shell.h
|
||||||
|
*
|
||||||
|
* Created on: Aug 1, 2016
|
||||||
|
* Author: tkl
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_FIRMWARE_KERNEL_INTERFACE_SHELL_H_
|
||||||
|
#define SOURCE_FIRMWARE_KERNEL_INTERFACE_SHELL_H_
|
||||||
|
|
||||||
|
typedef void *(*command_callback)(const char*);
|
||||||
|
|
||||||
|
struct command {
|
||||||
|
const char *command;
|
||||||
|
const char *description;
|
||||||
|
const command_callback command_callback;
|
||||||
|
struct list_node item;
|
||||||
|
};
|
||||||
|
|
||||||
|
int shell_init(const struct driver *shell_device);
|
||||||
|
int shell_add_command(struct command *command);
|
||||||
|
|
||||||
|
#endif /* SOURCE_FIRMWARE_KERNEL_INTERFACE_SHELL_H_ */
|
BIN
source/os/debug/libkosmos-arm-stm32f4-discovery-0.0.5-dbg.a
Normal file
BIN
source/os/debug/libkosmos-arm-stm32f4-discovery-0.0.5-dbg.a
Normal file
Binary file not shown.
Binary file not shown.
1
source/os/debug/libkosmos-arm-stm32f4-discovery-dbg.a
Symbolic link
1
source/os/debug/libkosmos-arm-stm32f4-discovery-dbg.a
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
libkosmos-arm-stm32f4-discovery-0.0.5-dbg.a
|
@ -3,10 +3,14 @@
|
|||||||
#ifndef BOARD_DEVICES_H
|
#ifndef BOARD_DEVICES_H
|
||||||
#define BOARD_DEVICES_H
|
#define BOARD_DEVICES_H
|
||||||
|
|
||||||
|
extern const struct driver pwm_4;
|
||||||
|
extern const struct driver pwm_3;
|
||||||
|
extern const struct driver pwm_2;
|
||||||
|
extern const struct driver pwm_1;
|
||||||
extern const struct driver uart_1;
|
extern const struct driver uart_1;
|
||||||
extern const struct driver led_3;
|
extern const struct driver gpio_c0;
|
||||||
extern const struct driver led_4;
|
extern const struct driver gpio_c1;
|
||||||
extern const struct driver led_5;
|
extern const struct driver gpio_c2;
|
||||||
extern const struct driver led_6;
|
extern const struct driver gpio_c3;
|
||||||
|
|
||||||
#endif /* BOARD_DEVICES_H */
|
#endif /* BOARD_DEVICES_H */
|
||||||
|
@ -8,10 +8,13 @@
|
|||||||
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
#ifndef SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||||
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
#define SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_
|
||||||
|
|
||||||
|
#define IOCTL_PWM_SET_DUTY_CYCLE 0
|
||||||
|
|
||||||
enum driver_type {
|
enum driver_type {
|
||||||
DRIVER_TYPE_ADC,
|
DRIVER_TYPE_ADC,
|
||||||
DRIVER_TYPE_GPIO,
|
DRIVER_TYPE_GPIO,
|
||||||
DRIVER_TYPE_I2C,
|
DRIVER_TYPE_I2C,
|
||||||
|
DRIVER_TYPE_PWM,
|
||||||
DRIVER_TYPE_RTC,
|
DRIVER_TYPE_RTC,
|
||||||
DRIVER_TYPE_SPI,
|
DRIVER_TYPE_SPI,
|
||||||
DRIVER_TYPE_UART
|
DRIVER_TYPE_UART
|
||||||
@ -26,5 +29,6 @@ int open(const struct driver *driver);
|
|||||||
int close(const struct driver *driver);
|
int close(const struct driver *driver);
|
||||||
int read(const struct driver *driver, char *buffer, int len);
|
int read(const struct driver *driver, char *buffer, int len);
|
||||||
int write(const struct driver *driver, const char *buffer, int len);
|
int write(const struct driver *driver, const char *buffer, int len);
|
||||||
|
int ioctl(const struct driver *driver, unsigned int cmd, const void *data);
|
||||||
|
|
||||||
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */
|
||||||
|
BIN
source/os/release/libkosmos-arm-stm32f4-discovery-0.0.5.a
Normal file
BIN
source/os/release/libkosmos-arm-stm32f4-discovery-0.0.5.a
Normal file
Binary file not shown.
Binary file not shown.
1
source/os/release/libkosmos-arm-stm32f4-discovery.a
Symbolic link
1
source/os/release/libkosmos-arm-stm32f4-discovery.a
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
libkosmos-arm-stm32f4-discovery-0.0.5.a
|
Loading…
Reference in New Issue
Block a user