UART in LPC17xx has fractional divider for more precise baudrate selection.įunction UART_iter tries all combinations and uses the best combination. clk_cpu for main system clock, clk_uart0 for UART0 etc. List or supported peripherals can be found in Common.h, e.g. If freq parameter is zero, internal RC oscillator is used and PLL is swithced off.Īnother function is used to return current frequency for selected periphery. It uses global variable const unsigned long XTosc, which should contain crystall frequency for XT oscillator. Function selects the best PLL setting to achieve selected value. This function sets PLL frequency to selected value. Three functions are prepared for easier clock setup in LPC17xx MCUs: If variable is read only (no modification needed), regular access has to be used. User should either repeat sem_ function or skip it depending on code functionality. If another exclusive access was parfomed between LDREX and STREX instructions, no data is written and one is returned. Returned value can be modified and has to be written back using sem_putB function.įunctions sem_setB and sem_clrB are used to set or clear bits in byte on requested address.Īll functions used for writing to memory return success code: if data is written successfully, zero is returned. This function opens exclusive access "window". Unsigned sem_getB (void * ptr) unsigned sem_putB (void * ptr, unsigned data) unsigned sem_setB (volatile void * ptr, unsigned mask) unsigned sem_clrB (volatile void * ptr, unsigned mask) įunction sem_getB returns value from requested address. If regular access to these variables is used (without sem_ functions), exclusive access won't work correctly!įor the present, only byte functions are prepared: To get correct behaviour, this functions has to be used everywhere in code to access modified variables. These instructions allow to safely support read-modify-write access. Second bank is allocated at address 0x20000000, which supports bit-banding.įortunately, Cortex-M3 has special instructions for exclusive memory access - LDREX and STREX instructions. Unfortunately, not all RAM is accessible this way.įor example: LPC17xx have two RAM regions: one is allocated at address 0x10000000 (this RAM has faster access but lacks bit-banding feature), Int task_stack_usage (task_struct * ctrl) ĪRM Cortex-M3 MCUs can access single bits in RAM as atomic operations - this feature is called bit-banding. Function task_stack_usage returns unused stack size for requested task.įor main task, main_task control structure is used. Stack usage can be checked if compiled with TASK_STACK_MARK defined. Void task_delay (task_struct * ctrl, int tick) įunction can give up current time slice by calling function: removed from tasks list and then returned back to it.įor this purpose, two functions are prepared:Įvery task can be delayed for some amount of SysTicks by calling function: Task can be suspended and back resumed, i.e. Another way is just to return from task function. If task is to be terminated, task_exit function has to be called. If change of time slots is needed, this parameter is stored in control structure as variable ctrl->slot. Simple example can be found in tasks.zip file. Last parameter ctrl is pointer to task control structure, which contains all important information about task. Parameter slot defines number of time slices used by task. Parameters stack and stack_size define stack for this new task. Task_struct * MY_TASK (task_struct * ctrl) All task functions have to have this prototype: Void task_start (task_struct* (* task)(task_struct*), void * stack, unsigned long stack_size, unsigned char slot, task_struct * ctrl) įirst parameter i pointer to task function. To run another tasks, call this function: Stack defined in linker script remains for main task. System stack is used for all interrupt calls including SVC calls. This function accepts two parameters: pointer to system stack and size of this stack. Void task_init (void * int_stack, unsigned long stack_size) Now we can start TASKS by calling task_init function: To use this function, SYSTICK_USER_CALLBACK has to be defined in tasks.h file. If user wants to use SysTick, callback function can be defined: SysTick handler is included in TASKS source code. To prepare Tasks for run, SysTick initialization function has to be prepared to get required SysTick time. When I create applications, I often use cooperative multitasking (event driven programs).Īlmost all tasks can be programmed using this approach.īut what to do if long calculations are to be done?įor this purpose I wrote small multitasking system, which uses many features of Cortex-M3 MCUs. TASKS - easy multitasker for Cortex-M3 TASKS - easy mulstitasker for Cortex-M3
0 Comments
Leave a Reply. |