/
main.c
126 lines (99 loc) · 2.78 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* This file is§ part of LP-blink
*
* Copyright (C) 2013 Mirco Gysin <miagox@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <msp430.h>
#include <msp430g2553.h>
#include <clock.h>
#include <timerA.h>
#include <launchpad.h>
#include <message.h>
#include <queue.h>
#include <task.h>
#include <events.h>
#include <scheduler.h>
#include <button.h>
#include <led.h>
#include <cli.h>
#include <users.h>
#include <info.h>
#include <com_uart.h>
#define interrupt(x) void __attribute__((interrupt (x)))
void mainHandler( message *msg );
message *mainMessage;
unsigned char cmdNameMain[] = "main";
task mainTask;
int timerCount;
int main( void ){
disableWDT();// Stop watchdog timer
initQueue();
initScheduler();
initButton();
initLed();
initComUart();
initInfo();
mainTask.cmdName = cmdNameMain;
mainTask.user = main_user;
mainTask.handler = &mainHandler;
registerTask( &mainTask );
setDCOCLK( DCO_1M );
setSMCLK( SMCLK_DCO, CLK_DIV_1 );
if( getFreeMessage( &mainMessage ) == queue_ok ){
mainMessage->source = main_user;
mainMessage->destination = led_user;
mainMessage->id = MSG_ID_LED_GREEN;
mainMessage->priority = normal_priority;
mainMessage->event = undef_event;
putMessage( mainMessage );
}
if( getFreeMessage( &mainMessage ) == queue_ok){
mainMessage->destination = com_uart_user;
mainMessage->source = main_user;
mainMessage->id = MSG_ID_UART_WELCOME;
putMessage( mainMessage );
}
initCli();
enableTimerA0CCInterrupt();
setTimerA0Mode( TAMODE_CONT );
setTimerA0ClockSource( TA_SMCLK );
setTimerA0Divider( TA_DIV_1 );
__enable_interrupt();
__bis_SR_register( 0x18 );
//__bis_SR_register( 0x18 ); // LPM0 with interrupts enabled
while( 1 ){};
return 0;
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void timerA0ISR( void )
{
timerCount = ( timerCount + 1 ) % 16;
if ( timerCount == 0 ) {
if( getFreeMessage( &mainMessage ) == queue_ok ){
mainMessage->source = main_user;
mainMessage->destination = led_user;
mainMessage->id = MSG_ID_LED_GREEN;
mainMessage->event = toggle_event;
putMessage( mainMessage );
} else {
ledToggle( MSG_ID_LED_RED );
}
}
scheduler();
}
void mainHandler( message *msg ){
}