Skip to main content

RTX Real-Time Operating System Issues

RTX Real-Time Operating System Issues

Tổng hợp các vấn đề tôi đã bị vướng khi làm việc với Keil - RTX (for STM32)

1. Sizeof base on MCU platform.
Keyword: sizeof in Keil ARM, sizeof of struct, checksum, BKP_ReadBackupRegister,
BKP_WriteBackupRegister.
Description: Return wrong size of struct when you call sizeof(YourStruct);

Trong ví dụ dưới, ứng với mỗi kiểu khai báo thứ tự của các member trong struct khác nhau, sẽ trả về size of struct khác nhau. Vì vậy, nếu không chắc chắn về sizeof, hãy debug để xác định chính xác toán tử này trả về bao nhiêu trong từng trường hợp cụ thể.
Bạn hoàn toàn có thể dính trấu trong trường hợp sử dụng sizeof để tính checksum, hoặc làm việc với Ram Backup.
Example:
typedef struct
{
uint16_t mem1;
uint32_t mem2;
}foo1_t;

typedef struct
{
uint16_t mem1;
uint16_t dummy;
uint32_t mem2;
}foo2_t;

typedef struct
{
uint16_t mem1;
uint8_t dummy;
uint32_t mem2;
}foo3_t;


len1 = sizeof(foo1_t);
len2 = sizeof(foo2_t);
len3 = sizeof(foo3_t);
Result: len1 = len2 = len3 = 8;

In another case:
typedef struct
{
uint8_t mem1;
uint8_t mem2;
}foo1_t;
len1 = sizeof(foo1_t) = 2;

typedef struct
{
uint8_t mem1;
uint16_t mem2;
}foo1_t;
len1 = sizeof(foo1_t) = 4;

typedef struct
{
uint8_t mem1;
uint16_t mem2;
uint16_t mem3;
}foo1_t;
len1 = sizeof(foo1_t) = 6;

typedef struct
{
uint8_t mem1;
uint16_t mem2;
uint32_t mem3;
}foo1_t;
len1 = sizeof(foo1_t) = 8;

typedef struct
{
uint8_t mem1;
uint32_t mem3;
}foo1_t;
len1 = sizeof(foo1_t) = 8;

2. Time management (các loại wait, delay trong RTX)
Keyword: os_dly_wait, os_itv_set, os_itv_wait.
Description:
Reference:
http://www.eng.auburn.edu/~nelson/courses/elec5260_6260/RL-ARM%20Real-Time%20Executive%20(RTX).pdf

Just one thing to remember that:
Cannot mix os_itv_wait and os_dly_wait in one task. Because, os_dly_wait will change interval time of task what is set by os_itv_set before.

3. Mutex (stand for “Mutual Exclusion”)
Keyword: Mutex, semaphore
Description: How to use mutex...
Reference: http://www.dejazzer.com/ee379/labs/lab6_rtos.pdf
When:
The main use of a Mutex is to control access to a chip resource
such as a peripheral/register.
os_mut_wait also change priority of the owning task of the mutex
http://www.keil.com/support/man/docs/rlarm/rlarm_os_mut_wait.htm

Hàm os_mut_wait có thể làm thay đổi priority của 1 task
Q&A
1. Khai tối đa được bao nhiêu mutex?
/* Definition of Mutex type */
typedef U32 OS_MUT[3];
Ex: OS_MUT  GsmMutex // GsmMutex là 1 mảng 3 phần tử có định dạng là U32
2. Tại sao lại có 3 phần tử?


4. Task managemet
Keyword: RL-RTX, state, 
Description: How to use mutex...
http://www.keil.com/support/man/docs/rlarm/rlarm_ar_task_mgmt.htm







Comments

Post a Comment

Popular posts from this blog

[STM32] How to configure Timer 1, Channel 3 is PWM 1kHz, duty cycle 20% to control BLDC motor

 To configure Timer1 for a 1 kHz PWM signal with a 20% duty cycle on an STM32H7S3L8 microcontroller, follow these steps: 1. Understand the Timer Parameters PWM Frequency : 1 kHz → Period = 1 ms. Duty Cycle : 20% → ON time = 0.2 ms. The timer’s clock frequency is derived from the APB clock (e.g., TIMCLK). Let’s assume you know the APB clock frequency. The Timer prescaler and auto-reload register (ARR) define the PWM frequency. 2. Compute Timer Parameters Formula: PWM Frequency = Timer Clock (Prescaler + 1) * (ARR + 1) \text{PWM Frequency} = \frac{\text{Timer Clock}}{\text{(Prescaler + 1) * (ARR + 1)}} PWM Frequency = (Prescaler + 1) * (ARR + 1) Timer Clock ​ For 1 kHz PWM: A R R = Timer Clock PWM Frequency ∗ ( Prescaler + 1) − 1 ARR = \frac{\text{Timer Clock}}{\text{PWM Frequency} * (\text{Prescaler + 1)}} - 1 A RR = PWM Frequency ∗ ( Prescaler + 1) Timer Clock ​ −...

[CanadaLife] Example of answers for final test in Smart Service Ontario 2024

If you have failed the final exam in the first attempt. Congratulations, you are not odd. Here, take a look and grab some corrected answers for your next attempt.  Don't waste your money and time for more failure.  Good luck bros. Quick note: remember that, the system will change the bunch of questions after each attempt. Then your next questionnaire will be different compared with the first trial. ========================================== =============FINAL TEST=================== ========================================== TIP: Here is a list of questions you did not answer correctly. *Please note: You will only be able to view this list immediately following your test attempt. ========================================== Alcohol slows down the central nervous system and impacts how a person thinks, acts, and moves. This means alcohol is a: depressant ========================================== Alcohol is metabolized in the body at a set rate. For most people, that rate is: one...

[Mentorship] First day at work - question for your co-workers (casual and friendly tone)

Summary Learn essential tips to make a positive first impression on your first day at a new job, ensuring success and connection with colleagues. Highlights⏰ Be punctual: Arrive early to show commitment. ( 15 minutes before your shift ) 🚫 Avoid gossip: Maintain professionalism and integrity. ❌ Don’t ask for time off: Show dedication to your new role. 🤝 Firm handshake: A confident greeting sets a great tone. 📚 Ask questions: Engage with your new role actively. 🗂️ Organize your workspace: Keep your area tidy for respect. ☕ Accept social invites: Build rapport with co-workers. Key Insights ⏳ First Impressions Matter: Your colleagues will form opinions quickly, so be on your best behavior right from the start. 🌟 Professional Appearance: Dressing smartly conveys seriousness about your role and can positively influence how others perceive you. 💬 Communication is Key: A warm greeting and engaging dialogue can help break the ice and make you more approachable. 📝 Active Learning: Asking ...