HAL COMP Use Cases

HAL COMP Handle Initialization

@startuml
'skinparam handwritten true
title: Initialization

' Fix order of each column
participant "User Application" as appli
participant "HAL GENERIC" as GENERIC
participant "HAL RCC" as RCC
participant "HAL GPIO" as GPIO
participant "HAL CORTEX\n(NVIC)" as CORTEX
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI

hnote over COMP: global_state=RESET
appli->GENERIC : HAL_Init()
note right
Required to initialize HAL delay services,
used for time out in HAL COMP driver
end note
GENERIC --> appli

appli->RCC : Configure system clock
RCC --> appli

note across
Potential use case: Two COMP handles initialized
and corresponding to two COMP instances (noted upper/lower threshold below) belonging to the same COMP common instance.
Each COMP instance must have its peripherals dependencies configured (kernel clock, NVIC interruption line, ...)
end note

group#LemonChiffon #LightYellow Peripherals dependencies initialization

alt#lightgrey #LightYellow if USE_HAL_COMP_CLK_ENABLE_MODEL == HAL_CLK_ENABLE_NO
appli->RCC : Enable COMP kernel clock
RCC --> appli
end

opt#lightgrey #LightYellow if GPIO(s) needed
appli->GPIO : Initialization of GPIO(s)
GPIO-->appli
end

opt#lightgrey #LightYellow if interrupt needed
appli->CORTEX : Enable needed interrupt
CORTEX-->appli
end

end

group#LightBlue #AliceBlue COMP initialization
appli->COMP : HAL_COMP_Init(<handle **COMP_a**>)
alt#lightgrey #AliceBlue if USE_HAL_COMP_CLK_ENABLE_MODEL != HAL_CLK_ENABLE_NO
COMP->RCC : Enable **COMP_a** kernel clock
RCC --> COMP
end
opt#lightgrey #AliceBlue if USE_HAL_COMP_EXTI == 1
COMP->EXTI : Set EXTI line
RCC --> COMP
end
COMP --> appli

opt#lightgrey #AliceBlue if multiple COMP instances used
appli->COMP : HAL_COMP_Init(<handle **COMP_b**>)
alt#lightgrey #AliceBlue If USE_HAL_COMP_CLK_ENABLE_MODEL != HAL_CLK_ENABLE_NO
COMP->RCC : Enable **COMP_b** kernel clock
RCC --> COMP
end
opt#lightgrey #AliceBlue if USE_HAL_COMP_EXTI == 1
COMP->EXTI : Set EXTI line
RCC --> COMP
end
COMP --> appli

appli->COMP : HAL_COMP_WINDOW_SetHandle(<handle upper threshold>, <handle hcomp_lower_threshold>)
COMP --> appli
end

end

hnote over COMP: global_state=INIT

@enduml

Functions called:

Deinitialization

@startuml

title: Deinitialization

participant "User application" as appli
participant "HAL RCC" as RCC
participant "HAL GPIO" as GPIO
participant "HAL CORTEX\n(NVIC)" as CORTEX
participant "<font color=green><b>HAL COMP</b></font>" as COMP

hnote over COMP: global_state= all possible values
group#LightBlue #AliceBlue COMP deinitialization
appli->COMP : HAL_COMP_DeInit()
appli<--COMP
end

group#LemonChiffon #LightYellow Peripherals dependencies deinitialization

appli->RCC : Disable COMP kernel clock
RCC --> appli

opt#lightgrey if interrupt enabled
appli->CORTEX : Disable enabled interrupt
CORTEX-->appli
end

opt#lightgrey if GPIO(s) configured
appli->GPIO : DeInitialization of GPIO(s)
GPIO-->appli
end

end

hnote over COMP: global_state=RESET

@enduml

Functions called:

COMP Basic Operation Using Polling

@startuml
title: COMP basic operation using programming model: polling

participant "User Application" as appli
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI

hnote over COMP: global_state=RESET
group#LightBlue #AliceBlue Initialization
appli->COMP : HAL COMP and peripherals dependencies initialization
note right
Refer to sequence diagram "Initialization"
end note
return
end

hnote over COMP: global_state=INIT

group#TECHNOLOGY #HoneyDew COMP configuration
appli->COMP : HAL_COMP_SetConfig()
opt #AliceBlue if USE_HAL_COMP_EXTI == 1 (for system wake up)
'opt #AliceBlue if USE_HAL_COMP_EXTI == 1 (use poll for event or system wake up)
COMP -> EXTI : Set EXTI line
return
end
appli<-COMP
end

hnote over COMP: global_state=IDLE

group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_Start()
COMP->COMP : Activate comparator analog features
COMP->appli

hnote over COMP: global_state=ACTIVE

