Cleanup and refactoring of the STM32w port
This is a general cleanup of things like code style issues and code structure of the STM32w port to make it more like the rest of Contiki is structured.
This commit is contained in:
parent
12b3d02ba1
commit
a5046e83c7
118 changed files with 4470 additions and 4281 deletions
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -27,23 +33,18 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki OS
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Real-timer specific implementation for STM32W.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "sys/energest.h"
|
||||
#include "sys/rtimer.h"
|
||||
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
|
@ -52,123 +53,116 @@
|
|||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
static uint16_t saved_TIM1CFG;
|
||||
static uint32_t time_msb = 0; /* Most significant bits of the current time. */
|
||||
|
||||
|
||||
static uint32_t time_msb = 0; // Most significant bits of the current time.
|
||||
|
||||
// time of the next rtimer event. Initially is set to the max value.
|
||||
/* time of the next rtimer event. Initially is set to the max
|
||||
value. */
|
||||
static rtimer_clock_t next_rtimer_time = 0;
|
||||
|
||||
static uint16_t saved_TIM1CFG;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void halTimer1Isr(void){
|
||||
|
||||
|
||||
if(INT_TIM1FLAG & INT_TIMUIF){ // Overflow event.
|
||||
|
||||
//PRINTF("O %4x.\r\n", TIM1_CNT);
|
||||
//printf("OV ");
|
||||
|
||||
void
|
||||
halTimer1Isr(void)
|
||||
{
|
||||
if(INT_TIM1FLAG & INT_TIMUIF) {
|
||||
rtimer_clock_t now, clock_to_wait;
|
||||
/* Overflow event. */
|
||||
/* PRINTF("O %4x.\r\n", TIM1_CNT); */
|
||||
/* printf("OV "); */
|
||||
time_msb++;
|
||||
rtimer_clock_t now = ((rtimer_clock_t)time_msb << 16)|TIM1_CNT;
|
||||
|
||||
rtimer_clock_t clock_to_wait = next_rtimer_time - now;
|
||||
|
||||
if(clock_to_wait <= 0x10000 && clock_to_wait > 0){ // We must set now the Timer Compare Register.
|
||||
|
||||
TIM1_CCR1 = (int16u)clock_to_wait;
|
||||
now = ((rtimer_clock_t) time_msb << 16) | TIM1_CNT;
|
||||
clock_to_wait = next_rtimer_time - now;
|
||||
|
||||
if(clock_to_wait <= 0x10000 && clock_to_wait > 0) {
|
||||
/* We must now set the Timer Compare Register. */
|
||||
TIM1_CCR1 = (uint16_t) clock_to_wait;
|
||||
INT_TIM1FLAG = INT_TIMCC1IF;
|
||||
INT_TIM1CFG |= INT_TIMCC1IF; // Compare 1 interrupt enable.
|
||||
}
|
||||
|
||||
INT_TIM1CFG |= INT_TIMCC1IF; /* Compare 1 interrupt enable. */
|
||||
}
|
||||
INT_TIM1FLAG = INT_TIMUIF;
|
||||
|
||||
} else {
|
||||
if(INT_TIM1FLAG & INT_TIMCC1IF) {
|
||||
/* Compare event. */
|
||||
INT_TIM1CFG &= ~INT_TIMCC1IF; /* Disable the next compare interrupt */
|
||||
PRINTF("\nCompare event %4x\r\n", TIM1_CNT);
|
||||
PRINTF("INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
rtimer_run_next();
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
INT_TIM1FLAG = INT_TIMCC1IF;
|
||||
}
|
||||
}
|
||||
|
||||
else if(INT_TIM1FLAG & INT_TIMCC1IF){ // Compare event.
|
||||
|
||||
INT_TIM1CFG &= ~INT_TIMCC1IF; // Disable the next compare interrupt
|
||||
|
||||
PRINTF("\nCompare event %4x\r\n", TIM1_CNT);
|
||||
PRINTF("INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
rtimer_run_next();
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
INT_TIM1FLAG = INT_TIMCC1IF;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rtimer_arch_init(void)
|
||||
{
|
||||
TIM1_CR1 = 0;
|
||||
|
||||
TIM1_PSC = RT_PRESCALER;
|
||||
|
||||
TIM1_ARR = 0xffff; // Counting from 0 to the maximum value.
|
||||
|
||||
// Bits of TIMx_CCMR1 as default.
|
||||
|
||||
TIM1_EGR = TIM_UG; // Update Generation.
|
||||
|
||||
TIM1_PSC = RTIMER_ARCH_PRESCALER;
|
||||
|
||||
/* Counting from 0 to the maximum value. */
|
||||
TIM1_ARR = 0xffff;
|
||||
|
||||
/* Bits of TIMx_CCMR1 as default. */
|
||||
/* Update Generation. */
|
||||
TIM1_EGR = TIM_UG;
|
||||
INT_TIM1FLAG = 0xffff;
|
||||
|
||||
INT_TIM1CFG = INT_TIMUIF; // Update interrupt enable (interrupt on overflow).
|
||||
|
||||
TIM1_CR1 = TIM_CEN; // Counter enable.
|
||||
|
||||
INT_CFGSET = INT_TIM1; // Enable top level interrupt.
|
||||
|
||||
/* Update interrupt enable (interrupt on overflow).*/
|
||||
INT_TIM1CFG = INT_TIMUIF;
|
||||
|
||||
/* Counter enable. */
|
||||
TIM1_CR1 = TIM_CEN;
|
||||
|
||||
/* Enable top level interrupt. */
|
||||
INT_CFGSET = INT_TIM1;
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void rtimer_arch_disable_irq(void)
|
||||
void
|
||||
rtimer_arch_disable_irq(void)
|
||||
{
|
||||
ATOMIC(
|
||||
saved_TIM1CFG = INT_TIM1CFG;
|
||||
INT_TIM1CFG = 0;
|
||||
)
|
||||
ATOMIC(saved_TIM1CFG = INT_TIM1CFG; INT_TIM1CFG = 0;)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void rtimer_arch_enable_irq(void)
|
||||
void
|
||||
rtimer_arch_enable_irq(void)
|
||||
{
|
||||
INT_TIM1CFG = saved_TIM1CFG;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rtimer_clock_t rtimer_arch_now(void)
|
||||
rtimer_clock_t
|
||||
rtimer_arch_now(void)
|
||||
{
|
||||
return ((rtimer_clock_t)time_msb << 16)|TIM1_CNT;
|
||||
rtimer_clock_t t;
|
||||
|
||||
ATOMIC(t = ((rtimer_clock_t) time_msb << 16) | TIM1_CNT;)
|
||||
return t;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
rtimer_arch_schedule(rtimer_clock_t t)
|
||||
{
|
||||
|
||||
PRINTF("rtimer_arch_schedule time %4x\r\n", /*((uint32_t*)&t)+1,*/(uint32_t)t);
|
||||
|
||||
rtimer_clock_t now, clock_to_wait;
|
||||
PRINTF("rtimer_arch_schedule time %4x\r\n", /*((uint32_t*)&t)+1, */
|
||||
(uint32_t)t);
|
||||
next_rtimer_time = t;
|
||||
|
||||
rtimer_clock_t now = rtimer_arch_now();
|
||||
|
||||
rtimer_clock_t clock_to_wait = t - now;
|
||||
|
||||
now = rtimer_arch_now();
|
||||
clock_to_wait = t - now;
|
||||
|
||||
PRINTF("now %2x\r\n", TIM1_CNT);
|
||||
PRINTF("clock_to_wait %4x\r\n", clock_to_wait);
|
||||
|
||||
if(clock_to_wait <= 0x10000){ // We must set now the Timer Compare Register.
|
||||
|
||||
TIM1_CCR1 = (int16u)now + (int16u)clock_to_wait;
|
||||
|
||||
if(clock_to_wait <= 0x10000) {
|
||||
/* We must now set the Timer Compare Register. */
|
||||
TIM1_CCR1 = (uint16_t)now + (uint16_t)clock_to_wait;
|
||||
INT_TIM1FLAG = INT_TIMCC1IF;
|
||||
INT_TIM1CFG |= INT_TIMCC1IF; // Compare 1 interrupt enable.
|
||||
|
||||
INT_TIM1CFG |= INT_TIMCC1IF; /* Compare 1 interrupt enable. */
|
||||
PRINTF("2-INT_TIM1FLAG %2x\r\n", INT_TIM1FLAG);
|
||||
|
||||
}
|
||||
// else compare register will be set at overflow interrupt closer to the rtimer event.
|
||||
|
||||
/* else compare register will be set at overflow interrupt closer to
|
||||
the rtimer event. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue