Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mdr32f8_port.h>
- #include <mdr32f8_clkctrl.h>
- #include <mdr32f8_can.h>
- #include "spec.h"
- #include "Setup_func.h"
- #include "blinky.h"
- #include "Can_Receive.h"
- #include "mdr32f8_tim.h"
- //#pragma import(__use_no_heap_region)
- /**
- ******************************************************************************
- * @file main.c
- * @author Applied IR spectroscopy laboratory
- * @version V1.0.0
- * @date 30/10/2018
- * @brief This is demonstration of CAN packets transmittion
- ******************************************************************************
- * <br><br>
- *
- *
- * <h2><center>© COPYRIGHT 2018 MIPT</center></h2>
- */
- PORT_InitTypeDef PORT_InitStructure;
- CAN_InitTypeDef CAN_InitStructure;
- CAN_TxMsgTypeDef TxMsg;
- CAN_RxMsgTypeDef RxMsg;
- CAN_DataTypeDef RecBuf;
- void INT_TMR0_Handler(void);
- void Decode_Message(void);
- void Erase_Packets(void);
- void Initialise(void);
- void Line_Aquisition(void);
- void Temp_Stab(void);
- void Line_Stab(float, float);
- float Line_Center_Search(void);
- void Re_Decode_Message(void);
- void Set_Timer(int);
- int Status_Check(void);
- void Set_PI_Temp(int);
- void Set_PI_Line(int);
- volatile uint32_t Debug_message_1, Debug_message_2;
- volatile uint32_t DEBG;
- volatile uint32_t Write_incr, Enable_to_Write=0;
- volatile uint16_t Data_Samples[1024];
- volatile uint8_t CAN_DLC,CAN_IDE,CAN_PRIOR_0;
- volatile uint32_t CAN_ID ; // for CAN
- volatile uint16_t ISS[32]; //сообщение от ИСС
- volatile uint16_t MAI_0[10][1024]; // сообщение от МАИ
- volatile uint32_t Receiving_A2 = 0, Temp_Mes[2];
- /*Переменные для работы с сообщением от ИСС*/
- volatile uint32_t Device_Identifier, EP_MAI_Mode, Scan_Mode, Delta_Current, Control_Byte;
- volatile uint64_t LM1_Parameters, LM2_Parameters;
- volatile uint8_t Search, UKS_Enable, SRAM_On, PhD_Gain, N, Delt_I1, Delt_I2, MD1, MD2,\
- AC_Laser_Current_LM1,DC_Laser_Current_LM1, DC_Laser_Current_LM2, AC_Laser_Current_LM2, Start;
- volatile uint16_t Temperature_1_LM1, Temperature_2_LM1, Temperature_1_LM2, Temperature_2_LM2;
- volatile uint8_t Enable_Heater, Enable_Line_Stab, Current_Work_State;
- volatile uint8_t A2_increment = 0;
- /*Переменные для отправки к ИСС*/
- volatile uint16_t Tref, TC_dT, Tbase, Planned_Temperature;
- volatile uint8_t LM_module_number, LM_module_number_mode, TEC_Error, TP;
- volatile uint16_t Tdet, Tdet_B;
- volatile uint8_t Start_EP_MAI, PreAmps, Initial_DC_Laser_Current, Initial_AC_Laser_Current;
- volatile uint8_t Step_Counter, Cycle_Counter;
- volatile uint16_t TU_Tb, TU_Tt, TU_Tc, TC_DAC;
- volatile uint8_t Command_Error, Ack_0, Data_end, Saturation, Hardware_Error, LM_Error, UKS_Error;
- volatile uint8_t N_converted, N_converted_current;
- volatile uint8_t Sending_process = 0, Experiment_Status = 0, TIMER_Counter = 0, Experiment_Init = 0;
- volatile uint32_t Number_of_packets_send = 0;
- volatile uint8_t Experiment_Re_Init = 0, Enable_Experiment = 0, Timer_Handler_Occured = 0, Enable_Temp_Stab = 0;
- volatile uint8_t Enable_Line_Stab = 0, Enable_Data_Aquisition = 0, Enable_Data_Averaging = 0;
- volatile uint8_t Cyclogram_Laser[4], Cyclogram_Temp[4];
- volatile float Line_Center = 0;
- volatile uint32_t Cyclogram_Counter=0, Timer_Counter = 0, Data_Packets_Counter = 0, Single_Frame_Counter = 1, Line_Center_required = 0;
- int main(void)
- {
- //POR_disable(); //POR - power on reset
- Cache_Setup();
- Clock_Setup_8();
- Can_Port_Setup();
- Can_Init_80();
- Can_Setup();
- Timer_Setup();
- IRQ_Init();
- Erase_Packets();
- Initialise();
- int i, j;
- while (1){
- if(Experiment_Init == 1){
- Experiment_Init = 0;
- Cyclogram_Counter = 0;
- Erase_Packets();
- Initialise();
- Decode_Message();
- while(Cyclogram_Counter < 4){
- if (Status_Check() == 1){
- break;
- }
- Erase_Packets();
- Initialise();
- Set_Timer(Cyclogram_Counter);
- Set_PI_Temp(Cyclogram_Counter);
- Set_PI_Line(Cyclogram_Counter);
- Enable_Experiment = 1;
- while(Enable_Experiment == 1){
- if (Status_Check() == 1){
- break;
- }
- Line_Aquisition();
- Line_Center = Line_Center_Search();
- if(Enable_Temp_Stab == 1){
- Temp_Stab();
- }
- else if(Enable_Line_Stab == 1){
- Line_Stab(Line_Center, Line_Center_required);
- }
- if((Enable_Data_Aquisition == 1)&&(Single_Frame_Counter < 512)){ // Data accumulation
- Single_Frame_Counter++;
- for(j = 0; j < 1024; j++){
- Data_Samples[j] += j;
- }
- }
- }
- }
- }
- }
- }
- void INT_TMR0_Handler(){
- Timer_Handler_Occured = 1;
- Timer_Counter += 1;
- if(Timer_Counter < 3){
- Enable_Temp_Stab = 1;
- Enable_Line_Stab = 0;
- Enable_Data_Aquisition = 0;
- }
- else if(Timer_Counter == 3){
- Enable_Temp_Stab = 0;
- Enable_Line_Stab = 1;
- Enable_Data_Aquisition = 0;
- }
- else if(Timer_Counter == 6){
- Enable_Temp_Stab = 0;
- Enable_Line_Stab = 1;
- Enable_Data_Aquisition = 1;
- Single_Frame_Counter = 1;
- Data_Packets_Counter = 0;
- }
- else if((Timer_Counter > 6) && (Timer_Counter < 16)){
- if(Data_Packets_Counter < 9){
- int i;
- for(i = 0; i < 1024; i++){
- MAI_0[Data_Packets_Counter][i] = Data_Samples[i]/Single_Frame_Counter;
- Data_Samples[i] = 0;
- }
- Single_Frame_Counter = 1;
- Data_Packets_Counter++;
- }
- }
- else if(Timer_Counter >= 16){
- Enable_Temp_Stab = 1;
- Enable_Line_Stab = 0;
- Enable_Data_Aquisition = 0;
- Data_Packets_Counter = 0;
- //Enable_Experiment = 0;
- MDR_TMR0->CNTRL = 0;
- if(Cyclogram_Counter >= 4){
- }
- }
- MDR_TMR0->CNT = 0x00000000;
- TIMER_ClearFlag(MDR_TMR0, TIMER_STATUS_CNT_ARR);
- }
- void Erase_Packets(){
- int i, j;
- for(i = 0; i < 1024; i++){
- Data_Samples[i] = 0;
- }
- for(j = 0; j < 10; j++){
- for(i = 0; i < 1024; i++){
- MAI_0[j][i] = 0;
- }
- }
- }
- void Decode_Message(){
- int i,j;
- for(j = 0; j < 10; j++){
- for(i = 0; i < 32; i++){
- MAI_0[j][i] = ISS[i];
- }
- MAI_0[j][1023] = j;
- }
- for(i = 0; i < 4; i++){
- Cyclogram_Laser[i] = 0;
- Cyclogram_Temp[i] = 0;
- }
- /*fill up cyclogram*/
- for(i = 0; i < 4; i++){
- Cyclogram_Laser[i] = 1;
- Cyclogram_Temp[i] = 1;
- }
- /*decide from UKS bits*/
- Line_Center_required = 850;
- }
- void Set_Timer(int i){
- MDR_TMR0->CNTRL = 1; // enable timer
- }
- void Initialise(){
- Experiment_Re_Init = 0;
- Experiment_Init = 0;
- Number_of_packets_send = 0;
- Timer_Counter = 0;
- Data_Packets_Counter = 0;
- Single_Frame_Counter = 1;
- Enable_Experiment = 0;
- Enable_Temp_Stab = 0;
- Enable_Line_Stab = 0;
- Enable_Data_Aquisition = 0;
- Enable_Data_Averaging = 0;
- Enable_to_Write = 0;
- }
- int Status_Check(){
- if(Experiment_Init == 1){
- return 1;
- }
- else if(Experiment_Re_Init == 1){
- Experiment_Re_Init = 0;
- if(Cyclogram_Counter < 4){
- Cyclogram_Counter++;
- }
- return 1;
- }
- else{
- return 0;
- }
- }
- void Line_Aquisition(){
- }
- void Temp_Stab(){
- }
- void Line_Stab(float Line_Center, float Line_Center_required){
- }
- void Set_PI_Temp(int i){
- }
- void Set_PI_Line(int i){
- }
- float Line_Center_Search(){
- return 0;
- }
- void HardFault_Handler(){
- Enable_to_Write = 0;
- }
- void MemoryMngFault_Handler(){
- }
- void BusFault_Handler(){
- }
- void UsageFault_Handler(){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement