Skip to content

Commit fdcba3e

Browse files
author
Rei Vilo
committed
Implementation of micros() — Fix for issue energia#58
1 parent 897a17b commit fdcba3e

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// micros_430.ino
3+
// Sketch
4+
// ----------------------------------
5+
// Developed with embedXcode
6+
//
7+
// Project micros
8+
// Created by Rei VILO on 30/05/12
9+
// Copyright © 2012 http://embeddedcomputing.weebly.com
10+
// Licence CC = BY SA NC
11+
//
12+
//
13+
// Based on Serial_430
14+
// © Rei VILO 2012
15+
// PUSH2 on pin 5
16+
// Press push 2 to end and clear the serial port
17+
//
18+
19+
// Core library
20+
#if defined(__MSP430G2452__)
21+
#include "Energia.h"
22+
#else
23+
#error MSP540G2452 required
24+
#endif
25+
26+
#include "TimerSerial.h"
27+
TimerSerial mySerial;
28+
29+
void setup() {
30+
mySerial.begin();
31+
mySerial.print("\n\n\n*** Serial test starts \n");
32+
mySerial.print("PUSH2 to end\n");
33+
pinMode(PUSH2, INPUT_PULLUP);
34+
}
35+
36+
37+
void loop() {
38+
39+
mySerial.print(1.0*millis(), 0);
40+
mySerial.print("\t ");
41+
mySerial.println(1.0*micros(), 0);
42+
delay(500);
43+
44+
if (digitalRead(PUSH2)==LOW) {
45+
mySerial.print("\n\n*** Serial test ends. \n");
46+
mySerial.end();
47+
while(true); // endless loop
48+
}
49+
}
50+
51+
52+
53+
54+

hardware/msp430/cores/msp430/Energia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ extern const uint16_t port_to_input[];
141141

142142
// Implemented in wiring.c
143143
void delayMicroseconds(unsigned int us);
144+
unsigned long micros();
144145
unsigned long millis();
145146

146147
#ifdef __cplusplus

hardware/msp430/cores/msp430/wiring.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void initClocks(void)
8787
const uint32_t WDT_FREQUENCY = SMCLK_FREQUENCY / WDT_DIVIDER;
8888
volatile uint32_t wdtCounter = 0;
8989

90+
unsigned long micros()
91+
{
92+
return (1000 * wdtCounter) / (WDT_FREQUENCY / 1000);
93+
}
94+
9095
unsigned long millis()
9196
{
9297
return wdtCounter / (WDT_FREQUENCY / 1000);

0 commit comments

Comments
 (0)