Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
darwin_stm32_fw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
darwin
darwin_stm32_fw
Commits
798dc9bd
Commit
798dc9bd
authored
5 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Added a second scheduler with a higher priority for the dynamixel slave loop.
parent
15e88d4c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/darwin_sch2.h
+10
-0
10 additions, 0 deletions
include/darwin_sch2.h
src/darwin_sch2.c
+121
-0
121 additions, 0 deletions
src/darwin_sch2.c
with
131 additions
and
0 deletions
include/darwin_sch2.h
0 → 100644
+
10
−
0
View file @
798dc9bd
#ifndef _DARWIN_SCH2_H
#define _DARWIN_SCH2_H
#include
"stm32f1xx.h"
#include
"scheduler.h"
TScheduler
*
darwin_sch2_init
(
void
);
#endif
This diff is collapsed.
Click to expand it.
src/darwin_sch2.c
0 → 100644
+
121
−
0
View file @
798dc9bd
#include
"darwin_sch2.h"
/* private variables */
TIM_HandleTypeDef
darwin_sch2_timer_handle
;
TScheduler
darwin_scheduler2
;
/* interrupt handlers */
void
TIM5_IRQHandler
(
void
)
{
/* Capture compare 1 event */
if
(
__HAL_TIM_GET_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC1
)
!=
RESET
)
{
if
(
__HAL_TIM_GET_IT_SOURCE
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC1
)
!=
RESET
)
{
__HAL_TIM_CLEAR_IT
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC1
);
__HAL_TIM_CLEAR_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC1
);
scheduler_interrupt
(
&
darwin_scheduler2
,
SCHED_CH1
);
}
}
/* Capture compare 2 event */
if
(
__HAL_TIM_GET_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC2
)
!=
RESET
)
{
if
(
__HAL_TIM_GET_IT_SOURCE
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC2
)
!=
RESET
)
{
__HAL_TIM_CLEAR_IT
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC2
);
__HAL_TIM_CLEAR_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC2
);
scheduler_interrupt
(
&
darwin_scheduler2
,
SCHED_CH2
);
}
}
/* Capture compare 3 event */
if
(
__HAL_TIM_GET_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC3
)
!=
RESET
)
{
if
(
__HAL_TIM_GET_IT_SOURCE
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC3
)
!=
RESET
)
{
__HAL_TIM_CLEAR_IT
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC3
);
__HAL_TIM_CLEAR_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC3
);
scheduler_interrupt
(
&
darwin_scheduler2
,
SCHED_CH3
);
}
}
/* Capture compare 4 event */
if
(
__HAL_TIM_GET_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC4
)
!=
RESET
)
{
if
(
__HAL_TIM_GET_IT_SOURCE
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC4
)
!=
RESET
)
{
__HAL_TIM_CLEAR_IT
(
&
darwin_sch2_timer_handle
,
TIM_IT_CC4
);
__HAL_TIM_CLEAR_FLAG
(
&
darwin_sch2_timer_handle
,
TIM_FLAG_CC4
);
scheduler_interrupt
(
&
darwin_scheduler2
,
SCHED_CH4
);
}
}
}
/* private functions */
void
darwin_sch2_start
(
unsigned
short
int
channel_id
)
{
HAL_TIM_OC_Start_IT
(
&
darwin_sch2_timer_handle
,
channel_id
);
}
void
darwin_sch2_stop
(
unsigned
short
int
channel_id
)
{
HAL_TIM_OC_Stop_IT
(
&
darwin_sch2_timer_handle
,
channel_id
);
}
void
darwin_sch2_set_pulse
(
unsigned
short
int
channel_id
,
unsigned
short
int
pulse
,
unsigned
char
running
)
{
TIM_OC_InitTypeDef
out_comp_config
;
unsigned
short
int
capture
;
if
(
running
==
0x00
)
{
if
(
darwin_scheduler2
.
channels
[
scheduler_get_id
(
channel_id
)].
enabled
==
0x00
)
{
out_comp_config
.
OCMode
=
TIM_OCMODE_TIMING
;
capture
=
HAL_TIM_ReadCapturedValue
(
&
darwin_sch2_timer_handle
,
channel_id
);
out_comp_config
.
Pulse
=
capture
+
pulse
;
out_comp_config
.
OCPolarity
=
TIM_OCPOLARITY_HIGH
;
out_comp_config
.
OCFastMode
=
TIM_OCFAST_DISABLE
;
HAL_TIM_OC_ConfigChannel
(
&
darwin_sch2_timer_handle
,
&
out_comp_config
,
channel_id
);
}
}
else
{
capture
=
HAL_TIM_ReadCapturedValue
(
&
darwin_sch2_timer_handle
,
channel_id
);
__HAL_TIM_SetCompare
(
&
darwin_sch2_timer_handle
,
channel_id
,
capture
+
pulse
);
}
}
/* public functions */
TScheduler
*
darwin_sch2_init
(
void
)
{
TIM_ClockConfigTypeDef
sClockSourceConfig
=
{
0
};
TIM_MasterConfigTypeDef
sMasterConfig
=
{
0
};
__HAL_RCC_TIM5_CLK_ENABLE
();
darwin_sch2_timer_handle
.
Instance
=
TIM5
;
darwin_sch2_timer_handle
.
Init
.
Prescaler
=
72
;
darwin_sch2_timer_handle
.
Init
.
CounterMode
=
TIM_COUNTERMODE_UP
;
darwin_sch2_timer_handle
.
Init
.
Period
=
0xFFFF
;
darwin_sch2_timer_handle
.
Init
.
ClockDivision
=
TIM_CLOCKDIVISION_DIV1
;
HAL_TIM_Base_Init
(
&
darwin_sch2_timer_handle
);
sClockSourceConfig
.
ClockSource
=
TIM_CLOCKSOURCE_INTERNAL
;
HAL_TIM_ConfigClockSource
(
&
darwin_sch2_timer_handle
,
&
sClockSourceConfig
);
HAL_TIM_OC_Init
(
&
darwin_sch2_timer_handle
);
sMasterConfig
.
MasterOutputTrigger
=
TIM_TRGO_RESET
;
sMasterConfig
.
MasterSlaveMode
=
TIM_MASTERSLAVEMODE_DISABLE
;
HAL_TIMEx_MasterConfigSynchronization
(
&
darwin_sch2_timer_handle
,
&
sMasterConfig
);
/* Peripheral interrupt init */
HAL_NVIC_SetPriority
(
TIM5_IRQn
,
2
,
0
);
HAL_NVIC_EnableIRQ
(
TIM5_IRQn
);
scheduler_init
(
&
darwin_scheduler2
,
4
,
72
);
darwin_scheduler2
.
start
=
darwin_sch2_start
;
darwin_scheduler2
.
stop
=
darwin_sch2_stop
;
darwin_scheduler2
.
set_pulse
=
darwin_sch2_set_pulse
;
return
&
darwin_scheduler2
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment