<commit_before>{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}

module Ivory.BSP.STM32.Interrupt where

import Ivory.Language
import Ivory.Tower
import Ivory.HW
import Ivory.BSP.ARMv7M.Exception
import Ivory.BSP.ARMv7M.SystemControl.NVIC


class STM32Interrupt i where
  interruptIRQn             :: i -> IRQn
  interruptTable            :: i -> [Maybe i]
  interruptHandlerName      :: i -> String

data HasSTM32Interrupt = forall i. (STM32Interrupt i)
                       => HasSTM32Interrupt i

instance STM32Interrupt HasSTM32Interrupt where
  interruptIRQn (HasSTM32Interrupt i) = interruptIRQn i
  interruptTable (HasSTM32Interrupt i) = map (fmap HasSTM32Interrupt) (interruptTable i)
  interruptHandlerName (HasSTM32Interrupt i) = interruptHandlerName i

data IRQ i = Exception Exception
           | Interrupt i
           deriving (Eq, Show)

instance (STM32Interrupt i) => Signalable (IRQ i) where
  signalName = irqHandlerName
  signalHandler i b = incl $ proc (irqHandlerName i) $ body $ b >> retVoid
  signalInit (Exception _) = return ()
  signalInit (Interrupt i) =
    interrupt_set_priority i max_syscall_priority
    -- XXX MAGIC NUMBER: in tower/freertos, syscalls must be lower (numerically greater
    -- than) level 11. XXX how to make this cross OS platform safely?
    where max_syscall_priority = (12::Uint8)

irqn :: (STM32Interrupt i) => IRQ i -> IRQn
irqn (Exception e) = exceptionIRQn e
irqn (Interrupt i) = interruptIRQn i
<commit_msg>ivory-bsp-stm32: Update for Signalable effects change.<commit_after>{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}

module Ivory.BSP.STM32.Interrupt where

import Ivory.Language
import Ivory.Tower
import Ivory.HW
import Ivory.BSP.ARMv7M.Exception
import Ivory.BSP.ARMv7M.SystemControl.NVIC


class STM32Interrupt i where
  interruptIRQn             :: i -> IRQn
  interruptTable            :: i -> [Maybe i]
  interruptHandlerName      :: i -> String

data HasSTM32Interrupt = forall i. (STM32Interrupt i)
                       => HasSTM32Interrupt i

instance STM32Interrupt HasSTM32Interrupt where
  interruptIRQn (HasSTM32Interrupt i) = interruptIRQn i
  interruptTable (HasSTM32Interrupt i) = map (fmap HasSTM32Interrupt) (interruptTable i)
  interruptHandlerName (HasSTM32Interrupt i) = interruptHandlerName i

data IRQ i = Exception Exception
           | Interrupt i
           deriving (Eq, Show)

instance (STM32Interrupt i) => Signalable (IRQ i) where
  signalName = irqHandlerName
  signalHandler i b = incl $ voidProc (irqHandlerName i) $ body $ noReturn b
  signalInit (Exception _) = return ()
  signalInit (Interrupt i) =
    interrupt_set_priority i max_syscall_priority
    -- XXX MAGIC NUMBER: in tower/freertos, syscalls must be lower (numerically greater
    -- than) level 11. XXX how to make this cross OS platform safely?
    where max_syscall_priority = (12::Uint8)

irqn :: (STM32Interrupt i) => IRQ i -> IRQn
irqn (Exception e) = exceptionIRQn e
irqn (Interrupt i) = interruptIRQn i

{'fraction_non_alphanumeric': 0.08404966571155682, 'fraction_numerical': 0.021649156319643426, 'mean_word_length': 3.634218289085546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393816', 'n_tokens_mistral': 1050, 'n_tokens_neox': 994, 'n_words': 297}