Files
TencentOS-tiny/board/STM8L052R8T6/USER/main.c
daishengdong 405e5d970a support stm8
1. see: TencentOS-tiny\board\STM8L052R8T6\IAR\hello_world
2. compile/debug/run with IAR for STM8
2020-02-15 16:39:00 +08:00

154 lines
3.1 KiB
C

#include "tos_k.h"
#include "stm8l15x.h"
#include "uart.h"
#include "rtc.h"
#include "tim.h"
//this is a stm8 rtc demo UART1 print,the baud rate is 57600.
//LED GPIOB0
//Init LED IO
void LED_GPIO_Init(void)
{
GPIO_Init(GPIOB, GPIO_Pin_0, GPIO_Mode_Out_PP_Low_Slow);
}
//set the GPIOB0 Pin to high
void LED_On(void)
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
}
//set the GPIOB0 Pin to low
void LED_Off(void)
{
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
}
//About 1 second, not exactly, just for demonstration purposes
void Delay(unsigned int time)
{
unsigned int i;
while (time--)
{
for (i = 300; i > 0; i--)
{
asm("nop");
}
}
}
void disp_rtc(void)
{
RTC_Get_Time();
UART1_Send_String("Current Time:");
UART1_Send_Dec(clock.cYear, 2); /* YY-MM-DD */
UART1_Send_String("-");
UART1_Send_Dec(clock.cMonth, 2);
UART1_Send_String("-");
UART1_Send_Dec(clock.cDay, 2);
UART1_Send_String(" "); /* HH:MM:SS */
UART1_Send_Dec(clock.cHour, 2);
UART1_Send_String(":");
UART1_Send_Dec(clock.cMinute, 2);
UART1_Send_String(":");
UART1_Send_Dec(clock.cSecond, 2);
UART1_Send_String(" \r\n");
}
#if 0
int main(void)
{
LED_GPIO_Init();
LED_On();
UART1_Init(57600); //Init the UART1 and the baud rate is 57600
UART1_Send_String("RTC Demo Code\r\n");
RTC_Setting_Init(); //Init RTC
while (1)
{
RTC_Get_Time();
UART1_Send_String("Current Time:");
UART1_Send_Dec(clock.cYear, 2); //YY-MM-DD
UART1_Send_String("-");
UART1_Send_Dec(clock.cMonth, 2);
UART1_Send_String("-");
UART1_Send_Dec(clock.cDay, 2);
UART1_Send_String(" "); //HH:MM:SS
UART1_Send_Dec(clock.cHour, 2);
UART1_Send_String(":");
UART1_Send_Dec(clock.cMinute, 2);
UART1_Send_String(":");
UART1_Send_Dec(clock.cSecond, 2);
UART1_Send_String(" ");
LED_On();
Delay(200);
LED_Off();
Delay(200);
}
}
#endif
void task1_entry(void *arg)
{
while (1) {
UART1_Send_String("task1\r\n");
tos_task_delay(200);
}
}
void task2_entry(void *arg)
{
while (1) {
UART1_Send_String("task2\r\n");
tos_task_delay(300);
}
}
k_task_t task1;
k_stack_t task1_stack[512];
k_task_t task2;
k_stack_t task2_stack[512];
int main(void)
{
LED_GPIO_Init();
UART1_Init(57600); /* Init the UART1, baud rate 57600 */
RTC_Setting_Init(); /* Init RTC */
/* use as systick, interrupt handler see TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler */
Timer2_Init(TOS_CFG_CPU_CLOCK, TOS_CFG_CPU_TICK_PER_SECOND);
LED_On();
UART1_Send_String("welcome to TencentOS tiny!\r\n");
tos_knl_init();
tos_task_create(&task1, "task1", task1_entry, NULL,
4,
task1_stack, sizeof(task1_stack),
0);
#if 1
tos_task_create(&task2, "task2", task2_entry, NULL,
4,
task2_stack, sizeof(task2_stack),
0);
#endif
tos_knl_start();
return 0;
}