aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs
blob: 1727a2c6e7bdcd6f4e76ed7da97d072e6e8b0f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Transport.Web;

namespace Tango.MachineStudio.Common.Web
{
    public class LoginRequest : WebRequestMessage
    {
        public String Version { get; set; }
        public String Email { get; set; }
        public String Password { get; set; }
        public LoginMethod Method { get; set; }
    }
}
#include "include.h"
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>

#include "driverlib/epi.h"
#include "inc/hw_memmap.h"
#include <driverlib/gpio.h>

#include "FPGA_COMM.h"
#include "driverlib/sysctl.h" //for SysCtlDelay
#include <driverlib/sysctl.h>
#include <DataDef.h>


unsigned short GPO_01_Reg;

int FPGA_Test()
{
    GP_Out_01 Gpo_01;

    Gpo_01.bits.F3_GPO_LED4 = 1;
    Gpo_01.bits.F3_GPO_LED3 = 1;
    Gpo_01.bits.F3_GPO_LED2 = 0;
    Gpo_01.bits.F3_GPO_LED1 = 1;
    Gpo_01.bits.F3_GPO_EXTWINDER_SSR11_CTRL = 1;
    Gpo_01.bits.F3_GPO_BUZZER = 0;
    Gpo_01.bits.F3_SPARE2_ROTENC_CLK = 1;
    Gpo_01.bits.F3_SPARE1_ROTENC_CLK = 1;
    Gpo_01.bits.RESERVE = 0xF5;

    GPO_01_Reg = Gpo_01.ushort;

    return 0;
}

int FPGA_Test_ReadBack(unsigned char FPGA_NUM, unsigned short Value, unsigned short *ReadBackValue)// = 0x1234)
{

    //TODO to update the deley
    unsigned short readValue = 0;
     if(FPGA_NUM == 1)
     {
         F1_Test = Value;
         SysCtlDelay(1000);
         readValue = F1_Test;
         *ReadBackValue = readValue;
         if(Value == (uint16_t) ~((unsigned int) readValue))
             return PASSED;
         if((Value == 0xFFFF) && (readValue == 0))
             return PASSED;
     }

     if(FPGA_NUM == 2)
     {
         F2_Test = Value;
         SysCtlDelay(100);
         readValue = F2_Test;
         *ReadBackValue = readValue;
         if(Value == (uint16_t) ~((unsigned int) readValue))
             return PASSED;
         if((Value == 0xFFFF) && (readValue == 0))
             return PASSED;
     }

     if(FPGA_NUM == 3)
     {
         F3_Test = Value;
         SysCtlDelay(100);
         readValue = F3_Test;
         *ReadBackValue = readValue;
         if(Value == (uint16_t) ~((unsigned int) readValue))
             return PASSED;
         if((Value == 0xFFFF) && (readValue == 0))
             return PASSED;
     }

    return FAILED;
}


int  FPGA_ReadVersion(unsigned char FPGA_NUM, unsigned char *Version, unsigned char *Year, unsigned char *Month, unsigned char *Day)
{
    VER1 Ver1;
    VER2 Ver2;
#ifndef EVALUATION_BOARD

    switch(FPGA_NUM)
    {
        case 1:
                Ver1.ushort = F1_Ver1_D;
                Ver2.ushort = F1_Ver2_D;
            break;
        case 2:
                Ver1.ushort = F2_Ver1_D;
                Ver2.ushort = F2_Ver2_D;
            break;
        case 3:
                Ver1.ushort = F3_Ver1_D;
                Ver2.ushort = F3_Ver2_D;
            break;
        default:
            break;
    }

 /*   if( (Ver1.bytes.Month > 12) || (Ver1.bytes.Day > 31) || (Ver2.bytes.Year < 17) )
    {
        return FAILED;
    }
*/

    *Month = Ver1.bytes.Month;
    *Day = Ver1.bytes.Day;
    *Year = Ver2.bytes.Year;  // to check how many digits is needed
    *Version = Ver2.bytes.Ver_num;
#endif
    return PASSED;
}

void FPGA_Init()
{

#ifndef EVALUATION_BOARD
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_6); // start FPGA (clear HW RESET)
    ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_6, GPIO_PIN_6);
    // Enable EPI
    SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0);
    while (!(SysCtlPeripheralReady(SYSCTL_PERIPH_EPI0)));

    //PreScale + PWM
    //60MHz / PreScaler / (PWM High + PWM Low)
    //for SPI Motor driver the maximum is 5MHz the default is the FPGA is 4 (60/2/(2+3)) = 4

    //EPI Host-Bus 8 Configuration 3 (EPIHB8CFG3)
    //    Value Description
    //    0x0 Active WRn is 2 EPI clocks
    //    0x1 Active WRn is 4 EPI clocks <--
    //    0x2 Active WRn is 6 EPI clocks
    //    0x3 Active WRn is 8 EPI clocks

//    EPIModeSet(EPI0_BASE, EPI_MODE_HB16);
//    EPIConfigHB16Set(EPI0_BASE, EPI_HB16_MODE_ADMUX | EPI_HB16_WRWAIT_1 | EPI_HB16_RDWAIT_1 | EPI_HB16_ALE_LOW | EPI_HB16_WORD_ACCESS, 0);
//    EPIConfigHB16Set(EPI0_BASE, EPI_HB16_WRWAIT_1 | EPI_HB16_RDWAIT_1, 0);

    EPIModeSet(EPI0_BASE, EPI_MODE_GENERAL);
    //uint32_t temp = *(uint32_t)(EPI0_BASE+0x10);

