Skip to content

Instantly share code, notes, and snippets.

@sourceperl
Last active December 17, 2015 06:48
Show Gist options
  • Save sourceperl/5567850 to your computer and use it in GitHub Desktop.
Save sourceperl/5567850 to your computer and use it in GitHub Desktop.
CC = msp430-gcc
CFLAGS = -Os -Wall -g -mmcu=$(MCU)
TARGET = wdt
OBJS = wdt.o
BIN = $(TARGET).elf
MCU = msp430g2553
all: $(OBJS)
$(CC) $(CFLAGS) -o $(BIN) $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -c $<
clean:
rm -f $(BIN) $(OBJS)
#include <msp430g2553.h>
#include <legacymsp430.h>
#define RED_LED BIT0
typedef struct {
unsigned long every;
unsigned long last_call;
void (*job_ptr) (void);
} jobs;
jobs job_list[4];
unsigned long millis = 0;
int i;
int main(void)
{
/* Set watchdog timer interval to 32ms */
WDTCTL = WDT_MDLY_32;
/* "Interrupt enable 1" for the Watchdog Timer interrupt */
IE1 |= WDTIE;
/* Set the LED pin as an output pin */
P1DIR |= RED_LED;
/* Turn on LED pin */
P1OUT |= RED_LED;
/* Init job list */
for (i = 0; i < 4; i++)
{
job_list[i].every = 0;
job_list[i].last_call = 0;
job_list[i].job_ptr = 0;
}
/* Do nothing...forever */
while(1)
{
/* Go into low power mode 0, general interrupts enabled */
__bis_SR_register( LPM0_bits + GIE );
/* Wake up here, check for schedule job */
for (i = 0; i < 4; i++)
{
/* if (millis() > job_list[i].last_call + job_list[i].every) {
} */
}
}
}
// TODO safe access routine for millis
/* Watchdog Timer interrupt service routine. The function prototype
* tells the compiler that this will service the Watchdog Timer, and
* then the function follows.
*/
interrupt(WDT_VECTOR) watchdog_ISR(void)
{
millis += 32;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment