📄 main.c
字号:
/***************************************************************************************************
* Filename : MAIN.C
* Last Modified : 23 Jan 2002.
* Version : 1.3
* Originator : Texas Instruments, DSP Digital Control Systems Group.
***************************************************************************************************
* Description
* This file supplies an example of the application of embedded flash
* programming algorithms.
*
* Revision history :
* Version 1.0 (25 May 2001):
* New implementation for the embeddable flash algos.
*
* Version 1.2 (16 Oct 2001):
* 1.Modified the header to include the version/date.
* Version 1.3 (23 Jan 2002):
* Made the following changes to this file:
* 1. Made this example functional for BOTH LF2407x and LF2401A devices.
* Changes include using SECTOR1 only for the sector mask and additional
* commenting.
*
*************************************************************************************************/
/* The following is the sequence to re-program a section of the flash:
*
* 1. Copy the flash programming algorithms to RAM.
* This is because NO code can run from flash at-all while reprogramming
* the flash.
*
* 2. Copy the sequencer / kernel to the RAM. This would contain the
* implementation of all control code / communications routines etc.
*
* 3. Before running the flash algorithms, the watchdog is shut down. The
* flash programming algorithms must not be interrupted. So before
* calling any algos, all interrupts must be shut off as well.
* 4. This example can be used as is on the LF2407 as well as the LF2401A devices,
* the only change needed is the device selection in the VAR.H file included.
*
*/
/* Compiler directives to place all the kernel functions in the KER_text section.
* This section is handled by the linker command file to have a load address in the
* flash memory but a run addres in the SARAM block. This is copied at run time
* to the run address by the copyKernel function.
*/
#pragma CODE_SECTION(kernelControlLoop,"KER_text")
#pragma CODE_SECTION(AnotherKernelFunction,"KER_text")
/* Function prototypes and constants, registers etc.
*/
void lf240xInitSys(void);
/* Import the function prototypes and variable information from the
* flash algorithms
*/
#include "..\\flashalgos\\include\\CFlash.h"
/* Import the function prototypes and variable information from the
* flash algorithms
*/
#include "regs240x.h"
/* Buffer to hold data for programming into flash
*/
int bufferArray[]={0x1245,0x7436,0x8436,0x8733,0x4398 };
main()
{
/*
* Call the system initialization function.
* For flash programming at a minimum the Watchdog must be shut down
* and the PLL initialized
*/
lf240xInitSys();
copyKernel();
kernelControlLoop();
while(1);
}
int kernelControlLoop(void)
{
copyClearAlgo();
flashAlgoVars.SECTOR_CMD=(SECTOR1);
/* The code here assumes that clearFlash suceeds, a real app
would do error checking.*/
clearFlash(&flashAlgoVars);
copyEraseAlgo();
flashAlgoVars.SECTOR_CMD=(SECTOR1);
eraseFlash(&flashAlgoVars);
/* The code here assumes that eraseFlash suceeds, a real app
would do error checking.*/
copyProgramAlgo();
/* Setup the sector permissions */
flashAlgoVars.SECTOR_CMD=(SECTOR1);
/* Setup ptr to data buffer. */
flashAlgoVars.DATA_PTR=(int)(&bufferArray);
/* Number of words to program */
flashAlgoVars.FL_SECEND=0x4;
/* Block address */
flashAlgoVars.ADDR=0x1023;
/* Call the program routine */
programFlash(&flashAlgoVars);
/* The code here assumes that programFlash suceeds, a real app
would do error checking.*/
/* Map in the flash into the program space */
/* SCSR2=0xb; */
/* Map in the ext-RAM into the program space */
/* SCSR2=0x7;*/
}
int AnotherKernelFunction(void)
{
}
void lf240xInitSys(void)
{
WDCR=0x6f; /* Dis-able the watchdog */
SCSR1=0x0; /* PLL = x4 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -