1. Homepage
  2. Programming
  3. CEG3136 Computer Architecture II - Lab3 Complex State machine

CEG3136 Computer Architecture II - Lab3 Complex State machine

Engage in a Conversation
OttawaCEG3136Computer Architecture IIComplex State machineC

CEG3136 – Lab3 Complex State machine (C) CourseNana.COM

Objectives CourseNana.COM

To implement a state machine for an alarm system monitoring. The system consists of the following components: CourseNana.COM

  • -  Keypad UI CourseNana.COM

  • -  Alarm sensors CourseNana.COM

  • -  Alarm Bells (Alarms) CourseNana.COM

  • -  Central control CourseNana.COM

    Introduction CourseNana.COM

    In this lab we’re going to use the architecture flow shown next. The flow start by the system and peripheral initialization. Then it goes into a continuous loop with a background task handling mainly the user interface (UI). At the forefront there are 3 interrupt service routines responsible for monitoring the sensors and firing the alarms when necessary. CourseNana.COM

Hereafter is the description of the system software components – note that software components represent low level hardware components at the low (physical) level, then more complex virtual (software) components handle the control/processing of the system data. CourseNana.COM

  • -  Console Application: this is the main function of the c-program. It initialize the Alarm System, followed by a background task of handling user input. User input is operator login to Arm/Disarm the system and to quit the application at the end of simulation. CourseNana.COM

  • -  Alarm System Central Control: this is a data structure (class) that include the low level system components and manages the system state machine CourseNana.COM

  • -  Sensor: is a structure holding the state of a physical sensor component. The system supports up to 64 sensors. Sensors can be in one of the following states: {INACTIVE, IDLE, TRIGGERED, MALFUNCTION} CourseNana.COM

  • -  Alarm: is a data structure holding the state of a physical alarm bell component. The system supports up to 64 alarms. Alarms can be in one of the following states: { ALARM_OFF, ALARM_ON} CourseNana.COM

  • -  User: represent the database record of a system user, including the name, passcode of the user, and weather it has the privilege of a super user CourseNana.COM

  • -  Super User: is a class extension of the user class, it contain an instance of the user class that has the super flag set. CourseNana.COM

    The high level class diagram is shown below: CourseNana.COM

    The User Interface CourseNana.COM

    The user interface has two components: input and output
    - UI Output: provide the system logging of all interesting events taking place at all times CourseNana.COM

- UI Input: is always ready for user login, if a valid passcode is entered the login event triggers an CourseNana.COM

interrupt (EXTI1). EXTI1 interrupt handler notifies the central control of the login even to take CourseNana.COM

proper actions
During initialization 8 users are initialized and 8 super-users are initialized. The passcodes are hardwired for simplicity as follows:
CourseNana.COM

  • -  Super2: passcode super23 CourseNana.COM

  • -  etc. CourseNana.COM

  • -  Super 7: passcode super78 CourseNana.COM

    State Machine CourseNana.COM

    As explained earlier, the system’s behavior is described/developed using a state machine. The behavior of the system changes based on the current system state as well as the external events that takes place and are monitored by the system. The state diagram of the central control is shown below. CourseNana.COM

The external events are listed below: CourseNana.COM

  • -  Sensor triggering an interrupt (EXTI0), it represent an alarm sensor detecting a risk event, e.g. CourseNana.COM

    window or door open, motion detected, etc. CourseNana.COM

  • -  User login: triggers user input like arming and disarming the system CourseNana.COM

  • -  Time delay: used to adjust the system timing, e.g. in transition from Arming to Armed states CourseNana.COM

    Refer to “The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors”, chapter 9.5: The SysTick timer. CourseNana.COM

The actions performed by the system (see state diagram) are: CourseNana.COM

  • -  Set the alarm ON when switching from ARMED state to TRIGGERED state CourseNana.COM

  • -  Set the alarm OFF when moving from TRIGGERED state to IDLE state CourseNana.COM

  • -  Reset TickCount on exit from Idle state CourseNana.COM

The SysTick timer CourseNana.COM

TickCount<500 CourseNana.COM

The Cortex-M processors have a small integrated timer called the SysTick (System Tick) timer. It is integrated as part of the nested vector interrupt controller (NVIC). It can generate the SysTick exception (#15). The SysTick timer is a simple decrement 24-bit counter and can run on either processor clock or a reference clock. The reason for having the timer inside the processor is to help software portability between Cortex-M processor systems. The SysTick timer can be used as a simple timer peripheral for periodic interrupt generation, delay generation, or timing measurement. CourseNana.COM

Using the SysTick timer CourseNana.COM

If you only want to generate s periodic SysTick interrupt, the easiest way is to use a CMSIS-Core function: uint32_t SysTick_Config (uint32_t ticks).
For example for a 1 millisecond interval, you can use: SysTick_Config ( systemCoreClock / 1000 ). That means when we divide the core clock frequency in Hz by 1000, we get the number of clocks per millisecond. The timer interrupt handler: void SysTick_Handler(void), will be invoked every 1 millisecod.
In this lab the SysTick_Handler is used for:
CourseNana.COM

  • -  Monitor the signaled sensor triggers and induce EXTI0_IRQn interrupt CourseNana.COM

  • -  Call system_update_state function CourseNana.COM

  • -  Induce EXTI2_IRQn periodically to print the ^beep^ message to indicate alarms when the CourseNana.COM

system is in Alarmed state CourseNana.COM

Interrupt Vector CourseNana.COM

Reference startup_stm32f417xx.s the vendor specified interrupt table is as follows. We’ll be using external interrupt ports 0 & 1 in our development. EXTI0 is connected to the sensors and is ORed, which means any sensor (or group of sensors) will trigger the interrupt if they are tripped. EXTI1 is CourseNana.COM

connected to the keypad, which detects a legitimate user login. EXTI2 is used to display “^beep^” message when the system is in ALARMED state. CourseNana.COM

; Vector Table Mapped to Address 0 at Reset AREA RESET, DATA, READONLY CourseNana.COM

EXPORT __Vectors EXPORT __Vectors_End EXPORT __Vectors_Size CourseNana.COM

__Vectors DCD __initial_sp DCD Reset_Handler CourseNana.COM

; Top of Stack ; Reset Handler ; NMI Handler CourseNana.COM

; Hard Fault Handler
; MPU Fault Handler
CourseNana.COM

; Bus Fault Handler
; Usage Fault Handler
CourseNana.COM

DCD NMI_Handler
DCD HardFault_Handler DCD MemManage_Handler DCD BusFault_Handler DCD UsageFault_Handler
CourseNana.COM

DCD 0
DCD 0
DCD 0
DCD 0
DCD SVC_Handler
DCD DebugMon_Handler
DCD 0 ; Reserved
CourseNana.COM

DCD PendSV_Handler DCD SysTick_Handler CourseNana.COM

; PendSV Handler ; SysTick Handler CourseNana.COM

; External Interrupts
DCD WWDG_IRQHandler
DCD PVD_IRQHandler
DCD TAMP_STAMP_IRQHandler DCD RTC_WKUP_IRQHandler DCD FLASH_IRQHandler
DCD RCC_IRQHandler
DCD EXTI0_IRQHandler
DCD EXTI4_IRQHandler
DCD DMA1_Stream0_IRQHandler DCD DMA1_Stream1_IRQHandler DCD DMA1_Stream2_IRQHandler DCD DMA1_Stream3_IRQHandler DCD DMA1_Stream4_IRQHandler DCD DMA1_Stream5_IRQHandler DCD DMA1_Stream6_IRQHandler DCD ADC_IRQHandler ;
CourseNana.COM

; Reserved ; Reserved ; Reserved ; Reserved CourseNana.COM

; SVCall Handler
; Debug Monitor Handler
CourseNana.COM

; Window WatchDog
; PVD through EXTI Line detection
CourseNana.COM

; Tamper and TimeStamps through the EXTI line ; RTC Wakeup through the EXTI line CourseNana.COM

; FLASH ; RCC CourseNana.COM

; EXTI Line0 ; EXTI Line1 ; EXTI Line2 ; EXTI Line3 ; EXTI Line4 CourseNana.COM

; DMA1 Stream 0 ; DMA1 Stream 1 ; DMA1 Stream 2 ; DMA1 Stream 3 ; DMA1 Stream 4 ; DMA1 Stream 5 ; DMA1 Stream 6 CourseNana.COM

ADC1, ADC2 and ADC3s CourseNana.COM

DCD CAN1_TX_IRQHandler
DCD CAN1_RX0_IRQHandler
DCD CAN1_RX1_IRQHandler
DCD CAN1_SCE_IRQHandler
DCD EXTI9_5_IRQHandler
DCD TIM1_BRK_TIM9_IRQHandler
DCD TIM1_UP_TIM10_IRQHandler
DCD TIM1_TRG_COM_TIM11_IRQHandler ; TIM1 Trigger and Commutation and
CourseNana.COM

TIM11 CourseNana.COM

; TIM8 Update and TIM13 DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare CourseNana.COM

DCD DMA1_Stream7_IRQHandler CourseNana.COM

; DMA1 Stream7 CourseNana.COM

DCD FMC_IRQHandler
DCD SDIO_IRQHandler
DCD TIM5_IRQHandler
DCD SPI3_IRQHandler
DCD UART4_IRQHandler DCD UART5_IRQHandler DCD TIM6_DAC_IRQHandler DCD TIM7_IRQHandler
CourseNana.COM

; FMC ; SDIO ; TIM5 CourseNana.COM

; SPI3
; UART4 ; UART5
CourseNana.COM

; TIM6 and DAC1&2 underrun errors ; TIM7 CourseNana.COM

DCD DMA2_Stream0_IRQHandler DCD DMA2_Stream1_IRQHandler DCD DMA2_Stream2_IRQHandler DCD DMA2_Stream3_IRQHandler DCD DMA2_Stream4_IRQHandler DCD ETH_IRQHandler ; DCD ETH_WKUP_IRQHandler CourseNana.COM

; DMA2 Stream 0 ; DMA2 Stream 1 ; DMA2 Stream 2 ; DMA2 Stream 3 ; DMA2 Stream 4 CourseNana.COM

Ethernet
; Ethernet Wakeup through EXTI line
CourseNana.COM

; CAN1 TX
; CAN1 RX0 ; CAN1 RX1
CourseNana.COM

DCD TIM3_IRQHandler
DCD TIM4_IRQHandler
DCD USART3_IRQHandler
DCD EXTI15_10_IRQHandler
DCD RTC_Alarm_IRQHandler
DCD OTG_FS_WKUP_IRQHandler
DCD TIM8_BRK_TIM12_IRQHandler
DCD TIM8_UP_TIM13_IRQHandler
DCD TIM8_TRG_COM_TIM14_IRQHandler ; TIM8 Trigger and Commutation and
CourseNana.COM

; TIM3 ; TIM4 CourseNana.COM

; SPI1 ; SPI2 CourseNana.COM

; USART1 ; USART2 ; USART3 CourseNana.COM

; TIM1 Break and TIM9
; TIM1 Update and TIM10
CourseNana.COM

; TIM1 Capture Compare ; TIM2 CourseNana.COM

; I2C1 Event ; I2C1 Error ; I2C2 Event ; I2C2 Error CourseNana.COM

; External Line[15:10]s
; RTC Alarm (A and B) through EXTI Line
CourseNana.COM

; USB OTG FS Wakeup through EXTI line ; TIM8 Break and TIM12 CourseNana.COM

DCD CAN2_TX_IRQHandler
DCD CAN2_RX0_IRQHandler
DCD CAN2_RX1_IRQHandler
DCD CAN2_SCE_IRQHandler
DCD OTG_FS_IRQHandler
DCD DMA2_Stream5_IRQHandler DCD DMA2_Stream6_IRQHandler DCD DMA2_Stream7_IRQHandler DCD USART6_IRQHandler
CourseNana.COM

DCD I2C3_EV_IRQHandler
DCD I2C3_ER_IRQHandler
DCD OTG_HS_EP1_OUT_IRQHandler DCD OTG_HS_EP1_IN_IRQHandler DCD OTG_HS_WKUP_IRQHandler DCD OTG_HS_IRQHandler
DCD DCMI_IRQHandler
DCD CRYP_IRQHandler
DCD HASH_RNG_IRQHandler
DCD FPU_IRQHandler
CourseNana.COM

__Vectors_End CourseNana.COM

; CAN2 TX
; CAN2 RX0 ; CAN2 RX1
; DCMI CourseNana.COM

; CRYPTO CourseNana.COM

; Hash and Rng ; FPU CourseNana.COM

Class Diagram CourseNana.COM

The detailed class diagram of the alarm system is shown below: CourseNana.COM

The following global (shared) variables are used to pass data from UI and Signal function (to be discussed next) to the alarm system: CourseNana.COM

- uint64_t sensor_states: represet updated sensor state, to be set from a signal function CourseNana.COM

- user_t *logged_in_user: the user object that was last sussesfuly loged in the system, used to check if it is a super user CourseNana.COM

Signal File CourseNana.COM

ARM-Keil allows the simulation of external events using what is known as signal function. This is a c- like function that is able to read/write to memory and wait on CPU clock among other things. We use it to simulate sensor triggering during testing of the system state machine. CourseNana.COM

The source cod of the signal function is shown below: CourseNana.COM

signal void set_sensors (unsigned long status1, unsigned long
status2) {
  {
    printf("wait started \n");
    _WDWORD(&sensor_states, status1);
    _WDWORD(&sensor_states+4, status2);
    twatch (0xFFFFF);
    printf("wait is done \n");
    _WDWORD(&sensor_states, 0);
    _WDWORD(&sensor_states+4, 0);

} } CourseNana.COM

The signal function set_sensors takes 2 arguments of unsigned long (32b) that represent the 64 sensors of the system. It writes the status arguments directly into the global uint64_t sensor_states variable (address 0x20000000, 0x20000004). Then it waits for some time using twatch function and then reset the sensor states back to 0 (IDLE). This way we can emulate sensor tripping during our simulation – more details later. CourseNana.COM

Running Simulation CourseNana.COM

To run the simulation, first compile the code and then press on the debugger button (magnifier on a d). Before you start the simulation, click on the debug menu and select “Function Editor” CourseNana.COM

Open the signal.ini file (include in zip file) and then press compile button – it should compile with no errors. You can then close the function editor window. Later you can call the signal function during CourseNana.COM

CourseNana.COM

simulation from the command line argument (at the bottom left) to induce sensor events – see below: CourseNana.COM

Your Tasks CourseNana.COM

The provided code include the console application and all the above mentioned classes: - sensor: sensor.h, sensor.c CourseNana.COM

  • -  alarm: alarm.h, alarm.c CourseNana.COM

  • -  user: user.h, user.c CourseNana.COM

  • -  super user: super_user.h, super_user.c CourseNana.COM

  • -  alarm system: alarm_system.h, alarm_system.c CourseNana.COM

    The state machine implemented in the system_update_state() function is left as skeleton, your task is to implement the system state machine according to the state diagram provided.
    You should test the system behavior and make sure all states are visited and all transitions are tested. At the end of the test if enter ‘q’ the UI loop is broken and the coverage for the FSM is displayedas shown below.
    CourseNana.COM

FSM State Coverage:
    UNARMED  ARMING   ARMED   ALARMED

UNARMED 1 0 0 0 ARMING 0 0 0 0 ARMED0 0 0 0 ALARMED 0 0 0 0 CourseNana.COM

Make sure that all the above highlighted States & Transitions have non-zero coverage. CourseNana.COM

The Lab report should include the following:
1) Code snip-it of the system_update_state() function.
CourseNana.COM

  1. 2)  You simulation log, showing all FSM cover points highlighted above covered with non-zero CourseNana.COM

    coverage value. CourseNana.COM

  2. 3)  The source code of the whole project (after cleaning all targets) CourseNana.COM

    Zip all of the above in one zip file and submit t Bright Space.  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Ottawa代写,CEG3136代写,Computer Architecture II代写,Complex State machine代写,C代写,Ottawa代编,CEG3136代编,Computer Architecture II代编,Complex State machine代编,C代编,Ottawa代考,CEG3136代考,Computer Architecture II代考,Complex State machine代考,C代考,Ottawahelp,CEG3136help,Computer Architecture IIhelp,Complex State machinehelp,Chelp,Ottawa作业代写,CEG3136作业代写,Computer Architecture II作业代写,Complex State machine作业代写,C作业代写,Ottawa编程代写,CEG3136编程代写,Computer Architecture II编程代写,Complex State machine编程代写,C编程代写,Ottawaprogramming help,CEG3136programming help,Computer Architecture IIprogramming help,Complex State machineprogramming help,Cprogramming help,Ottawaassignment help,CEG3136assignment help,Computer Architecture IIassignment help,Complex State machineassignment help,Cassignment help,Ottawasolution,CEG3136solution,Computer Architecture IIsolution,Complex State machinesolution,Csolution,