forked from guiott/wordclock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Descr.txt
executable file
·83 lines (64 loc) · 2.97 KB
/
Descr.txt
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
*** COMMUNICATION FINITE STATE MACHINE ***
When a new cycle need to be started in the communication Finite State Machine,
to kick off the FSM execution call:
StartCommFsmSched(FsmStruct);
where FsmStruct is the structure
already defined with the sequence to perform.
===========================================
Example, to read time with WiFly from INRIM:
struct FsmTable
{// Scheduler for Finite State Machine
unsigned char Stat; // status index
const unsigned char * Str; // string to send or receive
FsmCallbackFunc pCallback; // function to call after RX or TX is over
};
.......
struct FsmTable ReadTimeFsm[] =
{/* scheduler used for comm protocol with WiFLy
this reads time from http://www.inrim.it
*/
{FsmTx, "$$$", (FsmCallbackFunc)CommFsmIdle},
{FsmRx, "CMD", (FsmCallbackFunc)CommFsmIdle},
{FsmTx, "open", (FsmCallbackFunc)CommFsmIdle},
{FsmRx, "*close*", (FsmCallbackFunc)TimeDecode},
{FsmEnd, "", (FsmCallbackFunc)CommFsmIdle}
};
this defines the operations to perform in each status (Stat), the string to send
in TX operation or to wait as a terminator in RX and the function to call back
at the end of the specific status.
.......
StartCommFsmSched(ReadTimeFsm); // read time from http://www.inrim.it
.......
===========================================
CommFsmSched() is initialized and starts with the first process in the queue.
In the example it is TX of the string "$$$" to enter WiFLy in command mode.
Then waits for the answer "CMD".
All the operations but the last one returns doing nothing, simply executing the
dummy procedure "CommFsmIdle". At the last step the string received is decoded
to set the internal clock with the correct time.
The TX operation is started by the FSM calling "StartTx()" function.
This one fills up the TX buffer with string to transmit:
ReadTimeFsm[FsmIndx].Str
and enabling Usart TX interrupt. After that all the characters in the buffer
are transmitted only using the ISR triggered by the Usart peripheral.
When the buffer has been all transmitted, the ISR disables the TX interrupt
itself and enables the CommFsmFlag to call the FSM scheduler in order to perform
the next step. Each FSM operation has two phases, the first one calls the main
operation, the second one the callback function.
*OPEN*15 OCT 2012 22:44:39 CEST
*CLOS*
===========================================
1ms timer
matrix refresh every Xms
start Timer1 to PWM the LEDs light
Example:
* time ON for each column = 1ms
* total time for 10 columns = 10ms = 100Hz frame refresh rate
* if TMR1 switches off the light after 0,3ms the lightness is 30%
* set the duration of TMR1 to partialize the cycle
* the DutyCycle value must be computed as a percentage of TMR0 duration
* according to the desired lightness
* Timer1Count = 65535 - (DutyCycle * FCY / PRESCALER1);
beacause the time required to scan the column matrix for every 1ms row scanning
is 36us, the minimum duty cycle can be approx 4%
===========================================