opt #AliceBlue
loop#lightgrey Possible multiple iterations
/'
opt #AliceBlue if USE_HAL_COMP_EXTI == 1 (use poll for event or system wake up)
appli->COMP : HAL_COMP_PollForEvent()
COMP -> EXTI : Manage EXTI line flag
return
appli<-COMP
end
'/
appli->COMP : HAL_COMP_GetOutputLevel()
COMP --> appli: Logical level high/low
end
end
appli->COMP : HAL_COMP_Stop()
return

hnote over COMP: global_state=IDLE

end

group#LightBlue #AliceBlue Denitialization
appli->COMP : HAL COMP and peripherals dependencies deinitialization
note right
Refer to sequence diagram "Deinitialization"
end note
return
end

hnote over COMP: global_state=RESET

@enduml

Functions called:

COMP Basic Operation Using Interruption

@startuml
title: COMP basic operation using programming model: interruption

participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI
participant "System HW interruption" as interruption

hnote over COMP: global_state=RESET
group#LightBlue #AliceBlue Initialization
appli->COMP : HAL COMP and peripherals dependencies initialization
note right
Refer to sequence diagram "Initialization"
end note
return
end

hnote over COMP: global_state=INIT

group#TECHNOLOGY #HoneyDew COMP configuration
appli->COMP : HAL_COMP_SetConfig()
COMP -> EXTI : Set EXTI line
return
appli<-COMP
end

hnote over COMP: global_state=IDLE

group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_Start_IT()
COMP->COMP : Enable selected interruptions\nActivate comparator analog features
COMP->appli

hnote over COMP: global_state=ACTIVE

loop#lightgrey Possible multiple iterations
interruption <[#red]-x? : <font color=red><b>COMP IRQ event
interruption -> appli_IRQ : COMPx_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> COMP : HAL_COMP_IRQHandler()
COMP -> EXTI : Manage EXTI line flag
COMP <- EXTI
COMP -> appli_IRQ: HAL_COMP_OutputTriggerCallback()
appli_IRQ->COMP : HAL_COMP_GetOutputLevel()
COMP --> appli_IRQ: Logical level high/low
appli_IRQ -> interruption : (return from ISR)
deactivate appli_IRQ
end
appli->COMP : HAL_COMP_Stop_IT()
return

hnote over COMP: global_state=IDLE

end

group#LightBlue #AliceBlue Denitialization
appli->COMP : HAL COMP and peripherals dependencies deinitialization
note right
Refer to sequence diagram "Deinitialization"
end note
return
end

hnote over COMP: global_state=RESET

@enduml

Functions called:

COMP Window Mode Operation Using Interruption

@startuml
title: COMP window mode operation using programming model: interruption

participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI
participant "System HW interruption" as interruption

note across #Bisque
Requirement for this use case: Two COMP handles initialized
and corresponding to two COMP instances (noted upper/lower threshold below) belonging to the same COMP common instance featuring window mode.
end note

hnote over COMP: global_state=RESET
group#LightBlue #AliceBlue Initialization
appli->COMP : HAL COMP and peripherals dependencies initialization
note right
Refer to sequence diagram "Initialization"
end note
return
hnote over COMP: global_state=INIT
appli->COMP : HAL_COMP_WINDOW_SetHandle(<handle upper threshold>, <handle lower threshold>)
COMP --> appli
end

hnote over COMP: global_state=LINKED

group#TECHNOLOGY #HoneyDew COMP configuration
appli->COMP : HAL_COMP_WINDOW_SetConfig()
COMP -> EXTI : Set EXTI line
return
appli<-COMP
end

hnote over COMP: global_state=WINDOW_IDLE

group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_WINDOW_Start_IT()
COMP->COMP : Enable selected interruptions\nActivate comparator analog features
COMP->appli

hnote over COMP: global_state=WINDOW_ACTIVE

loop#lightgrey Possible multiple iterations
interruption <[#red]-x? : <font color=red><b>COMP IRQ event
interruption -> appli_IRQ : COMPx_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> COMP : HAL_COMP_IRQHandler()
COMP -> EXTI : Manage EXTI line flag
COMP <- EXTI
COMP -> appli_IRQ: HAL_COMP_OutputTriggerCallback()
appli_IRQ->COMP : HAL_COMP_WINDOW_GetOutputLevel()
COMP --> appli_IRQ: Level below/within/above
appli_IRQ -> interruption : (return from ISR)
deactivate appli_IRQ
end
appli->COMP : HAL_COMP_WINDOW_Stop_IT()
return
end

hnote over COMP: global_state=WINDOW_IDLE

group#LightBlue #AliceBlue Denitialization
appli->COMP : HAL COMP and peripherals dependencies deinitialization
note right
Refer to sequence diagram "Deinitialization"
end note
return
end

hnote over COMP: global_state=RESET

@enduml

Functions called: