• Tidak ada hasil yang ditemukan

Paulos F040

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "Paulos F040"

Copied!
310
0
0

Teks penuh

In particular, it deals with a modified version of the original PaulOS cooperative RTOS to be compatible with the Silicon Labs C8051F040 device, with its increased number of SFR pages, timers, Control Area Network (CAN bus) and interrupts. It has basically the same format as the book for the C8051F020 device (Debono, 2015), but the software has of course been adapted to take full advantage of the architecture of the C8051F040. Namely, the RTOS has the ability to use any one of the 5 timers available on the device as the source of its tick timer.

This book is structured in 4 chapters and 2 appendices with complete source code listings of the PaulOS RTOS and of the example programs. A complete list of the modified CAN bus RTOS with a sample program is also given in this chapter.

ACKNOWLEDGEMENTS

To my wife Maria for being so supportive and patient with me, my two sons Neil and Luke for their continuous

1 C8051F040 BASICS

  • INTRODUCTION
  • MEMORY TYPES
  • PROGRAM/DATA MEMORY (FLASH)
  • EXTERNAL DATA ADDRESS SPACE (XRAM)
    • INTERNAL DATA ADDRESS SPACE (RAM)
  • bytes that remain in Internal RAM, from address 30h through address 7Fh, may be used to store any user variables that need to be accessed frequently or at high-speed during
    • SPECIAL FUNCTION REGISTER (SFR) MEMORY
    • Save the current SFR page (stored in SFRPAGE register) in a temporary location/variable
    • Select the appropriate SFR page number using the SFRPAGE register
    • Use direct accessing mode to read from or write to the required SFR (MOV instruction)
    • Restore the original SFR from the temporary variable by writng it back to the SFRPAGE register

The internal memory layout of the C8051F040 is represented in the memory folder shown in Table 1-2, which is identical to the base 8051, except of course that it now has more SFRs, as this device is much more powerful than the base 8051, with a much larger list of peripherals. devices. Bit memory is another part of internal RAM that, as the name suggests, can store and manipulate bit variables. Special Function Registers (SFRs) are located in areas of internal memory that control the specific functionality of the C8051F040 chip, as shown in Table 1-3.

In general, as noted in Table 1-3 itself, some SFRs are used to control the operation or configuration of some aspect of the 8051. Upon execution of the RETI command, the SFR page is automatically restored to the SFR page that was in use prior to the interrupt .

Table 1-1 C8051F040 on-chip memory map
Table 1-1 C8051F040 on-chip memory map

2 PAULOS_F040 – A CO- OPERATIVE RTOS

DESCRIPTION OF THE RTOS OPERATION

The RTOS tick timer is selectable by the user, who can choose from the various timers available on the controller. When set, on each timer overflow an interrupt call is made to the main RTOS tick timer interrupt routine. This is the most important routine in the program, since at each interrupt the RTOS must check the status of all the tasks in order to determine whether a task can be moved from the waiting queue to the ready to execute queue (see Figure 2-1) or a task swap , if main() was running, is required.

The RTOS accomplishes this by counting down the parameter variables that hold the individual wait time required for these tasks in the queue. Only the main() code can be forced to give up its time, so if at any time while the main() code is.

Figure 2-1 RTOS Task states diagram
Figure 2-1 RTOS Task states diagram

RUNNING

WAITING

The actual job is queued when OS_WAITP (wait for periodic interval) occurs.

READY

PAULOS_F040.C SYSTEM COMMANDS

These are first listed or grouped by whether or not they take any parameters. The list is then repeated, this time sorted by whether or not the command causes a task switch. OS_SCHECK (void); // Checks if the running task's signal bit is set, returning a bit value // of 1 if the signal is already present.

The list of commands can also be grouped as those that cause a task change, may cause a task change, and those that do not cause a task change. OS_WAITS (uint ticks); // Waits for a signal within a number of ticks If the signal is already present when the command is issued, then no task switch is performed, otherwise a task switch is performed.

DESCRIPTIONS OF THE COMMANDS

  • OS_CREATE_TASK(TASK NO:, TASK NAME)
  • OS_RUNNING_TASK_ID( )

This system command must be the first command to be issued in the main program to initialize the RTOS variables. Set each task's Stack Pointer (SP) variable to point to the exact location in the stack area of ​​the given task. This system command is used in the main program for each task to be created.

This system command is only used ONCE in the main program when the RTOS would be required to start monitoring the processes. This system command is used by a task to get the number of the task itself.

MASTER IN MANAGEMENT

It returns an unsigned character value (1 byte) and continues to perform the same task after executing this system command.

10 WORLDWIDE

OS_SIGNAL_TASK(TASK NO:)

If the second task was already waiting for a signal, the second task is placed in the Ready queue and its waiting for signal flag is cleared. The task issuing the OS_SIGNAL_TASK command continues to run regardless of whether or not the called task was waiting for the signal. If we need to stop the task after the OS_SIGNAL_TASK command to make room for other tasks, we need to use the OS_DEFER() system command after the OS_SIGNAL_TASK command.

If the called (signaled) task has not waited, it sets its wait for signal (SIGW) flag and exits to continue the same task. If the signal task has already been waiting, it places the called task in the Ready queue and it clears both the signal waiting (SIGW) and the signal present (SIGS) flags.

OS_PERIODIC (UINT TICKS)

It also sets a flag (TINQFLAG) to indicate that a new task has been placed in the Ready Queue. This flag is used by the RTOS_TIMER_INT routine (every half a millisecond) to decide if there should be a task change.

OS_WAITP (VOID)

