data/full_repos/permissive/103649428/VendingMachine.v
1: b'%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:359: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hfd\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                            AN[7:0] <= 9\'b11111101;\n                                    ^~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:407: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                        AN[7:0] <= 9\'b11011111;\n                                                ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:427: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:447: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:467: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:487: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:507: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:532: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'hdf\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                    AN[7:0] <= 9\'b11011111;\n                                            ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:672: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'h7f\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                 AN[7:0] <= 9\'b01111111;\n                                         ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:715: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'h7f\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                 AN[7:0] <= 9\'b01111111;\n                                         ^~\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:734: Operator ASSIGN expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'h7f\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                 AN[7:0] = 9\'b01111111;\n                                         ^\n%Warning-WIDTH: data/full_repos/permissive/103649428/VendingMachine.v:753: Operator ASSIGN expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'9\'h7f\' generates 9 bits.\n                                                                         : ... In instance VendingMachine.show\n                                 AN[7:0] = 9\'b01111111;\n                                         ^\n%Error: Exiting due to 12 warning(s)\n'
module VendingMachine(reset, clk, SEG, AN, item1, item2, coin1, coin2, confirm_flag, buy, 
 is_sale, power_on, op_start, cancel_flag, hold_ind, drinktk_ind, charge_ind, is_sale_xdc);


    input reset, clk;
    input item1, item2, coin1, coin2, buy;
    input is_sale, op_start, cancel_flag, confirm_flag;
    output [7:0]SEG;
    output [7:0]AN;
    output reg is_sale_xdc;
    output reg power_on, hold_ind, charge_ind;
    output drinktk_ind;


    reg [2:0] state;
    reg [4:0] chargeMoney;
    reg [2:0] cnt;
    reg cancel;
    wire ck;
    wire over;
    wire [4:0] money;
    reg hasBuy;
    wire is_charge;

    parameter off        =      0,
               start      =      1,
               toSale     =      2,
               chooseItem =      3,
               pay        =      4,
               charge     =      5;
    initial begin
        cnt = 0;
        power_on = 0;
        hold_ind = 0;
        state = 0;
        chargeMoney = 0;
        is_sale_xdc = 0;
        hasBuy = 0;
        cancel = 0;
    end
    
    Time timing(.state(state), .clk(clk), .hasBuy(hasBuy), .drinktk_ind(drinktk_ind), .over(over));
    Divider #(200_000) divider(.clk(clk), .ck(ck));
    Show show(.ck(ck), .item1(item1), .item2(item2), .state(state), .money(money), .chargeMoney(chargeMoney), .SEG(SEG), .AN(AN));
    Pay paymoney(.state(state), .buy(buy), .coin1(coin1), .coin2(coin2), .money(money));

    always @(posedge clk) begin
        case (state)
            off: begin
                power_on = 0;
                hold_ind = 0;
                is_sale_xdc = 0;
                charge_ind = 0;
                 if(reset)
                     state = start;
                 else 
                     state = off;
            end
            start: begin
                power_on = 1;
                hold_ind = 0;
                is_sale_xdc = 0;
                charge_ind = 0;
                hasBuy = 0;
                cancel = 0;
                if(is_sale)
                    state = toSale;
                else
                    state = start;
                if(!reset)
                    state = off;
            end
            toSale: begin
                power_on = 1;
                hold_ind = 0;
                is_sale_xdc = 1;
                charge_ind = 0;
                if(op_start)
                    state = chooseItem;
                else 
                    state = toSale;
                if(!is_sale)
                    state = start;
                if(!reset)
                    state = off;
            end
            chooseItem: begin
                power_on = 1;
                hold_ind = 1;
                is_sale_xdc = 1;
                charge_ind = 0;
                if(confirm_flag)
                    state = pay;
                else
                    state = chooseItem;
                if(!op_start)
                    state = toSale;
                if(!reset)
                    state = off;
            end
            pay: begin
                power_on <= 1;
                hold_ind <= 1;
                is_sale_xdc <= 1;
                if(cancel_flag) begin
                    cancel <= 1;
                    if(money > 0) begin
                        state <= charge;
                        hasBuy <= 0;
                        charge_ind <= 1;
                    end
                    else if(money == 0)
                        state <= start;
                end
                else begin
                    if(item1) begin
                        if (money >= 3) begin
                            hasBuy <= 1;
                            charge_ind <= 1;
                            state <= charge;
                        end
                        else if(money < 3)
                            state <= pay;
                    end
                    else if(item2)begin
                        if(money >= 5) begin
                            hasBuy <= 1;
                            if(money > 5)
                                charge_ind <= 1;
                            else if(money == 5)
                                charge_ind <= 0;
                            state <= charge;
                        end
                        else if(money < 5)
                            state <= pay;
                    end
                end
            end
            charge: begin
                power_on = 1;
                hold_ind = 1;
                is_sale_xdc = 1;
                if(cancel) begin
                    chargeMoney = 2 * money;
                end
                else begin
                    if(item1) begin
                        chargeMoney = 2 * money - 5;
                    end
                    else if(item2)
                       chargeMoney = 2 * money - 10;              
                end
                if(over)
                    state = start;
                else
                    state = charge;
            end
        endcase
    end
