Commit 985a0095 authored by Federico Vaga's avatar Federico Vaga

common: add freewatch utilities

Create a set of internal utilities for the project. For the time being,
just the SuperCar blinking for the first MCU dev kit, and the delay
function.
Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent d3465d67
#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "freewatch_utils.h"
/* Counts 1ms timeTicks */
volatile uint32_t msTicks;
/**************************************************************************//**
* @brief SysTick_Handler
* Interrupt Service Routine for system tick counter
*****************************************************************************/
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}
/**************************************************************************//**
* @brief Delays number of msTick Systicks (typically 1 ms)
* @param dlyTicks Number of ticks to delay
*****************************************************************************/
void Delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks);
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
void supercar_blink(int delay, int rep)
{
int i, c = rep;
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1);
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
for (i = 1; i < 5; ++i) {
GPIO_PinModeSet(gpioPortD, i, gpioModePushPull, 0);
}
/* Infinite blink loop */
while (c--) {
for (i = 1; i < 5; ++i) {
GPIO_PinOutToggle(gpioPortD, i);
Delay(delay);
}
}
}
#ifndef __FREEWATCH_UTILS_H__
#define __FREEWATCH_UTILS_H__
extern void supercar_blink(int delay, int rep);
extern void Delay(uint32_t dlyTicks);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment