HAL SAI Use Cases

Prerequisite

@startuml

participant "User Application" as p1

participant "System Driver" as p2



== Prerequisite ==

p1->p2: HAL_Init()

p2-->p1

p1->p2: Configure system clock

p2-->p1

@enduml

Full Initialization

@startuml



participant App as "User application"

participant "<font color=green><b>HAL SAI</b></font>" as SAI

participant "HAL CORTEX\n(NVIC)" as CORTEX

participant "HAL DMA" as DMA

participant "HAL RCC" as RCC

participant "HAL GPIO" as GPIO

participant "System Driver" as SYSTEM



==SAI HAL Initialization  ==

App -> SAI : HAL_SAI_Init()

alt#grey #lightgrey If USE_HAL_SAI_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO

SAI->RCC : Enable the SAI clock

RCC-->SAI

end

App <-- SAI : HAL_OK



==SAI System Initialization==

Note over App : SAI System initialization can be called before\nSAI HAL initialization



App->SYSTEM : Configure and enable kernel clock

SYSTEM --> App



alt#grey #lightgrey If USE_HAL_SAI_CLK_ENABLE_MODEL == HAL_CLK_ENABLE_NO

App->RCC : Enable the SAI clock

RCC --> App

end



alt#grey #lightgrey If USE_HAL_SAI_DMA == 1

App->DMA : Initialization of DMA

DMA-->App

App->SAI : HAL_SAI_SetTxDMA() / HAL_SAI_SetRxDMA()

SAI-->App

end



alt#grey #lightgrey If interrupts needed

App->CORTEX : Enable needed interrupts

CORTEX-->App

end



alt#grey #lightgrey If GPIOs needed

App->GPIO : Initialization of GPIOs

GPIO-->App

end



==SAI Configuration==

App -> SAI : HAL_SAI_SetConfig()

App <-- SAI :HAL_OK



note over App : Driver state is IDLE,\nUser can start any process or execute any configuration.

==Advanced SAI Configuration==

App -> SAI : HAL_SAI_SetConfigXxx()

App <-- SAI :HAL_OK

App -> SAI : HAL_SAI_EnableXxx()

App <-- SAI :HAL_OK

@enduml

Called functions:

Full Deinitialization

@startuml

participant App as "User application"

participant "<font color=green><b>HAL SAI</b></font>" as SAI

participant "HAL CORTEX\n(NVIC)" as CORTEX

participant "HAL DMA" as DMA

participant "HAL RCC" as RCC

participant "HAL GPIO" as GPIO

participant "System Driver" as SYSTEM



==SAI DeInitialization==

App->SAI : HAL_SAI_DeInit()

App<--SAI



==SAI system DeInitalization==

App->RCC : Disable the SAI clock

RCC --> App



App->SYSTEM : Disable kernel clock

SYSTEM --> App



alt#grey #lightgrey If USE_HAL_SAI_DMA == 1

App->DMA : DeInitialization of DMA

DMA-->App

end



alt#grey #lightgrey If interrupts needed

App->CORTEX : Disable needed interrupts

CORTEX-->App

end



alt#grey #lightgrey If GPIOs needed

App->GPIO : DeInitialization of GPIOs

GPIO-->App

end



@enduml

Called functions:

Process Receive Polling

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2



== SAI HAL Receive in Polling mode ==

loop

p1->p2: HAL_SAI_Receive()

p2-->p1: HAL_OK



note over p1: All data have been received

end

@enduml

Called functions:

Process Transmit Polling

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2



== SAI HAL Transmit in Polling mode ==

loop

p1->p2: HAL_SAI_Transmit()

p2-->p1: HAL_OK



note over p1: All data have been transmitted

end

@enduml

Called functions:

Process Receive Interrupt

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "NVIC" as p5



== SAI HAL Receive in Interrupt mode ==

loop

p1->p2: HAL_SAI_Receive_IT()

p2-->p1: HAL_OK



p2<-p5: SAIx complete interrupt

p2->p1: HAL_SAI_RxCpltCallback()

note over p1: All data have been received

p1-->p2

p2-->p5

end

@enduml

Called functions:

Process Transmit Interrupt

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "NVIC" as p5



== SAI HAL Transmit in Interrupt mode ==

loop

p1->p2: HAL_SAI_Transmit_IT()

p2-->p1: HAL_OK



p2<-p5: SAIx complete interrupt

p2->p1: HAL_SAI_TxCpltCallback()

note over p1: All data have been transmitted

p1-->p2

p2-->p5

end

@enduml

Called functions:

Process Receive DMA

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "HAL DMA" as p3

participant "NVIC" as p5



== SAI HAL Receive DMA in circular mode ==

p1->p3: HAL_DMA_SetConfigPeriphLinkedListCircularXfer()

p3-->p1: HAL_OK

loop

p1->p2: HAL_SAI_Receive_DMA()

p2->p3: HAL_DMA_Start_IT()

p3-->p2: HAL_OK

p2-->p1: HAL_OK



p3<-p5: DMAx half complete interrupt

p3->p2: RxHalfCpltCallback