endmodule
module VendingMachine(reset, clk, SEG, AN, item1, item2, coin1, coin2, confirm_flag, buy, 
 is_sale, power_on, op_start, cancel_flag, hold_ind, drinktk_ind, charge_ind, is_sale_xdc);



    input reset, clk;
    input item1, item2, coin1, coin2, buy;
    input is_sale, op_start, cancel_flag, confirm_flag;
    output [7:0]SEG;
    output [7:0]AN;
    output reg is_sale_xdc;
    output reg power_on, hold_ind, charge_ind;
    output drinktk_ind;


    reg [2:0] state;
    reg [4:0] chargeMoney;
    reg [2:0] cnt;
    reg cancel;
    wire ck;
    wire over;
    wire [4:0] money;
    reg hasBuy;
    wire is_charge;

    parameter off        =      0,
               start      =      1,
               toSale     =      2,
               chooseItem =      3,
               pay        =      4,
               charge     =      5;
    initial begin
        cnt = 0;
        power_on = 0;
        hold_ind = 0;
        state = 0;
        chargeMoney = 0;
        is_sale_xdc = 0;
        hasBuy = 0;
        cancel = 0;
    end
    
    Time timing(.state(state), .clk(clk), .hasBuy(hasBuy), .drinktk_ind(drinktk_ind), .over(over));
    Divider #(200_000) divider(.clk(clk), .ck(ck));
    Show show(.ck(ck), .item1(item1), .item2(item2), .state(state), .money(money), .chargeMoney(chargeMoney), .SEG(SEG), .AN(AN));
    Pay paymoney(.state(state), .buy(buy), .coin1(coin1), .coin2(coin2), .money(money));

    always @(posedge clk) begin
        case (state)
            off: begin
                power_on = 0;
                hold_ind = 0;
                is_sale_xdc = 0;
                charge_ind = 0;
                 if(reset)
                     state = start;
                 else 
                     state = off;
            end
            start: begin
                power_on = 1;
                hold_ind = 0;
                is_sale_xdc = 0;
                charge_ind = 0;
                hasBuy = 0;
                cancel = 0;
                if(is_sale)
                    state = toSale;
                else
                    state = start;
                if(!reset)
                    state = off;
            end
            toSale: begin
                power_on = 1;
                hold_ind = 0;
                is_sale_xdc = 1;
                charge_ind = 0;
                if(op_start)
                    state = chooseItem;
                else 
                    state = toSale;
                if(!is_sale)
                    state = start;
                if(!reset)
                    state = off;
            end
            chooseItem: begin
                power_on = 1;
                hold_ind = 1;
                is_sale_xdc = 1;
                charge_ind = 0;
                if(confirm_flag)
                    state = pay;
                else
                    state = chooseItem;
                if(!op_start)
                    state = toSale;
                if(!reset)
                    state = off;
            end
            pay: begin
                power_on <= 1;
                hold_ind <= 1;
                is_sale_xdc <= 1;
                if(cancel_flag) begin
                    cancel <= 1;
                    if(money > 0) begin
                        state <= charge;
                        hasBuy <= 0;
                        charge_ind <= 1;
                    end
                    else if(money == 0)
                        state <= start;
                end
                else begin
                    if(item1) begin
                        if (money >= 3) begin
                            hasBuy <= 1;
                            charge_ind <= 1;
                            state <= charge;
                        end
                        else if(money < 3)
                            state <= pay;
                    end
                    else if(item2)begin
                        if(money >= 5) begin
                            hasBuy <= 1;
                            if(money > 5)
                                charge_ind <= 1;
                            else if(money == 5)
                                charge_ind <= 0;
                            state <= charge;
                        end
                        else if(money < 5)
                            state <= pay;
                    end
                end
            end
            charge: begin
                power_on = 1;
                hold_ind = 1;
                is_sale_xdc = 1;
                if(cancel) begin
                    chargeMoney = 2 * money;
                end
                else begin
                    if(item1) begin
                        chargeMoney = 2 * money - 5;
                    end
                    else if(item2)
                       chargeMoney = 2 * money - 10;              
                end
                if(over)
                    state = start;
                else
                    state = charge;
            end
        endcase
    end
endmodule