Skip to content

Commit

Permalink
Micro:bit interrupt priorities, tick timing.
Browse files Browse the repository at this point in the history
  * microbit/adainclude/FreeRTOSConfig.h: allow 10 priority
      levels. Adjust comments to note that Interrupt_Priority is 8 to
      10.
  * microbit/adainclude/nrf51_clock.adb: adjust comments as above.
  * microbit/adainclude/system.ads: likewise.
    (Tick): set to 1.0 / 1024.
    (Max_Interrupt_Priority): increased to 10.
  • Loading branch information
simonjwright committed Feb 16, 2020
1 parent 1442541 commit dd7cd7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
11 changes: 6 additions & 5 deletions microbit/adainclude/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( 16000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1024 )
#define configTICK_RATE_HZ ( ( TickType_t ) 1024 )

/* Extend the number of priority levels to cope with Ada ceiling
priorities, which mean we need to raise a task waiting for an ISR
to a priority corresponding to that interrupt's priority. So we
need the additional priorities 8 (interrupt priority 3) to 9
(interrupt priority 2, the highest that can use API interrupt-safe
need the additional priorities 8 (interrupt priority 3) to 10
(interrupt priority 1, the highest that can use API interrupt-safe
functions). */
#define configMAX_PRIORITIES ( 9 )
#define configMAX_PRIORITIES ( 10 )

#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16 * 1024 ) )
Expand All @@ -55,6 +55,7 @@
#define configUSE_APPLICATION_TASK_TAG 1 /* for Task_Id in TCB */
#define configUSE_COUNTING_SEMAPHORES 0
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_QUEUE_SETS 0

#define configUSE_TIME_SLICING 0 /* don't want round-robin */

Expand Down Expand Up @@ -105,6 +106,7 @@ function. */
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
/* UNCLEAR THAT THIS IS TRUE FOR A CM0 PART, WHICH DOESN'T HAVE BASEPRI */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 1

/* Interrupt priorities used by the kernel port layer itself. These are generic
Expand All @@ -122,7 +124,6 @@ header file. */
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler

#define xPortSysTickHandler SysTick_Handler

#endif /* FREERTOS_CONFIG_H */
9 changes: 5 additions & 4 deletions microbit/adainclude/nrf51_clock.adb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
-- below:
--
-- priority 0 (highest): FreeRTOS use only
-- priority 1: RTC1_IRQHandler
-- priority 2 .. 3: applications, arranged in this RTS as (interrupt)
-- priorities 9, 8 respectively.
-- priority 1 .. 3: applications, arranged in this RTS as (interrupt)
-- priorities 10, 9, 8 respectively.

-- RTC1_IRQHandler runs at ARM priority 3, Interrupt_Priority'First.

with nrf51.CLOCK;
with nrf51.RTC;
Expand Down Expand Up @@ -128,7 +129,7 @@ package body nRF51_Clock is
Address => System'To_Address (16#E000E100#);

Interrupt : constant := 17;
Prio : constant := System.Priority'Last + 1;
Prio : constant := System.Interrupt_Priority'First;
begin
declare
Index : constant Natural := Interrupt / 4;
Expand Down
11 changes: 6 additions & 5 deletions microbit/adainclude/system.ads
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
-- (ARM Cortex M Version) --
-- (Derived from GNU-Linux/ARMEL Version) --
-- --
-- Copyright (C) 1992-2010, 2016-2018, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2010, 2016-2018, 2020 --
-- Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
Expand Down Expand Up @@ -74,7 +75,7 @@ package System is
Max_Mantissa : constant := 63;
Fine_Delta : constant := 2.0 ** (-Max_Mantissa);

Tick : constant := 0.01;
Tick : constant := 1.0 / 1024;

-- Storage-related Declarations

Expand Down Expand Up @@ -110,12 +111,12 @@ package System is

-- These declarations correspond to FreeRTOS as originally
-- configured in STM Cube (thread priorities 0 .. 7), with
-- priorities 8 to 9 mapped to Cortex interrupt priorities 3
-- (lowest) to 2 (highest that can be used by ISRs that call
-- priorities 8 to 10 mapped to Cortex interrupt priorities 3
-- (lowest) to 1 (highest that can be used by ISRs that call
-- interrupt-safe FreeRTOS API functions).

Max_Priority : constant Positive := 7;
Max_Interrupt_Priority : constant Positive := 9;
Max_Interrupt_Priority : constant Positive := 10;

subtype Any_Priority is Integer range 0 .. Max_Interrupt_Priority;
subtype Priority is Any_Priority
Expand Down

0 comments on commit dd7cd7c

Please sign in to comment.