p2->p1: HAL_SAI_RxHalfCpltCallback()

note over p1: Half of the data has been received

p1-->p2

p2-->p3

p3-->p5



p3<-p5: DMAx complete interrupt

p3->p2: RxCpltCallback

p2->p1: HAL_SAI_RxCpltCallback()

note over p1: All data have been received

p1-->p2

p2-->p3

p3-->p5

end

@enduml

Called functions:

Process Transmit DMA

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "HAL DMA" as p3

participant "NVIC" as p5



== SAI HAL Transmit DMA in circular mode ==

p1->p3: HAL_DMA_SetConfigPeriphLinkedListCircularXfer()

p3-->p1: HAL_OK

loop

p1->p2: HAL_SAI_Transmit_DMA()

p2->p3: HAL_DMA_Start_IT()

p3-->p2: HAL_OK

p2-->p1: HAL_OK



p3<-p5: DMAx half complete interrupt

p3->p2: TxHalfCpltCallback

p2->p1: HAL_SAI_TxHalfCpltCallback()

note over p1: Half of the data has been transmitted

p1-->p2

p2-->p3

p3-->p5



alt Pause/Resume DMA

p1->p2: HAL_SAI_Pause_DMA()

p2-->p1: HAL_OK

note over p1 : Data are no more sent

p1->p2: HAL_SAI_Resume_DMA()

p2-->p1: HAL_OK

note over p1 : Data transmission resumes

end



p3<-p5: DMAx complete interrupt

p3->p2: TxCpltCallback

p2->p1: HAL_SAI_TxCpltCallback()

note over p1: All data have been transmitted

p1-->p2

p2-->p3

p3-->p5

end

@enduml

Called functions:

Process Abort

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "HAL DMA" as p3



== SAI HAL Abort ==

p1->p2: HAL_SAI_Abort()

p2->p3: HAL_DMA_Abort()

p3-->p2: HAL_OK

p2-->p1: HAL_OK



note over p1 : Driver state is IDLE,\nUser can start any process or execute any configuration.

@enduml

Called functions:

Process Abort IT

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "HAL DMA" as p3

participant "NVIC" as p5



== SAI HAL Abort IT ==

p1->p2: HAL_SAI_Abort_IT()

p2->p3: HAL_DMA_Abort_IT()

p3-->p2: HAL_OK

p2-->p1: HAL_OK



p3<-p5: DMAx interrupt

p3->p2: AbortCpltCallback

p2->p1: HAL_SAI_AbortCpltCallback()

p1-->p2

p2-->p3

p3-->p5



note over p1 : Driver state is IDLE,\nUser can start any process or execute any configuration.

@enduml

Called functions:

Mute Rx

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2

participant "HAL DMA" as p3

participant "NVIC" as p5



== SAI HAL Receive Mute ==

p1->p2: HAL_SAI_EnableRxMuteDetection(counter)

p2-->p1: HAL_OK

p1->p2: HAL_SAI_Receive_IT()

p2-->p1: HAL_OK

p3<-p5: SAIx interrupt

p3->p2: MuteCallback

p2->p1: HAL_SAI_MuteCallback()

p1-->p2

p2-->p3

p3-->p5



p1->p2: HAL_SAI_DisableRxMuteDetection()

p2-->p1: HAL_OK

@enduml

Called functions:

Mute Tx

@startuml

participant "User Application" as p1

participant "<font color=green><b>HAL SAI</b></font>" as p2



== SAI HAL Transmit Mute ==

p1->p2: HAL_SAI_Transmit_DMA()

p2-->p1: HAL_OK

note over p1 : Transmission started.

p1->p2: HAL_SAI_TxMute(mode)

p2-->p1: HAL_OK

note over p1 : The user can choose to send zeroes on muted slots\nor the previously transmitted value depending on mode.

p1->p2: HAL_SAI_TxUnmute()

p2-->p1: HAL_OK

@enduml

Called functions:

Acquire/Release

@startuml

participant "User 1" as p1

participant "User 2" as p2

participant "HAL SAI driver" as p3

participant "HAL OS wrapper" as p4



p1-[#green]->p3 : <color #Green> HAL_SAI_AcquireBus() </color>

p3-[#green]->p4 : <color #Green> HAL_OS_SemaphoreTake() </color>

p4-[#green]-->p3

p3-[#green]-->p1: <color #Green> HAL_OK </color>

note over p3

Bus acquired by user 1. Any Process can be executed. For instance : HAL_SAI_Receive_DMA()

end note

p2-[#red]->p3 : <color #Red> HAL_SAI_AcquireBus() </color>

p3-[#red]->p4 : <color #Red> HAL_OS_SemaphoreTake() </color>

p1-[#green]->p3 : <color #Green> HAL_SAI_ReleaseBus() </color>

p3-[#green]-->p1:<color #Green>  HAL_OK </color>

p4-[#red]-->p3

p3-[#red]-->p2: <color #Red> HAL_OK </color>

note over p3

Bus acquired by user 2. Any Process can be executed. For instance : HAL_SAI_Receive_DMA()

end note

@enduml

Called functions: