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,22 +33,20 @@
|
|||
* 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
|
||||
* Clock.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include <stdio.h>
|
||||
#include "hal/error.h"
|
||||
#include "hal/hal.h"
|
||||
#include "dev/stm32w_systick.h"
|
||||
#include "dev/stm32w-systick.h"
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/clock.h"
|
||||
|
@ -54,46 +58,39 @@
|
|||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* The value that will be load in the SysTick value register. */
|
||||
#define RELOAD_VALUE 24000-1 /* 1 ms with a 24 MHz clock */
|
||||
#define RELOAD_VALUE 24000-1 /* 1 ms with a 24 MHz clock */
|
||||
|
||||
static volatile clock_time_t count;
|
||||
static volatile unsigned long current_seconds = 0;
|
||||
static unsigned int second_countdown = CLOCK_SECOND;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
SysTick_Handler(void)
|
||||
{
|
||||
count++;
|
||||
|
||||
if(etimer_pending()) {
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
if (--second_countdown == 0) {
|
||||
|
||||
if(--second_countdown == 0) {
|
||||
current_seconds++;
|
||||
second_countdown = CLOCK_SECOND;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
clock_init(void)
|
||||
{
|
||||
|
||||
{
|
||||
ATOMIC(
|
||||
|
||||
//Counts the number of ticks.
|
||||
count = 0;
|
||||
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
||||
SysTick_SetReload(RELOAD_VALUE);
|
||||
SysTick_ITConfig(ENABLE);
|
||||
SysTick_CounterCmd(SysTick_Counter_Enable);
|
||||
|
||||
)
|
||||
|
||||
/* Counts the number of ticks. */
|
||||
count = 0;
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
||||
SysTick_SetReload(RELOAD_VALUE);
|
||||
SysTick_ITConfig(ENABLE);
|
||||
SysTick_CounterCmd(SysTick_Counter_Enable);)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
|
@ -108,16 +105,16 @@ clock_time(void)
|
|||
void
|
||||
clock_delay(unsigned int i)
|
||||
{
|
||||
for (; i > 0; i--) { /* Needs fixing XXX */
|
||||
for(; i > 0; i--) { /* Needs fixing XXX */
|
||||
unsigned j;
|
||||
for (j = 50; j > 0; j--)
|
||||
asm ("nop");
|
||||
for(j = 50; j > 0; j--) {
|
||||
asm("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Wait for a multiple of 1 ms.
|
||||
*
|
||||
*/
|
||||
void
|
||||
clock_wait(clock_time_t i)
|
||||
|
@ -125,7 +122,7 @@ clock_wait(clock_time_t i)
|
|||
clock_time_t start;
|
||||
|
||||
start = clock_time();
|
||||
while(clock_time() - start < (clock_time_t)i);
|
||||
while(clock_time() - start < (clock_time_t) i);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned long
|
||||
|
@ -133,49 +130,5 @@ clock_seconds(void)
|
|||
{
|
||||
return current_seconds;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
sleep_seconds(int seconds)
|
||||
{
|
||||
int32u quarter_seconds = seconds * 4;
|
||||
uint8_t radio_on;
|
||||
|
||||
halPowerDown();
|
||||
radio_on = stm32w_radio_is_on();
|
||||
stm32w_radio_driver.off();
|
||||
|
||||
halSleepForQsWithOptions(&quarter_seconds, 0);
|
||||
|
||||
|
||||
ATOMIC(
|
||||
|
||||
halPowerUp();
|
||||
|
||||
/* Update OS system ticks. */
|
||||
current_seconds += seconds - quarter_seconds / 4 ; /* Passed seconds */
|
||||
count += seconds * CLOCK_SECOND - quarter_seconds * CLOCK_SECOND / 4 ;
|
||||
|
||||
if(etimer_pending()) {
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
||||
SysTick_SetReload(RELOAD_VALUE);
|
||||
SysTick_ITConfig(ENABLE);
|
||||
SysTick_CounterCmd(SysTick_Counter_Enable);
|
||||
)
|
||||
|
||||
stm32w_radio_driver.init();
|
||||
if(radio_on) {
|
||||
stm32w_radio_driver.on();
|
||||
}
|
||||
|
||||
uart1_init(115200);
|
||||
leds_init();
|
||||
rtimer_init();
|
||||
|
||||
PRINTF("WakeInfo: %04x\r\n", halGetWakeInfo());
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue