原创 ZRTOS 应用实例

2009-1-5 00:59 2738 5 5 分类: 汽车电子

也许大家有疑问ZRTOS真的好用吗?有没有已知或未知的bug呢?可以负责地讲只要正确地使用,ZRTOS is bug-free. 现在向大家展示一个ZRTOS的应用实例。


here is the source codes...

/* bsp_build.c */
/*
Author: lao4

The following is the main () subroutine for Z Technologies' Telematics vehicle unit
The MCU is HC12 or HC12X (MC9S12XDG128, 12K RAM, 128K ROM). The size of executable code is
about 80 K. The whole application only uses 10 K RAM to accomplish the goal.

The real operating system used here is ZRTOS that is developed by Z Technologies
for embedded controller.

*/
#include "build_config.h" 

const U16 eeprom_protected_reg @ 0x0FFC = 0xFF88;     //initialize EEPROM Proteced Register
const U16 protected_block_3_2 @ 0xFF0A = 0x9ca4;//initialize FLASH protected block Register;
const U16 protected_block_1_0 @ 0xFF0C = 0xa420;//initialize FLASH protected block Register;
const U16 security_byte @ 0xFF0E = 0xfffe;//initialize FLASH security Register;


static char mem_task[_USED_BY_TASKS];         //allocate RAM space
static char mem_iolib[_USED_BY_IOS];           //allocate RAM space
static char mem_heap[_USED_BY_MALLOC];    //allocate RAM space

void main(void)             //main start
{    
  short key = rtos_intLock();     //block interrupts
  int n;
 
  HardwareSetup(); //hardware set up: basic hardware setup,
                   //such as register map, chips modes (signal chip or expaned chip), etc.
                   //
    
  init_factory_rst();     //Check the integrities of the executable code
 
  //Initialize the task sub-system in ZRTOS                                    
  if (rtos_taskInit(mem_task, servWD, NUMBER_OF_TASKS) == (RTOS_STATUS) ERROR) {
    for(;;);//If the initialization failed, do not go any  further                                                      
  }
 
  //Initialize the device driver sub-system in ZRTOS
  if (rtos_iosInit(mem_iolib, NUMBER_OF_DEVICE) == (RTOS_STATUS) ERROR) {
    for(;;);//If the initialization failed, do not go any further
  }
  
  //Initialize the RAM memory manager sub-system in ZRTOS
  if (memPartitionInit(mem_heap, HEAP_MEM_SIZE, NUM_HEAPED_MEM) > _USED_BY_MALLOC) {    //memory too small
    for(;;);//If the initialization failed, do not go any further
  } 
 
  rtos_mainTimer_Init();//Initialize the timers
 
  /*
  Since some tasks have to use file system, but the initialization of file system
  may take a bit of delay, the following initialization step is to make sure that
  those tasks shall start only after the file system has been running.
  */
  initial_nv();//
 
  //Wait a bit to allow other MCU in the vehicle's CAN to digest the power on impact of this unit
  #define _POWER_ON_DELAY (97)//(799)//(399)//3.99s //1.11s //5-10 s
  for(n = 0; n < _POWER_ON_DELAY; n++) {
    _delay_timer(7500);
  }
 
  irq_init();//Initialize IRQ, XIRQ interrupt, sleep and wake up processes
 
  //Initialize the encryption sub system, to create a 126-bit encryption/decryption key            
  crypt_init((unsigned char *) KEY_FILE, BLOCK_SIZE, 0);     //
 
  _file_init();//Initialize the file sub-system (Flash ROM) in ZRTOS

  
  devInit();//initialize device drivers
  paraInit();//Initialize the parameter sub system
  faultInit();//Initialize the fault sub system
  sleep_init();//Initialize the sleep or power saving
 

  spi_Init();//Initialize the SPI sub system     
  rtc_Init();//Initialize the real time clock
  lcd_Init();//Initialize the LCD display system
 
  displayShortMsg((char *) NULL); //displaying a default message on the LCD screen

  initialTsip(); //Initialize the GPS unit which uses TSIP (Trimble Standard Interface Protocol)
 
  digit_radio_init();//Initialize the business radio system
 
  cmx868_init();//Initialize the Cellular phone module

  com_init();//Initialize the COM
  //(communication channels: a) CAN; b) business radio; c) cellular phone module; etc.)

   
  led_init();//Initialize the LED lights
 
  sos_init(SOS_OUTPUT_PWM_CH);//Initialize the SOS push button
 
  pwm_monitor();//Initialize the PWM output
 
  geo_fence_init();//Initialize the GEO fence 
 
  bkoffice_init();//Initialize the back office interface
 
  initialRecorder();//Initialize the vehicle data recorder and monitor system
 
  ic_reader_init();//Initialize the IC card reader
 
  key_bd_Init();//Initialize the key board

  tasksInit();//Initialize the user application tasks
 
  usb_host_init();//Initialize the USB storage device
   
  rtos_intUnlock(key);//enable interrupt

  rtos_taskScheduler();//the whole system starts to run

}


PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
5
关闭 站长推荐上一条 /3 下一条