cal_stack

#include <stdio.h>
#define MAX 100
struct operand
{
    int data[MAX];
    int top;
};
struct operator_ch
{
    int top;
    char data[MAX];
};

typedef struct operand OPND;
typedef struct operator_ch OPCH;
void init_OPND_stack(OPND *stack)
{
    stack->top = -1;
}
void init_OPCH_stack(OPCH *stack)
{
    stack->top = -1;
}
void is_empty_OPND(OPND *stack)
{
    if(stack->top == -1)
    {
        return -1;
    }
    return 0;
}
void is_empty_OPCH(OPCH *stack)
{
    if(stack->top == -1)
    {
        return -1;
    }
    return 0;
}
int get_OPND_top(OPND *stack)
{
    if(is_empty_OPND(stack) == -1)
    {
        return -1;
    }
    return stack->data[stack->top];
}
int get_OPCH_top(OPCH *stack)
{
    if(is_empty_OPCH(stack) == -1)
    {
        return -1;
    }
    return stack->data[stack->top];
}
int push_OPND(OPND *stack, int num)
{
    stack->data[++(stack->top)] = num;
}
int push_OPCH(OPND *stack, char ch)
{
    stack->data[++(stack->top)] = ch;
}
int pop_OPND(OPND *stack)
{
    if(is_empty_OPND(stack) == -1)
    {
        return -1;
    }
   
    int num = stack->data[stack->top];
    (stack->top)--;
    return num;
}
char pop_OPCH(OPCH *stack)
{
    if(is_empty_OPCH(stack) == -1)
    {
        return -1;
    }
   
    char ch = stack->data[stack->top];
    (stack->top)--;
    return ch;
}
int get_priority(char ch)
{
    if(ch == '+' || ch == '-')
    {
        return 1;
    }
    if(ch == '*' || ch == '/')
    {
        return 2;
    }
}
int compare_priority(char op_ch, char ch)
{
    if(get_priority(op_ch) > get_priority(ch))
    {
        return 1;
    }
    return -1;
}
int count(int num1, int num2, char ch)
{
    int result;
    switch(ch)
    {
        case '+':
        {
            result = a + b;
            break;
        }
        case '-':
        {
            result = a - b;
            break;
        }
       
        case '*':
        {
            result = a * b;
            break;
        }
       
        case '-':
        {
            result = a / b;
            break;
        }
    }
    return result;
}
int main()
{
    char ch;
    char op_ch;
    while((ch = getchar()) != '\n')
    {
        if(ch >= '0' && ch <= '9')
        {
            push_stack1();
        }
        if(ch == '+' || ch == '-' || ch == '*' || ch == '/')
        {
            op_ch = pop_stack2();
            if(compare(op_ch,ch) > 0)
            {
                push_stack2(ch);
            }
            else
            {
                count(a,b,op_ch);
            }
        }
    }
    return 0;
}
/* lcf file for MPC5634M processor */ /* */ /* 1.5 MB Flash, 94KB SRAM */ MEMORY { resetvector: org = 0x00000000, len = 0x00000008 APP_ENTRY: org = 0x00010000, len = 0x00000100 init: org = 0x00010100, len = 0x00000F00 exception_handlers: org = 0x00011000, len = 0x00001000 internal_flash: org = 0x00012000, len = 0x0006C800 /*434K*/ crc32_flash: org = 0x0007E800, len = 0x00001800 /*6K*/ ASW_flash_A: org = 0x00080000, len = 0x00060000 /*384K*/ cal_flash_A: org = 0x000E0000, len = 0x00020000 /*128K*/ ASW_flash_B: org = 0x00100000, len = 0x00060000 /*384K*/ cal_flash_B: org = 0x00160000, len = 0x00020000 /*128K*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ cal_ram: org = 0x40000000, len = 0x00008000 /*32K*/ internal_ram: org = 0x40008000, len = 0x0000A800 /*42K*/ crc32_ram: org = 0x40012800, len = 0x00001800 /*6K*/ heap : org = 0x40014000, len = 0x00002000 /*8K*/ stack : org = 0x40016000, len = 0x00001800 /*6K*/ } /* This will ensure the rchw and reset vector are not stripped by the linker */ FORCEACTIVE { "bam_rchw" "bam_resetvector" } SECTIONS { .__bam_bootarea LOAD (0x00000000): {} > resetvector .app_entry (VLECODE) LOAD(0x00010000) : {} > APP_ENTRY GROUP : { .init LOAD (0x10100) : {} .init_vle (VLECODE) LOAD (_e_init) : { *(.init) *(.init_vle) } } > init .__exception_handlers (VLECODE) LOAD (0x00011000) : {} > exception_handlers GROUP : { .text : {} .text_vle (VLECODE) ALIGN(0x08): { *(.text) *(.text_vle) } .rodata (CONST) : { *(.rdata) *(.rodata) } .ctors : {} .dtors : {} extab : {} extabindex : {} } > internal_flash /************将应用层代码和const数据放在ASW_flash************/ GROUP : { .ASW_text (VLECODE) ALIGN(0x08) LOAD (0x00080000): { KEEP(*(.ASW_function)) Sensor.o(.text) EEpromSaveVal.o(.text) CanSend.o(.text) CanReceive.o(.text) BKLrn.o(.text) ClTrqMapLrn.o(.text) TmPosCal.o(.text) EngMotCtrl.o(.text) ClCtrl.o(.text) SlopeEst_Single.o(.text) VehCtl.o(.text) SftMotPidCtrl.o(.text) ClMotPidCtrl.o(.text) TrgtGearSub.o(.text) SftCtrl.o(.text) SftCtrl_TrgtCurrSub.o(.text) TempEst.o(.text) AveCalculate_DBzCpi0h.o(.text) BINARYSEARCH_real32_T.o(.text) InValStdJdgSub_EJoZRQLM.o(.text) InValStdJdgSub_INONT01g.o(.text) look1_iflf_binlcapw.o(.text) look1_iflf_binlxpw.o(.text) look2_iflf_binlcapw.o(.text) look2_iflf_binlcpw.o(.text) look2_iflf_binlxpw.o(.text) LookUp_real32_T_real32_T.o(.text) Myfun_TimeChr2eWq0hbv.o(.text) rt_nonfinite.o(.text) rtGetInf.o(.text) rtGetNaN.o(.text) } .ASW_data (CONST) : { Sensor_data.o(.rodata) const_params.o(.rodata) ClCtrl.o(.rodata) VehCtl_data.o(.rodata) TempEst_data.o(.rodata) } } > ASW_flash_A GROUP : { .__uninitialized_intc_handlertable ALIGN(2048) : {} .data : {} .sdata : {} .sbss : {} .sdata2 : {} .sbss2 : {} .bss : {} } > internal_ram .crc32_section LOAD (0x0007E800): { KEEP(*(.crc32_section)) } > crc32_ram /************param_cal************/ .cal_section LOAD (0x000E0000) : { KEEP(*(.cal_section)) } > cal_ram } /* Freescale CodeWarrior compiler address designations */ _stack_addr = ADDR(stack)+SIZEOF(stack); _stack_end = ADDR(stack); _heap_addr = ADDR(heap); _heap_end = ADDR(heap)+SIZEOF(heap); /* Exceptions Handlers Location (used in Exceptions.c IVPR initialization)*/ EXCEPTION_HANDLERS = ADDR(exception_handlers); /* L2 SRAM Location (used for L2 SRAM initialization) */ L2SRAM_LOCATION = 0x40000000; ~~~~~~~~~~~ mpc5634链接文件flash分区, 应用层程序对应的flash区域为:ASW_flash_A/ASW_flash_B, 标定量对应的flash区域为:cal_flash_A/cal_flash_B, 都做了两个分区,即一个为激活分区,一个为备用分区,想实现对应的flash区域刷写失败后,可以切换到备用分区,我不太清楚具体怎么实现,在链接文件中,我只能指定代码或者标定参数放在ASW_flash_A,cal_flash_A中,没有办法同时放在两个段,A-B的数据刷写只能在刷写A之前写入到B中,那么在程序运行的时候,我怎么指定是运行A中或者B中的代码或者参数呢?标定参数上电是需要复制到ram中的,这个我可以处理,比较麻烦的是代码是直接在flash中运行的,怎么指定使用哪个区域的代码呢?
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值