Porting Notes of AWTK on Tencent TOS

This paper takes STM32f103ze as an example to introduce the experience of AWTK porting on RTOS.It's more about integration than porting.Because RTOS usually does not provide a standard LCD driver interface, no special changes are required in the display part.All you have done is put AWTK in one thread of the RTOS to execute it.

1. Add TOS related files.

AWTK has been ported to the STM32f103ze bare system, and for simplicity, it is available directly in awtk-stm32f103ze-raw Add TOS support on the basis.

  • Add the following files to Keil:
TencentOS/kernel/core/tos_event.c
TencentOS/kernel/core/tos_fifo.c
TencentOS/kernel/core/tos_global.c
TencentOS/kernel/core/tos_mmblk.c
TencentOS/kernel/core/tos_mmheap.c
TencentOS/kernel/core/tos_msg.c
TencentOS/kernel/core/tos_mutex.c
TencentOS/kernel/core/tos_pend.c
TencentOS/kernel/core/tos_queue.c
TencentOS/kernel/core/tos_robin.c
TencentOS/kernel/core/tos_sched.c
TencentOS/kernel/core/tos_sem.c
TencentOS/kernel/core/tos_sys.c
TencentOS/kernel/core/tos_task.c
TencentOS/kernel/core/tos_tick.c
TencentOS/kernel/core/tos_time.c
TencentOS/kernel/core/tos_timer.c
TencentOS/kernel/pm/tos_pm.c
TencentOS/kernel/pm/tos_tickless.c
TencentOS/arch/arm/arm-v7m/common/tos_cpu.c
TencentOS/arch/arm/arm-v7m/common/tos_fault.c
TencentOS/arch/arm/arm-v7m/cortex-m3/armcc/port_c.c
TencentOS/arch/arm/arm-v7m/cortex-m3/armcc/port_s.S
  • Increase include Path
TencentOS/arch/arm/arm-v7m/common/include
TencentOS/arch/arm/arm-v7m/cortex-m3/armcc
TencentOS/kernel/core/include
TencentOS/kernel/hal/include
TencentOS/kernel/pm/include
TencentOS/TOS-CONFIG
  • Modify Profile

Modify the configuration TencentOS/TOS-CONFIG/tos_config.h to suit your needs:

Normally no modifications are required, just use the official offer.I'm using TencentOS-Demo In the project.

2. Add threads and synchronization functions for the TOS implementation.

src/platforms/tos/mutex.c
src/platforms/tos/semaphore.c
src/platforms/tos/thread.c
src/platforms/common/sys_tick.c

3. Implement rtos.c.

The main thing is the implementation of the SysTick interrupt, just copy it from TencentOS-Demo.

ret_t rtos_init(void) {
  tos_knl_init();
  tos_robin_config(TOS_ROBIN_STATE_ENABLED, (k_timeslice_t)500u);

  return RET_OK;
}

ret_t rtos_start(void) {
  tos_knl_start();

  return RET_OK;
}

void rtos_tick(void) {
  if (tos_knl_is_running()) {
    tos_knl_irq_enter();
    tos_tick_handler();
    tos_knl_irq_leave();
  }
}

void rtos_delay(uint32_t ms) {
  tos_task_delay(ms);
}

4. Start AWTK in the thread

void* awtk_thread(void* args) {
  gui_app_start(320, 480);

  return NULL;
}

static ret_t awtk_start_ui_thread(void) {
  tk_thread_t* ui_thread = tk_thread_create(awtk_thread, NULL);
  return_value_if_fail(ui_thread != NULL, RET_BAD_PARAMS);

  tk_thread_set_priority(ui_thread, 3);
  tk_thread_set_name(ui_thread, "awtk");
  tk_thread_set_stack_size(ui_thread, 2048);

  return tk_thread_start(ui_thread);
}

int main() {
  hardware_prepare();
  platform_prepare();

  rtos_init();
  awtk_start_ui_thread();
  rtos_start();
	
	return 0;
}

There are two main differences from bare systems here:

    1. Start AWTK in the thread.
    1. To call platform_prepare ahead of time, platform_prepare is responsible for initializing memory and is placed in tk_init a little late and needs to be called separately.

The platform_prepare function is handled to prevent duplicate calls.

static bool_t s_inited = FALSE;
static uint32_t s_heam_mem[4096];

ret_t platform_prepare(void) {
	if(!s_inited) {
		s_inited = TRUE;
    tk_mem_init(s_heam_mem, sizeof(s_heam_mem));
	}
  return RET_OK;
}

AWTK integration of RTOS is very simple, the above process took about 2 hours.As long as the RTOS itself is portable, integrating AWTK with RTOS is a matter of minutes.

Posted by gazolinia on Fri, 08 Nov 2019 17:52:00 -0800