//    volatile uint32_t *temp;
//    temp = (volatile uint32_t *) (EPI0_BASE+0x10);

    // Set EPI Mode
    EPIConfigGPModeSet(EPI0_BASE, EPI_GPMODE_CLKPIN |EPI_GPMODE_FRAME50 | EPI_GPMODE_ASIZE_12 | EPI_GPMODE_DSIZE_16, 4, 0);
    //Set EPI CLK
    EPIDividerSet(EPI0_BASE, 10);//60MHz

    EPIAddressMapSet(EPI0_BASE, EPI_ADDR_RAM_BASE_6  | EPI_ADDR_RAM_SIZE_64KB);

//    *temp |= 0x50;


    //FPGA_WRITE();
#endif

}


//---------------------------------- Limit_Switches ------------------------------------------------

//Limit_Switch1_REG   Limit_Switch1;
//Limit_Switch2_REG   Limit_Switch2;
//Limit_Switch3_REG   Limit_Switch3;
//
//void FPGA_Read_limit_Switches()
//{
//    Limit_Switch1.ushort = F1_GPI_LS1_D;
//    Limit_Switch2.ushort = F1_GPI_LS2_D;
//    Limit_Switch3.ushort = F1_GPI_LS3_D;
//}

uint32_t Calculate_Tacho_Fan_Speed(uint32_t OSC_IN, uint8_t PPR, uint16_t Prescaler, uint16_t Tacho_reg) //Oscilator IN , Pulse/Round
{
    uint32_t   temp, Fan_Speed_RPM;

    temp = 60 / PPR;//60 Sec
    temp = temp   * OSC_IN;
    temp = temp / Tacho_reg;
    Fan_Speed_RPM = (temp /  Prescaler);
    return Fan_Speed_RPM;

}


uint32_t Read_Fans_Tacho()
{
    uint32_t Status = 0;
    uint32_t Drawer_Fan_Speed_RPM = 0;
#ifndef EVALUATION_BOARD

    // The big Fan in the drawer
    Drawer_Fan_Speed_RPM = Calculate_Tacho_Fan_Speed(25000000, 0X02, F1_Prescaler1_reg5, F1_Tacho_reg0);

    if( Drawer_Fan_Speed_RPM < 1000 )  // need to work around 3000 RPM
        Status|= 0x01;// not working / Low Speed
    else
        Status&= ~0x01;//working (Speed ~0x400)

    // The 4 small Fans in the drawer
    // F1_gpi_FANS
    // �0� Fan not working
    // �1� Fan working
    if (F1_gpi_FANS == 0x0F )
    {
        Status&= ~(0x0F<<1);//working
    }
    else
    {
        bool F1_FAN1_TACH =  F1_gpi_FANS & 0x01;
        bool F1_FAN2_TACH = (F1_gpi_FANS & 0x02)>>0x01;
        bool F1_FAN3_TACH = (F1_gpi_FANS & 0x04)>>0x02;
        bool F1_FAN4_TACH = (F1_gpi_FANS & 0x08)>>0x03;

        if( F1_FAN1_TACH == 0) // Small Fan in the drawer
            Status|=  (0x01<<1);// not working
        else
            Status&= ~(0x01<<1);//working

        if( F1_FAN2_TACH == 0) // Small Fan in the drawer
            Status|=  (0x01<<2);// not working
        else
            Status&= ~(0x01<<2);//working

        if( F1_FAN3_TACH == 0) // Small Fan in the drawer
            Status|=  (0x01<<3);// not working
        else
            Status&= ~(0x01<<3);//working

        if( F1_FAN4_TACH == 0) // Small Fan in the drawer
            Status|=  (0x01<<4);// not working
        else
            Status&= ~(0x01<<4);//working
    }
#endif
    return Status;
}

//------------------------- WHS ----------------------
uint32_t WHS_Read_Blower_Tach()
{
    //TODO: check if we need to change the Prescaler
    //F2_Prescaler1_reg10  - prescaled clocks for counter of signal Blower Tacho. 8 bits


    /*
    RPM=60* (Sys_clk/PreScalar)/ F2_Tacho_reg0

    Where :

    Sys_clk                                =25*10^6 (25Mhz)
    PresScalar(default)           =250

    Mati
     */
    uint32_t RPM;
    uint32_t Temp = 6000000; // 60* (Sys_clk/PreScalar)
    RPM = Temp / GPI_BLOWER_TACH;

    return RPM;
}

//------------------------- Dryer Blower ----------------------

uint32_t Dryer_Read_Blower_Tach()
{
    uint32_t RPM;
    //TBD
    RPM =  WHS_Read_Blower_Tach(); // Temporary using WHS Tacho
    return RPM;
}


void Dryer_Control_Blower_PWM(uint8_t PWN_Command_Precent)// 0 - 100%
{
    // change to cycle to 100 in order to work with %, with constant FREQ

    uint8_t Freq = 0xFF;//divider Clock = 25M/divider

    if(PWN_Command_Precent > 100)
        PWN_Command_Precent = 100;

    GPO_BLOWER_PWM_FREQ = Freq;
    GPO_BLOWER_PWM_LOW  = PWN_Command_Precent + 1;
    GPO_BLOWER_PWM_HIGH = 101 - PWN_Command_Precent;

    // low + high = 0xFF in order use the same freq (and change the freq only by Add 0x112).
    // there is option to change only the high (low + freq constasnt) this will chnga the freq
}