Created
April 13, 2016 17:56
-
-
Save pi19404/928e024cd8008e814357738877cfd67e to your computer and use it in GitHub Desktop.
mbed test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
#include <rtos.h> | |
#define APPLICATION_JUMP_TIMEOUT 8 //in seconds | |
#define APPLICATION_ADDRESS 0x08000000 //Starting at 50 kB | |
#define APPLICATION_SIZE 150 //in kB | |
Serial serial(PA_2 ,PA_3 ); | |
extern bool jump_to_main_app_flag; | |
Timer jump_timer; | |
uint16_t jump_time; | |
DigitalOut led1(LED1); | |
DigitalOut led2(LED3); | |
typedef void (*pFunction)(void); | |
pFunction execute_application = (pFunction)*(__IO uint32_t*)(APPLICATION_ADDRESS + 4); | |
void jump_application() | |
{ | |
__disable_irq(); | |
NVIC_DisableIRQ(TIM2_IRQn); | |
__set_MSP(*(__IO uint32_t*)APPLICATION_ADDRESS); | |
serial.printf("\n\nApplication address set!"); | |
serial.printf("\nJumping to main application...\n\n"); | |
execute_application(); | |
serial.printf("\infinte loop main application...\n\n"); | |
while(1); | |
} | |
void switch_off_system() | |
{ | |
serial.printf("\nSwitching off system..."); | |
while(1); | |
} | |
void main1(void const * args) | |
{ | |
led1 = 0; | |
led2 = 1; | |
int hash_val; | |
uint32_t application_address = APPLICATION_ADDRESS; | |
jump_timer.start(); | |
while(1) | |
{ | |
jump_time = jump_timer.read_ms(); | |
if(jump_time > APPLICATION_JUMP_TIMEOUT*1000) | |
{ | |
serial.printf("\nProgram jump flag set!"); | |
jump_to_main_app_flag = true; | |
jump_application(); | |
} | |
led2 = !led2; | |
wait_ms(1000); | |
} | |
} | |
int main() | |
{ | |
led2 = 1; | |
serial.baud(9600); | |
serial.printf("\n-----Bootlader RTOS FIRMWARE TEST-----"); | |
Thread thread3(main1); | |
/* We should never get here as control is now taken by the scheduler */ | |
for( ;; ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,I have a question. I make the bootloader 's .bin and combine with application.bin.The bootloader's function is jump directly application.But it does not.
The follow is bootloader code.
#include <events/mbed_events.h>
#include <mbed.h>
int main()
{
mbed_start_application(POST_APPLICATION_ADDR);
}