If the periodic interval has not yet expired, as is generally the case, the periodic interval flag is set to indicate that it is waiting for the periodic interval and issues a voluntary task change. However, if the periodic interval has already expired (this is usually due to bad programming, in cases where the task's code itself takes longer to execute than the required periodic interval), then it clears the periodic interval flag and it closed.

OS_WAITI(INTERRUPT NO:)

If the signal is already present (previously set or signaled by another task), then the signal is simply deleted and the task continues. If the signal does not arrive within the specified timeout period, the task resumes in the same manner. However, a timeout number of 0 would mean that the task must keep waiting for a signal indefinitely.

If the signal does not arrive, the job is never resumed and the job is effectively aborted. If the signal is present, it clears the signal flag, exits and continues to drive.

OS_WAITT(TIMEOUT)

For example, if the TICKTIME command was set to 10, the reference unit would be 10 milliseconds, and OS_WAITT(60) would mean wait or sleep for 600 milliseconds. The task would then enter sleep or wait mode for 600 ms and a new task would take over.

OS_KILL_IT( )

OS_DEFER( )

ENHANCED EVENT-WAITING AND OTHER ADD-ON MACROS

In the case of OS_WAITT() and OS_PERIODIC() calls, the number of ticks is automatically changed to 1, which means an interval of 1 tick time.

STAND-ALONE INTERRUPT SERVICE ROUTINES

OS_PAUSE_RTOS() // Disable RTOS used in standalone ISR /* Our service routine code is here.

PAULOS_F040 PARAMETERS HEADER FILE

EXAMPLE USING PAULOS_F040 RTOS

  • BLINKY2.C
  • F04X_OSC_INIT.H
  • UART0_T1.C

Also note that to use the printf function, // you need to make sure you are on the correct SFR page.

Figure 2-2 Blinking LED example
Figure 2-2 Blinking LED example

3 MASTER-SLAVE CAN BUS RTOS

MULTI-CONTROLLER RTOSS

CAN BUS RTOS EXAMPLE

  • PAULOS_F040_CAN_STARTUP.A51

Description : This system call initializes the RTOS variables, the task SPs, and * enables any necessary interrupts. Description : This system call is used in the main program for each task to be created for use in the application. Description : This system call is used to check whether the current task has its signal set.

Description: This system call is used by a job to wait for the end of its job.

Figure 3-2 Screen shot showing the MASTER option
Figure 3-2 Screen shot showing the MASTER option

4 PROGRAMMING TIPS AND PITFALLS

  • RAM SIZE
  • SFRS
  • SETUP FAULTS
    • SYSTEM CLOCK SETUP
    • WATCHDOG TIMER SETUP
  • SERIAL PORT (UART0)
  • INTERRUPTS
  • RTOSS PITFALLS
  • C TIPS

Free locations are reserved for future versions of the microcontroller and if we use this area our program will not be compatible with future versions of the microcontroller as the same locations may be used for special extra SFRs in the upgraded version. Furthermore, certain unused locations may actually be non-existent, in the sense that the actual cells for this memory would not form part of the memory mask when they are produced, and even if we write the code to use these locations, there is no actual data would be stored. If we write a program that uses the new SFRs that are specific to a given derived chip (and therefore were not included in the standard base 8051 SFR list), our program will not run correctly on a standard 8051 where these SFRs simply did not. exists.

Therefore, it is best to use non-standard SFRs only if we are sure that our program will only need to run on that specific microcontroller. If we happen to write code that uses non-standard SFRs and then share it with a third party, we must inform that person that our code uses non-standard SFRs and can only be used with that particular device. For the C8051F040 in particular, since we have more than one page of SFRs, it's important to make sure we're on the right page when reading or writing to them.

Checking the stabilization of the clock during a simulation run can cause problems in cases where the simulation of the clock is not well implemented as mentioned in section 1.8.1. Another very common mistake made by newbies to this unit is setting the wrong configuration of the crossbar SFRs: XBR0, XBR1 and XBR2. The same problem occurs if we forget to clear the RI or TI flags when using Serial Interrupt.

Otherwise, it could happen that a task starts with one value of a global variable, then goes on to a wait state, and when it starts running again later, it can end up using the wrong value of the same variable simply because it was in the meantime modified by another task. The same problem exists in the RTOS with register banks and tasks that use the same functions not re-entering. Set the NUMBER_OF_TASKS, TICKTIME and TICK_TIMER definitions in the PaulOS_ F040_Parameter.h header file to match your application program.

Figure 4-1 Screenshot of the Keil Target setup
Figure 4-1 Screenshot of the Keil Target setup

APPENDIX A PAULOS_F040.C SOURCE CODE LISTING

PaulOS_F040_Parameters.h

PaulOS_F040.h

If the conversion from absolute time to ticks results in 0. all parameters are 0 or overflow) this.

Startup_PaulOS_F040.A51

PaulOS_F040.c

Description: This system call is used in the main program for every task to be created. Description: This system call causes a job to wait for a signal within a certain number. Description: This system call is used by a job to wait for the end of its periodic job.

Description : This system call is used to stop the current task in sequence to the next one.

Gambar

Figure 1-1 C8051F040TB Board
Table 1-1 C8051F040 on-chip memory map
Table 1-2 C8051F040 Internal Data Address Space
Table 1-3 provides tabular representation of the C8051F040’s SFRs, their name, and their  address in hexadecimal
+7

Referensi

Dokumen terkait

Surat Penetapan Waktu Seminar Desain Penelitian... Surat Telah Melaksanakan Seminar