Texas Instruments MSP50C6xx User Manual
Page 340
C– – Efficiency
5-44
mov *seconds_passed, a0
inte
mov a0, a0~
ret
The file only has one C– – callable function, getSecondsPassed. The function
reads the value in seconds_passed and returns it in A0. All C– – functions have
an underscore preceding their name in assembly. The underscore is ignored
when programming in C– –. In C– – a call to this function would look like
int result = getSecondsPassed();
Notice that the underscore is not used here because C– – is being used instead
of assembly. getSecondsPassed() has very simple functionality, but it
illustrates several important points. First, interrupts are disabled with the intd
instruction. This is extremely important because it is not possible to read the
value in seconds_passed and clear it in an atomic operation. If the value is
read and the timer fires before it is cleared, one second will be lost. The next
important feature to note is the inclusion of rpt2–2 before the intd instruction.
Because of pipeline latency, interrupts can still fire for two clock cycles after
an intd instruction. The rpt temporarily disables interrupts and ensures that an
interrupt does not fire and execute an inte before the intd makes it through the
pipeline. Disabling interrupts ensures that the timer will not fire while the value
in seconds_passed is being read and altered.
The sixth file, cmm1_ram.asm, allocates memory for cmm1.asm.
;****************************************************************
; CMM1_RAM.IRX
;
; Start of memory for asmroutines module is defined in
;
include
”..\ram\ram.irx”
;****************************************************************
; Variables
; End of memory
RAMEND_CMM1
equ RAMSTART_CMM1
RAMLENGTH_CMM1
equ RAMEND_CMM1 – RAMSTART_CMM1
In this project, cmm1.asm did not use any RAM, but it can be allocated just like
the RAM for the ISRs. For example, a variable named tempa could be
allocated as follows.
; Variables
tempa
equ RAMSTART_CMM1 + 2 * 1
; End of memory
RAMEND_CMM1
equ tempa
The last file is the C– – program, main.cmm. This provides all of the top level
functionality for the project. Once all of the previous supporting files have been
written, writing the C– – program is very much like writing a regular C program.
/****************************************************************