0
\$\begingroup\$

I'm doing a filtering project and I'm writing a module that feeds a lot of data to some compute units. There's a lot of really repetitive code and I was wondering if there was any way to condense it, like a task or a function.

I looked into it though and it seems that tasks are non-synthesizable but allow for timing constraints. Usually used in simulation and testbenches. Functions are synthesizable but do not allow timing constraints.

case(row_count) 
        
            0: begin //row_count = 0 means in between frames
                pixel_address <= 0;
                pixel_value <= 0;
                pixel_valid <= 0;
                minion0_select <= 0;
                minion1_select <= 0;
                minion2_select <= 0;
                byte_count <= 0;
                target_row <= 0;
            end
            
            1: begin //greyscale_valid has gone high for the first time in the frame
                minion0_select <= 1; //select minion 1
                minion0_target <= 0; //set minion0 to compute row 0
                case(greyscale_valid)
                    0: begin
                        pixel_address <= 0;
                        pixel_value <= 0;
                        pixel_valid <= 0;
                    end
                    1: begin //send the data until greyscale_valid is deasserted
                        case(fsm_state) 
                            s0_default: begin
                                pixel_address <= byte_count * 8;
                                pixel_value <= greyscale_value;
                                pixel_valid <= 1;
                                fsm_state <= s1_timer;
                                count <= 7;
                            end
                            s1_timer: begin
                                count <= (count == 0) ? 0:(count-1);
                                fsm_state <= (count == 0) ? s0_default:s1_timer;
                                byte_count <= (count == 0) ? (byte_count + 1):byte_count;
                            end
                        endcase
                    end
                endcase
            end
            
            2: begin //greyscale_valid has gone high for the second time in the frame
                minion1_select <= 1; //minion0 is already selected, select minion1 as well
                minion1_target <= 1; //set minion1 to compute row 1
                case(greyscale_valid)
                    0: begin
                        pixel_address <= 0;
                        pixel_value <= 0;
                        pixel_valid <= 0;
                    end
                    1: begin //send the data until greyscale_valid is deasserted
                        case(fsm_state) 
                            s0_default: begin
                                pixel_address <= byte_count * 8;
                                pixel_value <= greyscale_value;
                                pixel_valid <= 1;
                                fsm_state <= s1_timer;
                                count <= 7;
                            end
                            s1_timer: begin
                                count <= (count == 0) ? 0:(count-1);
                                fsm_state <= (count == 0) ? s0_default:s1_timer;
                                byte_count <= (count == 0) ? (byte_count + 1):byte_count;
                            end
                        endcase
                    end
                endcase
            end
            
            3: begin //greyscale_valid has gone high for the third time in the frame
                minion2_select <= 1; //select minion2, all minions currently receiving data
                case(greyscale_valid)
                    0: begin
                        pixel_address <= 0;
                        pixel_value <= 0;
                        pixel_valid <= 0;
                    end
                    1: begin //send the data until greyscale_valid is deasserted
                        case(fsm_state) 
                            s0_default: begin
                                pixel_address <= byte_count * 8;
                                pixel_value <= greyscale_value;
                                pixel_valid <= 1;
                                fsm_state <= s1_timer;
                                count <= 7;
                            end
                            s1_timer: begin
                                count <= (count == 0) ? 0:(count-1);
                                fsm_state <= (count == 0) ? s0_default:s1_timer;
                                byte_count <= (count == 0) ? (byte_count + 1):byte_count;
                            end
                        endcase
                    end
                endcase
            end
        
            
        endcase
endcase

It's pretty much just that case statement case(greyscale_valid). Any help would be appreciated!

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I would move the case grayscale_valid completely outside (and after) the case row_count.

Wrap the case grayscale_valid in if (row_count > 0) so it only gets executed when row_count is not zero.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.